permitAdd.vue 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074
  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. append-to-body
  11. destroy-on-close
  12. >
  13. <el-form
  14. label-width="115px"
  15. :model="formData"
  16. :rules="formRules"
  17. ref="formRef"
  18. v-loading="loading"
  19. :disabled="type == 'detail'"
  20. >
  21. <el-row>
  22. <el-col :span="8">
  23. <el-form-item label="行业类别" prop="industryType">
  24. <el-select
  25. v-model="formData.industryType"
  26. placeholder="请选择行业类别"
  27. style="width: 100%"
  28. @change="industryTypeChange"
  29. >
  30. <el-option
  31. v-for="item in industryTypeList"
  32. :key="item.value"
  33. :label="item.label"
  34. :value="item.value"
  35. />
  36. </el-select>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="8">
  40. <el-form-item label="业务分类" prop="businessType">
  41. <el-select
  42. v-model="formData.businessType"
  43. placeholder="请选择业务分类"
  44. style="width: 100%"
  45. @change="businessTypeChange"
  46. >
  47. <el-option
  48. v-for="item in businessTypeList"
  49. :key="item.value"
  50. :label="item.label"
  51. :value="item.value"
  52. />
  53. </el-select>
  54. </el-form-item>
  55. </el-col>
  56. <el-col :span="8">
  57. <el-form-item label="模块划分" prop="reportWorkType">
  58. <el-select
  59. v-model="formData.reportWorkType"
  60. placeholder="请选择模块划分"
  61. style="width: 100%"
  62. @change="reportWorkTypeChange"
  63. >
  64. <el-option
  65. v-for="item in reportWorkTypeList"
  66. :key="item.value"
  67. :label="item.label"
  68. :value="item.value"
  69. />
  70. </el-select>
  71. </el-form-item>
  72. </el-col>
  73. <el-col :span="8">
  74. <el-form-item label="应用场景" prop="classify">
  75. <el-select
  76. v-model="formData.classify"
  77. placeholder="请选择应用场景"
  78. style="width: 100%"
  79. @change="classifyChange"
  80. >
  81. <el-option
  82. v-for="item in classifyList"
  83. :key="item.value"
  84. :label="item.label"
  85. :value="item.value"
  86. />
  87. </el-select>
  88. </el-form-item>
  89. </el-col>
  90. <el-col :span="8">
  91. <el-form-item label="模板样式" prop="recordTemplateStyle">
  92. <el-select
  93. v-model="formData.recordTemplateStyle"
  94. placeholder="请选择模板样式"
  95. style="width: 100%"
  96. >
  97. <el-option
  98. v-for="item in recordTemplateStyleList"
  99. :key="item.value"
  100. :label="item.label"
  101. :value="item.value"
  102. />
  103. </el-select>
  104. </el-form-item>
  105. </el-col>
  106. <el-col :span="8">
  107. <el-form-item label="编码" prop="code">
  108. <el-input
  109. v-model="formData.code"
  110. :disabled="true"
  111. placeholder="系统自动生成"
  112. ></el-input>
  113. </el-form-item>
  114. </el-col>
  115. <el-col :span="8">
  116. <el-form-item label="版本">
  117. <el-input
  118. :value="versionText"
  119. disabled
  120. placeholder="系统自动生成"
  121. ></el-input>
  122. </el-form-item>
  123. </el-col>
  124. <el-col :span="8">
  125. <el-form-item label="名称" prop="name">
  126. <el-input
  127. v-model="formData.name"
  128. placeholder="请输入"
  129. :disabled="type == 'processEdit'"
  130. ></el-input>
  131. </el-form-item>
  132. </el-col>
  133. <el-col :span="8">
  134. <el-form-item
  135. label="启用日期"
  136. prop="startDate"
  137. :rules="
  138. !qmsReportWorkType.includes(formData.reportWorkType)
  139. ? [
  140. {
  141. required: true,
  142. message: '请选择启用日期',
  143. trigger: 'blur'
  144. },
  145. {
  146. required: true,
  147. message: '请选择启用日期',
  148. trigger: 'change'
  149. },
  150. { validator: validateStartDate, trigger: 'change' }
  151. ]
  152. : []
  153. "
  154. >
  155. <el-date-picker
  156. v-model="formData.startDate"
  157. type="date"
  158. placeholder="请选择启用日期"
  159. style="width: 100%"
  160. :picker-options="{
  161. disabledDate: (time) =>
  162. time.getTime() < new Date(new Date().toDateString()).getTime()
  163. }"
  164. :disabled="type == 'processEdit'"
  165. />
  166. </el-form-item>
  167. </el-col>
  168. <el-col :span="8">
  169. <el-form-item
  170. label="停用日期"
  171. prop="stopDate"
  172. :rules="
  173. !qmsReportWorkType.includes(formData.reportWorkType)
  174. ? [
  175. {
  176. required: true,
  177. message: '请选择停用时间',
  178. trigger: 'change'
  179. },
  180. { validator: validateStopDate, trigger: 'change' }
  181. ]
  182. : []
  183. "
  184. >
  185. <el-date-picker
  186. v-model="formData.stopDate"
  187. type="date"
  188. placeholder="请选择停用日期"
  189. style="width: 100%"
  190. :disabled="type == 'processEdit'"
  191. />
  192. </el-form-item>
  193. </el-col>
  194. <el-col v-if="formData.recordTemplateStyle == '2'" :span="8">
  195. <el-form-item label="关联设备" prop="deviceName" required>
  196. <el-input
  197. v-model="formData.deviceName"
  198. placeholder="请选择设备"
  199. :readonly="true"
  200. >
  201. <template #append>
  202. <el-button @click="selectDeviceId">选择设备</el-button>
  203. </template>
  204. </el-input>
  205. </el-form-item>
  206. </el-col>
  207. <el-col v-if="formData.reportWorkType == 2" :span="8">
  208. <el-form-item label="关联工序">
  209. <el-input
  210. v-model="formData.produceTaskName"
  211. @click.native="openProduceTaskDialog"
  212. readonly
  213. placeholder="关联工序"
  214. clearable
  215. :disabled="type == 'processEdit'"
  216. >
  217. <i
  218. v-if="formData.produceTaskName"
  219. slot="suffix"
  220. class="el-input__icon el-icon-close"
  221. size="24"
  222. @click.stop="clearProductTask"
  223. ></i>
  224. </el-input>
  225. </el-form-item>
  226. </el-col>
  227. <el-col v-if="formData.reportWorkType == 2" :span="8">
  228. <el-form-item label="是否有执行方式" label-width="130px">
  229. <el-radio-group
  230. v-model="formData.isExecuteMethod"
  231. @change="isExecuteMethodChange"
  232. >
  233. <el-radio :label="1">是</el-radio>
  234. <el-radio :label="0">否</el-radio>
  235. </el-radio-group>
  236. </el-form-item>
  237. </el-col>
  238. <el-col
  239. v-if="formData.isExecuteMethod == 1 && formData.reportWorkType == 2"
  240. :span="8"
  241. >
  242. <el-form-item label="执行方式" required prop="executeMethodId">
  243. <el-select
  244. v-model="formData.executeMethodId"
  245. filterable
  246. placeholder="请选择"
  247. style="width: 100%"
  248. @change="executeMethodIdChange"
  249. >
  250. <el-option
  251. v-for="item in executeMethodList"
  252. :key="item.id"
  253. :label="item.name"
  254. :value="item.id"
  255. >
  256. </el-option>
  257. </el-select>
  258. </el-form-item>
  259. </el-col>
  260. </el-row>
  261. <el-row v-if="!qmsReportWorkType.includes(formData.reportWorkType)">
  262. <el-col :span="24">
  263. <el-form-item label="周期" prop="frequencyValue" required>
  264. <rule-cycle
  265. ref="cycleMultipleRef"
  266. :formData="formData"
  267. :pageType="type"
  268. :isBindPlan="type == 'processEdit'"
  269. />
  270. </el-form-item>
  271. </el-col>
  272. </el-row>
  273. <header-title
  274. title="规则明细"
  275. v-if="!qmsReportWorkType.includes(formData.reportWorkType)"
  276. >
  277. </header-title>
  278. <el-tabs
  279. v-if="
  280. formData.recordTemplateStyle == '4' &&
  281. !qmsReportWorkType.includes(formData.reportWorkType)
  282. "
  283. v-model="statisticsType"
  284. type="card"
  285. >
  286. <el-tab-pane
  287. v-for="i in statisticsTypeList"
  288. :label="i.label"
  289. :name="i.value"
  290. :key="i.value"
  291. >
  292. </el-tab-pane>
  293. </el-tabs>
  294. <ele-pro-table
  295. v-if="!qmsReportWorkType.includes(formData.reportWorkType)"
  296. ref="table"
  297. :columns="bankColumns"
  298. :datasource="detialsDatasource"
  299. :need-page="false"
  300. row-key="id"
  301. class="table_list"
  302. :cache-key="cacheKeyUrl"
  303. >
  304. <template v-slot:toolbar>
  305. <div style="display: flex; align-items: center; gap: 10px">
  306. <el-button
  307. type="primary"
  308. icon="el-icon-plus"
  309. class="ele-btn-icon"
  310. @click="addRow"
  311. >
  312. 新建
  313. </el-button>
  314. </div>
  315. </template>
  316. <template v-slot:sortNum="{ row }">
  317. <el-input-number
  318. style="width: 80px"
  319. v-model.number="row.sortNum"
  320. placeholder="请输入排序"
  321. size="mini"
  322. type="number"
  323. :min="1"
  324. controls-position="right"
  325. ></el-input-number>
  326. </template>
  327. <template v-slot:paramType="{ row }">
  328. <el-select
  329. v-model="row.paramType"
  330. placeholder="请选择参数类型"
  331. size="mini"
  332. @change="paramTypeChange(row)"
  333. >
  334. <el-option label="数值" :value="1" />
  335. <el-option label="选择" :value="2" />
  336. <el-option label="上下限" :value="3" />
  337. <el-option label="规格" :value="4" />
  338. <el-option label="时间" :value="5" />
  339. <el-option label="范围" :value="6" />
  340. <el-option label="文本" :value="7" />
  341. <!-- <el-option label="枚举" :value="8" /> -->
  342. <el-option label="计算" :value="9" />
  343. </el-select>
  344. </template>
  345. <template v-slot:paramValue="{ row }">
  346. <!-- 根据参数类型渲染不同的输入组件 -->
  347. <el-link
  348. v-if="formData.recordTemplateStyle == '3'"
  349. :underline="false"
  350. style="cursor: pointer"
  351. >
  352. <div class="ele-cell">
  353. <div @click="selectChooseModalProduct(row)">
  354. {{ row.productName ? row.productName : '请选择产品' }}
  355. </div>
  356. <i
  357. v-if="row.tools.length == 0"
  358. class="el-icon-arrow-down"
  359. @click="selectChooseModalProduct(row)"
  360. ></i>
  361. <i v-else class="el-icon-close" @click="clearProduct(row)"></i>
  362. </div>
  363. </el-link>
  364. <el-input
  365. v-else
  366. v-model="row.paramValue"
  367. placeholder="请输入参数内容"
  368. size="mini"
  369. type="textarea"
  370. rows="1"
  371. autosize
  372. ></el-input>
  373. </template>
  374. <template v-slot:formula="{ row }">
  375. <div v-if="row.paramType == 9" class="formula-builder">
  376. <div class="formula-builder__selects">
  377. <!-- 选择参数:从已填的非计算参数内容里取 -->
  378. <el-select
  379. v-model="row._paramSelect"
  380. placeholder="选择参数"
  381. size="mini"
  382. style="width: 100px; margin-right: 8px; flex-shrink: 0"
  383. @change="paramSelectChange($event, row)"
  384. >
  385. <el-option
  386. v-for="item in getSelectOptionsByDetails(row.statisticsType)"
  387. :key="item.value"
  388. :label="item.label"
  389. :value="item.value"
  390. />
  391. </el-select>
  392. <!-- 选择运算符 -->
  393. <el-select
  394. v-model="row._opSelect"
  395. :key="row._opSelect + '_opSelect'"
  396. placeholder="选择符号"
  397. size="mini"
  398. style="width: 100px; flex-shrink: 0"
  399. @change="opSelectChange($event, row)"
  400. >
  401. <el-option
  402. v-for="op in opSelectOptions"
  403. :key="op"
  404. :label="op"
  405. :value="op"
  406. />
  407. </el-select>
  408. <!-- 替换或者追加 -->
  409. <el-select
  410. v-if="row.activeIndex != undefined"
  411. v-model="row._replaceOrAppend"
  412. :key="row._replaceOrAppend + 'row._replaceOrAppend'"
  413. placeholder="选择"
  414. size="mini"
  415. style="width: 80px; margin-left: 8px; flex-shrink: 0"
  416. >
  417. <el-option key="append" label="追加" value="append" />
  418. <el-option key="replace" label="替换" value="replace" />
  419. </el-select>
  420. </div>
  421. <!-- 已组装公式标签展示 -->
  422. <div
  423. v-if="row.formulaParts && row.formulaParts.length"
  424. style="display: inline-flex; flex-wrap: wrap; max-width: 100%"
  425. >
  426. <el-tag
  427. v-for="(p, index) in row.formulaParts"
  428. :key="index"
  429. size="mini"
  430. closable
  431. :type="row.activeIndex === index ? 'primary' : 'info'"
  432. @click="formulaPartsTagClick(index, row)"
  433. @close="tagItemDelete(index, row)"
  434. >
  435. {{ p }}
  436. </el-tag>
  437. </div>
  438. <!-- 公式字符串展示(只读) -->
  439. <el-input
  440. v-if="row.formulaParts && row.formulaParts.length"
  441. :value="row.formulaParts.join('')"
  442. size="mini"
  443. type="textarea"
  444. disabled
  445. placeholder="公式"
  446. style="margin-top: 6px"
  447. />
  448. </div>
  449. </template>
  450. <template v-slot:defaultValue="{ row }">
  451. <el-row>
  452. <el-col :span="12">
  453. <!-- <el-select
  454. v-if="row.paramType != 7"
  455. v-model="row.symbol"
  456. placeholder="请选择"
  457. size="mini"
  458. >
  459. <el-option label=">" value=">"> </el-option>
  460. <el-option label="<" value="<"> </el-option>
  461. <el-option label="!=" value="!="> </el-option>
  462. <el-option label=">=" value=">="> </el-option>
  463. <el-option label="<=" value="<="> </el-option>
  464. <el-option label="~~" value="~~"> </el-option>
  465. <el-option label="+-" value="+-"> </el-option>
  466. <el-option label="......" value="......"> </el-option>
  467. </el-select> -->
  468. <DictSelection
  469. v-if="row.paramType != 7"
  470. clearable
  471. dictName="数学字符"
  472. v-model="row.symbol"
  473. placeholder="请选择逻辑"
  474. size="mini"
  475. ></DictSelection>
  476. </el-col>
  477. <el-col :span="row.paramType != 7 ? 12 : 24">
  478. <el-input
  479. v-model="row.defaultValue"
  480. placeholder="请输入默认值"
  481. size="mini"
  482. ></el-input>
  483. </el-col>
  484. </el-row>
  485. </template>
  486. <template v-slot:maxValue="{ row }">
  487. <el-input
  488. v-if="row.paramType == 3 || row.paramType == 6"
  489. v-model="row.maxValue"
  490. placeholder="请输入参数上限"
  491. size="mini"
  492. ></el-input>
  493. </template>
  494. <template v-slot:minValue="{ row }">
  495. <el-input
  496. v-if="row.paramType == 3 || row.paramType == 6"
  497. v-model="row.minValue"
  498. placeholder="请输入参数下限"
  499. size="mini"
  500. ></el-input>
  501. </template>
  502. <template v-slot:unitName="{ row }">
  503. <!-- <el-input
  504. v-model="row.unitName"
  505. placeholder="请输入参数单位"
  506. size="mini"
  507. ></el-input> -->
  508. <DictSelection
  509. v-if="row.paramType != 7"
  510. dictName="工艺参数单位"
  511. clearable
  512. filterable
  513. v-model="row.unitName"
  514. size="mini"
  515. >
  516. </DictSelection>
  517. </template>
  518. <template v-slot:toolName="{ row }">
  519. <el-link :underline="false" style="cursor: pointer">
  520. <div class="ele-cell">
  521. <div @click="handleAdd(row)">
  522. {{
  523. row.tools && row.tools.length > 0
  524. ? row.tools.map((i) => i.toolName).join(',')
  525. : '请选择'
  526. }}
  527. </div>
  528. <i
  529. v-if="row.tools.length == 0"
  530. class="el-icon-arrow-down"
  531. @click="handleAdd(row)"
  532. ></i>
  533. <i v-else class="el-icon-close" @click="clearTool(row)"></i>
  534. </div>
  535. </el-link>
  536. </template>
  537. <template v-slot:toolCodes="{ row }">
  538. <el-input
  539. :value="
  540. row.tools && row.tools.length > 0
  541. ? row.tools.map((i) => i.toolCode).join(',')
  542. : ''
  543. "
  544. placeholder="工具自动带出"
  545. disabled
  546. size="mini"
  547. ></el-input>
  548. </template>
  549. <template v-slot:remark="{ row }">
  550. <el-input
  551. v-model="row.remark"
  552. placeholder="请输入"
  553. size="mini"
  554. ></el-input>
  555. </template>
  556. <template v-slot:action="{ row }">
  557. <el-link
  558. v-if="type != 'detail'"
  559. type="danger"
  560. :underline="false"
  561. icon="el-icon-delete"
  562. @click="deleteRow(row)"
  563. >
  564. 删除
  565. </el-link>
  566. </template>
  567. </ele-pro-table>
  568. <header-title
  569. :title="
  570. formData.reportWorkType == 5
  571. ? '实验过程'
  572. : formData.reportWorkType == 6
  573. ? '工艺要求'
  574. : formData.reportWorkType == 7
  575. ? '实验记录'
  576. : ''
  577. "
  578. v-if="qmsReportWorkType.includes(formData.reportWorkType)"
  579. >
  580. </header-title>
  581. <experimentationProcess
  582. :edit="type!='detail'"
  583. v-if="qmsReportWorkType.includes(formData.reportWorkType)"
  584. ref="experimentationProcess"
  585. ></experimentationProcess>
  586. </el-form>
  587. <template v-slot:footer>
  588. <el-button
  589. v-if="type != 'detail' && type != 'processEdit'"
  590. :loading="btnLoading"
  591. type="primary"
  592. @click="saveAndPublish"
  593. >
  594. 保存并发布
  595. </el-button>
  596. <el-button
  597. v-if="type != 'detail' && type != 'processEdit'"
  598. :loading="btnLoading"
  599. type="primary"
  600. @click="confirm"
  601. >
  602. 保存
  603. </el-button>
  604. <el-button
  605. v-if="type == 'processEdit'"
  606. :loading="btnLoading"
  607. type="primary"
  608. @click="processEditSave"
  609. >
  610. 保存
  611. </el-button>
  612. <el-button :loading="btnLoading" @click="handleClose">取消</el-button>
  613. </template>
  614. <toolModal ref="toolModalRef" @chooseModal="chooseModal" />
  615. <toolModal
  616. ref="toolModalTowRef"
  617. @chooseModal="chooseModalProduct"
  618. :multiple="false"
  619. />
  620. <MaterialAdd
  621. ref="deviceSelectDialog"
  622. selectType="single"
  623. @chooseEquipment="chooseEquipment"
  624. :multiple="false"
  625. />
  626. <ProductModal
  627. ref="ProductModalRef"
  628. @changeProduct="changeProduct"
  629. ></ProductModal>
  630. <processModal
  631. ref="processModalRef"
  632. @chooseProcess="processChooseProcess"
  633. ></processModal>
  634. </ele-modal>
  635. </template>
  636. <script>
  637. import { getByCode } from '@/api/system/dictionary-data';
  638. // import RuleCycle from '../../matterRules/components/rule-cycle.vue';
  639. import RuleCycle from './rule-cycle.vue';
  640. import OperationGuideDialog from '@/views/rulesManagement/matterRules/components/operationGuideDialog.vue';
  641. import Details from './details.vue';
  642. import dictMixins from '@/mixins/dictMixins';
  643. import toolModal from './toolModal.vue';
  644. import MaterialAdd from '../../components/MaterialAdd.vue';
  645. import {
  646. recordrulesSave,
  647. recordrulesDetailPage,
  648. recordrulesUpdate,
  649. recordrulesPublish,
  650. recordrulesSaveAndPublish,
  651. recordrulesUpdateVersion,
  652. recordrulesCyclePage,
  653. recordrulesGetById,
  654. recordrulesTypePage
  655. } from '@/api/recordrules/index';
  656. import ProductModal from '@/components/selectProduct/ProductModal.vue';
  657. import { getTreeByPid } from '@/api/classifyManage';
  658. import processModal from './processModal.vue';
  659. import experimentationProcess from './experimentationProcess.vue';
  660. import ProductModalCorrelation from './ProductModal.vue';
  661. import { recordrulesexecutemethodPage } from '@/api/recordrulesexecutemethod/index';
  662. import { businessTypeList } from '@/views/regulationManagement/components/util';
  663. export default {
  664. mixins: [dictMixins],
  665. components: {
  666. OperationGuideDialog,
  667. RuleCycle,
  668. Details,
  669. ProductModal,
  670. MaterialAdd,
  671. toolModal,
  672. processModal,
  673. ProductModalCorrelation,
  674. experimentationProcess
  675. },
  676. props: {
  677. typeInfo: {
  678. type: Object,
  679. default: () => null
  680. }
  681. },
  682. computed: {
  683. bankColumns() {
  684. const list = [
  685. {
  686. width: 110,
  687. type: 'index',
  688. columnKey: 'index',
  689. align: 'center',
  690. label: '序号'
  691. },
  692. {
  693. prop: 'sortNum',
  694. label: '排序',
  695. align: 'center',
  696. slot: 'sortNum',
  697. minWidth: 110
  698. },
  699. {
  700. prop: 'paramType',
  701. label: '参数类型',
  702. align: 'center',
  703. slot: 'paramType',
  704. minWidth: 110
  705. },
  706. {
  707. prop: 'paramValue',
  708. label: '参数内容',
  709. align: 'center',
  710. slot: 'paramValue',
  711. minWidth: 261
  712. },
  713. {
  714. prop: 'formula',
  715. label: '计算公式',
  716. align: 'center',
  717. slot: 'formula',
  718. minWidth: 300
  719. },
  720. {
  721. prop: 'defaultValue',
  722. label: '默认值',
  723. align: 'center',
  724. slot: 'defaultValue',
  725. minWidth: 150
  726. },
  727. {
  728. prop: 'maxValue',
  729. label: '参数上限',
  730. align: 'center',
  731. slot: 'maxValue',
  732. minWidth: 110
  733. },
  734. {
  735. prop: 'minValue',
  736. label: '参数下限',
  737. align: 'center',
  738. slot: 'minValue',
  739. minWidth: 110
  740. },
  741. {
  742. prop: 'unitName',
  743. label: '参数单位',
  744. align: 'center',
  745. slot: 'unitName',
  746. minWidth: 110
  747. },
  748. {
  749. prop: 'toolName',
  750. label: '工具名称',
  751. align: 'center',
  752. slot: 'toolName',
  753. minWidth: 110
  754. },
  755. {
  756. prop: 'toolCodes',
  757. label: '工具编码',
  758. align: 'center',
  759. slot: 'toolCodes',
  760. minWidth: 110
  761. },
  762. {
  763. prop: 'remark',
  764. label: '备注',
  765. align: 'center',
  766. slot: 'remark',
  767. minWidth: 110
  768. },
  769. {
  770. columnKey: 'action',
  771. label: '操作',
  772. width: 110,
  773. align: 'center',
  774. resizable: false,
  775. slot: 'action',
  776. fixed: 'right'
  777. }
  778. ];
  779. if (this.formData.recordTemplateStyle != '4') {
  780. // 过滤掉 计算公式 列
  781. return list.filter((i) => i.prop != 'formula');
  782. }
  783. return list;
  784. },
  785. versionText() {
  786. if (this.type == 'change') {
  787. return '系统自动生成';
  788. }
  789. return (
  790. this.formData.bigVersion +
  791. this.formData.versionMark +
  792. this.formData.smallVersion
  793. );
  794. },
  795. productColumns() {
  796. return [
  797. {
  798. columnKey: 'index',
  799. type: 'index',
  800. width: 45,
  801. align: 'center',
  802. reserveSelection: true
  803. },
  804. {
  805. prop: 'code',
  806. label: '产品编码'
  807. },
  808. {
  809. prop: 'name',
  810. label: '产品名称',
  811. showOverflowTooltip: true
  812. },
  813. {
  814. prop: 'brandNum',
  815. label: '牌号'
  816. },
  817. {
  818. prop: 'modelType',
  819. label: '型号'
  820. },
  821. {
  822. prop: 'specification',
  823. label: '规格'
  824. },
  825. {
  826. prop: 'measuringUnit',
  827. label: '计量单位'
  828. },
  829. {
  830. prop: 'packingUnit',
  831. label: '包装单位'
  832. },
  833. {
  834. columnKey: 'action',
  835. label: '操作',
  836. width: 110,
  837. align: 'center',
  838. resizable: false,
  839. slot: 'action',
  840. fixed: 'right'
  841. }
  842. ];
  843. },
  844. cacheKeyUrl() {
  845. return `main-permit-add-2510181429-reportWorkType`;
  846. },
  847. detialsDatasource() {
  848. if (this.formData.recordTemplateStyle == '4') {
  849. // 根据 statisticsType 过滤
  850. return this.formData.details.filter(
  851. (i) => i.statisticsType == this.statisticsType
  852. );
  853. } else {
  854. return this.formData.details;
  855. }
  856. },
  857. // 根据typeList 计算行业类型列表
  858. // {
  859. // "id": "1991058936943173633",
  860. // "createTime": "2025-11-19 16:20:17",
  861. // "createUserId": "1881891196703911938",
  862. // "industryType": 1,
  863. // "industryName": "工程机械",
  864. // "businessType": 1,
  865. // "businessName": "生产",
  866. // "reportWorkType": 1,
  867. // "reportWorkName": "产前准备",
  868. // "sceneType": 1,
  869. // "sceneName": "清场清洁",
  870. // "templateStyleType": 1,
  871. // "templateStyleName": "通用模板",
  872. // "tenantId": "1",
  873. // "deptId": "1",
  874. // "factoriesId": "1916747066214232065"
  875. // }
  876. industryTypeList() {
  877. const seen = new Set();
  878. const res = [];
  879. for (const i of this.typeList || []) {
  880. const key = String(i.industryType);
  881. if (!seen.has(key)) {
  882. seen.add(key);
  883. res.push({
  884. label: i.industryName,
  885. value: key
  886. });
  887. }
  888. }
  889. return res;
  890. },
  891. // 根据typeList和formData.industryType计算业务分类列表
  892. businessTypeList() {
  893. const seen = new Set();
  894. const res = [];
  895. const list = this.typeList.filter(
  896. (i) => i.industryType == this.formData.industryType
  897. );
  898. for (const i of list || []) {
  899. const key = String(i.businessType);
  900. if (!seen.has(key)) {
  901. seen.add(key);
  902. res.push({
  903. label: i.businessName,
  904. value: key
  905. });
  906. }
  907. }
  908. return res;
  909. },
  910. // 根据typeList和formData.industryType、formData.businessType计算模块划分列表
  911. reportWorkTypeList() {
  912. const seen = new Set();
  913. const res = [];
  914. const list = this.typeList.filter(
  915. (i) =>
  916. i.industryType == this.formData.industryType &&
  917. i.businessType == this.formData.businessType
  918. );
  919. for (const i of list || []) {
  920. const key = String(i.reportWorkType);
  921. if (!seen.has(key)) {
  922. seen.add(key);
  923. res.push({
  924. label: i.reportWorkName,
  925. value: key
  926. });
  927. }
  928. }
  929. return res;
  930. },
  931. // 根据typeList和formData.industryType、formData.businessType、formData.reportWorkType计算应用场景列表
  932. classifyList() {
  933. const seen = new Set();
  934. const res = [];
  935. const list = this.typeList.filter(
  936. (i) =>
  937. i.industryType == this.formData.industryType &&
  938. i.businessType == this.formData.businessType &&
  939. i.reportWorkType == this.formData.reportWorkType
  940. );
  941. for (const i of list || []) {
  942. const key = String(i.sceneType);
  943. if (!seen.has(key)) {
  944. seen.add(key);
  945. res.push({
  946. label: i.sceneName,
  947. value: key
  948. });
  949. }
  950. }
  951. return res;
  952. },
  953. // 根据typeList和formData.industryType、formData.businessType、formData.reportWorkType、formData.classify计算模板样式列表
  954. recordTemplateStyleList() {
  955. const seen = new Set();
  956. const res = [];
  957. const list = this.typeList.filter(
  958. (i) =>
  959. i.industryType == this.formData.industryType &&
  960. i.businessType == this.formData.businessType &&
  961. i.reportWorkType == this.formData.reportWorkType &&
  962. i.sceneType == this.formData.classify
  963. );
  964. for (const i of list || []) {
  965. const key = String(i.templateStyleType);
  966. if (!seen.has(key)) {
  967. seen.add(key);
  968. res.push({
  969. label: i.templateStyleName,
  970. value: key
  971. });
  972. }
  973. }
  974. return res;
  975. }
  976. },
  977. data() {
  978. const formDateBase = {
  979. id: null,
  980. deviceId: null,
  981. deviceName: '',
  982. frequencyUnit: 2,
  983. frequencyValue: null,
  984. name: '',
  985. details: [],
  986. recordRulesCycleList: [],
  987. startDate: null,
  988. stopDate: null,
  989. version: 1,
  990. code: '',
  991. fromId: null,
  992. // 行业类型
  993. industryType: null,
  994. // 业务分类
  995. businessType: null,
  996. // 记录规则类型|应用场景
  997. classify: null,
  998. // 模块分类 参考字典项:record_rules_report_work_type
  999. reportWorkType: null,
  1000. // 模板样式
  1001. recordTemplateStyle: null,
  1002. // 执行方式
  1003. isExecuteMethod: 0,
  1004. executeMethodId: null,
  1005. executeMethodName: '',
  1006. produceTaskConfigs: [],
  1007. bigVersion: '',
  1008. versionMark: '',
  1009. smallVersion: '',
  1010. produceTaskId: '',
  1011. produceTaskName: ''
  1012. };
  1013. return {
  1014. qmsReportWorkType: ['5', '6', '7'],
  1015. dialogTitle: '',
  1016. visible: false,
  1017. formDateBase,
  1018. formData: JSON.parse(JSON.stringify(formDateBase)),
  1019. formRules: {
  1020. name: [
  1021. { required: true, message: '请输入名称', trigger: 'blur' }
  1022. ],
  1023. frequencyValue: [
  1024. { required: true, message: '请选择周期', trigger: 'blur' },
  1025. { required: true, message: '请选择周期', trigger: 'change' }
  1026. ],
  1027. frequencyUnit: [
  1028. { required: true, message: '请选择频率单位', trigger: 'change' }
  1029. ],
  1030. classify: [
  1031. { required: true, message: '请选择规则类型', trigger: 'change' }
  1032. ],
  1033. // startDate 启用日期要大于当前时间
  1034. // stopDate 停用时间要大于当前时间并且大于启用日期
  1035. // startDate: [
  1036. // { required: true, message: '请选择启用日期', trigger: 'blur' },
  1037. // { required: true, message: '请选择启用日期', trigger: 'change' },
  1038. // { validator: this.validateStartDate, trigger: 'change' }
  1039. // ],
  1040. // stopDate: [
  1041. // { required: true, message: '请选择停用时间', trigger: 'change' },
  1042. // { validator: this.validateStopDate, trigger: 'change' }
  1043. // ],
  1044. deviceName: [
  1045. { required: true, message: '请输入选择设备', trigger: 'blur' }
  1046. ],
  1047. businessType: [
  1048. { required: true, message: '请选择业务分类', trigger: 'blur' },
  1049. { required: true, message: '请选择业务分类', trigger: 'change' }
  1050. ],
  1051. industryType: [
  1052. { required: true, message: '请选择业行业类别', trigger: 'blur' },
  1053. { required: true, message: '请选择业行业类别', trigger: 'change' }
  1054. ],
  1055. reportWorkType: [
  1056. { required: true, message: '请选择业模块划分', trigger: 'blur' },
  1057. { required: true, message: '请选择业模块划分', trigger: 'change' }
  1058. ],
  1059. classify: [
  1060. { required: true, message: '请选择应用场景', trigger: 'blur' },
  1061. { required: true, message: '请选择应用场景', trigger: 'change' }
  1062. ],
  1063. recordTemplateStyle: [
  1064. { required: true, message: '请选择模板样式', trigger: 'blur' },
  1065. { required: true, message: '请选择模板样式', trigger: 'change' }
  1066. ],
  1067. executeMethodId: [
  1068. { required: true, message: '请选择执行方式', trigger: 'change' },
  1069. { required: true, message: '请选择执行方式', trigger: 'blur' }
  1070. ]
  1071. },
  1072. recordSheet: [], // 记录表
  1073. current: {},
  1074. dataIndex: null,
  1075. showEdit: false,
  1076. btnLoading: false,
  1077. currentRow: null,
  1078. type: '',
  1079. // 产品分类
  1080. productCategory: [],
  1081. loading: false,
  1082. produceTaskCode: '',
  1083. // 执行方式列表
  1084. executeMethodList: [],
  1085. // 1-成品统计,2-物料统计,3-工序统计"
  1086. statisticsType: '1',
  1087. statisticsTypeList: [
  1088. { label: '成品统计', value: '1' },
  1089. { label: '物料统计', value: '2' },
  1090. { label: '工序统计', value: '3' }
  1091. ],
  1092. opSelectOptions: ['+', '-', '*', '/', '%', '(', ')'],
  1093. typeList: []
  1094. };
  1095. },
  1096. mounted() {
  1097. this.getByCodeData();
  1098. this.getProductCategory();
  1099. console.log('this.formData 2233', this.formData);
  1100. this.getTypeList();
  1101. },
  1102. methods: {
  1103. open(row, type, title) {
  1104. this.dialogTitle = title;
  1105. this.type = type;
  1106. console.log('type', type, row);
  1107. this.getTypeList();
  1108. if (
  1109. type == 'edit' ||
  1110. type == 'detail' ||
  1111. type == 'change' ||
  1112. type == 'clone'
  1113. ) {
  1114. this.getDetils(row.id);
  1115. }
  1116. // 过程控制临时修改
  1117. if (type == 'processEdit') {
  1118. this.processEditSetValue(row);
  1119. }
  1120. if (type == 'add') {
  1121. this.formData.version = 1;
  1122. // 启用日期 默认为 今天
  1123. this.formData.startDate = new Date();
  1124. // 停用日期 默认为 2099-12-31
  1125. this.formData.stopDate = new Date('2099-12-31 00:00:00');
  1126. console.log('this.typeInfo', this.typeInfo);
  1127. // 类型
  1128. if (this.typeInfo) {
  1129. const node = this.typeInfo;
  1130. const item = node.item || node;
  1131. switch (node.type) {
  1132. case 'industry':
  1133. this.formData.industryType = item.industryType + '';
  1134. break;
  1135. case 'business':
  1136. this.formData.industryType = item.industryType + '';
  1137. this.formData.businessType = item.businessType + '';
  1138. break;
  1139. case 'reportWork':
  1140. this.formData.industryType = item.industryType + '';
  1141. this.formData.businessType = item.businessType + '';
  1142. this.formData.reportWorkType = item.reportWorkType + '';
  1143. break;
  1144. case 'scene':
  1145. this.formData.industryType = item.industryType + '';
  1146. this.formData.businessType = item.businessType + '';
  1147. this.formData.reportWorkType = item.reportWorkType + '';
  1148. this.formData.classify = item.sceneType + '';
  1149. break;
  1150. case 'templateStyle':
  1151. this.formData.industryType = item.industryType + '';
  1152. this.formData.businessType = item.businessType + '';
  1153. this.formData.reportWorkType = item.reportWorkType + '';
  1154. this.formData.classify = item.sceneType + '';
  1155. this.formData.recordTemplateStyle = item.templateStyleType + '';
  1156. break;
  1157. default:
  1158. // 直接赋值所有可用字段(兜底)
  1159. if (item.industryType != null)
  1160. this.formData.industryType = item.industryType + '';
  1161. if (item.businessType != null)
  1162. this.formData.businessType = item.businessType + '';
  1163. if (item.reportWorkType != null)
  1164. this.formData.reportWorkType = item.reportWorkType + '';
  1165. if (item.sceneType != null)
  1166. this.formData.classify = item.sceneType + '';
  1167. if (item.templateStyleType != null)
  1168. this.formData.recordTemplateStyle =
  1169. item.templateStyleType + '';
  1170. break;
  1171. }
  1172. }
  1173. }
  1174. this.visible = true;
  1175. console.log('this.formData', this.formData);
  1176. },
  1177. // 过程控制 修改规则详情
  1178. async processEditSetValue(row) {
  1179. const data = await recordrulesGetById(row.rulesId);
  1180. const info = JSON.parse(JSON.stringify(row));
  1181. data.details = info.produceTaskConfigRuleDetails;
  1182. // 处理详情的 公式 字段
  1183. data.details.forEach((item) => {
  1184. if (item.paramType == 9 && item.formula) {
  1185. // formula格式为[A][+][b][*][C] 拆分 -> ['A','+','b','*','C']
  1186. if (item.formula) {
  1187. const matches = item.formula.match(/\[([^\]]+)\]/g);
  1188. if (matches) {
  1189. this.$set(
  1190. item,
  1191. 'formulaParts',
  1192. matches.map((m) => m.slice(1, -1)).filter(Boolean)
  1193. );
  1194. }
  1195. } else {
  1196. this.$set(item, 'formulaParts', []);
  1197. }
  1198. }
  1199. });
  1200. this.$util.assignObject(this.formData, data);
  1201. this.$nextTick(() => {
  1202. this.$refs.cycleMultipleRef?.setRecordRulesCycleList(
  1203. this.formData.recordRulesCycleList
  1204. );
  1205. });
  1206. this.formData.executeMethodId = info.recordRulesExecuteMethodId;
  1207. this.formData.executeMethodName = info.recordRulesExecuteMethodName;
  1208. this.formData.startDate = new Date(info.startDate);
  1209. this.formData.stopDate = new Date(info.stopDate);
  1210. this.formData.classify = this.formData.classify + '';
  1211. this.formData.reportWorkType = this.formData.reportWorkType + '';
  1212. this.formData.industryType = this.formData.industryType + '';
  1213. this.formData.businessType = this.formData.businessType + '';
  1214. this.formData.reportWorkType = this.formData.reportWorkType + '';
  1215. this.formData.recordTemplateStyle =
  1216. this.formData.recordTemplateStyle + '';
  1217. console.log('this.formData~~~~', this.formData);
  1218. this.getExecuteMethodList();
  1219. this.loading = false;
  1220. },
  1221. async getDetils(id) {
  1222. this.loading = true;
  1223. try {
  1224. const data = await recordrulesGetById(id);
  1225. this.$util.assignObject(this.formData, data);
  1226. this.$nextTick(() => {
  1227. this.$refs.cycleMultipleRef?.setRecordRulesCycleList(
  1228. this.formData.recordRulesCycleList
  1229. );
  1230. if (this.qmsReportWorkType.includes(this.formData.reportWorkType)) {
  1231. this.$refs.experimentationProcess.init(data.tempJson.tempJson);
  1232. }
  1233. });
  1234. this.formData.startDate = new Date(data.startDate);
  1235. this.formData.stopDate = new Date(data.stopDate);
  1236. this.formData.classify = this.formData.classify + '';
  1237. this.formData.industryType = this.formData.industryType + '';
  1238. this.formData.businessType = this.formData.businessType + '';
  1239. this.formData.reportWorkType = this.formData.reportWorkType + '';
  1240. this.formData.recordTemplateStyle =
  1241. this.formData.recordTemplateStyle + '';
  1242. if (this.type == 'change') {
  1243. this.formData.fromId = id;
  1244. this.formData.id = null;
  1245. }
  1246. if (this.type == 'clone') {
  1247. this.formData.fromId = null;
  1248. this.formData.id = null;
  1249. this.formData.produceTaskId = null;
  1250. this.formData.produceTaskName = null;
  1251. this.formData.executeMethodId = null;
  1252. this.formData.executeMethodName = '';
  1253. this.executeMethodList = [];
  1254. // startDate 小于当前日期则取当前日期
  1255. const now = new Date();
  1256. if (this.formData.startDate < now) {
  1257. this.formData.startDate = now;
  1258. }
  1259. } else {
  1260. this.getExecuteMethodList();
  1261. }
  1262. // 处理详情的 公式 字段
  1263. this.formData.details.forEach((item) => {
  1264. if (item.paramType == 9 && item.formula) {
  1265. // formula格式为[A][+][b][*][C] 拆分 -> ['A','+','b','*','C']
  1266. if (item.formula) {
  1267. const matches = item.formula.match(/\[([^\]]+)\]/g);
  1268. if (matches) {
  1269. this.$set(
  1270. item,
  1271. 'formulaParts',
  1272. matches.map((m) => m.slice(1, -1)).filter(Boolean)
  1273. );
  1274. }
  1275. } else {
  1276. this.$set(item, 'formulaParts', []);
  1277. }
  1278. this.$set(item, '_paramSelect', null);
  1279. this.$set(item, '_opSelect', null);
  1280. this.$set(item, '_replaceOrAppend', '');
  1281. }
  1282. });
  1283. this.loading = false;
  1284. } catch (error) {
  1285. console.log(error, 'error');
  1286. this.loading = false;
  1287. }
  1288. },
  1289. async getByCodeData() {
  1290. let res = await getByCode('record_sheet');
  1291. let list = res.data.map((item) => {
  1292. let values = Object.keys(item);
  1293. return {
  1294. value: values[0],
  1295. label: item[values[0]]
  1296. };
  1297. });
  1298. this.recordSheet = list;
  1299. console.log('this.recordSheet', this.recordSheet);
  1300. },
  1301. itemDel(index) {
  1302. this.formData.details.splice(index, 1);
  1303. },
  1304. /* 打开操作手册编辑款 */
  1305. openOperationGuideDialogDialog(row, index) {
  1306. this.$refs.operationGuideDialog.open(row, index);
  1307. },
  1308. handleClose() {
  1309. // 清空表单数据
  1310. this.formData = JSON.parse(JSON.stringify(this.formDateBase));
  1311. this.executeMethodList = [];
  1312. this.$refs['formRef'].resetFields();
  1313. this.visible = false;
  1314. },
  1315. // 保存
  1316. confirm() {
  1317. console.log('this.formData', this.formData);
  1318. // 验证表单规则
  1319. this.$refs.formRef.validate(async (valid) => {
  1320. if (!valid) {
  1321. return false;
  1322. }
  1323. if (
  1324. this.formData.details.length == 0 &&
  1325. !this.qmsReportWorkType.includes(this.formData.reportWorkType)
  1326. ) {
  1327. return this.$message.warning('至少条件一条规则项');
  1328. }
  1329. try {
  1330. const valid = this.validateFormula();
  1331. if (!valid) {
  1332. return;
  1333. }
  1334. this.btnLoading = true;
  1335. const body = this.formatBody();
  1336. if (this.type == 'add' || this.type == 'clone') {
  1337. await recordrulesSave(body);
  1338. } else if (this.type == 'change') {
  1339. await recordrulesUpdateVersion(body);
  1340. } else {
  1341. // 编辑
  1342. body.fromId = null;
  1343. await recordrulesUpdate(body);
  1344. }
  1345. this.btnLoading = false;
  1346. this.$message.success('操作成功');
  1347. this.handleClose();
  1348. this.$emit('reload');
  1349. this.$emit('reloadTypeList');
  1350. } catch (error) {
  1351. console.log(error, 'dasda');
  1352. this.btnLoading = false;
  1353. }
  1354. });
  1355. },
  1356. // 保存并发布
  1357. saveAndPublish() {
  1358. // 验证表单规则
  1359. this.$refs.formRef.validate(async (valid) => {
  1360. if (!valid) {
  1361. return false;
  1362. }
  1363. if (!this.qmsReportWorkType.includes(this.formData.reportWorkType)) {
  1364. if (this.formData.details.length == 0) {
  1365. return this.$message.warning('至少条件一条规则项');
  1366. }
  1367. if (this.formData.reportWorkType == 4) {
  1368. // 生产统计过滤掉非成品统计的明细
  1369. this.formData.details = this.formData.details.filter(
  1370. (i) => i.statisticsType
  1371. );
  1372. }
  1373. // 判断参数类型是否选择
  1374. for (const detail of this.formData.details) {
  1375. if (!detail.paramType) {
  1376. console.log('detail', detail);
  1377. return this.$message.warning('请选择规则明细中的参数类型!');
  1378. }
  1379. }
  1380. }
  1381. try {
  1382. this.btnLoading = true;
  1383. const body = this.formatBody();
  1384. if (this.type != 'saveAndPublish') {
  1385. await recordrulesSaveAndPublish(body);
  1386. } else {
  1387. this.$emit('processSave', body);
  1388. }
  1389. this.btnLoading = false;
  1390. this.$message.success('操作成功');
  1391. this.handleClose();
  1392. this.$emit('reload');
  1393. } catch (error) {
  1394. console.log(error, 'error');
  1395. this.btnLoading = false;
  1396. }
  1397. });
  1398. },
  1399. // 保存或发布时验证公式是否正确
  1400. validateFormula() {
  1401. let invalid = false;
  1402. this.formData.details.forEach((detail) => {
  1403. if (invalid) return; // 已发现无效,后续直接跳过避免重复提示
  1404. if (detail.paramType == 9) {
  1405. const formula = detail.formula;
  1406. if (!formula || !formula.trim()) {
  1407. console.log('formula', formula);
  1408. this.$message.warning('规则明细中计算类型的公式不能为空!');
  1409. invalid = true;
  1410. }
  1411. // 解析公式为 token 列表
  1412. const rawTokens = (formula.match(/\[([^\]]+)\]/g) || [])
  1413. .map((m) => m.slice(1, -1))
  1414. .filter(Boolean);
  1415. if (!rawTokens.length) {
  1416. console.log('rawTokens', rawTokens, formula);
  1417. this.$message.warning('规则明细中计算类型的公式不能为空!');
  1418. invalid = true;
  1419. return;
  1420. }
  1421. const operators = new Set(this.opSelectOptions);
  1422. const availableParams = this.formData.details
  1423. .filter((d) => d !== detail && d.paramType != 9 && d.paramValue)
  1424. .map((d) => d.paramValue);
  1425. const varsSet = new Set();
  1426. let parenBalance = 0;
  1427. let lastWasOperator = true; // 开头不能是普通数字/变量
  1428. let expression = '';
  1429. for (let i = 0; i < rawTokens.length; i++) {
  1430. const t = rawTokens[i];
  1431. if (invalid) break;
  1432. if (operators.has(t)) {
  1433. // 括号
  1434. if (t === '(') {
  1435. parenBalance++;
  1436. lastWasOperator = true;
  1437. } else if (t === ')') {
  1438. parenBalance--;
  1439. if (parenBalance < 0) {
  1440. this.$message.warning('公式括号不匹配');
  1441. invalid = true;
  1442. break;
  1443. }
  1444. lastWasOperator = false;
  1445. } else {
  1446. // 普通运算符不能连续出现
  1447. if (lastWasOperator) {
  1448. this.$message.warning('公式存在连续运算符或位置不合法');
  1449. invalid = true;
  1450. break;
  1451. }
  1452. lastWasOperator = true;
  1453. }
  1454. expression += t;
  1455. } else {
  1456. // 变量
  1457. if (!t.trim()) {
  1458. this.$message.warning('公式中存在空变量');
  1459. invalid = true;
  1460. break;
  1461. }
  1462. // 变量前必须是运算符或者开头或左括号
  1463. if (!lastWasOperator) {
  1464. this.$message.warning('公式中变量之间缺少运算符');
  1465. invalid = true;
  1466. break;
  1467. }
  1468. varsSet.add(t);
  1469. // 校验变量是否存在于其他明细 排除要求生产数量
  1470. if (!availableParams.includes(t) && t != '要求生产数量') {
  1471. this.$message.warning(
  1472. `公式中引用的参数 "${t}" 未在非计算类型的明细中定义`
  1473. );
  1474. invalid = true;
  1475. break;
  1476. }
  1477. // 用顺序数字替换变量
  1478. expression += varsSet.size; // 1,2,3...
  1479. lastWasOperator = false;
  1480. }
  1481. }
  1482. if (invalid) return;
  1483. if (parenBalance !== 0) {
  1484. this.$message.warning('公式括号不匹配');
  1485. invalid = true;
  1486. return;
  1487. }
  1488. if (lastWasOperator) {
  1489. this.$message.warning('公式不能以运算符结尾');
  1490. invalid = true;
  1491. return;
  1492. }
  1493. // 最终表达式字符合法性校验
  1494. if (!/^[0-9+\-*/%() ]+$/.test(expression)) {
  1495. this.$message.warning('公式包含非法字符');
  1496. invalid = true;
  1497. return;
  1498. }
  1499. // 计算测试
  1500. try {
  1501. const result = Function(`"use strict";return (${expression})`)();
  1502. if (Number.isNaN(result) || !isFinite(result)) {
  1503. this.$message.warning('公式计算结果非法');
  1504. invalid = true;
  1505. return;
  1506. }
  1507. } catch (e) {
  1508. this.$message.warning('公式计算失败,请检查语法');
  1509. invalid = true;
  1510. return;
  1511. }
  1512. // 回填拆分后的 parts
  1513. detail.formulaParts = rawTokens;
  1514. }
  1515. });
  1516. if (invalid) {
  1517. return false;
  1518. }
  1519. return true;
  1520. },
  1521. // 数据格式化
  1522. formatBody() {
  1523. this.formData.recordRulesCycleList =
  1524. this.$refs.cycleMultipleRef &&
  1525. this.$refs.cycleMultipleRef.recordRulesCycleList
  1526. .map((i) => {
  1527. // 根据月日时分排序计算权重排序
  1528. let sortNum = 0;
  1529. if (i.month) {
  1530. sortNum += i.month * 60 * 24 * 30;
  1531. }
  1532. if (i.day) {
  1533. sortNum += i.day * 60 * 24;
  1534. }
  1535. if (i.hour) {
  1536. sortNum += i.hour * 60;
  1537. }
  1538. if (i.minute) {
  1539. sortNum += i.minute * 1;
  1540. }
  1541. return { ...i, sortNum };
  1542. })
  1543. .sort((a, b) => a.sortNum - b.sortNum)
  1544. .map((i, index) => {
  1545. return { ...i, sortNum: index + 1 };
  1546. });
  1547. const body = JSON.parse(JSON.stringify(this.formData));
  1548. body.startDate = this.$util.toDateString(
  1549. body.startDate,
  1550. 'yyyy-MM-dd HH:mm:ss'
  1551. );
  1552. body.stopDate = this.$util.toDateString(
  1553. body.stopDate,
  1554. 'yyyy-MM-dd HH:mm:ss'
  1555. );
  1556. if (this.qmsReportWorkType.includes(body.reportWorkType)) {
  1557. let tempJson = this.$refs.experimentationProcess.getValue();
  1558. if (tempJson) {
  1559. body.tempJson = {
  1560. tempJson: JSON.stringify(tempJson)
  1561. };
  1562. }
  1563. }
  1564. // details 根据下标添加 sortNum
  1565. body.details = body.details.map((item, index) => {
  1566. return { ...item };
  1567. });
  1568. return body;
  1569. },
  1570. // startDate 启用日期要大于当前时间
  1571. validateStartDate(rule, value, callback) {
  1572. const startDate = this.formData.startDate;
  1573. if (!startDate) {
  1574. return callback(new Error('启用日期不能为空'));
  1575. }
  1576. // 启用日期大于等于今天
  1577. // const today = new Date();
  1578. // today.setHours(0, 0, 0, 0); // 设置为当天的开始时间
  1579. // if (new Date(startDate) < today) {
  1580. // return callback(new Error('启用日期必须大于等于当前日期'));
  1581. // }
  1582. callback();
  1583. },
  1584. // stopDate 停用时间要大于当前时间并且大于启用日期
  1585. validateStopDate(rule, value, callback) {
  1586. const startDate = this.formData.startDate;
  1587. const stopDate = this.formData.stopDate;
  1588. if (
  1589. stopDate &&
  1590. startDate &&
  1591. new Date(stopDate) <= new Date(startDate)
  1592. ) {
  1593. return callback(new Error('停用时间必须大于启用日期'));
  1594. }
  1595. callback();
  1596. },
  1597. // 去选择设备
  1598. selectDeviceId() {
  1599. this.$refs.deviceSelectDialog.open([]);
  1600. },
  1601. // 选择设备回调
  1602. chooseEquipment(data, index, categoryId) {
  1603. console.log('data', data, index, categoryId);
  1604. this.formData.deviceId = data?.id || null;
  1605. this.formData.deviceName = data?.name || '';
  1606. },
  1607. // 添加
  1608. addRow() {
  1609. // 最大sortNum 值 +1
  1610. let sortNum = 1;
  1611. if (this.formData.details.length > 0) {
  1612. const maxSortNum = Math.max(
  1613. ...this.formData.details.map((item) => item.sortNum || 0)
  1614. );
  1615. sortNum = maxSortNum + 1;
  1616. }
  1617. this.formData.details.push({
  1618. id: new Date().getTime(),
  1619. defaultValue: '',
  1620. maxValue: null,
  1621. minValue: null,
  1622. paramType: null,
  1623. paramValue: null,
  1624. remark: '',
  1625. symbol: null,
  1626. tools: [],
  1627. unitName: null,
  1628. productName: '',
  1629. productCode: '',
  1630. // 1-成品统计,2-物料统计,3-工序统计"
  1631. statisticsType:
  1632. this.formData.recordTemplateStyle == '4'
  1633. ? this.statisticsType
  1634. : null,
  1635. // 公式
  1636. formula: '',
  1637. _paramSelect: null,
  1638. _opSelect: null,
  1639. _replaceOrAppend: '',
  1640. formulaParts: [],
  1641. sortNum
  1642. });
  1643. console.log('this.formData.details', this.formData.details);
  1644. },
  1645. deleteRow(row) {
  1646. const index = this.formData.details.indexOf(row);
  1647. if (index !== -1) {
  1648. this.formData.details.splice(index, 1);
  1649. }
  1650. },
  1651. handleAdd(row) {
  1652. this.currentRow = row;
  1653. this.$refs.toolModalRef.open(row.toolCodes);
  1654. },
  1655. chooseModal(data) {
  1656. console.log('data', data);
  1657. this.currentRow.tools = data.map((i) => {
  1658. return {
  1659. toolCode: i.code,
  1660. toolName: i.name
  1661. };
  1662. });
  1663. },
  1664. // 规则明细表
  1665. async recordrulesDetailPage(row) {
  1666. const { list } = await recordrulesDetailPage({
  1667. // deptId: row.deptId,
  1668. pageNum: 1,
  1669. rulesId: row.id,
  1670. size: 9999
  1671. });
  1672. console.log('list 数据', list);
  1673. this.formData.details = list;
  1674. },
  1675. // 清空工具
  1676. clearTool(row) {
  1677. row.tools = [];
  1678. },
  1679. // 查询 recordrulesCyclePage
  1680. async recordrulesCyclePage(row) {
  1681. const { list } = await recordrulesCyclePage({
  1682. pageNum: 1,
  1683. size: 9999,
  1684. recordRulesId: row.id,
  1685. orderBy: 'descending'
  1686. });
  1687. console.log('list 周期数据', list);
  1688. this.formData.recordRulesCycleList = list;
  1689. this.$nextTick(() => {
  1690. this.$refs.cycleMultipleRef.setRecordRulesCycleList(list);
  1691. });
  1692. },
  1693. // 去选择产品
  1694. selectProduct(row) {
  1695. this.currentRow = row;
  1696. this.$refs.ProductModalRef.open();
  1697. },
  1698. // 选择产品
  1699. changeProduct(current) {
  1700. console.log('current', current);
  1701. this.currentRow.productName = current.name;
  1702. this.currentRow.productCode = current.code;
  1703. },
  1704. // 选择物品 产品、物料等
  1705. selectChooseModalProduct(row) {
  1706. this.currentRow = row;
  1707. this.$refs.toolModalTowRef.open([], '选择物品');
  1708. },
  1709. chooseModalProduct(current) {
  1710. console.log('current', current);
  1711. this.currentRow.productName = current.name;
  1712. this.currentRow.productCode = current.code;
  1713. this.currentRow.unitName = current.weightUnit;
  1714. console.log('this.currentRow', this.currentRow);
  1715. },
  1716. // 清空产品
  1717. clearProduct(row) {
  1718. row.productName = '';
  1719. row.productCode = '';
  1720. },
  1721. // 获取产品分类
  1722. async getProductCategory() {
  1723. let { data } = await getTreeByPid(9);
  1724. console.log('产品分类', data);
  1725. this.productCategory = data;
  1726. },
  1727. // 选择工序
  1728. openProduceTaskDialog() {
  1729. this.$refs.processModalRef.open();
  1730. },
  1731. // 工序
  1732. processChooseProcess(process) {
  1733. console.log('选择的工序', process);
  1734. this.formData.produceTaskId = process.id;
  1735. this.formData.produceTaskName = process.name;
  1736. this.formData.executeMethodId = null;
  1737. this.formData.executeMethodName = '';
  1738. // 查询工序下的执行方式
  1739. this.getExecuteMethodList();
  1740. },
  1741. clearProductTask() {
  1742. this.formData.produceTaskId = '';
  1743. this.formData.produceTaskName = '';
  1744. this.formData.executeMethodId = null;
  1745. this.formData.executeMethodName = '';
  1746. this.executeMethodList = [];
  1747. },
  1748. // 查询执行方式
  1749. async getExecuteMethodList() {
  1750. if (
  1751. this.formData.produceTaskId == '' &&
  1752. this.formData.reportWorkType == 2
  1753. ) {
  1754. this.executeMethodList = [];
  1755. return;
  1756. }
  1757. const data = await recordrulesexecutemethodPage({
  1758. pageNum: 1,
  1759. size: 9999,
  1760. enable: 1,
  1761. produceTaskId: this.formData.produceTaskId
  1762. });
  1763. this.executeMethodList = data.list;
  1764. // 有执行方式
  1765. if (
  1766. this.executeMethodList.length &&
  1767. this.formData.reportWorkType == 2
  1768. ) {
  1769. this.formData.isExecuteMethod = 1;
  1770. }
  1771. },
  1772. // 过程控制修改 保存
  1773. processEditSave() {
  1774. // 只验证详情内容
  1775. if (!this.qmsReportWorkType.includes(this.formData.reportWorkType)) {
  1776. if (this.formData.details.length == 0) {
  1777. return this.$message.warning('至少条件一条规则项');
  1778. }
  1779. // 判断参数类型是否选择
  1780. for (const detail of this.formData.details) {
  1781. if (!detail.paramType) {
  1782. return this.$message.warning('请选择规则明细中的参数类型!');
  1783. }
  1784. }
  1785. }
  1786. this.$emit('processSave', this.formatBody());
  1787. this.handleClose();
  1788. },
  1789. // 执行方式改变 同步执行方式名称
  1790. executeMethodIdChange() {
  1791. const selected = this.executeMethodList.find(
  1792. (item) => item.id === this.formData.executeMethodId
  1793. );
  1794. if (selected) {
  1795. this.formData.executeMethodName = selected.name;
  1796. } else {
  1797. this.formData.executeMethodName = '';
  1798. }
  1799. },
  1800. isExecuteMethodChange() {
  1801. if (this.formData.isExecuteMethod == 0) {
  1802. this.formData.executeMethodId = null;
  1803. this.formData.executeMethodName = '';
  1804. }
  1805. },
  1806. classifyChagne() {
  1807. // 生产统计
  1808. if (this.formData.recordTemplateStyle == '4') {
  1809. // 模块分类- 生产统计
  1810. this.formData.reportWorkType = '4';
  1811. // 清空规则明细
  1812. this.formData.details = [];
  1813. // 重置统计类型
  1814. this.statisticsType = '1';
  1815. } else {
  1816. if (this.formData.reportWorkType == '4') {
  1817. this.formData.reportWorkType = '1';
  1818. }
  1819. }
  1820. },
  1821. // 基于详情返回selectOptions
  1822. getSelectOptionsByDetails(statisticsType) {
  1823. let paramTypeOptions = [];
  1824. for (const detail of this.formData.details.filter(
  1825. (i) => i.statisticsType == statisticsType
  1826. )) {
  1827. if (detail.paramType != 9 || !detail.paramType) {
  1828. paramTypeOptions.push({
  1829. value: detail.paramValue,
  1830. label: detail.paramValue
  1831. });
  1832. }
  1833. }
  1834. // 过滤空值
  1835. paramTypeOptions = paramTypeOptions.filter((i) => i.value);
  1836. // 追加一个 (要求生产数量)
  1837. paramTypeOptions.push({
  1838. value: '要求生产数量',
  1839. label: '要求生产数量'
  1840. });
  1841. return paramTypeOptions;
  1842. },
  1843. paramSelectChange(val, row) {
  1844. if (!val) return;
  1845. row.formulaParts = row.formulaParts || [];
  1846. if (row.activeIndex != undefined) {
  1847. if (!row._replaceOrAppend || row._replaceOrAppend === 'replace') {
  1848. row.formulaParts.splice(row.activeIndex, 1, val);
  1849. } else if (row._replaceOrAppend === 'append') {
  1850. row.formulaParts.splice(row.activeIndex + 1, 0, val);
  1851. // 追加后activeIndex后移一位
  1852. this.$set(row, 'activeIndex', row.activeIndex + 1);
  1853. }
  1854. // row.activeIndex = undefined;
  1855. } else {
  1856. row.formulaParts.push(val);
  1857. }
  1858. row.formula = row.formulaParts.map((p) => `[${p}]`).join('');
  1859. row._paramSelect = null;
  1860. },
  1861. opSelectChange(val, row) {
  1862. if (!val) return;
  1863. row.formulaParts = row.formulaParts || [];
  1864. if (row.activeIndex != undefined) {
  1865. if (!row._replaceOrAppend || row._replaceOrAppend === 'replace') {
  1866. row.formulaParts.splice(row.activeIndex, 1, val);
  1867. } else if (row._replaceOrAppend === 'append') {
  1868. row.formulaParts.splice(row.activeIndex + 1, 0, val);
  1869. // 追加后activeIndex后移一位
  1870. this.$set(row, 'activeIndex', row.activeIndex + 1);
  1871. }
  1872. // row.activeIndex = undefined;
  1873. } else {
  1874. row.formulaParts.push(val);
  1875. }
  1876. row.formula = row.formulaParts.map((p) => `[${p}]`).join('');
  1877. row._opSelect = null;
  1878. },
  1879. tagItemDelete(index, row) {
  1880. if (this.type == 'detail') return;
  1881. row.formulaParts.splice(index, 1);
  1882. row.formula = row.formulaParts.map((p) => `[${p}]`).join('');
  1883. },
  1884. formulaPartsTagClick(index, row) {
  1885. if (this.type == 'detail') return;
  1886. if (!row._replaceOrAppend) {
  1887. // 默认追加
  1888. row._replaceOrAppend = 'append';
  1889. }
  1890. if (row.activeIndex && row.activeIndex === index) {
  1891. this.$set(row, 'activeIndex', undefined);
  1892. } else {
  1893. this.$set(row, 'activeIndex', index);
  1894. }
  1895. },
  1896. // 类型变化
  1897. paramTypeChange(row) {
  1898. if (row.pageType != 9) {
  1899. // 清空
  1900. row.formulaParts = [];
  1901. row.formula = '';
  1902. }
  1903. },
  1904. // 类型列表
  1905. async getTypeList() {
  1906. const { list = [] } = await recordrulesTypePage({
  1907. pageNum: 1,
  1908. size: 99999
  1909. });
  1910. this.typeList = list;
  1911. console.log('this.typeList', this.typeList);
  1912. },
  1913. industryTypeChange() {
  1914. this.formData.businessType = '';
  1915. this.formData.reportWorkType = '';
  1916. this.formData.classify = '';
  1917. this.formData.recordTemplateStyle = '';
  1918. },
  1919. businessTypeChange() {
  1920. this.formData.reportWorkType = '';
  1921. this.formData.classify = '';
  1922. this.formData.recordTemplateStyle = '';
  1923. },
  1924. reportWorkTypeChange() {
  1925. this.formData.classify = '';
  1926. this.formData.recordTemplateStyle = '';
  1927. },
  1928. classifyChange() {
  1929. this.formData.recordTemplateStyle = '';
  1930. }
  1931. }
  1932. };
  1933. </script>
  1934. <style scoped lang="scss">
  1935. .operationGuide_box {
  1936. width: 100%;
  1937. height: 48px;
  1938. display: flex;
  1939. overflow: hidden;
  1940. cursor: pointer;
  1941. box-sizing: border-box;
  1942. padding: 5px 10px;
  1943. .left_content {
  1944. width: 50%;
  1945. padding: 10px;
  1946. box-sizing: border-box;
  1947. border: 1px solid #c0c4cc;
  1948. border-radius: 10px;
  1949. margin-right: 10px;
  1950. overflow-y: auto;
  1951. }
  1952. .right_content {
  1953. flex: 1;
  1954. padding: 10px;
  1955. box-sizing: border-box;
  1956. border: 1px solid #c0c4cc;
  1957. border-radius: 10px;
  1958. overflow-y: auto;
  1959. }
  1960. }
  1961. ::v--deep .table_list {
  1962. .el-form-item {
  1963. .el-form-item__content {
  1964. margin-left: 0;
  1965. }
  1966. }
  1967. }
  1968. .formula-builder {
  1969. .formula-builder__selects {
  1970. margin-bottom: 6px;
  1971. display: flex;
  1972. flex-shrink: 0;
  1973. }
  1974. }
  1975. :deep(.el-dialog:not(.ele-dialog-form) .el-dialog__body .el-form) {
  1976. .el-form-item:last-child {
  1977. margin-bottom: 22px;
  1978. }
  1979. }
  1980. </style>