user-setting-matter-add.vue 11 KB

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