AddorUpdate.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. type="1"
  218. :disabledCode="templateCategoryList.map((item) => item.code)"
  219. >
  220. </EquipmentDialog>
  221. </ele-modal>
  222. </template>
  223. <script>
  224. import termPop from '@/views/inspectionTemplate/inspectionClassify/index.vue';
  225. import EquipmentDialog from '@/views/unqualifiedProduct/unqualifiedList/components/EquipmentDialog.vue';
  226. import { getByCode } from '@/api/system/dictionary-data';
  227. import {
  228. save,
  229. update,
  230. getById,
  231. templatecategoryPage
  232. } from '@/api/inspectionTemplate';
  233. import { getCode } from '@/api/login';
  234. export default {
  235. components: { termPop, EquipmentDialog },
  236. data() {
  237. return {
  238. visible: false,
  239. dataForm: {
  240. id: 0,
  241. type: null,
  242. qualitySchemeTemplateName: '',
  243. qualitySchemeTemplateCode: '',
  244. inspectionItemVOList: [],
  245. status: 1,
  246. templateRemark: ''
  247. },
  248. columns: [
  249. {
  250. width: 45,
  251. type: 'selection',
  252. columnKey: 'selection',
  253. align: 'center',
  254. reserveSelection: true
  255. },
  256. {
  257. columnKey: 'index',
  258. label: '序号',
  259. type: 'index',
  260. width: 55,
  261. align: 'center',
  262. showOverflowTooltip: true,
  263. fixed: 'left'
  264. },
  265. {
  266. prop: 'categoryLevelClassName',
  267. label: '质检类型',
  268. align: 'center',
  269. minWidth: 150
  270. },
  271. {
  272. prop: 'inspectionCode',
  273. label: '编码',
  274. showOverflowTooltip: true,
  275. align: 'center',
  276. minWidth: 150
  277. },
  278. {
  279. prop: 'inspectionName',
  280. slot: 'inspectionName',
  281. label: '名称',
  282. showOverflowTooltip: true,
  283. align: 'center',
  284. minWidth: 150
  285. },
  286. {
  287. prop: 'defaultValue',
  288. slot: 'defaultValue',
  289. label: '工艺参数',
  290. align: 'center',
  291. width: 400,
  292. columnKey: 'defaultValue'
  293. },
  294. {
  295. columnKey: 'action',
  296. label: '操作',
  297. width: 80,
  298. align: 'center',
  299. resizable: false,
  300. slot: 'action',
  301. fixed: 'right'
  302. }
  303. ],
  304. categoryColumns: [
  305. {
  306. width: 45,
  307. type: 'selection',
  308. columnKey: 'selection',
  309. align: 'center',
  310. reserveSelection: true
  311. },
  312. {
  313. columnKey: 'index',
  314. label: '序号',
  315. type: 'index',
  316. width: 55,
  317. align: 'center',
  318. showOverflowTooltip: true,
  319. fixed: 'left'
  320. },
  321. {
  322. prop: 'categoryLevelPath',
  323. label: '分类',
  324. align: 'center',
  325. minWidth: 150
  326. },
  327. {
  328. prop: 'code',
  329. label: '编码',
  330. showOverflowTooltip: true,
  331. align: 'center',
  332. minWidth: 150
  333. },
  334. {
  335. prop: 'name',
  336. label: '名称',
  337. showOverflowTooltip: true,
  338. align: 'center',
  339. minWidth: 150
  340. },
  341. {
  342. prop: 'specification',
  343. label: '规格',
  344. align: 'center',
  345. minWidth: 150
  346. },
  347. {
  348. prop: 'modelType',
  349. label: '型号',
  350. align: 'center',
  351. minWidth: 150
  352. },
  353. {
  354. prop: 'brandNum',
  355. label: '牌号',
  356. align: 'center',
  357. minWidth: 150
  358. },
  359. {
  360. columnKey: 'action',
  361. label: '操作',
  362. width: 80,
  363. align: 'center',
  364. resizable: false,
  365. slot: 'action',
  366. fixed: 'right'
  367. }
  368. ],
  369. dataRule: {
  370. type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
  371. qualitySchemeTemplateName: [
  372. { required: true, message: '请输入质检方案名称', trigger: 'blur' }
  373. ],
  374. status: [
  375. {
  376. required: true,
  377. message: '请选择状态',
  378. trigger: 'blur'
  379. }
  380. ]
  381. },
  382. list: [],
  383. templateCategoryList: [],
  384. typeList: []
  385. };
  386. },
  387. methods: {
  388. async getTnspectionPlanType() {
  389. let res = await getByCode('inspection_plan_type');
  390. if (res?.code == 0) {
  391. let list = res.data.map((item) => {
  392. let key = Object.keys(item)[0];
  393. return { value: key, label: item[key] };
  394. });
  395. this.typeList = list;
  396. }
  397. },
  398. handAdd(type) {
  399. if (type == 1) {
  400. this.$refs.termRef.open(this.list);
  401. }
  402. if (type == 2) {
  403. this.$refs.equipmentRefs.open();
  404. }
  405. },
  406. handleClose() {
  407. this.visible = false;
  408. },
  409. selectionChange(selection) {
  410. console.log(selection, 'selection');
  411. },
  412. selectChange(list) {
  413. this.list = list;
  414. },
  415. handDel(index, type) {
  416. if (type == 1) {
  417. this.list.splice(index, 1);
  418. }
  419. if (type == 2) {
  420. this.templateCategoryList.splice(index, 1);
  421. }
  422. },
  423. confirmChoose(list) {
  424. let categoryList = list.map((item) => {
  425. item['name'] = item.name;
  426. item['categoryId'] = item.id;
  427. item['id'] = '';
  428. return item;
  429. });
  430. this.templateCategoryList.push(...categoryList);
  431. },
  432. init(id) {
  433. this.getTnspectionPlanType();
  434. this.dataForm.id = id || 0;
  435. this.visible = true;
  436. this.$nextTick(async () => {
  437. this.$refs['dataForm'].resetFields();
  438. if (this.dataForm.id) {
  439. getById(this.dataForm.id).then(({ data }) => {
  440. this.dataForm = data;
  441. let itemVOList = [];
  442. if (data.inspectionItemVOList.length > 0) {
  443. itemVOList = data.inspectionItemVOList.map((item) => {
  444. item.inspectionItemId = this.dataForm.id;
  445. // item.push({
  446. // inspectionItemId: this.dataForm.id
  447. // });
  448. return item;
  449. });
  450. }
  451. // this.list = data.inspectionItemVOList;
  452. this.list = itemVOList;
  453. console.log(this.list);
  454. });
  455. templatecategoryPage({
  456. templateId: this.dataForm.id,
  457. size: -1
  458. }).then((data) => {
  459. console.log(data, 'data');
  460. this.templateCategoryList = data.list;
  461. });
  462. // this.templateCategoryList=data.templateCategoryList||[];
  463. } else {
  464. const code = await getCode('template_code');
  465. this.dataForm.qualitySchemeTemplateCode = code;
  466. this.list = [];
  467. }
  468. });
  469. },
  470. // 表单提交
  471. dataFormSubmit() {
  472. this.$refs['dataForm'].validate((valid) => {
  473. if (valid) {
  474. if (!this.dataForm.id) {
  475. delete this.dataForm.id;
  476. }
  477. const saveOrUpdate = this.dataForm.id ? update : save;
  478. if (this.dataForm.id) {
  479. this.dataForm.inspectionItemVOList = this.list.map((item) => {
  480. if (!item.inspectionItemId) {
  481. item.inspectionItemId = this.dataForm.id;
  482. item.id = '';
  483. }
  484. return item;
  485. });
  486. } else {
  487. this.dataForm.inspectionItemVOList = this.list.map((item) => {
  488. item.id = '';
  489. return item;
  490. });
  491. }
  492. this.dataForm.templateCategoryList = this.templateCategoryList;
  493. saveOrUpdate(this.dataForm)
  494. .then((msg) => {
  495. this.loading = false;
  496. this.$refs['dataForm'].resetFields();
  497. // this.dataForm = {};
  498. const info = this.dataForm.id ? '修改成功' : '新增成功';
  499. this.$message.success(info);
  500. this.visible = false;
  501. // this.updateVisible(false);
  502. this.$emit('refreshDataList');
  503. })
  504. .catch((e) => {
  505. this.loading = false;
  506. });
  507. }
  508. });
  509. }
  510. },
  511. watch: {
  512. 'dataForm.type': {
  513. handler(val) {
  514. if (val == 2) {
  515. this.templateCategoryList = [];
  516. }
  517. }
  518. }
  519. }
  520. };
  521. </script>