dict-data.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div>
  3. <!-- 数据表格 -->
  4. <ele-pro-table
  5. ref="table"
  6. :columns="columns"
  7. :datasource="datasource"
  8. :need-page="true"
  9. :toolkit="[]"
  10. :selection.sync="selection"
  11. height="calc(100vh - 350px)"
  12. full-height="calc(100vh - 116px)"
  13. tool-class="ele-toolbar-form"
  14. cache-key="systemDictDataTable"
  15. >
  16. <!-- 表头工具栏 -->
  17. <template v-slot:toolbar>
  18. <el-button
  19. size="small"
  20. type="primary"
  21. icon="el-icon-plus"
  22. class="ele-btn-icon"
  23. @click="openEdit()"
  24. >
  25. 添加
  26. </el-button>
  27. </template>
  28. <!-- 操作列 -->
  29. <template v-slot:appType="{ row }">
  30. {{ types[row.appType] }}
  31. </template>
  32. <template v-slot:action="{ row }">
  33. <el-link
  34. type="primary"
  35. :underline="false"
  36. icon="el-icon-edit"
  37. @click="openEdit(row)"
  38. >
  39. 修改
  40. </el-link>
  41. <el-popconfirm
  42. class="ele-action"
  43. title="确定要删除此字典项吗?"
  44. @confirm="remove(row)"
  45. >
  46. <template v-slot:reference>
  47. <el-link type="danger" :underline="false" icon="el-icon-delete">
  48. 删除
  49. </el-link>
  50. </template>
  51. </el-popconfirm>
  52. </template>
  53. </ele-pro-table>
  54. <!-- 编辑弹窗 -->
  55. <dict-edit :visible.sync="showEdit" :id="id" @done="reload" />
  56. </div>
  57. </template>
  58. <script>
  59. import DictDataSearch from './dict-data-search.vue';
  60. import DictDataEdit from './dict-data-edit.vue';
  61. import {
  62. pageDictionaryData,
  63. removeDictionaryData,
  64. removeDictionaryDataBatch
  65. } from '@/api/system/dictionary-data';
  66. import { listDictionaries, removeDictionary } from '@/api/system/dictionary';
  67. import DictEdit from './dict-edit.vue';
  68. export default {
  69. components: { DictDataSearch, DictDataEdit, DictEdit },
  70. data() {
  71. return {
  72. // 表格列配置
  73. columns: [
  74. {
  75. columnKey: 'index',
  76. type: 'index',
  77. width: 45,
  78. align: 'center',
  79. showOverflowTooltip: true,
  80. label:'序号'
  81. },
  82. {
  83. prop: 'code',
  84. label: '编码',
  85. align: 'center',
  86. showOverflowTooltip: true
  87. },
  88. {
  89. prop: 'name',
  90. label: '名称',
  91. align: 'center',
  92. showOverflowTooltip: true
  93. },
  94. {
  95. prop: 'group',
  96. label: '物料组',
  97. showOverflowTooltip: true,
  98. minWidth: 110
  99. },
  100. {
  101. prop: 'brand',
  102. align: 'center',
  103. label: '牌号',
  104. showOverflowTooltip: true,
  105. slot: 'appType'
  106. },
  107. {
  108. prop: 'model',
  109. label: '型号',
  110. align: 'center',
  111. showOverflowTooltip: true
  112. },
  113. {
  114. prop: 'specifications',
  115. label: '规格',
  116. align: 'center',
  117. showOverflowTooltip: true
  118. },
  119. {
  120. prop: 'measurement',
  121. label: '计量单位',
  122. showOverflowTooltip: true,
  123. minWidth: 110
  124. },
  125. {
  126. prop: 'unit',
  127. align: 'center',
  128. label: '包装单位',
  129. showOverflowTooltip: true,
  130. slot: 'appType'
  131. },
  132. {
  133. prop: 'category',
  134. label: '分类',
  135. align: 'center',
  136. showOverflowTooltip: true
  137. },
  138. {
  139. columnKey: 'action',
  140. label: '操作',
  141. width: 130,
  142. align: 'center',
  143. resizable: false,
  144. slot: 'action',
  145. showOverflowTooltip: true
  146. }
  147. ],
  148. types: {
  149. 1: '业务字典',
  150. 2: '数据字典'
  151. },
  152. // 表格选中数据
  153. selection: [],
  154. // 当前编辑数据
  155. current: null,
  156. // 是否显示编辑弹窗
  157. showEdit: false,
  158. id: ''
  159. };
  160. },
  161. methods: {
  162. /* 表格数据源 */
  163. datasource({ page, limit, where, order }) {
  164. return listDictionaries({ pageNum: page, size: limit, ...where });
  165. },
  166. /* 刷新表格 */
  167. reload(where) {
  168. this.$refs.table.reload({ page: 1, where: where });
  169. },
  170. /* 显示编辑 */
  171. openEdit(row) {
  172. if(row){
  173. this.id = row.id;
  174. this.current = row;
  175. }
  176. this.showEdit = true;
  177. },
  178. /* 删除 */
  179. remove(row) {
  180. const loading = this.$loading({ lock: true });
  181. removeDictionary(row.id)
  182. .then((msg) => {
  183. loading.close();
  184. this.$message.success('删除' + msg);
  185. this.reload();
  186. })
  187. .catch((e) => {
  188. loading.close();
  189. // this.$message.error(e.message);
  190. });
  191. },
  192. /* 批量删除 */
  193. removeBatch() {
  194. if (!this.selection.length) {
  195. this.$message.error('请至少选择一条数据');
  196. return;
  197. }
  198. this.$confirm('确定要删除选中的字典项吗?', '提示', {
  199. type: 'warning'
  200. })
  201. .then(() => {
  202. const loading = this.$loading({ lock: true });
  203. removeDictionaryDataBatch(this.selection.map((d) => d.dictDataId))
  204. .then((msg) => {
  205. loading.close();
  206. this.$message.success(msg);
  207. this.reload();
  208. })
  209. .catch((e) => {
  210. loading.close();
  211. // this.$message.error(e.message);
  212. });
  213. })
  214. .catch(() => {});
  215. }
  216. },
  217. watch: {
  218. // 监听字典id变化
  219. // dictId() {
  220. // this.reload();
  221. // }
  222. }
  223. };
  224. </script>