permitAdd.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. <template>
  2. <ele-modal
  3. :title="dialogTitle"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. width="80%"
  9. :maxable="true"
  10. >
  11. <el-form
  12. label-width="115px"
  13. :model="formData"
  14. :rules="formRules"
  15. ref="formRef"
  16. >
  17. <el-row style="margin-bottom: 10px">
  18. <el-col :span="8">
  19. <el-form-item label="记录规则类型" prop="classify" required>
  20. <el-select
  21. style="width: 100%"
  22. v-model="formData.classify"
  23. placeholder="请选择"
  24. >
  25. <el-option
  26. v-for="item in recordSheet"
  27. :key="item.value"
  28. :label="item.label"
  29. :value="item.value"
  30. >
  31. </el-option>
  32. </el-select>
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="8">
  36. <el-form-item label="记录规则编码" prop="code">
  37. <el-input
  38. v-model="formData.code"
  39. size="small"
  40. :disabled="true"
  41. placeholder="系统自动生成"
  42. ></el-input>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :span="8">
  46. <el-form-item label="记录规则版本" prop="version">
  47. <el-input
  48. :value="versionText"
  49. size="small"
  50. disabled
  51. placeholder="系统自动生成"
  52. ></el-input>
  53. </el-form-item>
  54. </el-col>
  55. </el-row>
  56. <el-row style="margin-bottom: 10px">
  57. <el-col :span="8">
  58. <el-form-item label="记录规则名称" prop="name">
  59. <el-input
  60. v-model="formData.name"
  61. placeholder="请输入"
  62. size="small"
  63. ></el-input>
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="8">
  67. <el-form-item label="启用日期" required prop="startDate">
  68. <el-date-picker
  69. v-model="formData.startDate"
  70. type="date"
  71. placeholder="请选择启用日期"
  72. size="small"
  73. style="width: 100%"
  74. ></el-date-picker>
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="8">
  78. <el-form-item label="停用日期" required prop="stopDate">
  79. <el-date-picker
  80. v-model="formData.stopDate"
  81. type="date"
  82. placeholder="请选择停用日期"
  83. size="small"
  84. style="width: 100%"
  85. />
  86. </el-form-item>
  87. </el-col>
  88. <el-col v-if="formData.classify == 3" :span="8">
  89. <el-form-item label="关联设备" prop="deviceName" required>
  90. <el-input
  91. v-model="formData.deviceName"
  92. placeholder="请选择设备"
  93. size="small"
  94. :readonly="true"
  95. >
  96. <template #append>
  97. <el-button size="small" @click="selectDeviceId"
  98. >选择设备</el-button
  99. >
  100. </template>
  101. </el-input>
  102. </el-form-item>
  103. </el-col>
  104. </el-row>
  105. <el-row style="margin-bottom: 10px">
  106. <el-col :span="8">
  107. <el-form-item label="模块分类" required prop="reportWorkType">
  108. <dict-selection
  109. v-model="formData.reportWorkType"
  110. dictName="记录规则报工类型"
  111. placeholder="请选择模块"
  112. :clearable="false"
  113. ></dict-selection>
  114. </el-form-item>
  115. </el-col>
  116. </el-row>
  117. <el-row style="margin-bottom: 10px">
  118. <el-col :span="24">
  119. <el-form-item label="周期" prop="frequencyValue" required>
  120. <rule-cycle
  121. ref="cycleMultipleRef"
  122. :formData="formData"
  123. pageType="add"
  124. />
  125. </el-form-item>
  126. </el-col>
  127. </el-row>
  128. <ele-pro-table
  129. ref="table"
  130. :columns="bankColumns"
  131. :datasource="formData.recordRulesDetailList"
  132. :need-page="false"
  133. row-key="id"
  134. class="table_list"
  135. >
  136. <template v-slot:toolbar>
  137. <el-button
  138. size="small"
  139. type="primary"
  140. icon="el-icon-plus"
  141. class="ele-btn-icon"
  142. @click="addRow"
  143. >
  144. 新建
  145. </el-button>
  146. </template>
  147. <template v-slot:paramType="{ row }">
  148. <el-select
  149. v-model="row.paramType"
  150. placeholder="请选择参数类型"
  151. size="mini"
  152. required
  153. >
  154. <el-option label="数值" :value="1" />
  155. <el-option label="选择" :value="2" />
  156. <el-option label="上下限" :value="3" />
  157. <el-option label="规格" :value="4" />
  158. <el-option label="时间" :value="5" />
  159. <el-option label="范围" :value="6" />
  160. <el-option label="文本" :value="7" />
  161. <!-- <el-option label="枚举" :value="8" /> -->
  162. </el-select>
  163. </template>
  164. <template v-slot:paramValue="{ row }">
  165. <!-- 根据参数类型渲染不同的输入组件 -->
  166. <el-link
  167. v-if="formData.classify == '4'"
  168. :underline="false"
  169. style="cursor: pointer"
  170. >
  171. <div class="ele-cell">
  172. <div @click="selectProduct(row)">
  173. {{ row.productName ? row.productName : '请选择产品' }}
  174. </div>
  175. <i
  176. v-if="row.tools.length == 0"
  177. class="el-icon-arrow-down"
  178. @click="selectProduct(row)"
  179. ></i>
  180. <i v-else class="el-icon-close" @click="clearProduct(row)"></i>
  181. </div>
  182. </el-link>
  183. <el-input
  184. v-else
  185. v-model="row.paramValue"
  186. placeholder="请输入参数内容"
  187. size="mini"
  188. ></el-input>
  189. </template>
  190. <template v-slot:defaultValue="{ row }">
  191. <el-row>
  192. <el-col :span="12">
  193. <!-- <el-select
  194. v-if="row.paramType != 7"
  195. v-model="row.symbol"
  196. placeholder="请选择"
  197. size="mini"
  198. >
  199. <el-option label=">" value=">"> </el-option>
  200. <el-option label="<" value="<"> </el-option>
  201. <el-option label="!=" value="!="> </el-option>
  202. <el-option label=">=" value=">="> </el-option>
  203. <el-option label="<=" value="<="> </el-option>
  204. <el-option label="~~" value="~~"> </el-option>
  205. <el-option label="+-" value="+-"> </el-option>
  206. <el-option label="......" value="......"> </el-option>
  207. </el-select> -->
  208. <DictSelection
  209. v-if="row.paramType != 7"
  210. clearable
  211. dictName="数学字符"
  212. v-model="row.symbol"
  213. placeholder="请选择逻辑"
  214. size="mini"
  215. ></DictSelection>
  216. </el-col>
  217. <el-col :span="row.paramType != 7 ? 12 : 24">
  218. <el-input
  219. v-model="row.defaultValue"
  220. placeholder="请输入默认值"
  221. size="mini"
  222. ></el-input>
  223. </el-col>
  224. </el-row>
  225. </template>
  226. <template v-slot:maxValue="{ row }">
  227. <el-input
  228. v-if="row.paramType == 3 || row.paramType == 6"
  229. v-model="row.maxValue"
  230. placeholder="请输入参数上限"
  231. size="mini"
  232. ></el-input>
  233. </template>
  234. <template v-slot:minValue="{ row }">
  235. <el-input
  236. v-if="row.paramType == 3 || row.paramType == 6"
  237. v-model="row.minValue"
  238. placeholder="请输入参数下限"
  239. size="mini"
  240. ></el-input>
  241. </template>
  242. <template v-slot:unitName="{ row }">
  243. <!-- <el-input
  244. v-model="row.unitName"
  245. placeholder="请输入参数单位"
  246. size="mini"
  247. ></el-input> -->
  248. <DictSelection
  249. v-if="row.paramType != 7"
  250. dictName="工艺参数单位"
  251. clearable
  252. filterable
  253. v-model="row.unitName"
  254. size="mini"
  255. >
  256. </DictSelection>
  257. </template>
  258. <template v-slot:toolName="{ row }">
  259. <el-link :underline="false" style="cursor: pointer">
  260. <div class="ele-cell">
  261. <div @click="handleAdd(row)">
  262. {{
  263. row.tools && row.tools.length > 0
  264. ? row.tools.map((i) => i.toolName).join(',')
  265. : '请选择'
  266. }}
  267. </div>
  268. <i
  269. v-if="row.tools.length == 0"
  270. class="el-icon-arrow-down"
  271. @click="handleAdd(row)"
  272. ></i>
  273. <i v-else class="el-icon-close" @click="clearTool(row)"></i>
  274. </div>
  275. </el-link>
  276. </template>
  277. <template v-slot:toolCodes="{ row }">
  278. <el-input
  279. :value="
  280. row.tools && row.tools.length > 0
  281. ? row.tools.map((i) => i.toolCode).join(',')
  282. : ''
  283. "
  284. placeholder="工具自动带出"
  285. disabled
  286. size="mini"
  287. ></el-input>
  288. </template>
  289. <template v-slot:remark="{ row }">
  290. <el-input
  291. v-model="row.remark"
  292. placeholder="请输入"
  293. size="mini"
  294. ></el-input>
  295. </template>
  296. <template v-slot:action="{ row }">
  297. <el-link
  298. type="danger"
  299. :underline="false"
  300. icon="el-icon-delete"
  301. @click="deleteRow(row)"
  302. >
  303. 删除
  304. </el-link>
  305. </template>
  306. </ele-pro-table>
  307. </el-form>
  308. <template v-slot:footer>
  309. <el-button
  310. v-if="type != 'detail'"
  311. :loading="btnLoading"
  312. type="primary"
  313. @click="saveAndPublish"
  314. >
  315. 保存并发布
  316. </el-button>
  317. <el-button
  318. v-if="type != 'detail'"
  319. :loading="btnLoading"
  320. type="primary"
  321. @click="confirm"
  322. >
  323. 保存
  324. </el-button>
  325. <el-button :loading="btnLoading" @click="handleClose">取消</el-button>
  326. </template>
  327. <toolModal ref="toolModalRef" @chooseModal="chooseModal" />
  328. <MaterialAdd
  329. ref="deviceSelectDialog"
  330. selectType="single"
  331. @chooseEquipment="chooseEquipment"
  332. />
  333. <ProductModal
  334. ref="ProductModalRef"
  335. @changeProduct="changeProduct"
  336. ></ProductModal>
  337. </ele-modal>
  338. </template>
  339. <script>
  340. import { getByCode } from '@/api/system/dictionary-data';
  341. // import RuleCycle from '../../matterRules/components/rule-cycle.vue';
  342. import RuleCycle from './rule-cycle.vue';
  343. import OperationGuideDialog from '@/views/rulesManagement/matterRules/components/operationGuideDialog.vue';
  344. import Details from './details.vue';
  345. import dictMixins from '@/mixins/dictMixins';
  346. import toolModal from './toolModal.vue';
  347. import MaterialAdd from '../../components/MaterialAdd.vue';
  348. import {
  349. recordrulesSave,
  350. recordrulesDetailPage,
  351. recordrulesUpdate,
  352. recordrulesPublish,
  353. recordrulesSaveAndPublish,
  354. recordrulesUpdateVersion,
  355. recordrulesCyclePage
  356. } from '@/api/recordrules/index';
  357. import ProductModal from './ProductModal.vue';
  358. export default {
  359. components: {
  360. OperationGuideDialog,
  361. RuleCycle,
  362. Details,
  363. ProductModal,
  364. MaterialAdd,
  365. toolModal
  366. },
  367. mixins: [dictMixins],
  368. computed: {
  369. bankColumns() {
  370. return [
  371. {
  372. width: 110,
  373. type: 'index',
  374. columnKey: 'index',
  375. align: 'center',
  376. label: '序号'
  377. },
  378. {
  379. prop: 'paramType',
  380. label: '参数类型',
  381. align: 'center',
  382. slot: 'paramType',
  383. minWidth: 110
  384. },
  385. {
  386. prop: 'paramValue',
  387. label: '参数内容',
  388. align: 'center',
  389. slot: 'paramValue',
  390. minWidth: 180
  391. },
  392. {
  393. prop: 'defaultValue',
  394. label: '默认值',
  395. align: 'center',
  396. slot: 'defaultValue',
  397. minWidth: 150
  398. },
  399. {
  400. prop: 'maxValue',
  401. label: '参数上限',
  402. align: 'center',
  403. slot: 'maxValue',
  404. minWidth: 110
  405. },
  406. {
  407. prop: 'minValue',
  408. label: '参数下限',
  409. align: 'center',
  410. slot: 'minValue',
  411. minWidth: 110
  412. },
  413. {
  414. prop: 'unitName',
  415. label: '参数单位',
  416. align: 'center',
  417. slot: 'unitName',
  418. minWidth: 110
  419. },
  420. {
  421. prop: 'toolName',
  422. label: '工具名称',
  423. align: 'center',
  424. slot: 'toolName',
  425. minWidth: 110
  426. },
  427. {
  428. prop: 'toolCodes',
  429. label: '工具编码',
  430. align: 'center',
  431. slot: 'toolCodes',
  432. minWidth: 110
  433. },
  434. {
  435. prop: 'remark',
  436. label: '备注',
  437. align: 'center',
  438. slot: 'remark',
  439. minWidth: 110
  440. },
  441. {
  442. columnKey: 'action',
  443. label: '操作',
  444. width: 110,
  445. align: 'center',
  446. resizable: false,
  447. slot: 'action'
  448. }
  449. ];
  450. },
  451. versionText() {
  452. return this.formData.version
  453. ? `V${this.formData.version.toFixed(1)}`
  454. : 'V1.0';
  455. }
  456. },
  457. data() {
  458. const formDateBase = {
  459. id: null,
  460. classify: null,
  461. deviceId: null,
  462. deviceName: '',
  463. frequencyUnit: 2,
  464. frequencyValue: null,
  465. name: '',
  466. recordRulesDetailList: [
  467. {
  468. id: 0,
  469. defaultValue: '',
  470. maxValue: null,
  471. minValue: null,
  472. paramType: null,
  473. paramValue: null,
  474. remark: '',
  475. symbol: null,
  476. tools: [],
  477. unitName: null,
  478. productName: '',
  479. productCode: ''
  480. }
  481. ],
  482. recordRulesCycleList: [],
  483. startDate: null,
  484. stopDate: null,
  485. version: 1,
  486. code: '',
  487. fromId: null,
  488. // 模块分类 参考字典项:record_rules_report_work_type
  489. reportWorkType: '1'
  490. };
  491. return {
  492. dialogTitle: '',
  493. visible: false,
  494. formDateBase,
  495. formData: JSON.parse(JSON.stringify(formDateBase)),
  496. formRules: {
  497. name: [
  498. { required: true, message: '请输入规则名称', trigger: 'blur' }
  499. ],
  500. frequencyValue: [
  501. { required: true, message: '请选择周期', trigger: 'blur' },
  502. { required: true, message: '请选择周期', trigger: 'change' }
  503. ],
  504. frequencyUnit: [
  505. { required: true, message: '请选择频率单位', trigger: 'change' }
  506. ],
  507. classify: [
  508. { required: true, message: '请选择规则类型', trigger: 'change' }
  509. ],
  510. // startDate 启用日期要大于当前时间
  511. // stopDate 停用时间要大于当前时间并且大于启用日期
  512. startDate: [
  513. { required: true, message: '请选择启用日期', trigger: 'blur' },
  514. { required: true, message: '请选择启用日期', trigger: 'change' },
  515. { validator: this.validateStartDate, trigger: 'change' }
  516. ],
  517. stopDate: [
  518. { required: true, message: '请选择停用时间', trigger: 'change' },
  519. { validator: this.validateStopDate, trigger: 'change' }
  520. ],
  521. deviceName: [
  522. { required: true, message: '请输入选择设备', trigger: 'blur' }
  523. ],
  524. reportWorkType: [
  525. { required: true, message: '请选择模块分类', trigger: 'change' },
  526. { required: true, message: '请选择模块分类', trigger: 'blur' }
  527. ]
  528. },
  529. recordSheet: [], // 记录表
  530. current: {},
  531. dataIndex: null,
  532. showEdit: false,
  533. btnLoading: false,
  534. currentRow: null,
  535. type: ''
  536. };
  537. },
  538. mounted() {
  539. this.getByCodeData();
  540. },
  541. methods: {
  542. open(row, type, title) {
  543. this.visible = true;
  544. this.dialogTitle = title;
  545. this.type = type;
  546. console.log('type', type, row);
  547. if (type == 'edit' || type == 'detail') {
  548. this.$util.assignObject(this.formData, row);
  549. this.formData.startDate = new Date(row.startDate);
  550. this.formData.stopDate = new Date(row.stopDate);
  551. this.formData.classify = this.formData.classify + '';
  552. this.formData.reportWorkType = this.formData.reportWorkType + '';
  553. this.recordrulesDetailPage(row);
  554. this.recordrulesCyclePage(row);
  555. console.log('this.formData', this.formData, this.formData.version);
  556. }
  557. if (type == 'clone') {
  558. this.$util.assignObject(this.formData, row);
  559. this.formData.name = this.formData.name + '-副本';
  560. this.formData.version += 1;
  561. this.formData.fromId = row.id;
  562. this.formData.id = null;
  563. this.formData.startDate = new Date(row.startDate);
  564. this.formData.stopDate = new Date(row.stopDate);
  565. this.formData.classify = this.formData.classify + '';
  566. this.recordrulesDetailPage(row);
  567. this.recordrulesCyclePage(row);
  568. }
  569. if (type == 'add') {
  570. this.formData.version = 1;
  571. // 停用日期 默认为 2099-12-31
  572. this.formData.stopDate = new Date('2099-12-31 00:00:00');
  573. }
  574. },
  575. async getByCodeData() {
  576. let res = await getByCode('record_sheet');
  577. let list = res.data.map((item) => {
  578. let values = Object.keys(item);
  579. return {
  580. value: values[0],
  581. label: item[values[0]]
  582. };
  583. });
  584. this.recordSheet = list;
  585. },
  586. itemDel(index) {
  587. this.formData.recordRulesDetailList.splice(index, 1);
  588. },
  589. /* 打开操作手册编辑款 */
  590. openOperationGuideDialogDialog(row, index) {
  591. this.$refs.operationGuideDialog.open(row, index);
  592. },
  593. handleClose() {
  594. this.visible = false;
  595. this.$refs['formRef'].resetFields();
  596. // 清空表单数据
  597. this.formData = JSON.parse(JSON.stringify(this.formDateBase));
  598. },
  599. // 保存
  600. confirm() {
  601. console.log('this.formData', this.formData);
  602. // 验证表单规则
  603. this.$refs.formRef.validate(async (valid) => {
  604. if (!valid) {
  605. return false;
  606. }
  607. if (this.formData.recordRulesDetailList.length == 0) {
  608. return this.$message.warning('至少条件一条规则项');
  609. }
  610. try {
  611. this.btnLoading = true;
  612. this.formData.recordRulesCycleList =
  613. this.$refs.cycleMultipleRef.recordRulesCycleList
  614. .map((i) => {
  615. // 根据月日时分排序计算权重排序
  616. let sortNum = 0;
  617. if (i.month) {
  618. sortNum += i.month * 60 * 24 * 30;
  619. }
  620. if (i.day) {
  621. sortNum += i.day * 60 * 24;
  622. }
  623. if (i.hour) {
  624. sortNum += i.hour * 60;
  625. }
  626. if (i.minute) {
  627. sortNum += i.minute * 1;
  628. }
  629. return { ...i, sortNum };
  630. })
  631. .sort((a, b) => a.sortNum - b.sortNum)
  632. .map((i, index) => {
  633. return { ...i, sortNum: index + 1 };
  634. });
  635. const body = { ...this.formData };
  636. body.startDate = this.$util.toDateString(
  637. body.startDate,
  638. 'yyyy-MM-dd HH:mm:ss'
  639. );
  640. body.stopDate = this.$util.toDateString(
  641. body.stopDate,
  642. 'yyyy-MM-dd HH:mm:ss'
  643. );
  644. if (this.type == 'add') {
  645. await recordrulesSave(body);
  646. } else if (this.type == 'clone') {
  647. await recordrulesUpdateVersion(body);
  648. } else {
  649. // 编辑
  650. body.fromId = null;
  651. await recordrulesUpdate(body);
  652. }
  653. this.btnLoading = false;
  654. this.$message.success('操作成功');
  655. this.handleClose();
  656. this.$emit('reload');
  657. } catch (error) {
  658. this.btnLoading = false;
  659. }
  660. });
  661. },
  662. // 保存并发布
  663. saveAndPublish() {
  664. // 验证表单规则
  665. this.$refs.formRef.validate(async (valid) => {
  666. if (!valid) {
  667. return false;
  668. }
  669. if (this.formData.recordRulesDetailList.length == 0) {
  670. return this.$message.warning('至少条件一条规则项');
  671. }
  672. try {
  673. this.btnLoading = true;
  674. this.formData.recordRulesCycleList =
  675. this.$refs.cycleMultipleRef.recordRulesCycleList
  676. .map((i) => {
  677. // 根据月日时分排序计算权重排序
  678. let sortNum = 0;
  679. if (i.month) {
  680. sortNum += i.month * 60 * 24 * 30;
  681. }
  682. if (i.day) {
  683. sortNum += i.day * 60 * 24;
  684. }
  685. if (i.hour) {
  686. sortNum += i.hour * 60;
  687. }
  688. if (i.minute) {
  689. sortNum += i.minute * 1;
  690. }
  691. return { ...i, sortNum };
  692. })
  693. .sort((a, b) => a.sortNum - b.sortNum)
  694. .map((i, index) => {
  695. return { ...i, sortNum: index + 1 };
  696. });
  697. const body = { ...this.formData };
  698. body.startDate = this.$util.toDateString(
  699. body.startDate,
  700. 'yyyy-MM-dd HH:mm:ss'
  701. );
  702. body.stopDate = this.$util.toDateString(
  703. body.stopDate,
  704. 'yyyy-MM-dd HH:mm:ss'
  705. );
  706. await recordrulesSaveAndPublish(body);
  707. this.btnLoading = false;
  708. this.$message.success('操作成功');
  709. this.handleClose();
  710. this.$emit('reload');
  711. } catch (error) {
  712. this.btnLoading = false;
  713. }
  714. });
  715. },
  716. // startDate 启用日期要大于当前时间
  717. validateStartDate(rule, value, callback) {
  718. const startDate = this.formData.startDate;
  719. if (!startDate) {
  720. return callback(new Error('启用日期不能为空'));
  721. }
  722. // 启用日期大于等于今天
  723. const today = new Date();
  724. today.setHours(0, 0, 0, 0); // 设置为当天的开始时间
  725. if (new Date(startDate) < today) {
  726. return callback(new Error('启用日期必须大于等于当前日期'));
  727. }
  728. callback();
  729. },
  730. // stopDate 停用时间要大于当前时间并且大于启用日期
  731. validateStopDate(rule, value, callback) {
  732. const startDate = this.formData.startDate;
  733. const stopDate = this.formData.stopDate;
  734. if (
  735. stopDate &&
  736. startDate &&
  737. new Date(stopDate) <= new Date(startDate)
  738. ) {
  739. return callback(new Error('停用时间必须大于启用日期'));
  740. }
  741. callback();
  742. },
  743. // 去选择设备
  744. selectDeviceId() {
  745. this.$refs.deviceSelectDialog.open([]);
  746. },
  747. // 选择设备回调
  748. chooseEquipment(data, index, categoryId) {
  749. console.log('data', data, index, categoryId);
  750. this.formData.deviceId = data[0]?.id || null;
  751. this.formData.deviceName = data[0]?.name || '';
  752. },
  753. // 添加
  754. addRow() {
  755. this.formData.recordRulesDetailList.push({
  756. id: new Date().getTime(),
  757. defaultValue: '',
  758. maxValue: null,
  759. minValue: null,
  760. paramType: null,
  761. paramValue: null,
  762. remark: '',
  763. symbol: null,
  764. tools: [],
  765. unitName: null,
  766. productName: '',
  767. productCode: ''
  768. });
  769. },
  770. deleteRow(row) {
  771. const index = this.formData.recordRulesDetailList.indexOf(row);
  772. if (index !== -1) {
  773. this.formData.recordRulesDetailList.splice(index, 1);
  774. }
  775. },
  776. handleAdd(row) {
  777. this.currentRow = row;
  778. this.$refs.toolModalRef.open(row.toolCodes);
  779. },
  780. chooseModal(data) {
  781. console.log('data', data);
  782. this.currentRow.tools = data.map((i) => {
  783. return {
  784. toolCode: i.code,
  785. toolName: i.name
  786. // rulesDetailId: this.currentRow.id,
  787. // rulesId: this.formData.id
  788. };
  789. });
  790. },
  791. // 规则明细表
  792. async recordrulesDetailPage(row) {
  793. const { list } = await recordrulesDetailPage({
  794. // deptId: row.deptId,
  795. pageNum: 1,
  796. rulesId: row.id,
  797. size: 9999
  798. });
  799. console.log('list 数据', list);
  800. this.formData.recordRulesDetailList = list;
  801. },
  802. // 清空工具
  803. clearTool(row) {
  804. row.tools = [];
  805. },
  806. // 查询 recordrulesCyclePage
  807. async recordrulesCyclePage(row) {
  808. const { list } = await recordrulesCyclePage({
  809. pageNum: 1,
  810. size: 9999,
  811. recordRulesId: row.id,
  812. orderBy: 'descending'
  813. });
  814. console.log('list 周期数据', list);
  815. this.formData.recordRulesCycleList = list;
  816. this.$nextTick(() => {
  817. this.$refs.cycleMultipleRef.setRecordRulesCycleList(list);
  818. });
  819. },
  820. // 去选择产品
  821. selectProduct(row) {
  822. this.currentRow = row;
  823. this.$refs.ProductModalRef.open();
  824. },
  825. // 选择产品
  826. changeProduct(current) {
  827. console.log('current', current);
  828. this.currentRow.productName = current.name;
  829. this.currentRow.productCode = current.code;
  830. },
  831. // 清空产品
  832. clearProduct(row) {
  833. row.productName = '';
  834. row.productCode = '';
  835. }
  836. }
  837. };
  838. </script>
  839. <style scoped lang="scss">
  840. .operationGuide_box {
  841. width: 100%;
  842. height: 48px;
  843. display: flex;
  844. overflow: hidden;
  845. cursor: pointer;
  846. box-sizing: border-box;
  847. padding: 5px 10px;
  848. .left_content {
  849. width: 50%;
  850. padding: 10px;
  851. box-sizing: border-box;
  852. border: 1px solid #c0c4cc;
  853. border-radius: 10px;
  854. margin-right: 10px;
  855. overflow-y: auto;
  856. }
  857. .right_content {
  858. flex: 1;
  859. padding: 10px;
  860. box-sizing: border-box;
  861. border: 1px solid #c0c4cc;
  862. border-radius: 10px;
  863. overflow-y: auto;
  864. }
  865. }
  866. ::v--deep .table_list {
  867. .el-form-item {
  868. .el-form-item__content {
  869. margin-left: 0;
  870. }
  871. }
  872. }
  873. </style>