AddorUpdate.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <!-- <el-dialog-->
  3. <!-- :title="!dataForm.id ? '新增' : '修改'"-->
  4. <!-- :close-on-click-modal="false"-->
  5. <!-- :visible.sync="visible"-->
  6. <!-- width="60%"-->
  7. <!-- >-->
  8. <ele-modal
  9. :title="!dataForm.id ? '新增' : '修改'"
  10. :visible.sync="visible"
  11. :before-close="handleClose"
  12. :close-on-click-modal="false"
  13. :close-on-press-escape="false"
  14. append-to-body
  15. width="80%"
  16. :maxable="true"
  17. >
  18. <el-form
  19. :model="dataForm"
  20. :rules="dataRule"
  21. ref="dataForm"
  22. @keyup.enter.native="dataFormSubmit()"
  23. label-width="80px"
  24. >
  25. <el-row style="margin-bottom: 10px">
  26. <el-col :span="4"
  27. ><el-form-item label="类型 " prop="type">
  28. <el-select
  29. clearable
  30. class="ele-block"
  31. v-model="dataForm.type"
  32. placeholder="请选择"
  33. >
  34. <el-option
  35. v-for="item in typeList"
  36. :label="item.label"
  37. :value="+item.value"
  38. :key="item.value"
  39. />
  40. </el-select> </el-form-item
  41. ></el-col>
  42. <el-col :span="8">
  43. <el-form-item label="名称" prop="qualitySchemeTemplateName">
  44. <el-input
  45. v-model="dataForm.qualitySchemeTemplateName"
  46. placeholder="质检方案名称"
  47. ></el-input>
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="8">
  51. <el-form-item label="编码" prop="qualitySchemeTemplateCode">
  52. <el-input
  53. v-model="dataForm.qualitySchemeTemplateCode"
  54. placeholder="质检方案编码"
  55. disabled
  56. ></el-input>
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="4"
  60. ><el-form-item label="状态 " prop="status">
  61. <el-select
  62. clearable
  63. class="ele-block"
  64. v-model="dataForm.status"
  65. placeholder="请选择"
  66. >
  67. <el-option label="失效" :value="0" />
  68. <el-option label="有效" :value="1" />
  69. </el-select> </el-form-item
  70. ></el-col>
  71. </el-row>
  72. <el-row>
  73. <el-col :span="24">
  74. <el-form-item label="备注" prop="templateRemark">
  75. <el-input
  76. type="textarea"
  77. v-model="dataForm.templateRemark"
  78. placeholder="请输入"
  79. ></el-input>
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. <el-row>
  84. <ele-pro-table
  85. ref="table"
  86. :columns="columns"
  87. :datasource="list"
  88. height="400px"
  89. tool-class="ele-toolbar-form"
  90. cache-key="inspectionClassify"
  91. row-key="qualityLevelId"
  92. @selection-change="selectionChange"
  93. >
  94. <template v-slot:toolbar>
  95. <el-button @click="handAdd(1)" size="mini" type="primary"
  96. >新增质检项</el-button
  97. >
  98. </template>
  99. <template v-slot:textType="{ row }">
  100. {{
  101. row.textType == 1
  102. ? '数值'
  103. : row.textType == 2
  104. ? '选择'
  105. : row.textType == 3
  106. ? '上下限'
  107. : row.textType == 4
  108. ? '规格'
  109. : row.textType == 5
  110. ? '时间'
  111. : row.textType == 6
  112. ? '范围'
  113. : row.textType == 7
  114. ? '文本'
  115. : ''
  116. }}
  117. </template>
  118. <template v-slot:type="{ row }">
  119. {{ getDictValue('质检标准类型', row.qualityStandardType) }}
  120. </template>
  121. <template v-slot:inspectionName="{ row }">
  122. <div>
  123. <el-input
  124. v-model="row.inspectionName"
  125. style="width: 160px"
  126. ></el-input
  127. ></div>
  128. </template>
  129. <template v-slot:defaultValue="{ row }">
  130. <div style="width: 100%; display: flex">
  131. <DictSelection
  132. style="width: 85px"
  133. clearable
  134. dictName="数学字符"
  135. v-model="row.symbol"
  136. ></DictSelection>
  137. <div v-if="row.textType == 3">
  138. <el-input v-model="row.minValue" style="width: 80px"></el-input
  139. >-
  140. <el-input v-model="row.maxValue" style="width: 80px">
  141. </el-input>
  142. </div>
  143. <div v-else>
  144. <el-input
  145. v-model="row.defaultValue"
  146. style="width: 170px"
  147. ></el-input>
  148. </div>
  149. <DictSelection
  150. dictName="工艺参数单位"
  151. clearable
  152. filterable
  153. v-model="row.unitName"
  154. style="width: 100px"
  155. >
  156. </DictSelection>
  157. </div>
  158. </template>
  159. <template v-slot:action="{ row, $index }">
  160. <el-popconfirm
  161. class="ele-action"
  162. title="确定要删除当前质检项吗?"
  163. @confirm="handDel($index, 1)"
  164. >
  165. <template v-slot:reference>
  166. <el-link type="danger" :underline="false" icon="el-icon-delete">
  167. 删除
  168. </el-link>
  169. </template>
  170. </el-popconfirm>
  171. </template>
  172. </ele-pro-table>
  173. </el-row>
  174. <el-row v-if="dataForm.type !== 2">
  175. <ele-pro-table
  176. ref="table"
  177. :columns="categoryColumns"
  178. :datasource="templateCategoryList"
  179. height="300px"
  180. tool-class="ele-toolbar-form"
  181. cache-key="inspectionClassify"
  182. row-key="qualityLevelId"
  183. @selection-change="selectionChange"
  184. :need-page="false"
  185. >
  186. <template v-slot:toolbar>
  187. <el-button @click="handAdd(2)" size="mini" type="primary"
  188. >选择物品</el-button
  189. >
  190. </template>
  191. <template v-slot:action="{ row, $index }">
  192. <el-popconfirm
  193. class="ele-action"
  194. title="确定要删除当前物品吗?"
  195. @confirm="handDel($index, 2)"
  196. >
  197. <template v-slot:reference>
  198. <el-link type="danger" :underline="false" icon="el-icon-delete">
  199. 删除
  200. </el-link>
  201. </template>
  202. </el-popconfirm>
  203. </template>
  204. </ele-pro-table>
  205. </el-row>
  206. </el-form>
  207. <span slot="footer" class="dialog-footer">
  208. <el-button @click="visible = false">取消</el-button>
  209. <el-button type="primary" @click="dataFormSubmit()">保存</el-button>
  210. </span>
  211. <termPop ref="termRef" @selectChange="selectChange"></termPop>
  212. <!-- 选择产品 -->
  213. <EquipmentDialog
  214. ref="equipmentRefs"
  215. @choose="confirmChoose"
  216. :typeS="['1']"
  217. :disabledCode="templateCategoryList.map((item) => item.code)"
  218. >
  219. </EquipmentDialog>
  220. </ele-modal>
  221. </template>
  222. <script>
  223. import termPop from '@/views/inspectionTemplate/inspectionClassify/index.vue';
  224. import EquipmentDialog from '@/views/unqualifiedProduct/unqualifiedList/components/EquipmentDialog.vue';
  225. import { getByCode } from '@/api/system/dictionary-data';
  226. import {
  227. save,
  228. update,
  229. getById,
  230. templatecategoryPage
  231. } from '@/api/inspectionTemplate';
  232. import { getCode } from '@/api/login';
  233. export default {
  234. components: { termPop, EquipmentDialog },
  235. data() {
  236. return {
  237. visible: false,
  238. dataForm: {
  239. id: 0,
  240. type: null,
  241. qualitySchemeTemplateName: '',
  242. qualitySchemeTemplateCode: '',
  243. inspectionItemVOList: [],
  244. status: 1,
  245. templateRemark: ''
  246. },
  247. columns: [
  248. {
  249. width: 45,
  250. type: 'selection',
  251. columnKey: 'selection',
  252. align: 'center',
  253. reserveSelection: true
  254. },
  255. {
  256. columnKey: 'index',
  257. label: '序号',
  258. type: 'index',
  259. width: 55,
  260. align: 'center',
  261. showOverflowTooltip: true,
  262. fixed: 'left'
  263. },
  264. {
  265. prop: 'categoryLevelClassName',
  266. label: '质检类型',
  267. align: 'center',
  268. minWidth: 150
  269. },
  270. {
  271. prop: 'inspectionCode',
  272. label: '编码',
  273. showOverflowTooltip: true,
  274. align: 'center',
  275. minWidth: 150
  276. },
  277. {
  278. prop: 'inspectionName',
  279. slot: 'inspectionName',
  280. label: '名称',
  281. showOverflowTooltip: true,
  282. align: 'center',
  283. minWidth: 150
  284. },
  285. {
  286. prop: 'defaultValue',
  287. slot: 'defaultValue',
  288. label: '工艺参数',
  289. align: 'center',
  290. width: 400,
  291. columnKey: 'defaultValue'
  292. },
  293. {
  294. columnKey: 'action',
  295. label: '操作',
  296. width: 80,
  297. align: 'center',
  298. resizable: false,
  299. slot: 'action',
  300. fixed: 'right'
  301. }
  302. ],
  303. categoryColumns: [
  304. {
  305. width: 45,
  306. type: 'selection',
  307. columnKey: 'selection',
  308. align: 'center',
  309. reserveSelection: true
  310. },
  311. {
  312. columnKey: 'index',
  313. label: '序号',
  314. type: 'index',
  315. width: 55,
  316. align: 'center',
  317. showOverflowTooltip: true,
  318. fixed: 'left'
  319. },
  320. {
  321. prop: 'categoryLevelPath',
  322. label: '分类',
  323. align: 'center',
  324. minWidth: 150
  325. },
  326. {
  327. prop: 'code',
  328. label: '编码',
  329. showOverflowTooltip: true,
  330. align: 'center',
  331. minWidth: 150
  332. },
  333. {
  334. prop: 'name',
  335. label: '名称',
  336. showOverflowTooltip: true,
  337. align: 'center',
  338. minWidth: 150
  339. },
  340. {
  341. prop: 'specification',
  342. label: '规格',
  343. align: 'center',
  344. minWidth: 150
  345. },
  346. {
  347. prop: 'modelType',
  348. label: '型号',
  349. align: 'center',
  350. minWidth: 150
  351. },
  352. {
  353. prop: 'brandNum',
  354. label: '牌号',
  355. align: 'center',
  356. minWidth: 150
  357. },
  358. {
  359. columnKey: 'action',
  360. label: '操作',
  361. width: 80,
  362. align: 'center',
  363. resizable: false,
  364. slot: 'action',
  365. fixed: 'right'
  366. }
  367. ],
  368. dataRule: {
  369. type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
  370. qualitySchemeTemplateName: [
  371. { required: true, message: '请输入质检方案名称', trigger: 'blur' }
  372. ],
  373. status: [
  374. {
  375. required: true,
  376. message: '请选择状态',
  377. trigger: 'blur'
  378. }
  379. ]
  380. },
  381. list: [],
  382. templateCategoryList: [],
  383. typeList: []
  384. };
  385. },
  386. methods: {
  387. async getTnspectionPlanType() {
  388. let res = await getByCode('inspection_plan_type');
  389. if (res?.code == 0) {
  390. let list = res.data.map((item) => {
  391. let key = Object.keys(item)[0];
  392. return { value: key, label: item[key] };
  393. });
  394. this.typeList = list;
  395. }
  396. },
  397. handAdd(type) {
  398. if (type == 1) {
  399. this.$refs.termRef.open(this.list);
  400. }
  401. if (type == 2) {
  402. this.$refs.equipmentRefs.open();
  403. }
  404. },
  405. handleClose() {
  406. this.visible = false;
  407. },
  408. selectionChange(selection) {
  409. console.log(selection, 'selection');
  410. },
  411. selectChange(list) {
  412. this.list = list;
  413. },
  414. handDel(index, type) {
  415. if (type == 1) {
  416. this.list.splice(index, 1);
  417. }
  418. if (type == 2) {
  419. this.templateCategoryList.splice(index, 1);
  420. }
  421. },
  422. confirmChoose(list) {
  423. let categoryList = list.map((item) => {
  424. item['name'] = item.name;
  425. item['id'] = '';
  426. return item;
  427. });
  428. this.templateCategoryList.push(...categoryList);
  429. },
  430. init(id) {
  431. this.getTnspectionPlanType();
  432. this.dataForm.id = id || 0;
  433. this.visible = true;
  434. this.$nextTick(async () => {
  435. this.$refs['dataForm'].resetFields();
  436. if (this.dataForm.id) {
  437. getById(this.dataForm.id).then(({ data }) => {
  438. this.dataForm = data;
  439. let itemVOList = [];
  440. if (data.inspectionItemVOList.length > 0) {
  441. itemVOList = data.inspectionItemVOList.map((item) => {
  442. item.inspectionItemId = this.dataForm.id;
  443. // item.push({
  444. // inspectionItemId: this.dataForm.id
  445. // });
  446. return item;
  447. });
  448. }
  449. // this.list = data.inspectionItemVOList;
  450. this.list = itemVOList;
  451. console.log(this.list);
  452. });
  453. templatecategoryPage({
  454. templateId: this.dataForm.id,
  455. size: -1
  456. }).then((data) => {
  457. console.log(data, 'data');
  458. this.templateCategoryList = data.list;
  459. });
  460. // this.templateCategoryList=data.templateCategoryList||[];
  461. } else {
  462. const code = await getCode('template_code');
  463. this.dataForm.qualitySchemeTemplateCode = code;
  464. this.list = [];
  465. }
  466. });
  467. },
  468. // 表单提交
  469. dataFormSubmit() {
  470. this.$refs['dataForm'].validate((valid) => {
  471. if (valid) {
  472. if (!this.dataForm.id) {
  473. delete this.dataForm.id;
  474. }
  475. const saveOrUpdate = this.dataForm.id ? update : save;
  476. if (this.dataForm.id) {
  477. this.dataForm.inspectionItemVOList = this.list.map((item) => {
  478. if (!item.inspectionItemId) {
  479. item.inspectionItemId = this.dataForm.id;
  480. item.id = '';
  481. }
  482. return item;
  483. });
  484. } else {
  485. this.dataForm.inspectionItemVOList = this.list.map((item) => {
  486. item.id = '';
  487. return item;
  488. });
  489. }
  490. this.dataForm.templateCategoryList = this.templateCategoryList;
  491. saveOrUpdate(this.dataForm)
  492. .then((msg) => {
  493. this.loading = false;
  494. this.dataForm = {};
  495. const info = this.dataForm.id ? '修改成功' : '新增成功';
  496. this.$message.success(info);
  497. this.visible = false;
  498. // this.updateVisible(false);
  499. this.$emit('refreshDataList');
  500. })
  501. .catch((e) => {
  502. this.loading = false;
  503. });
  504. }
  505. });
  506. }
  507. },
  508. watch: {
  509. 'dataForm.type': {
  510. handler(val) {
  511. if (val == 2) {
  512. this.templateCategoryList = [];
  513. }
  514. }
  515. }
  516. }
  517. };
  518. </script>