index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <!-- 搜索表单 -->
  5. <index-search :typeList="typeList" @search="reload" />
  6. <!-- 数据表格 -->
  7. <ele-pro-table
  8. ref="table"
  9. height="calc(100vh - 325px)"
  10. :columns="columns"
  11. :datasource="datasource"
  12. :selection.sync="selection"
  13. row-key="id"
  14. :pageSize="this.$store.state.tablePageSize"
  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('', 'add')"
  24. v-if="$hasPermission('main:version:save')"
  25. >
  26. 新建
  27. </el-button>
  28. <el-button
  29. size="small"
  30. type="danger"
  31. icon="el-icon-delete"
  32. class="ele-btn-icon"
  33. v-if="$hasPermission('main:version:delete')"
  34. @click="removeBatch"
  35. plain
  36. >
  37. 删除
  38. </el-button>
  39. <!-- <el-button-->
  40. <!-- size="small"-->
  41. <!-- type="primary"-->
  42. <!-- icon="el-icon-upload2"-->
  43. <!-- class="ele-btn-icon"-->
  44. <!-- plain-->
  45. <!-- >-->
  46. <!-- 导出-->
  47. <!-- </el-button>-->
  48. <!-- <el-button-->
  49. <!-- size="small"-->
  50. <!-- type="primary"-->
  51. <!-- icon="el-icon-download"-->
  52. <!-- class="ele-btn-icon"-->
  53. <!-- plain-->
  54. <!-- >-->
  55. <!-- 导入-->
  56. <!-- </el-button>-->
  57. </template>
  58. <!-- 操作列 -->
  59. <template v-slot:action="{ row }">
  60. <el-link
  61. v-if="row.status != 1 && $hasPermission('main:version:update')"
  62. type="primary"
  63. :underline="false"
  64. icon="el-icon-edit"
  65. @click="openEdit(row, 'edit')"
  66. >
  67. 修改
  68. </el-link>
  69. <el-link
  70. type="primary"
  71. :underline="false"
  72. icon="el-icon-setting"
  73. @click="openEdit(row, 'view')"
  74. >
  75. 详情
  76. </el-link>
  77. <el-popconfirm
  78. v-if="row.status != 1 && $hasPermission('main:version:delete')"
  79. class="ele-action"
  80. title="确定要删除当前版本规则吗?"
  81. @confirm="remove(row)"
  82. >
  83. <template v-slot:reference>
  84. <el-link type="danger" :underline="false" icon="el-icon-delete">
  85. 删除
  86. </el-link>
  87. </template>
  88. </el-popconfirm>
  89. </template>
  90. <template v-slot:status="scope">
  91. <el-switch
  92. @change="(val) => handleStatus(scope, val)"
  93. :active-value="1"
  94. :inactive-value="0"
  95. v-model="scope.row.status"
  96. active-color="#13ce66"
  97. inactive-color="#ff4949"
  98. >
  99. </el-switch>
  100. </template>
  101. </ele-pro-table>
  102. </el-card>
  103. <!-- 新增/编辑/详情弹窗 -->
  104. <add-or-edit-dialog
  105. :addOrEditDialogFlag.sync="addOrEditDialogFlag"
  106. v-if="addOrEditDialogFlag"
  107. ref="addOrEditDialogRef"
  108. :data="current"
  109. :typeList="typeList"
  110. @reload="reload"
  111. />
  112. </div>
  113. </template>
  114. <script>
  115. import addOrEditDialog from './components/addOrEditDialog.vue';
  116. import dictMixins from '@/mixins/dictMixins';
  117. import FileUpload from '@/components/upload/fileUpload.vue';
  118. import { getFile } from '@/api/system/file';
  119. import { reviewStatus } from '@/enum/dict';
  120. import {
  121. getSubTwoLevelAPI,
  122. getVersionManagePageAPI,
  123. updateStatus,
  124. versionManageDeleteAPI
  125. } from '@/api/versionManage';
  126. import indexSearch from '@/views/versionManage/components/index-search.vue';
  127. import { getSubPage } from '@/api/classifyManage';
  128. import { getByCode } from '@/api/system/dictionary-data';
  129. export default {
  130. name: 'technologyProduction',
  131. components: {
  132. FileUpload,
  133. indexSearch,
  134. addOrEditDialog
  135. },
  136. mixins: [dictMixins],
  137. data() {
  138. return {
  139. levelOptions: [
  140. {
  141. label: '初级',
  142. value: '1'
  143. },
  144. {
  145. label: '中级',
  146. value: '2'
  147. },
  148. {
  149. label: '高级',
  150. value: '3'
  151. }
  152. ],
  153. isView: false,
  154. // 表格列配置
  155. columns: [
  156. {
  157. columnKey: 'selection',
  158. type: 'selection',
  159. width: 45,
  160. align: 'center',
  161. fixed: 'left'
  162. },
  163. {
  164. label: '序号',
  165. type: 'index',
  166. width: 55,
  167. align: 'center'
  168. },
  169. {
  170. slot: 'name',
  171. prop: 'name',
  172. label: '名称',
  173. showOverflowTooltip: true,
  174. align: 'center',
  175. minWidth: 110
  176. },
  177. {
  178. slot: 'type',
  179. prop: 'type',
  180. label: '分类',
  181. showOverflowTooltip: true,
  182. align: 'center',
  183. formatter: (row, column) => {
  184. return this.getDictV('version_rule_type', row.type);
  185. },
  186. minWidth: 110
  187. },
  188. {
  189. prop: 'bigVersion',
  190. label: '规则示例',
  191. showOverflowTooltip: true,
  192. align: 'center',
  193. formatter: (_row, _column, cellValue) => {
  194. return (
  195. _row.symbol + _row.bigVersion + _row.mark + _row.smallVersion
  196. );
  197. },
  198. minWidth: 120
  199. },
  200. {
  201. label: '是否启用',
  202. prop: 'status',
  203. slot: 'status',
  204. align: 'center',
  205. width: 120
  206. },
  207. {
  208. columnKey: 'action',
  209. label: '操作',
  210. width: 260,
  211. align: 'center',
  212. resizable: false,
  213. slot: 'action',
  214. showOverflowTooltip: true
  215. }
  216. ],
  217. // 表格选中数据
  218. selection: [],
  219. dictList: {},
  220. // 当前编辑数据
  221. current: null,
  222. typeList: [],
  223. // 是否显示编辑弹窗
  224. addOrEditDialogFlag: false
  225. };
  226. },
  227. created() {
  228. this.getTypeList();
  229. },
  230. computed: {},
  231. methods: {
  232. // getTypeName(list, val, callBack) {
  233. // let find = list.find(item => callBack(item, val)) || {}
  234. // if (find.name) {
  235. // return find.name
  236. // } else {
  237. // for (let i = 0; i < list.length; i++) {
  238. // let find = list[i].subList.find(item => callBack(item, val)) || {}
  239. // if (find.name) {
  240. // return find.name
  241. // }
  242. // }
  243. // }
  244. // },
  245. getDictV(code, val) {
  246. if (!this.dictList[code]) return '';
  247. return this.dictList[code].find((item) => item.value == val)?.label;
  248. },
  249. async getDictList(code) {
  250. let { data: res } = await getByCode(code);
  251. this.dictList[code] = res.map((item) => {
  252. let values = Object.keys(item);
  253. return {
  254. value: values[0],
  255. label: item[values[0]]
  256. };
  257. });
  258. },
  259. /* 表格数据源 */
  260. async datasource({ page, limit, where, order }) {
  261. await this.getDictList('version_rule_type');
  262. return await getVersionManagePageAPI({
  263. ...where,
  264. ...order,
  265. pageNum: page,
  266. size: limit
  267. });
  268. },
  269. handleStatus(scope, val) {
  270. let msg = val == 1 ? '是否启用该规则' : '是否关闭该规则';
  271. this.$confirm(msg, '提示', {
  272. type: 'warning'
  273. })
  274. .then(async () => {
  275. await updateStatus({
  276. id: scope.row.id,
  277. status: val
  278. });
  279. this.$message.success('操作成功');
  280. })
  281. .catch(() => {
  282. scope.row.status = val == 1 ? 0 : 1;
  283. });
  284. },
  285. async getTypeList() {
  286. this.typeList = await getSubTwoLevelAPI({
  287. parentId: 0,
  288. pageNum: 1,
  289. size: 9999
  290. });
  291. console.log(this.typeList);
  292. },
  293. downloadFile(file) {
  294. getFile({ objectName: file.storePath }, file.name);
  295. },
  296. /* 刷新表格 */
  297. reload(where) {
  298. this.$refs.table.reload({ page: 1, where: where });
  299. },
  300. /* 打开编辑弹窗 */
  301. openEdit(row = {}, type) {
  302. console.log('row', row, type);
  303. this.addOrEditDialogFlag = true;
  304. this.$nextTick(() => {
  305. this.$refs.addOrEditDialogRef.init(type, { ...row });
  306. });
  307. },
  308. /* 删除 */
  309. remove(row) {
  310. const loading = this.$loading({ lock: true });
  311. versionManageDeleteAPI([row.id])
  312. .then((msg) => {
  313. loading.close();
  314. this.$message.success('删除成功');
  315. this.reload();
  316. })
  317. .catch((e) => {
  318. loading.close();
  319. // this.$message.error(e.message);
  320. });
  321. },
  322. /* 批量删除 */
  323. removeBatch() {
  324. if (!this.selection.length)
  325. return this.$message.error('请至少选择一条数据');
  326. if (this.selection.some((item) => item.status == 1))
  327. return this.$message.error('启用状态的规则不允许删除!请检查');
  328. this.$confirm('确定要删除选中的规则吗?', '提示', {
  329. type: 'warning'
  330. })
  331. .then(() => {
  332. const loading = this.$loading({ lock: true });
  333. versionManageDeleteAPI(this.selection.map((d) => d.id))
  334. .then((msg) => {
  335. loading.close();
  336. this.$message.success('删除成功');
  337. this.reload();
  338. })
  339. .catch((e) => {
  340. loading.close();
  341. // this.$message.error(e.message);
  342. });
  343. })
  344. .catch(() => {});
  345. }
  346. }
  347. };
  348. </script>