user-setting-matter-add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <ele-modal
  3. :visible="visible"
  4. :append-to-body="true"
  5. :close-on-click-modal="false"
  6. custom-class="ele-dialog-form"
  7. :title="title"
  8. @update:visible="updateVisible"
  9. :maxable="true"
  10. :before-close="handleClose"
  11. width="800px"
  12. >
  13. <el-form
  14. :model="formData"
  15. v-loading="dialogLoading"
  16. ref="formRef"
  17. label-width="120px"
  18. :rules="rules"
  19. >
  20. <el-form-item label="类型" required prop="itemType">
  21. <DictSelection
  22. dictName="记录规则事项类型"
  23. clearable
  24. v-model="formData.itemType"
  25. @change="itemTypeChange"
  26. >
  27. </DictSelection>
  28. </el-form-item>
  29. <el-form-item label="执行方式" required prop="executeMethod">
  30. <DictSelection
  31. dictName="记录规则执行方式"
  32. clearable
  33. v-model="formData.executeMethod"
  34. isProhibit
  35. >
  36. </DictSelection>
  37. </el-form-item>
  38. <el-form-item
  39. v-if="formData.itemType == '1'"
  40. label="选择设备"
  41. required
  42. prop="deviceName"
  43. >
  44. <div class="mask-box" @click="selectDeviceId">
  45. <el-input
  46. v-model="formData.deviceName"
  47. placeholder="请选择设备"
  48. size="small"
  49. :readonly="true"
  50. >
  51. <template #append>
  52. <el-button size="small">选择设备</el-button>
  53. </template>
  54. </el-input>
  55. </div>
  56. </el-form-item>
  57. <el-form-item
  58. v-if="formData.itemType == '3'"
  59. label="关联任务"
  60. prop="itemTaskName"
  61. >
  62. <!-- 下拉选择 -->
  63. <!-- <el-select
  64. placeholder="请选择关联任务"
  65. filterable
  66. clearable
  67. style="width: 100%"
  68. v-model="formData.taskId"
  69. >
  70. <el-option
  71. v-for="task in []"
  72. :key="task.id"
  73. :label="task.name"
  74. :value="task.id"
  75. />
  76. </el-select> -->
  77. <el-input
  78. v-model="formData.itemTaskName"
  79. placeholder="请输入任务名称"
  80. size="small"
  81. ></el-input>
  82. </el-form-item>
  83. <el-form-item
  84. v-if="formData.itemType == '2'"
  85. label="关联记录规则"
  86. required
  87. prop="rulesName"
  88. >
  89. <div class="mask-box" @click="selectReleaseId">
  90. <el-input
  91. v-model="formData.rulesName"
  92. placeholder="请选择记录规则名称"
  93. size="small"
  94. :readonly="true"
  95. >
  96. <template #append>
  97. <el-button size="small">选择规则</el-button>
  98. </template>
  99. </el-input>
  100. </div>
  101. </el-form-item>
  102. <el-form-item
  103. v-if="formData.itemType == '1'"
  104. label="关联事项规则"
  105. required
  106. prop="rulesId"
  107. >
  108. <div class="mask-box" @click="selectRulesId">
  109. <el-input
  110. v-model="formData.rulesName"
  111. placeholder="请选择设备有关计划规则,如保养规则,巡点检规则等"
  112. size="small"
  113. :readonly="true"
  114. >
  115. <template #append>
  116. <el-button size="small">选择规则</el-button>
  117. </template>
  118. </el-input>
  119. </div>
  120. </el-form-item>
  121. </el-form>
  122. <template v-slot:footer>
  123. <el-button type="primary" @click="confirm"> 确定 </el-button>
  124. <el-button @click="handleClose">取消</el-button>
  125. </template>
  126. <material-add
  127. ref="deviceSelectDialog"
  128. selectType="single"
  129. @chooseEquipment="chooseEquipment"
  130. ></material-add>
  131. <selectMatterRules
  132. ref="selectMatterRulesRef"
  133. @chooseRules="chooseRules"
  134. :filterType="[1, 2, 5]"
  135. ></selectMatterRules>
  136. <selectReleaseRules
  137. ref="selectReleaseRulesRef"
  138. @chooseRules="chooseReleaseRules"
  139. :notProduceTaskConfig="notProduceTaskConfig"
  140. ></selectReleaseRules>
  141. </ele-modal>
  142. </template>
  143. <script>
  144. import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  145. import dictMixins from '@/mixins/dictMixins';
  146. import rules from '@/components/bpmnProcessDesigner/src/modules/rules';
  147. import MaterialAdd from '@/views/rulesManagement/components/MaterialAdd.vue';
  148. import selectMatterRules from '@/components/selectMatterRules/select-matter-rules.vue';
  149. import selectReleaseRules from '@/components/selectReleaseRules/select-release-rules.vue';
  150. export default {
  151. name: 'UserSettingMatter',
  152. mixins: [dictMixins, tableColumnsMixin],
  153. emits: ['addMatter', 'editMatter'],
  154. props: {
  155. // 记录规则 NotProduceTaskConfig bool 是否排除已配置的记录规则 过程监测传true
  156. notProduceTaskConfig: {
  157. type: Boolean,
  158. default: false
  159. }
  160. },
  161. components: {
  162. MaterialAdd,
  163. selectMatterRules,
  164. selectReleaseRules
  165. },
  166. data() {
  167. const formBaseData = {
  168. id: null,
  169. // 设备id
  170. deviceId: null,
  171. //设备名称
  172. deviceName: '',
  173. // 记录规则执行方式,参考字典项:record_rules_execute_method
  174. executeMethod: '2',
  175. // 记录规则事项类型,参考字典项:record_rules_item_type
  176. itemType: '2',
  177. // 工序ID
  178. produceTaskId: null,
  179. // 记录规则报工类型,参考字典项:record_rules_report_work_type
  180. reportWorkType: null,
  181. // 规则id,包括事项规则id,记录规则id,根据事项类型区分
  182. rulesId: null,
  183. // 规则名称
  184. rulesName: '',
  185. // 任务id
  186. taskId: null,
  187. itemTaskName: '',
  188. // 是否执行中
  189. isUsing: 0
  190. };
  191. return {
  192. visible: false,
  193. type: 'add', // add新增 edit编辑
  194. formBaseData,
  195. formData: JSON.parse(JSON.stringify(formBaseData)),
  196. // 表单验证规则
  197. rules: {
  198. // 验证类型、执行方式、设备、关联事项规则
  199. executeMethod: [
  200. { required: true, message: '请选择执行方式', trigger: 'change' }
  201. ],
  202. itemType: [
  203. { required: true, message: '请选择事项类型', trigger: 'change' },
  204. { required: true, message: '请选择事项类型', trigger: 'blur' }
  205. ],
  206. deviceName: [
  207. { required: true, message: '请选择设备', trigger: 'change' },
  208. { required: true, message: '请选择设备', trigger: 'blur' }
  209. ],
  210. rulesName: [
  211. {
  212. required: true,
  213. message: '请选择关联事项规则',
  214. trigger: 'change'
  215. },
  216. { required: true, message: '请选择关联事项规则', trigger: 'blur' }
  217. ],
  218. itemTaskName: [
  219. {
  220. required: true,
  221. message: '请输入关联任务名称',
  222. trigger: 'blur'
  223. },
  224. { required: true, message: '请输入关联任务名称', trigger: 'change' }
  225. ],
  226. rulesId: [
  227. {
  228. required: true,
  229. message: '请选择关联规则',
  230. trigger: 'change'
  231. },
  232. { required: true, message: '请选择关联规则', trigger: 'blur' }
  233. ]
  234. },
  235. dialogLoading: false,
  236. title: '新增事项',
  237. // 选择的规则
  238. ruleInfo: null
  239. };
  240. },
  241. methods: {
  242. itemTypeChange() {
  243. this.formData.executeMethod = this.formData.itemType;
  244. this.formData.rulesId = null;
  245. this.formData.rulesName = '';
  246. this.$nextTick(() => {
  247. this.$refs.formRef.clearValidate();
  248. });
  249. },
  250. updateVisible(val) {
  251. this.visible = val;
  252. },
  253. openAdd(reportWorkType, produceTaskId) {
  254. this.type = 'add';
  255. this.title = '新增事项';
  256. this.visible = true;
  257. this.formData.reportWorkType = reportWorkType || '';
  258. this.formData.produceTaskId = produceTaskId || '';
  259. console.log(
  260. 'this.formData.reportWorkType',
  261. this.formData.reportWorkType
  262. );
  263. console.log('this.formData.produceTaskId', this.formData.produceTaskId);
  264. if (reportWorkType === '2') {
  265. // 过程监测
  266. this.formData.itemType = '2';
  267. this.formData.executeMethod = '2';
  268. }
  269. },
  270. openEdit(row) {
  271. this.title = '编辑事项';
  272. console.log('row', row);
  273. this.type = 'edit';
  274. this.visible = true;
  275. this.$util.assignObject(this.formData, row);
  276. this.formData.executeMethod = row.executeMethod + '';
  277. this.formData.itemType = row.itemType + '';
  278. this.formData.reportWorkType = row.reportWorkType + '';
  279. console.log('this.formData', this.formData);
  280. },
  281. // 去选择设备
  282. selectDeviceId() {
  283. this.$refs.deviceSelectDialog.open([]);
  284. },
  285. chooseEquipment(data, index, categoryId) {
  286. console.log('data', data, index, categoryId);
  287. this.formData.deviceId = data[0]?.id || null;
  288. this.formData.deviceName = data[0]?.name || '';
  289. if (this.rules && this.rules.length > 1) {
  290. // 提示用户选择的规则有多个事项规则
  291. this.$message.warning('所选设备包含多个设备,请注意选择');
  292. }
  293. },
  294. // 去选择事项规则
  295. selectRulesId() {
  296. this.$refs.selectMatterRulesRef.open();
  297. },
  298. confirm() {
  299. console.log('this.formData', this.formData);
  300. if (this.formData.isUsing) {
  301. this.$message.warning('当前事项正在执行中,无法修改');
  302. return;
  303. }
  304. // 验证表单
  305. this.$refs.formRef.validate((valid) => {
  306. if (valid) {
  307. if (this.type == 'add') {
  308. this.$emit('addMatter', this.formData, this.ruleInfo);
  309. } else {
  310. this.$emit('editMatter', this.formData, this.ruleInfo);
  311. }
  312. this.handleClose();
  313. }
  314. });
  315. },
  316. // 选择规则
  317. chooseRules(rules) {
  318. console.log('rules', rules);
  319. this.formData.rulesId = rules[0]?.id || null;
  320. this.formData.rulesName = rules[0]?.name || '';
  321. },
  322. // 关闭清空formData
  323. handleClose() {
  324. this.formData = JSON.parse(JSON.stringify(this.formBaseData));
  325. this.$nextTick(() => {
  326. this.$refs.formRef.clearValidate();
  327. this.visible = false;
  328. });
  329. },
  330. // 去选择记录规则
  331. selectReleaseId() {
  332. this.$refs.selectReleaseRulesRef.open(
  333. this.formData.reportWorkType,
  334. this.formData.produceTaskId
  335. );
  336. },
  337. // 选择记录规则
  338. chooseReleaseRules(rules) {
  339. console.log('rules', rules);
  340. this.ruleInfo = rules;
  341. this.formData.rulesId = rules.id || null;
  342. this.formData.rulesName = rules.name || '';
  343. }
  344. }
  345. };
  346. </script>
  347. <style scoped lang="scss">
  348. .mask-box {
  349. &::after {
  350. content: '';
  351. width: 100%;
  352. height: 100%;
  353. position: absolute;
  354. top: 0;
  355. left: 0;
  356. background: rgba(0, 0, 0, 0);
  357. cursor: pointer;
  358. }
  359. }
  360. </style>