globalEdit.vue 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305
  1. <template>
  2. <basic-container>
  3. <!-- 系统级 全局公式 -->
  4. <div class="flex flex-d-c h-100p">
  5. <div class="box-dashed flex jc-sb">
  6. <div class="flex">
  7. <div class="retain-box">
  8. <el-checkbox v-model="isRetain">保留</el-checkbox>
  9. <el-input-number v-model="retainNum" :step="1" :min="0" :max="5" :disabled="!isRetain"
  10. size="mini"></el-input-number>
  11. <span class="unit">位</span>
  12. </div>
  13. <div class="retain-box">
  14. <el-button size="mini" @click="deviationRange.show = !deviationRange.show">允许偏差值范围</el-button>
  15. </div>
  16. <div>
  17. <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
  18. <el-submenu v-for="(value, key, index) in formulaList" :key="key" :index="key">
  19. <template slot="title">
  20. <span>{{ key }}</span>
  21. </template>
  22. <el-menu-item v-for="(item2, index2) in value" :key="index2" :index="(index + 1) + '-' + (index2 + 1)">
  23. {{ item2.name }}
  24. </el-menu-item>
  25. </el-submenu>
  26. </el-menu>
  27. </div>
  28. </div>
  29. <div>
  30. <el-button size="small" @click="handwrit">手写模式</el-button>
  31. </div>
  32. </div>
  33. <div class="box-dashed">
  34. <div class="mg-b-20">函数公式.</div>
  35. <div class="edit-text">
  36. <div>
  37. <formula-item-big v-for="(item, index) in resultFormula" :key="index" :item="item"
  38. @click="obj => equationClick(obj, index, 'resultFormula')">
  39. </formula-item-big>
  40. </div>
  41. <span>=</span>
  42. <span v-for="(item, index) in processFormula" :key="index">
  43. <el-tooltip class="item" effect="light" placement="top-start" :disabled="item.type !== 'Element'">
  44. <div slot="content">{{ item.tableName }}</div>
  45. <formula-item-big :getname="getItemTableName(item)" :item="item"
  46. @click="obj => equationClick(obj, index, 'processFormula')" :isShowCursor="false">
  47. </formula-item-big>
  48. </el-tooltip>
  49. </span>
  50. </div>
  51. <div class="flex jc-sb">
  52. <div></div>
  53. <div><el-button type="info" size="small" @click="operationEdit">重置函数</el-button></div>
  54. </div>
  55. </div>
  56. <div v-show="operationVisible" class="operation-box flex1 flex flex-d-c ov-hidden">
  57. <div>选择参数设置</div>
  58. <div class="flex flex-d-c flex1 ov-hidden">
  59. <el-row :gutter="20" class="flex1 ov-hidden">
  60. <el-col :span="8" class="h-100p">
  61. <el-card shadow="never" v-loading="treeLoad" class="h-100p ov-auto">
  62. <div style="overflow: auto;flex:1;max-height:601px">
  63. <div class="flex">
  64. <el-input size="small" placeholder="输入关键字搜索" clearable @clear="clearFilterText"
  65. v-model="filterText">
  66. </el-input>
  67. <el-button size="small" class="mg-l-10" @click="treeFilter">搜索</el-button>
  68. </div>
  69. <el-tree style="display: inline-block;min-width: 100%;" class="filter-tree" :data="treeData"
  70. :default-expanded-keys="defaultExpanded" @node-click="getNodeDetail" :props="defaultProps"
  71. :expand-on-click-node="false" highlight-current node-key="id" ref="tree" lazy :load="treeLoadNode"
  72. v-show="!allTreeShow">
  73. </el-tree>
  74. <el-tree style="width: 100%" ref="treeAll" v-loading="treeLoading" :data="allTreeData"
  75. :props="defaultProps" @node-click="getNodeDetail" node-key="id" :expand-on-click-node="false"
  76. :filter-node-method="filterNode" v-show="allTreeShow">
  77. </el-tree>
  78. </div>
  79. </el-card>
  80. </el-col>
  81. <el-col :span="16" class="h-100p flex flex-d-c ov-hidden">
  82. <!-- 放出来的代码——start -->
  83. <div style="display:flex">
  84. <el-input placeholder="请输入你想搜索的元素字段" v-model="inputEle" clearable @clear="clearInput"> </el-input>
  85. <el-button type="primary" icon="el-icon-search" size="small" @click="searchChange">搜索</el-button>
  86. </div>
  87. <div class="mg-t-10 no-mb-col flex1 ov-hidden"
  88. style="height: 360px; overflow-y: auto; max-height: 360px;">
  89. <el-scrollbar style="height: 100%">
  90. <el-row v-loading="eleListable">
  91. <el-col :span="6" v-for="item in eleList" :key="item.id">
  92. <div class="ele-box">
  93. <span v-if="item.k">{{ item.name }}</span>
  94. <span v-else>{{ item.eName }}</span>
  95. <el-checkbox v-model="item.checked" @change="value => eleChang(value, item)"></el-checkbox>
  96. </div>
  97. </el-col>
  98. </el-row>
  99. </el-scrollbar>
  100. </div>
  101. <!-- 运算符选择区域 -->
  102. <div class="operation-box">
  103. <div class="flex jc-sb operation-symbol-box">
  104. <div class="icon-box ">
  105. <span>插入运算符:</span>
  106. <el-link type="primary" @click="addOperator('+')" icon="el-icon-circle-plus-outline"></el-link>
  107. <el-link type="primary" @click="addOperator('-')" icon="el-icon-remove-outline"></el-link>
  108. <el-link type="primary" @click="addOperator('*')" icon="el-icon-circle-close"></el-link>
  109. <el-link type="primary" @click="addOperator('%')">÷</el-link>
  110. <el-link type="primary" class="mg-r-10" @click="addBrackets('(', false)">(</el-link>
  111. <el-link type="primary" class="mg-r-10" @click="addBrackets(')', true)">)</el-link>
  112. <el-link type="primary" @click="addText">固定值</el-link>
  113. </div>
  114. <div class="flex">
  115. <span>操作</span>
  116. <el-link icon="el-icon-delete" type="danger" @click="handleDelete"></el-link>
  117. </div>
  118. </div>
  119. <div class="border-grey sele-ele-box1" tabindex="0" inputmode="none" @keydown.prevent="onKeyDown"
  120. @keydown.prevent.left="handleLeftArrow" @keydown.prevent.right="handleRightArrow"
  121. @keydown.prevent.delete="handleDelete" @focus="containerFocused = true"
  122. @blur="containerFocused = false">
  123. <draggable v-model="selectEleFormula" class="pane-box">
  124. <formula-item v-for="(item, index) in selectEleFormula" :key="index" :item="item"
  125. @click="obj => eleFormulaClick(obj, index)">
  126. </formula-item>
  127. </draggable>
  128. </div>
  129. <div class="flex mg-t-10" style="justify-content: space-between;width:100%;">
  130. <!-- <el-select v-model="eleTableId" @change="getTableEle" placeholder="请选择元素表1" style="width:45%"
  131. size="small">
  132. <el-option v-if="paramDataList.length" label="选择节点参数2" value="选择节点参数"></el-option>
  133. <el-option v-for="item in eleTableList" :key="item.id" :label="item.title"
  134. :value="(item.pkeyId !== null && item.pkeyId !== -1) ? item.pkeyId : item.id"></el-option>
  135. </el-select> -->
  136. <div class="text-align-c">
  137. <el-button size="small" @click="cancelOperationVisible">取消</el-button>
  138. <el-button size="small" @click="operationHandle" type="primary">保存</el-button>
  139. </div>
  140. </div>
  141. <!-- <div class="mg-t-10 no-mb-col flex1">
  142. <el-scrollbar style="height: 450px">
  143. <tableFormWrite :pkeyId="eleTableId" @element-selected="handleElementSelected"
  144. :initTableName="initTableName" :selectedTableKey="selectedTableKey" :key="1"
  145. :container-id="'excel-container-1'"></tableFormWrite>
  146. </el-scrollbar>
  147. </div> -->
  148. </div>
  149. </el-col>
  150. </el-row>
  151. <!-- <div class="text-align-c">
  152. <el-button size="small" @click="cancelOperationVisible">取消</el-button>
  153. <el-button size="small" @click="operationHandle" type="primary">保存</el-button>
  154. </div> -->
  155. </div>
  156. </div>
  157. <div v-show="!operationVisible && !showFunDetail && !deviationRange.show">
  158. <div class="box-dashed">
  159. <div class="mg-b-20">函数公式运算执行溯源</div>
  160. <div>
  161. <el-select v-model="projectId" @change="projectChange" placeholder="请选择项目" style="width: 380px">
  162. <el-option v-for="item in projectList" :key="item.id" :label="item.projectName"
  163. :value="item.id"></el-option>
  164. </el-select>
  165. <el-select v-model="contractId" placeholder="请选择合同段">
  166. <el-option v-for="item in contractList" :key="item.id" :label="item.contractName"
  167. :value="item.id"></el-option>
  168. </el-select>
  169. <el-button type="info">查询</el-button>
  170. </div>
  171. </div>
  172. </div>
  173. <div v-if="!operationVisible && showFunDetail" class="flex1">
  174. <el-tabs v-model="actiFunIndex" closable @tab-remove="removeFun" :before-leave="funLeave">
  175. <el-tab-pane v-for="(item, index) in equationSelectEle.children" :key="index" :label="item.name"
  176. :name="index.toString()">
  177. <template v-if="!componentMap[item.name]">
  178. <formula-template ref="dynamicComponent" :formulainfo="item" :curele="equationSelectEle"
  179. @sele-ele-handle="showChooseEle">
  180. </formula-template>
  181. </template>
  182. <template v-else>
  183. <div class="flex">
  184. <div class=" flex-d-c" style="width:40%">
  185. <component ref="dynamicComponent" v-bind:is="componentMap[item.name]" :formulainfo="item"
  186. :curele="equationSelectEle" :formulamap="formulaMap" :map="formulaDetailMap"
  187. @uncheck="unCheckEleComp" class="flex1" :moreConditions="moreConditions" :isMore="isMore"
  188. :isGetData="isGetData" :dataListGet="dataListGet" :isDataChange="isDataChange" :dataForm="dataForm"
  189. :remark="remark" :method="method">
  190. </component>
  191. <div class="flex1" v-show="item.showSelectEle" style="margin-top:10px;margin-bottom:30px">
  192. <div class="flex">
  193. <el-input size="small" placeholder="输入关键字搜索" clearable @clear="clearFilterText"
  194. v-model="filterText">
  195. </el-input>
  196. <el-button size="small" class="mg-l-10" @click="treeFilter">搜索</el-button>
  197. </div>
  198. <el-scrollbar style="height: 520px">
  199. <el-tree class="filter-tree" :data="treeData" :default-expanded-keys="defaultExpanded"
  200. @node-click="getNodeDetailComp" :props="defaultProps" :expand-on-click-node="false"
  201. highlight-current node-key="id" ref="tree" lazy :load="treeLoadNode" v-show="!allTreeShow">
  202. </el-tree>
  203. <el-tree style="width: 100%" ref="treeAll" v-loading="treeLoading" :data="allTreeData"
  204. :props="defaultProps" @node-click="getNodeDetailComp" node-key="id"
  205. :expand-on-click-node="false" :filter-node-method="filterNode" v-show="allTreeShow">
  206. </el-tree>
  207. </el-scrollbar>
  208. </div>
  209. </div>
  210. <div v-show="item.showSelectEle" style="width:60%">
  211. <div style="display:flex">
  212. <el-input placeholder="请输入你想搜索的元素字段" v-model="inputEleJudge" clearable @clear="clearInputJudge">
  213. </el-input>
  214. <el-button type="primary" icon="el-icon-search" size="small"
  215. @click="searchChangeJudge">搜索</el-button>
  216. </div>
  217. <div class="mg-t-10 mg-b-10 no-mb-col" style="width:100%">
  218. <el-scrollbar style="height:600px;">
  219. <el-row v-loading="eleListJudge">
  220. <el-col :span="6" v-for="item in eleListComp" :key="item.id">
  221. <div class="ele-box">
  222. <span v-if="item.k">{{ item.name }}</span>
  223. <span v-else>{{ item.eName }}</span>
  224. <el-checkbox v-model="item.checked"
  225. @change="value => setComponentEle(value, item, index)"></el-checkbox>
  226. </div>
  227. </el-col>
  228. </el-row>
  229. </el-scrollbar>
  230. </div>
  231. </div>
  232. </div>
  233. </template>
  234. </el-tab-pane>
  235. </el-tabs>
  236. </div>
  237. <!-- 允许偏差值范围 -->
  238. <div v-if="!operationVisible && !showFunDetail && deviationRange.show" class="flex1">
  239. <div class="flex">
  240. <div class=" flex-d-c" style="width:40%">
  241. <deviation-range ref="deviationRange" :formulainfo="deviationRange" :formulamap="formulaMap"
  242. @uncheck="unCheckEleComp" class="flex1"></deviation-range>
  243. <div class="flex1" v-show="deviationRange.showSelectEle" style="margin-top:10px;margin-bottom:30px">
  244. <div class="flex">
  245. <el-input size="small" placeholder="输入关键字搜索" clearable @clear="clearFilterText" v-model="filterText">
  246. </el-input>
  247. <el-button size="small" class="mg-l-10" @click="treeFilter">搜索</el-button>
  248. </div>
  249. <el-scrollbar style="height: 520px">
  250. <el-tree class="filter-tree" :data="treeData" :default-expanded-keys="defaultExpanded"
  251. @node-click="getNodeDetailComp" :props="defaultProps" :expand-on-click-node="false" highlight-current
  252. node-key="id" ref="tree" lazy :load="treeLoadNode" v-show="!allTreeShow">
  253. </el-tree>
  254. <el-tree style="width: 100%" ref="treeAll" v-loading="treeLoading" :data="allTreeData"
  255. :props="defaultProps" @node-click="getNodeDetailComp" node-key="id" :expand-on-click-node="false"
  256. :filter-node-method="filterNode" v-show="allTreeShow">
  257. </el-tree>
  258. </el-scrollbar>
  259. </div>
  260. </div>
  261. <div v-show="deviationRange.showSelectEle" style="width:60%">
  262. <div style="display:flex">
  263. <el-input placeholder="请输入你想搜索的元素字段" v-model="inputElePian" clearable @clear="clearInputPian"> </el-input>
  264. <el-button type="primary" icon="el-icon-search" size="small" @click="searchChangePian">搜索</el-button>
  265. </div>
  266. <div class="mg-t-10 mg-b-10 no-mb-col" style="width:100%">
  267. <el-scrollbar style="height:520px;">
  268. <el-row v-loading="eleListCompLoading">
  269. <el-col :span="6" v-for="item in eleListComp" :key="item.id">
  270. <div class="ele-box">
  271. <span v-if="item.k">{{ item.name }}</span>
  272. <span v-else>{{ item.eName }}</span>
  273. <el-checkbox v-model="item.checked"
  274. @change="value => setDeviationRangeEle(value, item)"></el-checkbox>
  275. </div>
  276. </el-col>
  277. </el-row>
  278. </el-scrollbar>
  279. </div>
  280. </div>
  281. </div>
  282. </div>
  283. <div class="text-align-c" v-show="!operationVisible">
  284. <el-button type="warning" @click="$emit('hideDialog')">取消</el-button>
  285. <el-button type="primary" @click="saveFormula">保存</el-button>
  286. </div>
  287. </div>
  288. <el-dialog title="输入值" :visible.sync="inputVisible" width="300px" append-to-body :close-on-click-modal="false">
  289. <el-input v-model="inputText" placeholder="请输入内容"></el-input>
  290. <div class="text-align-c mg-t-10">
  291. <el-button size="small" @click="addTextHandle" type="primary">保存</el-button>
  292. <el-button size="small" @click="inputVisible = false">取消</el-button>
  293. </div>
  294. </el-dialog>
  295. <el-dialog title="选择元素" :visible.sync="chooseEleVisible" width="70%" append-to-body :close-on-click-modal="false">
  296. <div>
  297. <el-row :gutter="20">
  298. <el-col :span="8">
  299. <el-card shadow="never">
  300. <div class="flex">
  301. <el-input size="small" placeholder="输入关键字搜索表单" clearable @clear="clearFilterText" v-model="filterText">
  302. </el-input>
  303. <el-button size="small" class="mg-l-10" @click="treeFilter">搜索</el-button>
  304. </div>
  305. <el-scrollbar style="height: 460px">
  306. <el-tree class="filter-tree" :data="treeData" :default-expanded-keys="defaultExpanded"
  307. @node-click="getNodeDetail" :props="defaultProps" :expand-on-click-node="false" highlight-current
  308. node-key="id" ref="tree" lazy :load="treeLoadNode" v-show="!allTreeShow">
  309. </el-tree>
  310. <el-tree style="width: 100%" ref="treeAll" v-loading="treeLoading" :data="allTreeData"
  311. :props="defaultProps" @node-click="getNodeDetail" node-key="id" :expand-on-click-node="false"
  312. :filter-node-method="filterNode" v-show="allTreeShow">
  313. </el-tree>
  314. </el-scrollbar>
  315. </el-card>
  316. </el-col>
  317. <el-col :span="16">
  318. <div style="display:flex">
  319. <el-input placeholder="请输入你想搜索的元素字段" v-model="inputEle" clearable @clear="clearInput"> </el-input>
  320. <el-button type="primary" icon="el-icon-search" size="small" @click="searchChange">搜索</el-button>
  321. </div>
  322. <div class="mg-t-10 mg-b-10 no-mb-col">
  323. <el-scrollbar style="height: 460px;">
  324. <el-row>
  325. <el-col :span="6" v-for="item in eleList" :key="item.id">
  326. <div class="ele-box">
  327. <span v-if="item.k">{{ item.name }}</span>
  328. <span v-else>{{ item.eName }}</span>
  329. <el-checkbox v-model="item.checked" @change="value => eleCheckHandle(value, item)"></el-checkbox>
  330. </div>
  331. </el-col>
  332. </el-row>
  333. </el-scrollbar>
  334. </div>
  335. </el-col>
  336. </el-row>
  337. <div class="text-align-c">
  338. <el-button size="small" @click="chooseEleHandle" type="primary">保存</el-button>
  339. <el-button size="small" @click="chooseEleVisible = false">取消</el-button>
  340. </div>
  341. </div>
  342. </el-dialog>
  343. <el-dialog title="手写模式" :visible.sync="handwritVisible" width="900px" append-to-body :close-on-click-modal="false">
  344. <div class="font-c-warning">tips:手写模式不保证能转换成配置模式!!即使能转换也不保证正确!!!</div>
  345. <div class="mg-b-20 font-c-warning">无法在手写模式手写加入新的元素!新的节点参数!</div>
  346. <editor v-model="handwritText" @init="editorInit" lang="javascript" theme="github" width="100%" height="200">
  347. </editor>
  348. <!-- <el-input
  349. type="textarea"
  350. :autosize="{ minRows: 5,}"
  351. placeholder="请输入内容"
  352. v-model="handwritText">
  353. </el-input> -->
  354. <span slot="footer" class="dialog-footer">
  355. <el-button @click="handwritVisible = false">取 消</el-button>
  356. <el-button type="primary" @click="handwritTransform">转 换</el-button>
  357. </span>
  358. </el-dialog>
  359. </basic-container>
  360. </template>
  361. <script>
  362. import { getProjectList } from "@/api/manager/projectinfo";
  363. import { findContractByProjectId } from "@/api/manager/contractinfo";
  364. import { getDetail as getEleDetail } from "@/api/manager/wbsformelement";
  365. import { getTypeMap, saveFormula, formulaDetail, updateFormula } from "@/api/formula/formula";
  366. import { tabTypeLazyTreeAll, tabTypeLazyTree } from "@/api/manager/wbsprivate";
  367. import { getTableElments } from "@/api/manager/wbstree";
  368. import { mapGetters } from "vuex";
  369. import formulaItem from "../component/formulaItem"
  370. import formulaItemBig from "../component/formulaItemBig"
  371. import formulaTemplate from "../component/formulaTemplate"
  372. import dateDeviation from "../component/funComponent/dateDeviation"
  373. import dateFormat from "../component/funComponent/dateFormat"
  374. import datasRepeat from "../component/funComponent/datasRepeat"
  375. import datasReme from "../component/funComponent/datasReme"
  376. import datasGetlist from "../component/funComponent/datasGetlist"
  377. import datasJoin from "../component/funComponent/datasJoin"
  378. import ifelse from "../component/funComponent/ifelse"
  379. import deviationRange from "../component/deviationRange/deviationRange"
  380. import { rangeToString } from "../component/deviationRange/rangeToString"
  381. import { formulaArrayToString } from "../formulaArrayToString"
  382. import { formulaStringToArray } from "../formulaStringToArray"
  383. import draggable from 'vuedraggable'
  384. import tableFormWrite from "../component/table-form-write.vue";
  385. import { formatArrayMore, restoreArrayMore, generateResult } from '../component/funComponent/multiIfElseTools'
  386. export default {
  387. components: {
  388. draggable,
  389. formulaItem,
  390. formulaItemBig,
  391. formulaTemplate,
  392. editor: require('vue2-ace-editor'),
  393. dateDeviation,
  394. dateFormat,
  395. datasRepeat,
  396. datasReme,
  397. datasGetlist,
  398. datasJoin,
  399. ifelse,
  400. deviationRange,
  401. tableFormWrite
  402. },
  403. props: {
  404. wbsid: {
  405. type: String,
  406. default: ''
  407. },
  408. eleid: {
  409. type: String,
  410. default: ''
  411. },
  412. globaltype: {
  413. type: Number,
  414. default: 10
  415. },
  416. elementType: {
  417. type: Boolean,//公有还是私有
  418. },
  419. nodeid: {
  420. type: String,
  421. default: ''
  422. },
  423. pid: {
  424. type: String,
  425. default: ''
  426. },
  427. projectid: {
  428. type: String,
  429. default: ''
  430. },
  431. fromcurNode: {
  432. type: Object,
  433. default: ''
  434. },
  435. tableType: {
  436. type: Boolean,
  437. default: false
  438. }
  439. },
  440. data() {
  441. return {
  442. // wbsid: "", //从哪个wbs树过来的
  443. // eleid: "", //元素id
  444. // nodeid:'',//所在树节点id
  445. // pid:'',//项目id 私有树才有
  446. filterText: '',//树形控件搜索文字
  447. allTreeShow: '',//搜索树显示
  448. formulaid: '',
  449. treeLoading: false,//搜索树加载效果
  450. allTreeData: [],//过滤树
  451. treeData: [],//树节点
  452. treeLoad: false,
  453. defaultExpanded: [],//默认展开节点
  454. isRetain: false, //是否保留小数
  455. retainNum: 2, //保留几位小数
  456. formulaList: {},
  457. formulaMap: {},
  458. activeIndex: "1-1", //当前选择的公式
  459. projectList: [], //项目备选列表
  460. projectId: "", //溯源的项目ID
  461. curProjiect: {}, //当前项目对象
  462. contractList: [], //合同段备选列表
  463. contractId: "", //合同段id
  464. operationVisible: false, //基础运算弹窗
  465. defaultProps: {
  466. children: "children",
  467. label: "title",
  468. isLeaf: function (data) {
  469. return !data.hasChildren;
  470. },
  471. },
  472. eleTableId: '',//选中的元素表id
  473. eleTableList: [],
  474. eleList: [],
  475. selectEleFormula: [],
  476. curSeleEleIndex: -1,//公式文字里面选中的元素索引
  477. inputVisible: false,//输入弹窗
  478. inputText: "",//输入值
  479. deleEleIndex: -1,//删除元素的位置,如果下次添加元素,先加到这个位置
  480. resultFormula: [],//=等号左边的数组
  481. processFormula: [],//=等号右边的数组
  482. checkGsId: '',//选中的公式id
  483. rightDict: [],//等号右边元素的字典
  484. processType: '',//选中的元素在等号哪边
  485. processSelectIndex: 0,//选中的索引
  486. actiFunIndex: 0,//元素下挂载的计算式的索引
  487. chooseEleVisible: false,//选择元素弹窗
  488. argumenObj: {},
  489. symbolReg: /(\+|-|\*|\/)(.+)/,
  490. operatorReg: /^\+|-|\*|%/,//加减乘除
  491. startFCRegExp: /^FC\.([a-zA-Z\d]+)\(/,// 匹配开始的FC.xxx(
  492. componentMap: {
  493. '日期偏移': 'date-deviation',
  494. '日期格式化': 'date-format',
  495. // '去重':'datas-repeat',
  496. // '去空':'datas-reme',
  497. '下标取数': 'datas-getlist',
  498. // '数组转字符串':"datas-join",
  499. '判断': 'ifelse',
  500. },
  501. eleListComp: [],//方法下面元素列表
  502. eleTableListComp: [],//方法下面元素表列表
  503. eleTableIdComp: '',//方法下面元素表id
  504. handwritVisible: false,//手写弹框
  505. handwritText: '',//文本
  506. handwritEleMap: '',//元素map
  507. paramDataList: [],//节点参数数组
  508. deviationRange: {
  509. show: false,//显示
  510. showSelectEle: false,//显示选择元素
  511. datas: {
  512. symbol: '【min,max】',
  513. model: '1',
  514. arguments1: '',
  515. arguments2: '',
  516. },
  517. },//允许偏差值范围
  518. version: 1,//版本号,以后可能会有不兼容旧公式的改动,留作以后可能用来判断
  519. curData: {},
  520. curNode: {},
  521. treeId: '',
  522. page: {
  523. size: 10,
  524. current: 1,
  525. total: 2
  526. },
  527. eleListable: false,
  528. eleListCompLoading: false,
  529. eleListJudge: false,
  530. input3: '',
  531. rootNodeData: [],
  532. nodeZero: null,
  533. resolveZero: null,
  534. loading: false,
  535. itemList: [],
  536. inputEle: '',
  537. inputElePian: '',
  538. inputEleJudge: '',
  539. moreConditions: [],//多条件判断数组
  540. isMore: false,//是否多条件
  541. isGetData: false,//是否获取数据
  542. dataListGet: [],//获取的数据列表
  543. isDataChange: false,//数据是否变化
  544. dataForm: '',
  545. remark: '',
  546. method: '',
  547. formulaDetailMap: {},//公式详情map
  548. containerFocused: false,//公式编辑区域是否聚焦
  549. };
  550. },
  551. computed: {
  552. ...mapGetters(["userInfo"]),
  553. // selectEleFormulaText:function(){
  554. // let text = '';
  555. // this.selectEleFormula.forEach((Element)=>{
  556. // text+=Element.name;
  557. // })
  558. // return text
  559. // }
  560. //等式中选中的元素
  561. equationSelectEle: function () {
  562. if (this.processType) {
  563. return this[this.processType][this.processSelectIndex];
  564. } else {
  565. return null;
  566. }
  567. },
  568. //是否显示元素下挂载的计算式信息
  569. showFunDetail: function () {
  570. if (this.equationSelectEle && this.equationSelectEle.children && this.equationSelectEle.children.length > 0) {
  571. return true;
  572. } else {
  573. return false;
  574. }
  575. },
  576. },
  577. watch: {
  578. selectEleFormula: {
  579. handler() {
  580. this.checkDefaultSelection();
  581. this.$nextTick(() => {
  582. this.$el.querySelector('.sele-ele-box1').focus();
  583. });
  584. },
  585. deep: true
  586. },
  587. },
  588. created() {
  589. // this.wbsid = this.$route.query.wbsid;
  590. // this.eleid = this.$route.query.eleid;
  591. // this.nodeid = this.$route.query.nodeid;
  592. this.pid = this.$route.query.pid;//项目id 私有树才有
  593. console.log(this.pid, 'this.pid');
  594. console.log(this.globaltype, 'this.globaltype');
  595. this.init();
  596. },
  597. methods: {
  598. onKeyDown(e) {
  599. if (!e.shiftKey) return;
  600. const key = e.key; // 物理键名
  601. console.log(key, 'key');
  602. const map = {
  603. '_': () => this.addOperator('-'),
  604. '——': () => this.addOperator('-'),
  605. '—': () => this.addOperator('-'),
  606. '-': () => this.addOperator('-'),
  607. '+': () => this.addOperator('+'),
  608. '*': () => this.addOperator('*'),
  609. '?': () => this.addOperator('%'),
  610. '?': () => this.addOperator('%'),
  611. '(': () => this.addBrackets('(', false),
  612. '(': () => this.addBrackets('(', false),
  613. ')': () => this.addBrackets(')', true),
  614. ')': () => this.addBrackets(')', true)
  615. };
  616. (map[key] || (() => { }))();
  617. },
  618. async init() {
  619. this.getEleDetail();
  620. this.getProjectList();
  621. // this.geTreeData();
  622. await this.getTypeMap();
  623. this.formulaStringToArray();
  624. },
  625. //#region 接口
  626. async tabTypeLazyTree(parentId, projectId, current, size, titleName) {//清表树
  627. const { data: res } = await tabTypeLazyTree({ parentId, projectId, current, size, titleName })
  628. if (res.code === 200) {
  629. return res.data;
  630. }
  631. },
  632. treeLoadNode(node, resolve) {
  633. let parentId = 12345678910;
  634. console.log(node.level, "node.level")
  635. if (node.level != 0) {
  636. parentId = node.data.id;
  637. }
  638. // 开启 “加载中” 动画
  639. if (node.level == 0) this.loading = true
  640. if (!this.elementType) {
  641. tabTypeLazyTreeAll({ parentId, current: 1, size: 1000, hasPartFormula: this.fromcurNode.hasPartFormula }).then(res => {
  642. // 请求接口,返回数据
  643. let data = res.data.data.records;
  644. this.loading = false
  645. resolve(data);
  646. this.$nextTick(() => {
  647. let expandid = this.tableType ? Number(this.fromcurNode.tableType) - 1 : Number(this.fromcurNode.parentId) - 1;
  648. node.childNodes[expandid].expand();
  649. let paramsId = this.fromcurNode.initTableId
  650. let isArray = Array.isArray(this.$refs.tree)
  651. console.log(isArray, "isArray")
  652. if (isArray) {
  653. // 根据 id 获取节点信息
  654. this.$refs.tree[0].setCurrentKey(paramsId);
  655. } else {
  656. this.$refs.tree.setCurrentKey(paramsId);
  657. }
  658. this.getNodeDetail(this.fromcurNode)
  659. this.getNodeDetailComp(this.fromcurNode)
  660. })
  661. })
  662. } else if (this.elementType) {
  663. tabTypeLazyTree({ parentId, projectId: this.projectid, pcurrent: 1, size: 1000 }).then(res => {
  664. // 请求接口,返回数据
  665. let data = res.data.data.records;
  666. this.loading = false
  667. resolve(data);
  668. this.$nextTick(() => {
  669. let expandid = Number(this.fromcurNode.parentId) - 1
  670. node.childNodes[expandid].expand();
  671. let paramsId = this.fromcurNode.id
  672. console.log(this.nodeid, 'this.initTableId');
  673. let isArray = Array.isArray(this.$refs.tree)
  674. if (isArray) {
  675. // 根据 id 获取节点信息
  676. this.$refs.tree[0].setCurrentKey(paramsId);
  677. } else {
  678. this.$refs.tree.setCurrentKey(paramsId);
  679. }
  680. this.getNodeDetail(this.fromcurNode)
  681. this.getNodeDetailComp(this.fromcurNode)
  682. })
  683. })
  684. }
  685. },
  686. //搜索树
  687. treeFilter() {
  688. console.log('搜索');
  689. this.eleTableList = [];
  690. this.eleList = [];
  691. this.eleListComp = [];
  692. this.eleTableListComp = [];
  693. this.eleTableId = '';
  694. this.eleTableIdComp = ''
  695. if (this.filterText) {
  696. this.allTreeShow = true;
  697. this.allTreeData = []
  698. if (!this.allTreeData.length) {
  699. this.treeLoading = true;
  700. if (!this.elementType) {
  701. let parentId = ''
  702. if (this.curData.hasChildren) {
  703. parentId = this.curData.id
  704. } else {
  705. // parentId=this.curData.parentId
  706. parentId = ''
  707. }
  708. tabTypeLazyTreeAll({ parentId: parentId, current: 1, size: 1000, titleName: this.filterText }).then((res) => {
  709. this.treeLoading = false;
  710. this.allTreeData = res.data.data.records;
  711. this.$nextTick(() => {
  712. console.log("过滤");
  713. this.$refs.treeAll.filter(this.filterText);
  714. });
  715. })
  716. } else if (this.elementType) {
  717. let parentId = ''
  718. if (this.curData.hasChildren) {
  719. parentId = this.curData.id
  720. } else {
  721. // parentId=this.curData.parentId
  722. parentId = ''
  723. }
  724. console.log(parentId, 'parentId');
  725. tabTypeLazyTree({ parentId: parentId, projectId: this.projectid, pcurrent: 1, size: 1000, titleName: this.filterText }).then((res) => {
  726. this.treeLoading = false;
  727. this.allTreeData = res.data.data.records;
  728. });
  729. this.$nextTick(() => {
  730. console.log("过滤");
  731. this.$refs.treeAll.filter(this.filterText);
  732. });
  733. }
  734. } else {
  735. this.$refs.treeAll.filter(this.filterText);
  736. }
  737. } else {
  738. this.$message.warning('请先输入文字')
  739. this.allTreeShow = false;
  740. }
  741. },
  742. clearFilterText() {
  743. this.allTreeShow = false;
  744. this.eleTableList = [];
  745. this.eleList = [];
  746. this.eleListComp = [];
  747. this.eleTableListComp = [];
  748. this.eleTableId = '';
  749. this.eleTableIdComp = ''
  750. },
  751. filterNode(value, data) {
  752. if (!value) return true;
  753. return data.title.indexOf(value) !== -1;
  754. },
  755. //获取项目列表
  756. getProjectList() {
  757. getProjectList(1, 999).then((res) => {
  758. this.projectList = res.data.data.records;
  759. });
  760. },
  761. //选择公式处理
  762. handleSelect(index, indexPath) {
  763. //console.log(index,'index')
  764. //console.log(indexPath,'indexPath')
  765. if (this.operationVisible) {
  766. this.openerationSelect(index, indexPath)
  767. } else {
  768. this.equationSelect(index, indexPath)
  769. }
  770. },
  771. //在选择元素模式下点选计算式
  772. openerationSelect(index, indexPath) {
  773. if (indexPath[0] != '基础运算') {
  774. this.$message({
  775. type: "warning",
  776. message: "当前只能使用基础运算"
  777. });
  778. return;
  779. }
  780. let formulaindex = Number(indexPath[1].split('-')[1]) - 1;
  781. this.eleAddFormulaHandle(this.formulaList[indexPath[0]][formulaindex]);
  782. },
  783. //溯源项目id切换
  784. projectChange(id) {
  785. for (let i = 0; i < this.projectList.length; i++) {
  786. if (id == this.projectList[i].id) {
  787. this.curProjiect = this.projectList[i];
  788. //根据项目id获取合同段列表
  789. findContractByProjectId(this.curProjiect.id).then((res) => {
  790. this.contractList = res.data.data;
  791. this.contractId = "";
  792. });
  793. return;
  794. }
  795. }
  796. },
  797. operationEdit() {
  798. this.selectEleFormula = JSON.parse(JSON.stringify(this.processFormula));
  799. this.operationVisible = true;
  800. // 确保容器获得焦点
  801. this.$nextTick(() => {
  802. this.$el.querySelector('.sele-ele-box1').focus();
  803. });
  804. },
  805. eleAddFormula() {
  806. for (let i = 0; i < this.eleList.length; i++) {
  807. if (this.eleList[i].checked) {
  808. this.eleAddFormulaHandle(this.eleList[i]);
  809. break;
  810. }
  811. }
  812. },
  813. eleChang(value, item) {
  814. if (value) {
  815. //简单语法判断
  816. if (this.itemList.length != 0 && this.deleEleIndex < 0) {
  817. let lastEle = this.itemList[this.itemList.length - 1];
  818. if (lastEle.type == 'Text') {
  819. this.$message({
  820. type: "warning",
  821. message: "元素无法连续出现在输入值后面"
  822. });
  823. item.checked = false;
  824. return;
  825. }
  826. if (lastEle.type == 'Brackets' && lastEle.name == ')') {
  827. this.$message({
  828. type: "warning",
  829. message: "元素无法连续出现在右括号后面"
  830. });
  831. item.checked = false;
  832. return;
  833. }
  834. }
  835. let lastEle = this.selectEleFormula[this.selectEleFormula.length - 1];
  836. if (this.selectEleFormula.length == 0 || lastEle.type == 'Operator' || lastEle.type == 'Brackets') { /* 存在运算符 */
  837. this.eleAddFormulaHandle(item);
  838. } else {
  839. this.itemList.push(item);
  840. }
  841. } else {
  842. let index = -1;
  843. for (let i = 0; i < this.itemList.length; i++) {
  844. if (this.itemList[i].id == item.id) {
  845. index = i;
  846. break;
  847. }
  848. }
  849. if (index > -1) {
  850. this.itemList.splice(index, 1);
  851. }
  852. }
  853. },
  854. //快捷添加运算符号
  855. addOperator(operator) {
  856. if (this.itemList.length > 0) {
  857. this.itemList.forEach(e => {
  858. let lastEle = this.selectEleFormula[this.selectEleFormula.length - 1];
  859. if (this.selectEleFormula.length != 0 && lastEle.type != 'Operator' && lastEle.type != 'Brackets' && lastEle.name != '(') { /* 不存在运算符 */
  860. this.eleAddFormulaHandle(this.formulaMap[operator]);
  861. }
  862. this.eleAddFormulaHandle(e);
  863. })
  864. } else {
  865. if (this.curSeleEleIndex === -1 || this.curSeleEleIndex === this.selectEleFormula.length - 1) { /* 没选择值或者选择最后一个的时候直接添加符号 */
  866. this.eleAddFormulaHandle(this.formulaMap[operator]);
  867. } else { /* 选择中间的值,如果下一个是符号这替换,反之则在指定的位置添加 */
  868. this.randomaddOperator(this.formulaMap[operator])
  869. }
  870. }
  871. this.itemList = [];
  872. },
  873. //随机插入运算符
  874. randomaddOperator(ele) {
  875. // 取消所有元素的选中状态
  876. this.selectEleFormula.forEach(item => {
  877. item.selected = false;
  878. });
  879. let item = {
  880. type: 'Operator',
  881. name: this.symbolReg.exec(ele.name)[1],
  882. selected: true,
  883. template: ele.template
  884. }
  885. let index = Number(this.curSeleEleIndex);
  886. let currentName = this.selectEleFormula[index]
  887. if (currentName.type === 'Operator') { /* 选择的符号的时候,直接替换 */
  888. this.selectEleFormula.splice(index, 1, item)
  889. } else { /* 选择元素的时候,如果下一个是符号则替换,如果下一个是元素则添加 */
  890. let size = index + 1;
  891. let lastName = this.selectEleFormula[size]
  892. if (lastName.type === 'Operator') { /* 是符号,替换 */
  893. this.selectEleFormula.splice(size, 1, item)
  894. } else { /* 是元素,添加 */
  895. this.selectEleFormula.splice(size, 0, item)
  896. this.curSeleEleIndex = size; // 光标移动到新添加的位置
  897. }
  898. }
  899. },
  900. //把元素加到公式里
  901. eleAddFormulaHandle(ele) {
  902. let newElementIndex = -1; // 记录新添加元素的索引
  903. if (ele.tableElementKey) {
  904. //元素
  905. if (this.deleEleIndex > -1 && this.selectEleFormula.length - 1 >= this.deleEleIndex) {
  906. //删除元素的位置,如果下次添加元素,先加到这个位置
  907. this.selectEleFormula.splice(this.deleEleIndex, 0, {
  908. type: 'Element',
  909. name: ele.eName,
  910. id: ele.id,
  911. selected: false,
  912. tableElementKey: ele.tableElementKey,
  913. children: [],
  914. })
  915. newElementIndex = this.deleEleIndex; // 新元素索引就是插入位置
  916. this.deleEleIndex = -1;
  917. } else {
  918. this.selectEleFormula.push({
  919. type: 'Element',
  920. name: ele.eName,
  921. id: ele.id,
  922. selected: false,
  923. tableElementKey: ele.tableElementKey,
  924. children: [],
  925. })
  926. newElementIndex = this.selectEleFormula.length - 1; // 新元素索引是最后一个
  927. this.deleEleIndex = -1;
  928. }
  929. // 选中新添加的元素并更新光标位置
  930. this.setActiveElement(newElementIndex);
  931. } else if (ele.template && ele.example) {
  932. //简单语法判断
  933. if (this.selectEleFormula.length == 0) {
  934. this.$message({
  935. type: "warning",
  936. message: "公式开头不能是运算符号"
  937. });
  938. return;
  939. } else {
  940. let lastEle = this.selectEleFormula[this.selectEleFormula.length - 1];
  941. if (lastEle.type == 'Operator') {
  942. this.$message({
  943. type: "warning",
  944. message: "运算符号无法连续出现在运算符号后面"
  945. });
  946. return;
  947. }
  948. if (lastEle.type == 'Brackets' && lastEle.name == '(') {
  949. this.$message({
  950. type: "warning",
  951. message: "运算符号无法连续出现在左括号后面"
  952. });
  953. return;
  954. }
  955. }
  956. //运算符号
  957. this.selectEleFormula.push({
  958. type: 'Operator',
  959. name: this.symbolReg.exec(ele.name)[1],
  960. selected: false,
  961. template: ele.template
  962. })
  963. newElementIndex = this.selectEleFormula.length - 1;
  964. this.setActiveElement(newElementIndex);
  965. } else if (ele.type == 'Brackets') {
  966. //括号
  967. this.selectEleFormula.splice(ele.selectIndex, 0, {
  968. type: 'Brackets',
  969. name: ele.name,
  970. selected: false,
  971. })
  972. newElementIndex = ele.selectIndex;
  973. this.setActiveElement(newElementIndex);
  974. } else if (ele.type == 'Text') {
  975. //输入值
  976. this.selectEleFormula.push({
  977. type: 'Text',
  978. name: ele.name,
  979. selected: false,
  980. })
  981. newElementIndex = this.selectEleFormula.length - 1;
  982. this.setActiveElement(newElementIndex);
  983. } else if (ele.k) {
  984. //节点参数
  985. this.selectEleFormula.push({
  986. type: 'ParamData',
  987. name: ele.name,
  988. selected: false,
  989. id: ele.id,
  990. v: ele.v,
  991. k: ele.k,
  992. children: [],
  993. })
  994. newElementIndex = this.selectEleFormula.length - 1;
  995. this.setActiveElement(newElementIndex);
  996. }
  997. },
  998. // 新增:设置指定索引的元素为选中状态并更新光标
  999. setActiveElement(index) {
  1000. console.log('setActiveElement-index', index);
  1001. this.$nextTick(() => {
  1002. // 取消所有元素的选中状态
  1003. this.selectEleFormula.forEach(item => {
  1004. item.selected = false;
  1005. });
  1006. // 选中新添加的元素
  1007. if (this.selectEleFormula[index]) {
  1008. this.selectEleFormula[index].selected = true;
  1009. this.curSeleEleIndex = index; // 更新光标索引
  1010. }
  1011. // 确保容器获得焦点
  1012. this.$el.querySelector('.sele-ele-box1').focus();
  1013. });
  1014. },
  1015. //添加括号
  1016. addBrackets(text, type) {
  1017. let lastEle = this.selectEleFormula[this.selectEleFormula.length - 1];
  1018. if (type) { // 如果是true 表示为 ')' 右括号
  1019. if (this.selectEleFormula.length === 0) {
  1020. this.$message.warning('公式开头不能是右括号');
  1021. return;
  1022. }
  1023. if (lastEle.type === 'Operator') {
  1024. this.$message.warning('右括号无法连续出现在运算符号后面');
  1025. return;
  1026. }
  1027. if (lastEle.type === 'Brackets' && lastEle.name === '(') {
  1028. this.$message.warning('右括号无法连续出现在左括号后面');
  1029. return;
  1030. }
  1031. } else if (this.selectEleFormula.length !== 0) { // 如果是false 表示为 '(' 左括号
  1032. if (lastEle.type === 'Brackets' && lastEle.name === ')') {
  1033. this.$message.warning('左括号无法连续出现在右括号后面');
  1034. return;
  1035. }
  1036. if (['Element', 'Text'].includes(lastEle.type)) {
  1037. this.$message.warning('左括号无法连续出现在元素或输入值后面');
  1038. return;
  1039. }
  1040. }
  1041. this.eleAddFormulaHandle({
  1042. type: 'Brackets',
  1043. name: text,
  1044. selectIndex: Number(this.curSeleEleIndex) + 1
  1045. })
  1046. //type 是true 表示在元素右边插入
  1047. // if (this.curSeleEleIndex == Number(this.curSeleEleIndex)) {
  1048. // this.eleAddFormulaHandle({
  1049. // type: 'Brackets',
  1050. // name: text,
  1051. // selectIndex: type ? Number(this.curSeleEleIndex) + 1 : this.curSeleEleIndex
  1052. // })
  1053. // //如果在左边插入index要增1
  1054. // if (!type) {
  1055. // this.curSeleEleIndex = Number(this.curSeleEleIndex) + 1;
  1056. // }
  1057. // }
  1058. },
  1059. addText() {
  1060. this.inputVisible = true;
  1061. },
  1062. //添加输入值
  1063. addTextHandle() {
  1064. //简单语法判断
  1065. if (this.selectEleFormula.length != 0) {
  1066. let lastEle = this.selectEleFormula[this.selectEleFormula.length - 1];
  1067. if (lastEle.type == 'Element') {
  1068. this.$message({
  1069. type: "warning",
  1070. message: "输入值无法连续出现在元素后面"
  1071. });
  1072. return;
  1073. }
  1074. if (lastEle.type == 'Text') {
  1075. this.$message({
  1076. type: "warning",
  1077. message: "输入值无法连续出现在输入值后面"
  1078. });
  1079. return;
  1080. }
  1081. if (lastEle.type == 'Brackets' && lastEle.name == ')') {
  1082. this.$message({
  1083. type: "warning",
  1084. message: "输入值无法连续出现在右括号后面"
  1085. });
  1086. return;
  1087. }
  1088. }
  1089. this.eleAddFormulaHandle({
  1090. type: 'Text',
  1091. name: this.inputText
  1092. })
  1093. this.inputVisible = false;
  1094. },
  1095. //勾选元素
  1096. eleCheckHandle(checked, item) {
  1097. if (checked) {
  1098. this.eleList.forEach((ele) => {
  1099. this.$set(ele, 'checked', false);
  1100. //ele.checked = false;
  1101. })
  1102. item.checked = true;
  1103. }
  1104. },
  1105. //点选公式中的元素
  1106. eleFormulaClick(obj, index) {
  1107. // 先取消所有选中状态
  1108. this.selectEleFormula.forEach(item => {
  1109. item.selected = false;
  1110. });
  1111. // 设置当前选中项
  1112. obj.item.selected = obj.selected;
  1113. this.curSeleEleIndex = index;
  1114. // 确保容器获得焦点以接收键盘事件
  1115. this.$el.querySelector('.sele-ele-box1').focus();
  1116. // 处理类型为ELEMENT的元素,提取tableElementKey
  1117. console.log(obj.item, 'obj.item.');
  1118. if (obj.item.type === 'Element' && obj.item.tableElementKey) {
  1119. // 从类似"m_20220928142210_1575007943793836032:key_1"的格式中提取key部分
  1120. const keyParts = obj.item.tableElementKey.split('key');
  1121. this.selectedTableKey = keyParts.length > 1 ? 'key' + keyParts[1] : null;
  1122. } else {
  1123. // 非ELEMENT类型清空选中状态
  1124. this.selectedTableKey = null;
  1125. }
  1126. },
  1127. //取消勾选
  1128. unCheckEleFormulac(eleId) {
  1129. for (let i = 0; i < this.eleList.length; i++) {
  1130. if (this.eleList[i].id == eleId) {
  1131. this.eleList[i].checked = false;
  1132. }
  1133. }
  1134. },
  1135. //删除点选公式中的元素
  1136. removeSelect() {
  1137. if (this.curSeleEleIndex > -1 && this.curSeleEleIndex <= this.selectEleFormula.length - 1) {
  1138. if (this.selectEleFormula[this.curSeleEleIndex].type == 'Element') {
  1139. //删除元素的位置,如果下次添加元素,先加到这个位置
  1140. this.deleEleIndex = this.curSeleEleIndex;
  1141. this.unCheckEleFormulac(this.selectEleFormula[this.curSeleEleIndex].id)
  1142. }
  1143. this.selectEleFormula.splice(this.curSeleEleIndex, 1);
  1144. //this.curSeleEleIndex = -1;
  1145. }
  1146. },
  1147. //赋值给等号右边的数组
  1148. operationHandle() {
  1149. //检测左右括号数量是否相等
  1150. let lBracketNum = 0;
  1151. let rBracketNum = 0;
  1152. this.selectEleFormula.forEach((ele) => {
  1153. if (ele.type == 'Brackets') {
  1154. if (ele.name == '(') {
  1155. lBracketNum++;
  1156. } else if (ele.name == ')') {
  1157. rBracketNum++;
  1158. }
  1159. }
  1160. })
  1161. if (lBracketNum != rBracketNum) {
  1162. this.$message({
  1163. type: "warning",
  1164. message: "左右括号数量不相等,请先检查是否正确"
  1165. });
  1166. return;
  1167. }
  1168. this.processFormula = JSON.parse(JSON.stringify(this.selectEleFormula));
  1169. this.operationVisible = false;
  1170. this.allTreeShow = false;
  1171. this.filterText = ''
  1172. },
  1173. cancelOperationVisible() {
  1174. this.operationVisible = false;
  1175. this.allTreeShow = false;
  1176. this.filterText = ''
  1177. this.treeId = ''
  1178. this.itemList = [];
  1179. this.eleList.forEach((ele) => {
  1180. this.$set(ele, 'checked', false);
  1181. //ele.checked = false;
  1182. })
  1183. console.log('取消');
  1184. },
  1185. //点选等式中的元素
  1186. equationClick({ selected, item }, index, arrName) {
  1187. this.checkGsId = item.id
  1188. if (selected) {
  1189. this.resultFormula.forEach((ele) => {
  1190. ele.selected = false;
  1191. })
  1192. this.processFormula.forEach((ele) => {
  1193. ele.selected = false;
  1194. })
  1195. this.processSelectIndex = index;
  1196. this.processType = arrName;
  1197. item.selected = true;
  1198. if (this.showFunDetail) {
  1199. //切到第一个
  1200. this.actiFunIndex = '0';
  1201. }
  1202. } else {
  1203. this.processType = '';
  1204. }
  1205. },
  1206. //获取当前元素的表名
  1207. getItemTableName(item) {
  1208. if (item.type === "Element") {
  1209. this.rightDict.forEach((ele) => {
  1210. if (ele.ekey === item.tableElementKey) {
  1211. item.tableName = ele.tableName
  1212. }
  1213. })
  1214. }
  1215. },
  1216. //在等式模式下点选计算式
  1217. equationSelect(index, indexPath) {
  1218. debugger
  1219. if (!this.equationSelectEle || (this.equationSelectEle && !(this.equationSelectEle.type == 'Element' || this.equationSelectEle.type == 'ParamData'))) {
  1220. this.$message({
  1221. type: "warning",
  1222. message: "请先选中元素"
  1223. });
  1224. return;
  1225. }
  1226. let formulaindex = Number(indexPath[1].split('-')[1]) - 1;
  1227. let expression = this.formulaList[indexPath[0]][formulaindex];
  1228. if (expression.type == 1) {
  1229. return;
  1230. }
  1231. //alert(JSON.stringify(expression.template))
  1232. //debugger
  1233. let obj = Object.assign({}, expression);
  1234. //obj.template = JSON.parse(obj.template);
  1235. obj.arguments = new Array(obj.template.args.length);
  1236. let ele = {};
  1237. if (this.equationSelectEle.type == 'ParamData') {
  1238. ele = {
  1239. type: 'ParamData',
  1240. name: this.equationSelectEle.name,
  1241. id: this.equationSelectEle.id,
  1242. selected: false,
  1243. v: this.equationSelectEle.v,
  1244. k: this.equationSelectEle.k,
  1245. }
  1246. } else {
  1247. ele = {
  1248. id: this.equationSelectEle.id,
  1249. name: this.equationSelectEle.name,
  1250. selected: false,
  1251. tableElementKey: this.equationSelectEle.tableElementKey,
  1252. type: "Element",
  1253. };
  1254. }
  1255. let tg = obj.template.args.findIndex(x => x.m !== '常量');
  1256. obj.arguments[tg] = ele;
  1257. this.equationSelectEle.children.push(obj);
  1258. //跳转到最新的标签
  1259. this.actiFunIndex = (this.equationSelectEle.children.length - 1).toString();
  1260. },
  1261. //选择元素
  1262. chooseEleHandle() {
  1263. for (let i = 0; i < this.eleList.length; i++) {
  1264. if (this.eleList[i].checked) {
  1265. let ele = this.eleList[i];
  1266. let obj = {};
  1267. if (ele.k) {
  1268. obj = {
  1269. type: 'ParamData',
  1270. name: ele.name,
  1271. id: ele.id,
  1272. selected: false,
  1273. v: ele.v,
  1274. k: ele.k,
  1275. children: [],
  1276. }
  1277. } else {
  1278. obj = {
  1279. type: 'Element',
  1280. name: ele.eName,
  1281. id: ele.id,
  1282. selected: false,
  1283. tableElementKey: ele.tableElementKey,
  1284. children: [],
  1285. }
  1286. }
  1287. this.$set(this.argumenObj.arguments, this.argumenObj.index, obj);
  1288. this.chooseEleVisible = false;
  1289. break;
  1290. }
  1291. }
  1292. },
  1293. //显示选择元素弹窗
  1294. showChooseEle(argumenObj) {
  1295. this.argumenObj = argumenObj;
  1296. this.chooseEleVisible = true;
  1297. // this.eleList=[];
  1298. // this.eleTableList=[];
  1299. this.eleTableId = '';
  1300. this.allTreeShow = false;
  1301. this.filterText = ''
  1302. this.eleList.forEach((ele) => {
  1303. this.$set(ele, 'checked', false);
  1304. //ele.checked = false;
  1305. })
  1306. // this.treeId=''
  1307. },
  1308. //移除挂载的函数
  1309. removeFun(name) {
  1310. //console.log(name)
  1311. this.equationSelectEle.children.splice(Number(name), 1);
  1312. },
  1313. //切换公式tab标签
  1314. funLeave(activeName, oldActiveName) {
  1315. if (oldActiveName) {
  1316. let formula = this.equationSelectEle.children[Number(oldActiveName)];
  1317. if (formula) {
  1318. return this.checkFormulaLegal(formula);
  1319. }
  1320. }
  1321. },
  1322. //检测公式合法
  1323. checkFormulaLegal(formula) {
  1324. if (!formula.arguments) {
  1325. return false;
  1326. }
  1327. //当前选中的元素
  1328. let curEle = this.equationSelectEle;
  1329. let isIn = false;
  1330. for (let i = 0; i < formula.arguments.length; i++) {
  1331. if (Array.isArray(formula.arguments[i])) {
  1332. for (let j = 0; j < formula.arguments[i].length; j++) {
  1333. if (formula.arguments[i][j] && formula.arguments[i][j].id == curEle.id) {
  1334. isIn = true;
  1335. break;
  1336. }
  1337. }
  1338. if (isIn) {
  1339. break;
  1340. }
  1341. } else if (formula.arguments[i] && formula.arguments[i].id == curEle.id) {
  1342. isIn = true;
  1343. break;
  1344. }
  1345. }
  1346. if (!isIn) {
  1347. this.$message({
  1348. type: "warning",
  1349. message: "参数必须有一个值是当前元素"
  1350. });
  1351. return false;
  1352. }
  1353. return true;
  1354. },
  1355. //保存公式
  1356. saveFormula() {
  1357. console.log('保存1-edit1', this.pid);
  1358. console.log(this.processFormula, 'this.processFormula1111111112333');
  1359. console.log(this.resultFormula, 'this.resultFormula1111111112333');
  1360. console.log(this.$refs.dynamicComponent, 'this.$refs.dynamicComponent');
  1361. // let obj = formulaArrayToString(this.processFormula,this.resultFormula);
  1362. if (this.$refs.dynamicComponent && this.$refs.dynamicComponent.length > 0 && this.$refs.dynamicComponent[0] && this.$refs.dynamicComponent[0].symbol == 'more') {
  1363. //多条件保存公式
  1364. console.log('this.$refs.conditionList[0]', this.$refs.dynamicComponent[0]);
  1365. const resMore = formatArrayMore(this.$refs.dynamicComponent[0].conditionList);
  1366. const resJson = generateResult(this.$refs.dynamicComponent[0].conditionList);
  1367. const remark = this.$refs.dynamicComponent[0].remark;
  1368. const method = this.$refs.dynamicComponent[0].method;
  1369. // console.log(remark, 'remark');
  1370. console.log(resJson, 'resJson');
  1371. if (this.formulaid) {
  1372. updateFormula({
  1373. id: this.formulaid,
  1374. formula: '',
  1375. formulas: resMore,
  1376. remark: remark,
  1377. method: method,
  1378. nodeId: this.nodeid,
  1379. elementId: this.eleid,
  1380. scale: this.isRetain ? this.retainNum : '',
  1381. number: number,
  1382. map: JSON.stringify(resJson),
  1383. scope: this.globaltype,
  1384. // projectId:this.curProjiect.id||this.projectId,
  1385. projectId: this.curProjiect.id || this.pid,
  1386. dev: deviationRangeText
  1387. }).then(() => {
  1388. this.formulaStringToArray();
  1389. this.$message({
  1390. type: "success",
  1391. message: "修改成功"
  1392. });
  1393. })
  1394. } else {
  1395. saveFormula({
  1396. formula: '',
  1397. formulas: resMore,
  1398. remark: remark,
  1399. method: method,
  1400. nodeId: this.nodeid,
  1401. elementId: this.eleid,
  1402. scale: this.isRetain ? this.retainNum : '',
  1403. number: number,
  1404. map: JSON.stringify(resJson),
  1405. scope: this.globaltype,
  1406. dev: deviationRangeText,
  1407. projectId: this.curProjiect.id || this.pid,
  1408. ver: this.version
  1409. }).then((res) => {
  1410. if (res.data.data) {
  1411. this.formulaid = res.data.data;
  1412. }
  1413. this.formulaStringToArray();
  1414. this.$message({
  1415. type: "success",
  1416. message: "保存成功"
  1417. });
  1418. })
  1419. }
  1420. return;
  1421. } else if (this.$refs.dynamicComponent && this.$refs.dynamicComponent.length > 0 && this.$refs.dynamicComponent[0] && this.$refs.dynamicComponent[0].symbol == 'getData') {
  1422. //数据获取保存公式
  1423. const dataRes = this.$refs.dynamicComponent[0].getDataConditionData();
  1424. console.log(dataRes, 'dataRes');
  1425. const result = dataRes.result;
  1426. const mapEle = JSON.stringify(dataRes.mapEle);
  1427. console.log(mapEle, 'mapEle');
  1428. if (this.formulaid) {
  1429. updateFormula({
  1430. id: this.formulaid,
  1431. formula: "FC.switchCase" + '(' + result + ')',
  1432. remark: '',
  1433. nodeId: this.nodeid,
  1434. elementId: this.eleid,
  1435. scale: this.isRetain ? this.retainNum : '',
  1436. number: number,
  1437. map: mapEle,
  1438. scope: this.globaltype,
  1439. // projectId:this.curProjiect.id||this.projectId,
  1440. projectId: this.curProjiect.id || this.pid,
  1441. dev: deviationRangeText
  1442. }).then(() => {
  1443. this.formulaStringToArray();
  1444. this.$message({
  1445. type: "success",
  1446. message: "修改成功"
  1447. });
  1448. })
  1449. } else {
  1450. saveFormula({
  1451. formula: "FC.switchCase" + '(' + result + ')',
  1452. remark: '',
  1453. nodeId: this.nodeid,
  1454. elementId: this.eleid,
  1455. scale: this.isRetain ? this.retainNum : '',
  1456. number: number,
  1457. map: mapEle,
  1458. scope: this.globaltype,
  1459. dev: deviationRangeText,
  1460. // projectId:this.curProjiect.id||this.projectId,
  1461. projectId: this.curProjiect.id || this.pid,
  1462. ver: this.version
  1463. }).then((res) => {
  1464. if (res.data.data) {
  1465. this.formulaid = res.data.data;
  1466. }
  1467. this.formulaStringToArray();
  1468. this.$message({
  1469. type: "success",
  1470. message: "保存成功"
  1471. });
  1472. })
  1473. }
  1474. return;
  1475. } else if (this.$refs.dynamicComponent && this.$refs.dynamicComponent.length > 0 && this.$refs.dynamicComponent[0] && this.$refs.dynamicComponent[0].formData) {
  1476. console.log(this.$refs.dynamicComponent[0], 'this.$refs.dynamicComponent[0');
  1477. const resForm = this.$refs.dynamicComponent[0].getDataChangeList();
  1478. console.log(resForm, 'resForm');
  1479. //数据自变保存
  1480. if (this.formulaid) {
  1481. updateFormula({
  1482. id: this.formulaid,
  1483. formula: resForm.test,
  1484. remark: '',
  1485. nodeId: this.nodeid,
  1486. elementId: this.eleid,
  1487. scale: this.isRetain ? this.retainNum : '',
  1488. number: number,
  1489. map: JSON.stringify(resForm.map),
  1490. scope: this.globaltype,
  1491. // projectId:this.curProjiect.id||this.projectId,
  1492. projectId: this.curProjiect.id || this.pid,
  1493. dev: deviationRangeText
  1494. }).then(() => {
  1495. this.formulaStringToArray();
  1496. this.$message({
  1497. type: "success",
  1498. message: "修改成功"
  1499. });
  1500. })
  1501. } else {
  1502. saveFormula({
  1503. formula: resForm.test,
  1504. remark: '',
  1505. nodeId: this.nodeid,
  1506. elementId: this.eleid,
  1507. scale: this.isRetain ? this.retainNum : '',
  1508. number: number,
  1509. map: JSON.stringify(resForm.map),
  1510. scope: this.globaltype,
  1511. dev: deviationRangeText,
  1512. // projectId:this.curProjiect.id||this.projectId,
  1513. projectId: this.curProjiect.id || this.pid,
  1514. ver: this.version
  1515. }).then((res) => {
  1516. if (res.data.data) {
  1517. this.formulaid = res.data.data;
  1518. }
  1519. this.formulaStringToArray();
  1520. this.$message({
  1521. type: "success",
  1522. message: "保存成功"
  1523. });
  1524. })
  1525. }
  1526. return
  1527. }
  1528. let arr = JSON.parse(JSON.stringify(this.processFormula));
  1529. console.log("aaaaaaaaaaaaaaaa===processFormula", arr,);
  1530. let filteredArr = arr.filter(item => item.id === this.checkGsId);
  1531. console.log("bbbbbbbbbbbbbbbb===filteredArr", filteredArr,);
  1532. // let obj = formulaArrayToString(filteredArr,this.resultFormula);
  1533. let obj
  1534. let obj2
  1535. obj = formulaArrayToString(this.processFormula, this.resultFormula);
  1536. console.log("ccccccccccccccccc===obj", obj,);
  1537. obj2 = formulaArrayToString(filteredArr, this.resultFormula);
  1538. console.log("ccccccccccccccccc===obj2", obj2,);
  1539. // 判断 obj2.text 是否包含 FC.ifelse
  1540. if (obj2.text && obj2.text.includes('FC.ifelse')) {
  1541. obj = obj2; // 如果包含 FC.ifelse,使用 obj2
  1542. }
  1543. let deviationRangeText = rangeToString(this.deviationRange.datas, obj.eleMap);
  1544. obj.eleMap.deviationRangeJson = JSON.stringify(this.deviationRange.datas);
  1545. //console.log(obj.eleMap)
  1546. //return;
  1547. //特殊公式会有number
  1548. let number = '';
  1549. for (let i = 0; i < this.processFormula.length; i++) {
  1550. if (this.processFormula[i].children) {
  1551. for (let j = 0; j < this.processFormula[i].children.length; j++) {
  1552. if (this.processFormula[i].children[j].number) {
  1553. number = this.processFormula[i].children[j].number;
  1554. break;
  1555. }
  1556. }
  1557. }
  1558. if (number) {
  1559. break;
  1560. }
  1561. }
  1562. if (number === '') {
  1563. for (let i = 0; i < this.resultFormula.length; i++) {
  1564. if (this.resultFormula[i].children) {
  1565. for (let j = 0; j < this.resultFormula[i].children.length; j++) {
  1566. if (this.resultFormula[i].children[j].number) {
  1567. number = this.resultFormula[i].children[j].number;
  1568. break;
  1569. }
  1570. }
  1571. }
  1572. if (number) {
  1573. break;
  1574. }
  1575. }
  1576. }
  1577. // console.log("55555555555", obj, obj.text);
  1578. if (this.formulaid) {
  1579. updateFormula({
  1580. id: this.formulaid,
  1581. formula: obj.text,
  1582. remark: '',
  1583. nodeId: this.nodeid,
  1584. elementId: this.eleid,
  1585. scale: this.isRetain ? this.retainNum : '',
  1586. number: number,
  1587. map: JSON.stringify(obj.eleMap),
  1588. scope: this.globaltype,
  1589. // projectId:this.curProjiect.id||this.projectId,
  1590. projectId: this.curProjiect.id || this.pid,
  1591. dev: deviationRangeText
  1592. }).then((result) => {
  1593. let msg = '修改成功';
  1594. if (result.data.msg == '公式已删除') { this.formulaid = ''; msg = result.data.msg; }
  1595. this.formulaStringToArray();
  1596. this.$message({
  1597. type: "success",
  1598. message: msg
  1599. });
  1600. })
  1601. } else {
  1602. saveFormula({
  1603. formula: obj.text,
  1604. remark: '',
  1605. nodeId: this.nodeid,
  1606. elementId: this.eleid,
  1607. scale: this.isRetain ? this.retainNum : '',
  1608. number: number,
  1609. map: JSON.stringify(obj.eleMap),
  1610. scope: this.globaltype,
  1611. // projectId:this.curProjiect.id||this.projectId,
  1612. projectId: this.curProjiect.id || this.pid,
  1613. dev: deviationRangeText,
  1614. ver: this.version
  1615. }).then((res) => {
  1616. if (res.data.data) {
  1617. this.formulaid = res.data.data;
  1618. }
  1619. this.formulaStringToArray();
  1620. this.$message({
  1621. type: "success",
  1622. message: "保存成功"
  1623. });
  1624. })
  1625. }
  1626. },
  1627. //把公式文本还原数组
  1628. async formulaStringToArray() {
  1629. let detail = (await formulaDetail({ elementId: this.eleid, scope: this.globaltype, nodeId: this.nodeid, projectId: this.curProjiect.id || this.pid })).data.data;
  1630. console.log('formulaStringToArray', detail.formula);
  1631. this.remark == detail.remark;
  1632. //判断公式特殊处理
  1633. if (detail && detail.formula.includes('FC.ifelseMulti')) {
  1634. detail.formula = detail.formula.replace('FC.ifelseMulti', 'FC.ifelse');
  1635. this.isMore = true;
  1636. this.formulaDetailMap = detail.map;
  1637. this.method = detail.method;
  1638. this.moreConditions = restoreArrayMore(detail.formulas, this.formulaDetailMap)
  1639. } else if (detail && detail.formula.includes('FC.switchCase')) {
  1640. //数据获取
  1641. this.formulaDetailMap = detail.map;
  1642. detail.formula = detail.formula.replace('FC.switchCase', 'FC.ifelse');
  1643. this.isGetData = true;
  1644. this.dataListGet = detail.formula
  1645. console.log(this.dataListGet, ' this.dataListGet');
  1646. } else if (detail && detail.formula.includes('FC.dataChange')) {
  1647. //数据自变
  1648. this.formulaDetailMap = detail.map;
  1649. this.isDataChange = true;
  1650. this.dataForm = detail.formula
  1651. console.log(this.dataForm, ' this.dataListGet');
  1652. }
  1653. else {
  1654. this.isMore = false;
  1655. this.moreConditions = []
  1656. this.formulaDetailMap = {}
  1657. this.isGetData = false;
  1658. this.dataListGet = ''
  1659. this.isDataChange = false;
  1660. this.dataForm = '';
  1661. }
  1662. if (detail && detail.id) {
  1663. //获取右边元素的字典
  1664. let dictMap = detail.dict
  1665. let dictArr = []
  1666. //遍历:
  1667. for (let i in dictMap) {
  1668. dictArr.push(dictMap[i])
  1669. }
  1670. this.rightDict = dictArr
  1671. this.formulaid = detail.id;
  1672. let formula = formulaStringToArray(detail.formula, detail.map, this.formulaMap);
  1673. this.processFormula = formula.processFormula;
  1674. formula.resultFormula[0].id = this.resultFormula[0].id;
  1675. formula.resultFormula[0].name = this.resultFormula[0].name;
  1676. formula.resultFormula[0].tableElementKey = this.resultFormula[0].tableElementKey;
  1677. this.resultFormula[0].children = formula.resultFormula[0].children;
  1678. //允许偏差值范围
  1679. let mapObj = JSON.parse(detail.map);
  1680. if (mapObj.deviationRangeJson) {
  1681. this.deviationRange.datas = JSON.parse(mapObj.deviationRangeJson);
  1682. }
  1683. }
  1684. if (detail && detail.scale != null && detail.scale >= 0) {
  1685. this.isRetain = true;
  1686. this.retainNum = detail.scale;
  1687. } else {
  1688. this.isRetain = false;
  1689. this.retainNum = 2
  1690. }
  1691. },
  1692. //设置动态组件里面的元素
  1693. setComponentEle(value, item, index) {
  1694. if (value) {
  1695. //console.log(this.$refs.dynamicComponent[index])
  1696. this.$refs.dynamicComponent[index].setELe(item);
  1697. }
  1698. },
  1699. //设置动态组件里面的元素
  1700. setDeviationRangeEle(value, item) {
  1701. if (value) {
  1702. //console.log(this.$refs.dynamicComponent[index])
  1703. this.$refs.deviationRange.setELe(item);
  1704. }
  1705. },
  1706. async tabTypeLazyTreeAll(parentId, current, size, titleName) {//清表树
  1707. console.log(parentId);
  1708. const { data: res } = await tabTypeLazyTreeAll({ parentId, current, size, titleName })
  1709. if (res.code === 200) {
  1710. return res.data
  1711. }
  1712. },
  1713. getNodeDetail(data, node) {
  1714. console.log(data, node, 'getNodeDetail');
  1715. this.curNode = node;
  1716. this.curData = data;
  1717. this.treeId = data.initTableId;
  1718. this.page.current = 1;
  1719. this.page.currentPage = 1;
  1720. this.input3 = ''
  1721. if (data.hasChildren === false || data.isLinkTable === 2) {
  1722. this.eleListable = true;
  1723. // 放出来的代码开始
  1724. getTableElments(data.initTableId).then((res) => {
  1725. if (res.data.code == 200) {
  1726. this.eleList = res.data.data;
  1727. this.eleTableList = res.data.data;
  1728. this.eleListable = false;
  1729. }
  1730. })
  1731. // 放出来的代码结束
  1732. this.eleTableList = [this.curData] || []
  1733. this.eleTableId = this.eleTableList[0].id;
  1734. }
  1735. else {
  1736. this.eleListable = true;
  1737. this.eleList = []
  1738. this.page.total = 0
  1739. setTimeout(() => {
  1740. this.eleListable = false
  1741. }, 1000);
  1742. }
  1743. },
  1744. getEleDetail() {
  1745. getEleDetail(this.eleid).then((res) => {
  1746. let ele = res.data.data;
  1747. this.resultFormula = [{
  1748. type: 'Element',
  1749. name: ele.eName,
  1750. id: ele.id,
  1751. selected: false,
  1752. tableElementKey: ele.tableElementKey.replace('_key',':key'),
  1753. children: [],
  1754. }]
  1755. })
  1756. },
  1757. searchChange() {
  1758. this.eleListable = true;
  1759. getTableElments(this.treeId, this.inputEle).then((res) => {
  1760. this.eleList = res.data.data;
  1761. this.eleListable = false;
  1762. })
  1763. },
  1764. searchChangePian() {
  1765. this.eleListCompLoading = true;
  1766. getTableElments(this.treeId, this.inputElePian).then((res) => {
  1767. this.eleListComp = res.data.data;
  1768. this.eleListCompLoading = false;
  1769. })
  1770. },
  1771. searchChangeJudge() {
  1772. this.eleListJudge = true;
  1773. getTableElments(this.treeId, this.inputEleJudge).then((res) => {
  1774. this.eleListComp = res.data.data;
  1775. this.eleListJudge = false;
  1776. })
  1777. },
  1778. clearInput() {
  1779. this.eleListable = true;
  1780. getTableElments(this.treeId).then((res) => {
  1781. this.eleList = res.data.data;
  1782. this.eleListable = false;
  1783. })
  1784. },
  1785. clearInputPian() {
  1786. // eleListComp
  1787. this.eleListCompLoading = true;
  1788. getTableElments(this.treeId).then((res) => {
  1789. this.eleListComp = res.data.data;
  1790. this.eleListCompLoading = false
  1791. })
  1792. },
  1793. clearInputJudge() {
  1794. this.eleListJudge = true;
  1795. getTableElments(this.treeId).then((res) => {
  1796. this.eleListComp = res.data.data;
  1797. })
  1798. this.eleListJudge = false;
  1799. },
  1800. getNodeDetailComp(data, node) {
  1801. this.treeId = data.initTableId;
  1802. this.curNode = node;
  1803. this.curData = data;
  1804. this.input3 = ''
  1805. if (data.hasChildren === false) {
  1806. getTableElments(data.initTableId).then((res) => {
  1807. if (res.data.code == 200) {
  1808. if (res.data.data.length) {
  1809. this.eleListComp = res.data.data;
  1810. this.eleTableListComp = res.data.data;
  1811. console.log(this.eleTableListComp, ' this.eleTableListComp');
  1812. this.eleTableIdComp = this.eleTableListComp[0].id;
  1813. }
  1814. }
  1815. })
  1816. }
  1817. else {
  1818. this.eleListComp = []
  1819. this.page.total = 0
  1820. }
  1821. },
  1822. //取消方法下面 元素勾选
  1823. unCheckEleComp(eleId) {
  1824. //console.log(eleId)
  1825. for (let i = 0; i < this.eleListComp.length; i++) {
  1826. if (this.eleListComp[i].id == eleId) {
  1827. this.eleListComp[i].checked = false;
  1828. }
  1829. }
  1830. },
  1831. //手写模式
  1832. handwrit() {
  1833. try {
  1834. let obj = formulaArrayToString(this.processFormula, this.resultFormula);
  1835. this.handwritText = obj.text;
  1836. this.handwritEleMap = JSON.stringify(obj.eleMap);
  1837. this.handwritVisible = true;
  1838. } catch (error) {
  1839. console.error(error)
  1840. this.$message({
  1841. type: "error",
  1842. message: "生成公式文本失败," + error
  1843. });
  1844. }
  1845. },
  1846. //转成配置用的数组
  1847. handwritTransform() {
  1848. try {
  1849. let formula = formulaStringToArray(this.handwritText, this.handwritEleMap, this.formulaMap);
  1850. this.processFormula = formula.processFormula;
  1851. formula.resultFormula[0].id = this.resultFormula[0].id;
  1852. formula.resultFormula[0].name = this.resultFormula[0].name;
  1853. formula.resultFormula[0].tableElementKey = this.resultFormula[0].tableElementKey;
  1854. this.resultFormula[0].children = formula.resultFormula[0].children;
  1855. this.handwritVisible = false;
  1856. } catch (error) {
  1857. console.error(error)
  1858. this.$message({
  1859. type: "error",
  1860. message: "转成配置用的数组失败," + error
  1861. });
  1862. }
  1863. },
  1864. editorInit: function (editor) {
  1865. console.log('editorInit')
  1866. require('brace/ext/searchbox') //添加搜索功能
  1867. require('brace/ext/language_tools') //language extension prerequsite...
  1868. require('brace/mode/javascript') //language
  1869. require('brace/theme/github')
  1870. require('brace/snippets/javascript') //snippet
  1871. editor.session.setUseWrapMode(true);//切换自动换行
  1872. editor.setHighlightActiveLine(false);//设置行高亮显示
  1873. editor.setShowPrintMargin(false);
  1874. editor.setOptions({
  1875. enableLiveAutocompletion: true,//语法提示和补全
  1876. showInvisibles: true,//显示隐藏,空格,回车等
  1877. fontSize: '16px'
  1878. })
  1879. },
  1880. getTypeMap() {
  1881. return new Promise((resolve) => {
  1882. getTypeMap().then((res) => {
  1883. //console.log(res)
  1884. this.formulaList = res.data.data;
  1885. //生成map,方便查找
  1886. for (let key in this.formulaList) {
  1887. if (typeof (this.formulaList[key]) == 'object') {
  1888. this.formulaList[key].forEach((formula) => {
  1889. formula.template = JSON.parse(formula.template);
  1890. if (this.operatorReg.test(formula.template.ft)) {
  1891. this.formulaMap[formula.template.ft] = formula;
  1892. } else if (this.startFCRegExp.test(formula.template.ft)) {
  1893. let regRes = formula.template.ft.match(this.startFCRegExp);
  1894. this.formulaMap[regRes[0]] = formula;
  1895. }
  1896. })
  1897. }
  1898. }
  1899. }).finally(() => {
  1900. resolve();
  1901. })
  1902. })
  1903. },
  1904. // 左箭头导航
  1905. handleLeftArrow(e) {
  1906. e.preventDefault(); // 阻止默认行为
  1907. if (this.curSeleEleIndex > 0) {
  1908. // 取消当前选中项
  1909. if (this.selectEleFormula[this.curSeleEleIndex]) {
  1910. this.selectEleFormula[this.curSeleEleIndex].selected = false;
  1911. }
  1912. // 选中左侧项
  1913. this.curSeleEleIndex--;
  1914. this.selectEleFormula[this.curSeleEleIndex].selected = true;
  1915. // this.selectedTableKey = this.selectEleFormula[this.curSeleEleIndex].tableElementKey;
  1916. console.log(this.selectEleFormula[this.curSeleEleIndex].tableElementKey);
  1917. if (this.selectEleFormula[this.curSeleEleIndex].tableElementKey) {
  1918. const keyParts = this.selectEleFormula[this.curSeleEleIndex].tableElementKey.split('key');
  1919. this.selectedTableKey = keyParts.length > 1 ? 'key' + keyParts[1] : null;
  1920. }
  1921. }
  1922. },
  1923. // 右箭头导航
  1924. handleRightArrow(e) {
  1925. e.preventDefault(); // 阻止默认行为
  1926. if (this.curSeleEleIndex < this.selectEleFormula.length - 1) {
  1927. // 取消当前选中项
  1928. if (this.selectEleFormula[this.curSeleEleIndex]) {
  1929. this.selectEleFormula[this.curSeleEleIndex].selected = false;
  1930. }
  1931. // 选中右侧项
  1932. this.curSeleEleIndex++;
  1933. this.selectEleFormula[this.curSeleEleIndex].selected = true;
  1934. // this.selectedTableKey = this.selectEleFormula[this.curSeleEleIndex].tableElementKey;
  1935. console.log(this.selectEleFormula[this.curSeleEleIndex].tableElementKey);
  1936. if (this.selectEleFormula[this.curSeleEleIndex].tableElementKey) {
  1937. const keyParts = this.selectEleFormula[this.curSeleEleIndex].tableElementKey.split('key');
  1938. this.selectedTableKey = keyParts.length > 1 ? 'key' + keyParts[1] : null;
  1939. }
  1940. }
  1941. },
  1942. // 处理删除操作
  1943. handleDelete(e) {
  1944. e.preventDefault();
  1945. // 增加更严格的索引检查
  1946. if (
  1947. this.curSeleEleIndex === null ||
  1948. this.curSeleEleIndex === undefined ||
  1949. this.curSeleEleIndex < 0 ||
  1950. this.curSeleEleIndex >= this.selectEleFormula.length
  1951. ) {
  1952. return;
  1953. }
  1954. // 保存当前要删除的元素索引(避免后续操作影响)
  1955. const indexToDelete = this.curSeleEleIndex;
  1956. const itemToDelete = this.selectEleFormula[indexToDelete];
  1957. // 处理元素取消勾选
  1958. if (itemToDelete && itemToDelete.type === 'Element') {
  1959. this.deleEleIndex = indexToDelete;
  1960. this.unCheckEleFormulac(itemToDelete.id);
  1961. }
  1962. // 执行删除(只删除指定索引的1个元素)
  1963. const deletedItems = this.selectEleFormula.splice(indexToDelete, 1);
  1964. // 正确更新当前选中索引
  1965. if (this.selectEleFormula.length > 0) {
  1966. // 如果删除的是第一个元素,选中第一个元素
  1967. this.curSeleEleIndex = indexToDelete == 0 ? 0 : indexToDelete - 1;
  1968. // 如果删除的是最后一个元素,选中前一个
  1969. // this.curSeleEleIndex = Math.min(
  1970. // indexToDelete - 1,
  1971. // this.selectEleFormula.length - 1
  1972. // );
  1973. if (this.selectEleFormula[this.curSeleEleIndex].tableElementKey) {
  1974. const keyParts = this.selectEleFormula[this.curSeleEleIndex].tableElementKey.split('key');
  1975. this.selectedTableKey = keyParts.length > 1 ? 'key' + keyParts[1] : null;
  1976. }
  1977. // 确保选中状态正确
  1978. this.selectEleFormula.forEach((item, idx) => {
  1979. item.selected = idx === this.curSeleEleIndex;
  1980. });
  1981. } else {
  1982. this.curSeleEleIndex = -1;
  1983. this.selectedTableKey = null;
  1984. }
  1985. },
  1986. checkDefaultSelection() {
  1987. const hasSelected = this.selectEleFormula.some(item => item.selected);
  1988. if (!hasSelected && this.selectEleFormula.length > 0) {
  1989. // 取消所有选中
  1990. this.selectEleFormula.forEach(item => {
  1991. item.selected = false;
  1992. });
  1993. // 选中最后一个元素
  1994. const lastIndex = this.selectEleFormula.length - 1;
  1995. this.selectEleFormula[lastIndex].selected = true;
  1996. this.curSeleEleIndex = lastIndex;
  1997. }
  1998. },
  1999. },
  2000. };
  2001. </script>
  2002. <style scoped lang="scss">
  2003. .box-dashed {
  2004. border: 1px dashed #bbbbbb;
  2005. border-radius: 6px;
  2006. padding: 10px;
  2007. margin-bottom: 10px;
  2008. }
  2009. .retain-box {
  2010. border-right: 1px dashed #bbbbbb;
  2011. display: flex;
  2012. align-items: center;
  2013. padding: 0 10px;
  2014. .unit {
  2015. padding-left: 6px;
  2016. }
  2017. }
  2018. .edit-text {
  2019. font-size: 26px;
  2020. margin-left: 20px;
  2021. display: flex;
  2022. flex-wrap: wrap;
  2023. }
  2024. .el-menu--popup .el-menu-item.is-active {
  2025. background-color: #fff;
  2026. }
  2027. .ele-box {
  2028. //border: 1px solid #bbb;
  2029. //height: 26px;
  2030. display: flex;
  2031. justify-content: space-between;
  2032. align-items: center;
  2033. padding: 6px;
  2034. height: 100%;
  2035. box-sizing: border-box;
  2036. overflow: hidden;
  2037. }
  2038. .no-mb-col .el-col {
  2039. margin-bottom: 0px;
  2040. border: 1px solid #bbb;
  2041. height: 100px;
  2042. }
  2043. .sele-ele-box {
  2044. height: 160px;
  2045. padding: 20px;
  2046. overflow-y: auto;
  2047. // margin-top: 10px;
  2048. }
  2049. </style>
  2050. <style lang="scss">
  2051. .basic-container.h-basic-full {
  2052. height: calc(100% - 30px);
  2053. overflow: auto;
  2054. .el-card,
  2055. .el-card .el-card__body {
  2056. height: 100%;
  2057. }
  2058. }
  2059. .el-select-dropdown {
  2060. max-width: 600px;
  2061. }
  2062. //.el-select-dropdown__item{
  2063. // display: inline-block;
  2064. //}
  2065. .el-select-dropdown__item span {
  2066. // min-width: 300px;
  2067. display: inline-block;
  2068. }
  2069. </style>
  2070. <style scoped lang="scss">
  2071. .operation-symbol-box {
  2072. display: flex;
  2073. align-items: center;
  2074. border: 1px solid rgb(229, 231, 235);
  2075. background-color: #F9FAFB;
  2076. padding: 10px 10px;
  2077. border-radius: 5px 5px 0px 0px;
  2078. margin-top: 10px;
  2079. span {
  2080. margin-right: 10px;
  2081. font-size: 16px;
  2082. }
  2083. ::v-deep .el-link {
  2084. font-size: 16px;
  2085. margin-right: 10px;
  2086. }
  2087. }
  2088. .sele-ele-box1 {
  2089. padding: 10px;
  2090. border: 1px solid rgb(229, 231, 235);
  2091. border-radius: 0px 0px 5px 5px;
  2092. overflow-y: scroll;
  2093. height: 50px;
  2094. .pane-box {
  2095. width: 100%;
  2096. display: flex;
  2097. flex-wrap: wrap;
  2098. align-items: center;
  2099. }
  2100. }
  2101. </style>