AddorUpdate.vue 12 KB

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