permitAdd.vue 62 KB

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