permitAdd.vue 65 KB

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