templateAdd.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <template>
  2. <ele-modal
  3. :title="title"
  4. :visible.sync="visible"
  5. :close-on-click-modal="false"
  6. @close="handleClose"
  7. resizable
  8. maxable
  9. width="80%"
  10. >
  11. <el-form
  12. ref="formRef"
  13. :model="form"
  14. :rules="rules"
  15. label-width="130px"
  16. v-loading="loading"
  17. :disabled="type == 'detail'"
  18. >
  19. <header-title title="基本信息"></header-title>
  20. <el-row style="margin-bottom: 15px" gap="10">
  21. <el-col :span="8">
  22. <el-form-item label="放行类型" prop="checklistType">
  23. <DictSelection
  24. dictName="放行类型"
  25. clearable
  26. v-model="form.checklistType"
  27. >
  28. </DictSelection>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="8">
  32. <el-form-item label="放行模板编码">
  33. <el-input
  34. v-model="form.templateCode"
  35. placeholder="系统自动生成"
  36. disabled
  37. ></el-input>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="8">
  41. <el-form-item label="放行模板名称" prop="templateName">
  42. <el-input
  43. v-model="form.templateName"
  44. placeholder="请输入"
  45. ></el-input>
  46. </el-form-item>
  47. </el-col>
  48. </el-row>
  49. <el-row style="margin-bottom: 15px" gap="10">
  50. <el-col :span="8">
  51. <el-form-item label="状态" prop="enable">
  52. <el-radio-group v-model="form.enable">
  53. <el-radio :label="1">启用</el-radio>
  54. <el-radio :label="0">停用</el-radio>
  55. </el-radio-group>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="16">
  59. <el-form-item label="备注">
  60. <el-input
  61. type="textarea"
  62. :rows="2"
  63. v-model="form.remark"
  64. placeholder="放行单业务说明"
  65. ></el-input>
  66. </el-form-item>
  67. </el-col>
  68. </el-row>
  69. <header-title title="生产放行规则">
  70. <el-button type="primary" icon="el-icon-plus" @click="addDetails(1)">
  71. 添加规则指标
  72. </el-button>
  73. </header-title>
  74. <ele-pro-table
  75. ref="scTable"
  76. row-key="id"
  77. :columns="columns"
  78. :datasource="scCheckTypeDetails"
  79. >
  80. <template v-slot:businessType="{ row }">
  81. <el-select
  82. v-model="row.businessType"
  83. placeholder="请选择业务类型"
  84. @change="businessTypeChange(row)"
  85. >
  86. <el-option
  87. v-for="i in indicatorUseLevelList"
  88. :key="i.businessType"
  89. :label="i.businessName"
  90. :value="i.businessType"
  91. >
  92. </el-option>
  93. </el-select>
  94. </template>
  95. <template v-slot:indicator="{ row }">
  96. <el-select
  97. v-if="row.businessType !== -1"
  98. v-model="row.indicator"
  99. placeholder="请选择考核指标"
  100. :key="row.businessType"
  101. @change="indicatorChange(row)"
  102. >
  103. <el-option
  104. v-for="i in getIndicatorList(row.businessType)"
  105. :key="i.indicator"
  106. :label="i.indicatorName"
  107. :value="i.indicator"
  108. >
  109. </el-option>
  110. </el-select>
  111. <el-input
  112. v-else
  113. v-model="row.indicatorName"
  114. placeholder="请输入"
  115. ></el-input>
  116. </template>
  117. <template v-slot:indicatorName="{ row }">
  118. <el-select
  119. v-if="row.businessType !== -1"
  120. v-model="row.mainIndicatorId"
  121. placeholder="请选择指标名称"
  122. :key="row.indicator"
  123. @change="mainIndicatorIdChange(row)"
  124. >
  125. <el-option
  126. v-for="i in getMainIndicatorIdList(
  127. row.businessType,
  128. row.indicator
  129. )"
  130. :key="i.id"
  131. :label="i.name"
  132. :value="i.id"
  133. >
  134. </el-option>
  135. </el-select>
  136. <el-input
  137. v-else
  138. v-model="row.mainIndicatorName"
  139. placeholder="请输入"
  140. ></el-input>
  141. </template>
  142. <template v-slot:isAutoCheck="{ row }">
  143. <el-select
  144. v-model="row.isAutoCheck"
  145. placeholder="请选择"
  146. :disabled="row.businessType === -1"
  147. >
  148. <el-option label="自动" :value="1"> </el-option>
  149. <el-option label="手动" :value="0"> </el-option>
  150. </el-select>
  151. </template>
  152. <template v-slot:action="{ row }">
  153. <div>
  154. <el-link type="danger" @click="deleteRow(row)">删除</el-link>
  155. </div>
  156. </template>
  157. </ele-pro-table>
  158. <header-title title="质检放行规则">
  159. <el-button type="primary" icon="el-icon-plus" @click="addDetails(2)">
  160. 添加规则指标
  161. </el-button>
  162. </header-title>
  163. <ele-pro-table
  164. ref="zjTable"
  165. row-key="id"
  166. :columns="columns"
  167. :datasource="zjCheckTypeDetails"
  168. >
  169. <template v-slot:businessType="{ row }">
  170. <el-select
  171. v-model="row.businessType"
  172. placeholder="请选择业务类型"
  173. @change="businessTypeChange(row)"
  174. >
  175. <el-option
  176. v-for="i in indicatorUseLevelList"
  177. :key="i.businessType"
  178. :label="i.businessName"
  179. :value="i.businessType"
  180. >
  181. </el-option>
  182. </el-select>
  183. </template>
  184. <template v-slot:indicator="{ row }">
  185. <el-select
  186. v-if="row.businessType !== -1"
  187. v-model="row.indicator"
  188. placeholder="请选择考核指标"
  189. :key="row.businessType"
  190. @change="indicatorChange(row)"
  191. >
  192. <el-option
  193. v-for="i in getIndicatorList(row.businessType)"
  194. :key="i.indicator"
  195. :label="i.indicatorName"
  196. :value="i.indicator"
  197. >
  198. </el-option>
  199. </el-select>
  200. <el-input
  201. v-else
  202. v-model="row.indicatorName"
  203. placeholder="请输入"
  204. ></el-input>
  205. </template>
  206. <template v-slot:indicatorName="{ row }">
  207. <el-select
  208. v-if="row.businessType !== -1"
  209. v-model="row.mainIndicatorId"
  210. placeholder="请选择指标名称"
  211. :key="row.indicator"
  212. @change="mainIndicatorIdChange(row)"
  213. >
  214. <el-option
  215. v-for="i in getMainIndicatorIdList(
  216. row.businessType,
  217. row.indicator
  218. )"
  219. :key="i.id"
  220. :label="i.name"
  221. :value="i.id"
  222. >
  223. </el-option>
  224. </el-select>
  225. <el-input
  226. v-else
  227. v-model="row.mainIndicatorName"
  228. placeholder="请输入"
  229. ></el-input>
  230. </template>
  231. <template v-slot:isAutoCheck="{ row }">
  232. <el-select v-model="row.isAutoCheck" placeholder="请选择">
  233. <el-option label="自动" :value="1"> </el-option>
  234. <el-option label="手动" :value="0"> </el-option>
  235. </el-select>
  236. </template>
  237. <template v-slot:action="{ row }">
  238. <div>
  239. <el-link type="danger" @click="deleteRow(row)">删除</el-link>
  240. </div>
  241. </template>
  242. </ele-pro-table>
  243. </el-form>
  244. <template v-slot:footer>
  245. <el-button
  246. v-if="type == 'edit'"
  247. type="primary"
  248. @click="submit('edit')"
  249. :loading="buttonLoading"
  250. >保 存</el-button
  251. >
  252. <el-button
  253. v-if="type == 'add' || type == 'clone'"
  254. type="primary"
  255. @click="submit('add')"
  256. :loading="buttonLoading"
  257. >提 交</el-button
  258. >
  259. <el-button @click="handleClose" style="margin-left: 20px"
  260. >取 消</el-button
  261. >
  262. </template>
  263. </ele-modal>
  264. </template>
  265. <script>
  266. import dictMixins from '@/mixins/dictMixins';
  267. import {
  268. checklisttemplateGetById,
  269. checktemplateSave,
  270. checklisttemplateUpdate
  271. } from '@/api/checklisttemplate/index';
  272. import { getIndicatorUseLevel } from '@/api/main/index';
  273. import { getByTypeAndIndicator } from '@/api/eom/index';
  274. export default {
  275. mixins: [dictMixins],
  276. data() {
  277. const formBaseData = {
  278. id: null,
  279. createUserName: '',
  280. details: [],
  281. enable: 1,
  282. remark: '',
  283. templateCode: '',
  284. templateName: '',
  285. checklistType: ''
  286. };
  287. return {
  288. visible: false,
  289. title: '新增放行单模版',
  290. formBaseData,
  291. form: JSON.parse(JSON.stringify(formBaseData)),
  292. rules: {
  293. checklistType: [
  294. { required: true, message: '请选择放行类型', trigger: 'blur' },
  295. { required: true, message: '请选择放行类型', trigger: 'change' }
  296. ],
  297. templateName: [
  298. { required: true, message: '请输入放行单名称', trigger: 'blur' },
  299. { required: true, message: '请输入放行单名称', trigger: 'change' }
  300. ],
  301. enable: [
  302. { required: true, message: '请选择状态', trigger: 'blur' },
  303. { required: true, message: '请选择状态', trigger: 'change' }
  304. ]
  305. },
  306. // 业务类型和考核指标
  307. indicatorUseLevelList: [],
  308. // 操作类型 add-新增 edit-编辑 clone-克隆
  309. type: 'add',
  310. loading: false,
  311. buttonLoading: false
  312. };
  313. },
  314. computed: {
  315. // 生产放行规则
  316. scCheckTypeDetails() {
  317. return this.form.details.filter((item) => item.checkType == 1);
  318. },
  319. // 质检放行规则
  320. zjCheckTypeDetails() {
  321. return this.form.details.filter((item) => item.checkType == 2);
  322. },
  323. columns() {
  324. return [
  325. {
  326. width: 55,
  327. type: 'index',
  328. columnKey: 'index',
  329. label: '序号',
  330. align: 'center'
  331. },
  332. {
  333. prop: 'businessType',
  334. label: '业务类型',
  335. slot: 'businessType',
  336. align: 'center',
  337. minWidth: 150,
  338. showOverflowTooltip: true
  339. },
  340. {
  341. prop: 'indicator',
  342. label: '考核指标',
  343. slot: 'indicator',
  344. align: 'center',
  345. minWidth: 150,
  346. showOverflowTooltip: true
  347. },
  348. {
  349. prop: 'indicatorName',
  350. label: '指标名称',
  351. slot: 'indicatorName',
  352. align: 'center',
  353. minWidth: 150,
  354. showOverflowTooltip: true
  355. },
  356. {
  357. prop: 'isAutoCheck',
  358. label: '结果输出类型',
  359. slot: 'isAutoCheck',
  360. align: 'center',
  361. minWidth: 150,
  362. showOverflowTooltip: true
  363. },
  364. {
  365. columnKey: 'action',
  366. label: '操作',
  367. width: 120,
  368. align: 'center',
  369. resizable: false,
  370. fixed: 'right',
  371. slot: 'action'
  372. }
  373. ];
  374. }
  375. },
  376. created() {
  377. this.getIndicatorUseLevel();
  378. },
  379. methods: {
  380. // 外部调用,打开弹窗
  381. open(type, data) {
  382. console.log('type, data', type, data);
  383. this.type = type;
  384. if (type == 'add') {
  385. this.title = '新增放行单模版';
  386. } else if (type == 'edit') {
  387. this.title = '编辑放行单模版';
  388. this.getDetails(data.id);
  389. } else if (type == 'detail') {
  390. this.title = '放行单模版详情';
  391. this.getDetails(data.id);
  392. } else {
  393. // 克隆
  394. this.title = '克隆放行单模版';
  395. this.getDetails(data.id);
  396. }
  397. this.visible = true;
  398. },
  399. async getDetails(id) {
  400. this.loading = true;
  401. try {
  402. const res = await checklisttemplateGetById(id);
  403. console.log('res', res);
  404. this.$util.assignObject(this.form, res);
  405. this.loading = false;
  406. } catch (error) {
  407. this.loading = false;
  408. }
  409. },
  410. // 关闭时清理表单
  411. handleClose() {
  412. this.visible = false;
  413. this.form = JSON.parse(JSON.stringify(this.formBaseData));
  414. this.$refs.formRef && this.$refs.formRef.resetFields();
  415. },
  416. // 提交
  417. submit(type) {
  418. console.log('this.form', this.form);
  419. console.log('this.form.details', this.form.details);
  420. this.$refs.formRef.validate(async (valid) => {
  421. if (valid) {
  422. if (this.form.details.length == 0) {
  423. return this.$message.warning('请至少添加一条放行规则!');
  424. }
  425. // 判断details中的 businessType、indicator、indicatorName 是否有空值
  426. for (let i = 0; i < this.form.details.length; i++) {
  427. const item = this.form.details[i];
  428. if (item.businessType === null) {
  429. return this.$message.warning(
  430. '请填写完整放行规则,业务类型、考核指标、指标名称不能为空!'
  431. );
  432. }
  433. if (
  434. item.businessType !== -1 &&
  435. (item.indicator == null || item.mainIndicatorId == null)
  436. ) {
  437. return this.$message.warning(
  438. '请填写完整放行规则,业务类型、考核指标、指标名称不能为空!'
  439. );
  440. }
  441. if (
  442. item.businessType == -1 &&
  443. (item.indicatorName == '' || item.mainIndicatorName == '')
  444. ) {
  445. return this.$message.warning(
  446. '请填写完整放行规则,业务类型、考核指标、指标名称不能为空!'
  447. );
  448. }
  449. }
  450. this.buttonLoading = true;
  451. try {
  452. if (type == 'add' || type == 'clone') {
  453. this.form.createUserName = this.$store.state.user?.info.name;
  454. this.form.id = null;
  455. // 重置id
  456. this.form.details.forEach((item) => {
  457. item.id = null;
  458. });
  459. await checktemplateSave(this.form);
  460. } else {
  461. // 过滤临时id
  462. this.form.details = this.form.details.map((item) => {
  463. if (
  464. typeof item.id === 'string' &&
  465. item.id.startsWith('tem-')
  466. ) {
  467. return { ...item, id: null };
  468. }
  469. return item;
  470. });
  471. // 编辑
  472. await checklisttemplateUpdate(this.form);
  473. }
  474. } catch (error) {
  475. return (this.buttonLoading = false);
  476. }
  477. this.buttonLoading = false;
  478. this.$message.success('操作成功');
  479. // 触发父组件刷新
  480. this.$emit('reload');
  481. this.handleClose();
  482. }
  483. });
  484. },
  485. // 获取获取指标根节点列表
  486. async getIndicatorUseLevel() {
  487. const data = await getIndicatorUseLevel();
  488. // 添加其他选项
  489. data.push({
  490. businessName: '其他',
  491. businessType: -1,
  492. children: []
  493. });
  494. this.indicatorUseLevelList = data;
  495. console.log('this.getIndicatorUseLevel', this.indicatorUseLevelList);
  496. },
  497. // 添加规则指标 1-生产放行规则,2-质检放行规则
  498. addDetails(checkType = 1) {
  499. const maxSortNum = this.form.details.reduce((max, item) => {
  500. return item.sortNum > max ? item.sortNum : max;
  501. }, 0);
  502. const newSortNum = maxSortNum + 1;
  503. this.form.details.push({
  504. businessType: null,
  505. businessName: '',
  506. checkType: checkType,
  507. createUserName: this.$store.state.user?.info.name,
  508. indicator: null,
  509. indicatorName: '',
  510. isAutoCheck: 1,
  511. sortNum: newSortNum,
  512. mainIndicatorId: null,
  513. mainIndicatorName: '',
  514. templateId: null,
  515. // 临时id
  516. id: `tem-${new Date().getTime()}`
  517. });
  518. },
  519. // 业务类型 考核指标
  520. getIndicatorList(businessType) {
  521. const item = this.indicatorUseLevelList.find(
  522. (item) => item.businessType == businessType
  523. );
  524. return item ? item.children : [];
  525. },
  526. // 业务类型改变 重置指标和指标名称
  527. businessTypeChange(row) {
  528. const item = this.indicatorUseLevelList.find(
  529. (item) => item.businessType == row.businessType
  530. );
  531. row.businessName = item ? item.businessName : '';
  532. row.indicator = null;
  533. row.indicatorName = '';
  534. row.mainIndicatorId = null;
  535. row.mainIndicatorName = '';
  536. if (row.businessType === -1) {
  537. row.isAutoCheck = 0;
  538. } else {
  539. // row.isAutoCheck = 1;
  540. }
  541. },
  542. // 修改 考核指标
  543. indicatorChange(row) {
  544. const list = this.getIndicatorList(row.businessType);
  545. const indicatorItem = list?.find(
  546. (item) => item.indicator == row.indicator
  547. );
  548. row.indicatorName = indicatorItem?.indicatorName || '';
  549. row.mainIndicatorId = null;
  550. row.mainIndicatorName = '';
  551. },
  552. // 指标名称列表
  553. getMainIndicatorIdList(businessType, indicator) {
  554. // 排除其他
  555. if (businessType == -1) return;
  556. const indicatorList = this.getIndicatorList(businessType);
  557. const indicatorItem = indicatorList?.find(
  558. (item) => item.indicator == indicator
  559. );
  560. console.log('indicatorItem', indicatorItem);
  561. return indicatorItem?.children || [];
  562. },
  563. // 删除行
  564. deleteRow(row) {
  565. this.form.details = this.form.details.filter(
  566. (item) => item.id !== row.id
  567. );
  568. },
  569. // 选择指标名称
  570. mainIndicatorIdChange(row) {
  571. const list = this.getMainIndicatorIdList(
  572. row.businessType,
  573. row.indicator
  574. );
  575. const item = list.find((i) => i.id == row.mainIndicatorId);
  576. row.mainIndicatorName = item ? item.name : '';
  577. }
  578. }
  579. };
  580. </script>
  581. <style scoped lang="scss"></style>