SetDataType.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div>
  3. <div class="communal-list">
  4. <div class="communal-title">
  5. <div>数据类型资料</div>
  6. <div class="communal-box">
  7. <el-input @input="Inquireclick()" placeholder="请输入数据类型名称" v-model="input" clearable
  8. style="width: 350px;">
  9. </el-input>
  10. <el-button type="primary" style="margin-left: 10px;" @click="AddSetDataType">新增</el-button>
  11. </div>
  12. </div>
  13. <template>
  14. <el-table :data="tableDatas.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border
  15. style="width: 100%" v-loading="loading" element-loading-text="拼命加载中...">
  16. <el-table-column prop="num" label="序 号" width="55">
  17. <template slot-scope="scope">
  18. {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
  19. </template>
  20. </el-table-column>
  21. <el-table-column prop="name" label="类型名称">
  22. </el-table-column>
  23. <el-table-column prop="isEnable" label="是否启用">
  24. <template slot-scope="isEnable">
  25. <span v-if="isEnable.row.isEnable == 1">是</span>
  26. <span v-else>否</span>
  27. </template>
  28. </el-table-column>
  29. <el-table-column prop="cnName" label="添加人">
  30. </el-table-column>
  31. <el-table-column prop="createTime" label="添加时间">
  32. </el-table-column>
  33. <el-table-column label="操作">
  34. <template slot-scope="scope">
  35. <el-button size="mini" @click="upDate(scope.$index, scope.row)">编辑</el-button>
  36. <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. </template>
  41. <div class="block">
  42. <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
  43. :current-page="currentPage" :page-sizes="[10, 12, 15, 20]" :page-size="pageSize"
  44. layout="total, sizes, prev, pager, next" :total="tableDatas.length">
  45. </el-pagination>
  46. </div>
  47. </div>
  48. <el-dialog :title="typeName" :visible.sync="AddSetDataTypeVisible" width="30%" :before-close="handleClose">
  49. <div>
  50. <el-form :model="OperationData" :rules="rules" ref="OperationData" label-width="100px"
  51. class="demo-ruleForm">
  52. <el-form-item label="数据类型" prop="name">
  53. <el-input placeholder="请输入内容" v-model="OperationData.name">
  54. </el-input>
  55. </el-form-item>
  56. <el-form-item label="是否启用" prop="isEnable">
  57. <el-switch v-model="OperationData.isEnable" :active-value=1 :inactive-value=0 active-color="#13ce66"
  58. inactive-color="#ff4949">
  59. </el-switch>
  60. </el-form-item>
  61. <el-form-item label="备 注" prop="remark">
  62. <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="OperationData.remark"></el-input>
  63. </el-form-item>
  64. </el-form>
  65. </div>
  66. <span slot="footer" class="dialog-footer">
  67. <el-button @click="AddSetDataTypeVisible = false">取 消</el-button>
  68. <el-button type="primary" @click="AddBtn">确 定</el-button>
  69. </span>
  70. </el-dialog>
  71. </div>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. loading: false,
  78. tableDatas: [],
  79. tableData: [],
  80. currentPage: 1, // 当前页码
  81. pageSize: 12,// 每页的数据条数
  82. input: '',
  83. token: '',
  84. userId: 0,
  85. typeName: "添加数据类型",
  86. OperationData: {
  87. status: 1,
  88. id: 0,
  89. name: "",
  90. isEnable: 1,
  91. createUserId: 0,
  92. remark: ""
  93. },
  94. AddSetDataTypeVisible: false,
  95. rules: {
  96. name: [
  97. { required: true, message: '请输数据类型名称', trigger: 'blur' },
  98. ],
  99. },
  100. }
  101. },
  102. methods: {
  103. //每页条数改变时触发 选择一页显示多少行
  104. handleSizeChange(val) {
  105. this.currentPage = 1;
  106. this.pageSize = val;
  107. },
  108. //当前页改变时触发 跳转其他页
  109. handleCurrentChange(val) {
  110. this.currentPage = val;
  111. },
  112. //关闭修改框
  113. handleClose(done) {
  114. done();
  115. },
  116. SetDataType() {
  117. this.loading = true
  118. var url = "/api/System/QuerySetDataType"
  119. var that = this
  120. this.$axios({
  121. method: 'post',
  122. url: url,
  123. headers: {
  124. Authorization: 'Bearer ' + this.token
  125. },
  126. data: {
  127. portType: 1,
  128. pageIndex: 0,
  129. pageSize: 0,
  130. name: "",
  131. cnName: ""
  132. }
  133. }).then(function (res) {
  134. console.log(res)
  135. if (res.data.code == 200) {
  136. that.tableData = res.data.data;
  137. that.tableDatas = that.tableData;
  138. if (that.tableDatas.slice((that.currentPage - 1) * that.pageSize, that.currentPage * that.pageSize).length == 0) {
  139. if (that.currentPage > 1) {
  140. that.currentPage = that.currentPage - 1;
  141. }
  142. }
  143. }
  144. that.loading = false
  145. }).catch(function (error) {
  146. that.loading = false
  147. that.$message.error("网络错误,请稍后重试");
  148. });
  149. },
  150. //搜索框处理
  151. Inquireclick() {
  152. var newarr = [];
  153. if (this.input == "") {
  154. newarr = this.tableData;
  155. } else {
  156. for (var i = 0; i < this.tableData.length; i++) {
  157. if (this.tableData[i].name.indexOf(this.input) != -1) {
  158. newarr.push(this.tableData[i]);
  159. }
  160. }
  161. }
  162. this.tableDatas = newarr;
  163. this.currentPage = 1;
  164. },
  165. //点击修改
  166. upDate(index, row) {
  167. this.AddSetDataTypeVisible = true;
  168. this.typeName = "修改数据类型"
  169. this.OperationData.status = 2;
  170. this.OperationData.id = row.id;
  171. this.OperationData.name = row.name;
  172. this.OperationData.isEnable = row.isEnable;
  173. this.OperationData.createUserId = row.createUserId;
  174. this.OperationData.remark = row.remark;
  175. },
  176. //点击添加
  177. AddSetDataType() {
  178. this.OperationData = {
  179. status: 1,
  180. id: 0,
  181. name: "",
  182. isEnable: 1,
  183. createUserId: 0,
  184. remark: ""
  185. },
  186. this.AddSetDataTypeVisible = true;
  187. this.typeName = "添加数据类型"
  188. },
  189. AddBtn() {
  190. this.$refs.OperationData.validate((valid) => {
  191. if (valid) {
  192. var that = this
  193. that.OperationData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  194. var url = "/api/System/OperationSetDataType"
  195. that.$axios({
  196. method: 'post',
  197. url: url,
  198. headers: {
  199. Authorization: 'Bearer ' + that.token
  200. },
  201. data: that.OperationData
  202. }).then(function (res) {
  203. if (res.data.code == 200) {
  204. that.$message({
  205. message: res.data.msg,
  206. type: 'success'
  207. });
  208. that.loading = true;
  209. that.AddSetDataTypeVisible = false;
  210. that.SetDataType()
  211. } else {
  212. that.$message.error(res.data.msg);
  213. }
  214. })
  215. } else {
  216. this.$message.error('请完善信息在保存!');
  217. return false;
  218. }
  219. })
  220. },
  221. //点击删除
  222. del(index, row) {
  223. var url = "/api/System/DelSetDataType"
  224. var that = this
  225. this.$axios({
  226. method: 'post',
  227. url: url,
  228. headers: {
  229. Authorization: 'Bearer ' + this.token
  230. },
  231. data: {
  232. Id: row.id,
  233. DeleteUserId: this.userId
  234. }
  235. }).then(function (res) {
  236. console.log(res)
  237. if (res.data.code == 200) {
  238. that.$message({
  239. message: '删除成功',
  240. type: 'success'
  241. });
  242. that.SetDataType();
  243. } else {
  244. that.$message.error('删除失败!');
  245. }
  246. that.loading = false
  247. }).catch(function (error) {
  248. that.loading = false
  249. that.$message.error("网络错误,请稍后重试");
  250. });
  251. }
  252. },
  253. mounted() {
  254. this.token = JSON.parse(localStorage.getItem('userinif')).token;
  255. this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  256. this.SetDataType();
  257. }
  258. }
  259. </script>
  260. <style>
  261. .communal-list {
  262. background-color: #fff;
  263. padding: 10px;
  264. box-shadow: 0 0 5px #0005;
  265. border-radius: 10px;
  266. }
  267. .communal-title {
  268. display: flex;
  269. font-size: 17px;
  270. font-weight: 600;
  271. color: #555;
  272. margin-top: 8px;
  273. margin-bottom: 10px;
  274. justify-content: space-between;
  275. align-items: center;
  276. }
  277. .communal-box {
  278. display: flex;
  279. }
  280. .communal-box>button {
  281. margin-left: 10px;
  282. padding: 8px 20px;
  283. }
  284. </style>