index.vue 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944
  1. <template>
  2. <div class="supervision-content-container">
  3. <!-- 搜索表单 -->
  4. <div class="search-panel">
  5. <el-form :inline="true" :model="searchForm" class="search-form">
  6. <el-form-item label="监审类别:">
  7. <el-cascader
  8. v-model="searchForm.catalogId"
  9. :options="catalogListOptions"
  10. placeholder=" 请选择监审类别"
  11. v-bind="props"
  12. style="width: 100%"
  13. clearable
  14. ></el-cascader>
  15. </el-form-item>
  16. <el-form-item label="模板名称:">
  17. <el-input
  18. v-model="searchForm.keyword"
  19. placeholder="请输入模板名称"
  20. clearable
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" @click="handleSearch">
  25. 搜索
  26. </el-button>
  27. <el-button
  28. plain
  29. type="primary"
  30. icon="el-icon-refresh"
  31. @click="handleReset"
  32. >
  33. 重置
  34. </el-button>
  35. </el-form-item>
  36. </el-form>
  37. </div>
  38. <!-- 操作按钮 -->
  39. <div class="operation-bar">
  40. <el-button
  41. v-region-permission="{
  42. category: 'costVerifyManage',
  43. action: 'add',
  44. }"
  45. plain
  46. type="success"
  47. icon="el-icon-circle-plus"
  48. @click="handleAdd"
  49. >
  50. <!-- v-region-permission="{
  51. category: 'costVerifyManage',
  52. action: 'add',
  53. }" -->
  54. 添加
  55. </el-button>
  56. <el-button
  57. v-region-permission="{
  58. category: 'costVerifyManage',
  59. action: 'delete',
  60. }"
  61. plain
  62. type="danger"
  63. icon="el-icon-delete"
  64. :disabled="selectedRows.length === 0"
  65. @click="handleBatchDelete"
  66. >
  67. 删除
  68. </el-button>
  69. </div>
  70. <!-- 表格 -->
  71. <div class="table-container">
  72. <el-table
  73. v-loading="loading"
  74. :data="tableData"
  75. border
  76. style="width: 100%"
  77. :default-sort="{ prop: 'createTime', order: 'descending' }"
  78. @selection-change="handleSelectionChange"
  79. >
  80. <!-- :default-sort="{ prop: 'createTime', order: 'descending' }" -->
  81. <el-table-column
  82. type="selection"
  83. width="55"
  84. align="center"
  85. show-overflow-tooltip
  86. ></el-table-column>
  87. <el-table-column
  88. type="index"
  89. label="序号"
  90. width="60"
  91. align="center"
  92. show-overflow-tooltip
  93. ></el-table-column>
  94. <el-table-column
  95. prop="catalogId"
  96. label="监审类别"
  97. align="center"
  98. show-overflow-tooltip
  99. >
  100. <template slot-scope="scope">
  101. <div>{{ getCatalogNames(scope.row) }}</div>
  102. </template>
  103. </el-table-column>
  104. <el-table-column
  105. prop="surveyTemplateName"
  106. label="核定模板名称"
  107. show-overflow-tooltip
  108. align="center"
  109. ></el-table-column>
  110. <el-table-column
  111. prop="versionNo"
  112. label="版本号"
  113. align="center"
  114. width="150"
  115. ></el-table-column>
  116. <el-table-column
  117. prop="status"
  118. label="状态"
  119. width="100"
  120. show-overflow-tooltip
  121. align="center"
  122. >
  123. <template slot-scope="scope">
  124. <span>
  125. {{
  126. scope.row.status == '-1'
  127. ? '草稿'
  128. : scope.row.status == '0'
  129. ? '启用'
  130. : '停用'
  131. }}
  132. </span>
  133. </template>
  134. </el-table-column>
  135. <el-table-column
  136. prop="createBy"
  137. label="创建人"
  138. width="120"
  139. show-overflow-tooltip
  140. align="center"
  141. ></el-table-column>
  142. <el-table-column
  143. prop="createTime"
  144. label="创建时间"
  145. width="160"
  146. show-overflow-tooltip
  147. align="center"
  148. sortable
  149. >
  150. <!-- sortable -->
  151. <template slot-scope="scope">
  152. <div>{{ scope.row.createTime.split(' ')[0] }}</div>
  153. <div>{{ scope.row.createTime.split(' ')[1] }}</div>
  154. </template>
  155. </el-table-column>
  156. <el-table-column
  157. label="操作"
  158. width="240"
  159. fixed="right"
  160. show-overflow-tooltip
  161. align="center"
  162. >
  163. <template slot-scope="scope">
  164. <el-button
  165. v-region-permission="{
  166. category: 'costVerifyManage',
  167. action: 'view',
  168. }"
  169. type="text"
  170. size="mini"
  171. @click="handleViewDetail(scope.row)"
  172. >
  173. 查看
  174. </el-button>
  175. <el-button
  176. v-if="scope.row.status != '0'"
  177. v-region-permission="{
  178. category: 'costVerifyManage',
  179. action: 'edit',
  180. targetData: scope.row,
  181. }"
  182. type="text"
  183. size="mini"
  184. @click="handleEdit(scope.row)"
  185. >
  186. 修改
  187. </el-button>
  188. <el-button
  189. v-region-permission="{
  190. category: 'costVerifyManage',
  191. action: 'edit',
  192. targetData: scope.row,
  193. }"
  194. type="text"
  195. size="mini"
  196. @click="handleStatusChange(scope.row)"
  197. >
  198. <!-- (-1草稿,0启用,1停用) -->
  199. {{ scope.row.status == '0' ? '停用' : '启用' }}
  200. </el-button>
  201. <el-button
  202. v-if="scope.row.status != '0'"
  203. v-region-permission="{
  204. category: 'costVerifyManage',
  205. action: 'delete',
  206. targetData: scope.row,
  207. }"
  208. type="text"
  209. size="mini"
  210. @click="handleDeleteRow(scope.row)"
  211. >
  212. 删除
  213. </el-button>
  214. </template>
  215. </el-table-column>
  216. </el-table>
  217. <el-pagination
  218. class="mt20"
  219. :current-page.sync="searchForm.page"
  220. :page-size="searchForm.pageSize"
  221. :page-sizes="[50, 100]"
  222. layout="total, sizes, prev, pager, next, jumper"
  223. :total="pagination.total"
  224. @current-change="handleCurrentChange"
  225. @size-change="handleSizeChange"
  226. ></el-pagination>
  227. </div>
  228. <!-- 添加/修改弹窗 -->
  229. <el-dialog
  230. :title="dialogTitle"
  231. :visible.sync="dialogVisible"
  232. width="75%"
  233. :close-on-click-modal="false"
  234. >
  235. <el-form
  236. ref="contentEditForm"
  237. :model="contentEditForm"
  238. :rules="contentEditFormRules"
  239. label-width="220px"
  240. class="content-form"
  241. :disabled="dialogTitle == '查看成本核定模板'"
  242. >
  243. <el-row :gutter="20">
  244. <el-col :span="12">
  245. <el-form-item label="监审类别:" prop="catalogId">
  246. <el-cascader
  247. v-model="contentEditForm.catalogId"
  248. :options="catalogListOptions"
  249. v-bind="props"
  250. style="width: 100%"
  251. ></el-cascader>
  252. </el-form-item>
  253. </el-col>
  254. <el-col :span="12">
  255. <el-form-item label="核定模板名称:" prop="surveyTemplateName">
  256. <el-input
  257. v-model="contentEditForm.surveyTemplateName"
  258. placeholder="请输入核定模板名称"
  259. ></el-input>
  260. </el-form-item>
  261. </el-col>
  262. </el-row>
  263. <el-row :gutter="20">
  264. <el-col :span="12">
  265. <el-form-item label="" prop="createtemplateid">
  266. <!-- :disabled="dialogTitle == '修改成本核定模板'" -->
  267. <template slot="label">
  268. <el-radio
  269. v-model="contentEditForm.createmode"
  270. label="1"
  271. :disabled="
  272. dialogTitle == '查看成本核定模板' ||
  273. dialogTitle == '修改成本核定模板' ||
  274. contentEditForm.surveyTemplateId != ''
  275. "
  276. @change="handleCreateModeChange"
  277. >
  278. 根据调查表生成:
  279. </el-radio>
  280. </template>
  281. <el-select
  282. v-model="contentEditForm.createtemplateid"
  283. placeholder="请选择"
  284. :disabled="
  285. dialogTitle == '查看成本核定模板' ||
  286. dialogTitle == '修改成本核定模板' ||
  287. contentEditForm.surveyTemplateId != ''
  288. "
  289. >
  290. <el-option
  291. v-for="item in surveyFormList"
  292. :key="item.id"
  293. :label="item.surveyTemplateName"
  294. :value="item.surveyTemplateId"
  295. ></el-option>
  296. </el-select>
  297. </el-form-item>
  298. </el-col>
  299. <el-col :span="12">
  300. <el-form-item label="" prop="">
  301. <template slot="label">
  302. <el-radio
  303. v-model="contentEditForm.createmode"
  304. label="2"
  305. :disabled="
  306. dialogTitle == '查看成本核定模板' ||
  307. dialogTitle == '修改成本核定模板' ||
  308. contentEditForm.surveyTemplateId != ''
  309. "
  310. @change="handleCreateModeChange"
  311. >
  312. 根据历史核定模板生成:
  313. </el-radio>
  314. </template>
  315. <el-select
  316. v-model="contentEditForm.createtemplateid1"
  317. placeholder="请选择"
  318. :disabled="
  319. dialogTitle == '查看成本核定模板' ||
  320. dialogTitle == '修改成本核定模板' ||
  321. contentEditForm.surveyTemplateId != ''
  322. "
  323. >
  324. <el-option
  325. v-for="item in contentEditFormList"
  326. :key="item.id"
  327. :label="item.surveyTemplateName"
  328. :value="item.surveyTemplateId"
  329. ></el-option>
  330. </el-select>
  331. </el-form-item>
  332. </el-col>
  333. </el-row>
  334. </el-form>
  335. <div>
  336. <div class="mb20">
  337. <el-button
  338. v-if="!contentEditForm.surveyTemplateId"
  339. type="primary"
  340. class="mr20"
  341. @click="handleGenerateTemplate"
  342. >
  343. 生成模版
  344. </el-button>
  345. </div>
  346. <div
  347. v-if="contentEditForm.surveyTemplateId"
  348. class="table-edit-container"
  349. >
  350. <div class="mb20">
  351. <el-button
  352. v-if="dialogTitle != '查看成本核定模板'"
  353. type="primary"
  354. @click="handleAddTableHeader('固定表表头')"
  355. >
  356. 添加表头
  357. </el-button>
  358. <el-button
  359. v-if="dialogTitle != '查看成本核定模板'"
  360. type="primary"
  361. @click="handleSaveContent('固定表表头')"
  362. >
  363. 下一步
  364. </el-button>
  365. </div>
  366. <div class="table-edit-container">
  367. <el-table
  368. :data="contentEditForm.fixedTable.tableHeaders"
  369. border
  370. style="width: 100%"
  371. >
  372. <el-table-column label="序号" width="80" align="center">
  373. <template slot-scope="scope">
  374. <span>{{ scope.$index + 1 }}</span>
  375. </template>
  376. </el-table-column>
  377. <el-table-column
  378. prop="fieldName"
  379. label="字段名称"
  380. min-width="150"
  381. align="center"
  382. >
  383. <template slot-scope="scope">
  384. <el-input
  385. v-model="scope.row.fieldName"
  386. placeholder="请输入字段名称"
  387. size="small"
  388. :disabled="
  389. scope.row.isReadOnly || dialogTitle == '查看成本核定模板'
  390. "
  391. @change="handleFieldNameChange(scope.row)"
  392. ></el-input>
  393. </template>
  394. </el-table-column>
  395. <el-table-column
  396. prop="fieldType"
  397. label="字段类型"
  398. width="120"
  399. align="center"
  400. >
  401. <template slot-scope="scope">
  402. <el-select
  403. v-model="scope.row.fieldType"
  404. placeholder="请选择字段类型"
  405. size="small"
  406. :disabled="
  407. scope.row.isReadOnly || dialogTitle == '查看成本核定模板'
  408. "
  409. @change="handleFieldTypeChange(scope.row)"
  410. >
  411. <el-option label="字符串" value="string"></el-option>
  412. <el-option label="整数" value="integer"></el-option>
  413. <el-option label="小数" value="double"></el-option>
  414. <el-option label="日期" value="datetime"></el-option>
  415. <el-option label="布尔值" value="boolean"></el-option>
  416. </el-select>
  417. </template>
  418. </el-table-column>
  419. <el-table-column
  420. prop="format"
  421. label="格式"
  422. width="220"
  423. align="center"
  424. >
  425. <template slot-scope="scope">
  426. <!-- 字符串类型格式 -->
  427. <div
  428. v-if="scope.row.fieldType === 'string'"
  429. class="format-input"
  430. >
  431. <span class="format-prefix">长度</span>
  432. <el-input
  433. v-model="scope.row.format"
  434. placeholder="请输入长度"
  435. size="small"
  436. style="width: calc(100% - 80px); margin-left: 5px"
  437. :disabled="
  438. scope.row.isReadOnly ||
  439. dialogTitle == '查看成本核定模板'
  440. "
  441. ></el-input>
  442. </div>
  443. <!-- 整数类型格式 -->
  444. <div
  445. v-else-if="scope.row.fieldType === 'integer'"
  446. class="format-input"
  447. >
  448. <span class="format-prefix">整数</span>
  449. <el-input
  450. v-model="scope.row.fieldTypelen"
  451. placeholder="整数位数"
  452. size="small"
  453. style="width: calc(100% - 80px); margin: 0 5px"
  454. :disabled="
  455. scope.row.isReadOnly ||
  456. dialogTitle == '查看成本核定模板'
  457. "
  458. ></el-input>
  459. </div>
  460. <!-- 小数类型格式 -->
  461. <div
  462. v-else-if="scope.row.fieldType === 'double'"
  463. class="format-input"
  464. >
  465. <span class="format-prefix">小数</span>
  466. <el-input
  467. v-model="scope.row.fieldTypenointlen"
  468. placeholder="小数位数"
  469. size="small"
  470. style="width: calc(100% - 80px); margin-left: 5px"
  471. :disabled="
  472. scope.row.isReadOnly ||
  473. dialogTitle == '查看成本核定模板'
  474. "
  475. ></el-input>
  476. </div>
  477. <!-- 日期类型格式 -->
  478. <div
  479. v-else-if="scope.row.fieldType === 'datetime'"
  480. class="format-input"
  481. >
  482. <el-select
  483. v-model="scope.row.format"
  484. placeholder="请选择日期格式"
  485. size="small"
  486. style="width: 100%"
  487. :disabled="
  488. scope.row.isReadOnly ||
  489. dialogTitle == '查看成本核定模板'
  490. "
  491. >
  492. <el-option
  493. label="yyyy-MM-dd HH:mm:ss"
  494. value="yyyy-MM-dd HH:mm:ss"
  495. ></el-option>
  496. <el-option
  497. label="yyyy-MM-dd"
  498. value="yyyy-MM-dd"
  499. ></el-option>
  500. </el-select>
  501. </div>
  502. <!-- 布尔类型格式 -->
  503. <div v-else-if="scope.row.fieldType === 'boolean'">
  504. <el-select
  505. v-model="scope.row.format"
  506. placeholder="请选择布尔值格式"
  507. size="small"
  508. style="width: 100%"
  509. :disabled="
  510. scope.row.isReadOnly ||
  511. dialogTitle == '查看成本核定模板'
  512. "
  513. >
  514. <el-option label="true" value="true"></el-option>
  515. <el-option label="false" value="false"></el-option>
  516. </el-select>
  517. </div>
  518. <!-- 默认情况 -->
  519. <el-input
  520. v-else
  521. v-model="scope.row.format"
  522. :placeholder="getFormatPlaceholder(scope.row.fieldType)"
  523. size="small"
  524. ></el-input>
  525. </template>
  526. </el-table-column>
  527. <el-table-column
  528. prop="isRequired"
  529. label="是否必填"
  530. width="120"
  531. align="center"
  532. >
  533. <template slot-scope="scope">
  534. <el-select
  535. v-model="scope.row.isRequired"
  536. size="small"
  537. :disabled="
  538. scope.row.isReadOnly || dialogTitle == '查看成本核定模板'
  539. "
  540. >
  541. <el-option label="是" value="true"></el-option>
  542. <el-option label="否" value="false"></el-option>
  543. </el-select>
  544. </template>
  545. </el-table-column>
  546. <el-table-column
  547. prop="showVisible"
  548. label="是否显示"
  549. width="120"
  550. align="center"
  551. >
  552. <template slot-scope="scope">
  553. <el-select
  554. v-model="scope.row.showVisible"
  555. size="small"
  556. :disabled="
  557. scope.row.isReadOnly || dialogTitle == '查看成本核定模板'
  558. "
  559. >
  560. <el-option label="是" value="1"></el-option>
  561. <el-option label="否" value="0"></el-option>
  562. </el-select>
  563. </template>
  564. </el-table-column>
  565. <el-table-column
  566. prop="isAuditPeriod"
  567. label="是否绑定监审期间"
  568. width="140"
  569. align="center"
  570. >
  571. <template slot-scope="scope">
  572. <el-select
  573. v-model="scope.row.isAuditPeriod"
  574. size="small"
  575. :disabled="
  576. scope.row.isReadOnly || dialogTitle == '查看成本核定模板'
  577. "
  578. >
  579. <el-option label="是" value="true"></el-option>
  580. <el-option label="否" value="false"></el-option>
  581. </el-select>
  582. </template>
  583. </el-table-column>
  584. <el-table-column prop="isDict" label="绑定字典" min-width="150">
  585. <template slot-scope="scope">
  586. <div class="bind-dict-column">
  587. <el-select
  588. v-model="scope.row.isDict"
  589. size="small"
  590. style="width: 80px"
  591. :disabled="
  592. scope.row.isReadOnly ||
  593. dialogTitle == '查看成本核定模板'
  594. "
  595. @change="handleBindDictChange(scope.row)"
  596. >
  597. <el-option label="是" value="true"></el-option>
  598. <el-option label="否" value="false"></el-option>
  599. </el-select>
  600. <el-select
  601. v-if="scope.row.isDict === 'true'"
  602. v-model="scope.row.dictid"
  603. placeholder="请选择字典"
  604. class="dict-select"
  605. size="small"
  606. style="width: 120px; margin-top: 5px"
  607. :disabled="
  608. scope.row.isReadOnly ||
  609. dialogTitle == '查看成本核定模板'
  610. "
  611. >
  612. <el-option
  613. v-for="(item, index) in dictTypeList"
  614. :key="index"
  615. :label="item.name"
  616. :value="String(item.id)"
  617. ></el-option>
  618. </el-select>
  619. </div>
  620. </template>
  621. </el-table-column>
  622. <el-table-column
  623. label="操作"
  624. width="150"
  625. fixed="right"
  626. align="center"
  627. >
  628. <template slot-scope="scope">
  629. <div class="table-actions">
  630. <el-button
  631. v-if="dialogTitle != '查看成本核定模板'"
  632. type="text"
  633. size="mini"
  634. :disabled="
  635. scope.row.isReadOnly ||
  636. dialogTitle == '查看成本核定模板'
  637. "
  638. @click="
  639. handleDeleteHeader(
  640. scope.$index,
  641. '固定表表头',
  642. scope.row
  643. )
  644. "
  645. >
  646. 删除
  647. </el-button>
  648. <el-button
  649. v-if="
  650. scope.$index !== 0 || dialogTitle != '查看成本核定模板'
  651. "
  652. type="text"
  653. size="mini"
  654. :disabled="
  655. scope.row.isReadOnly ||
  656. dialogTitle == '查看成本核定模板'
  657. "
  658. @click="handleMoveUp(scope.$index)"
  659. >
  660. 上升
  661. </el-button>
  662. <el-button
  663. v-if="
  664. scope.$index !==
  665. contentEditForm.fixedTable.tableHeaders.length - 1 ||
  666. dialogTitle == '查看成本核定模板'
  667. "
  668. type="text"
  669. size="mini"
  670. :disabled="
  671. scope.row.isReadOnly ||
  672. dialogTitle == '查看成本核定模板'
  673. "
  674. @click="handleMoveDown(scope.$index)"
  675. >
  676. 下降
  677. </el-button>
  678. </div>
  679. </template>
  680. </el-table-column>
  681. </el-table>
  682. </div>
  683. <div>
  684. <div class="button-group mt20 mb20">
  685. <el-button
  686. v-if="dialogTitle != '查看成本核定模板'"
  687. type="primary"
  688. @click="handleAddTableHeader('固定表项目')"
  689. >
  690. 添加项目
  691. </el-button>
  692. <el-button
  693. v-if="dialogTitle != '查看成本核定模板'"
  694. type="primary"
  695. @click="handleSaveTemplate"
  696. >
  697. 保存
  698. </el-button>
  699. </div>
  700. <div class="table-edit-container">
  701. <el-table
  702. :data="contentEditForm.fixedTable.fixedTables"
  703. border
  704. style="width: 100%"
  705. row-key="rowid"
  706. default-expand-all
  707. :tree-props="{
  708. children: 'children',
  709. hasChildren: 'hasChildren',
  710. }"
  711. @selection-change="handleSelectionChange"
  712. >
  713. <el-table-column label="父子节点" align="center" width="100">
  714. <template slot-scope="scope">
  715. <el-tag
  716. v-if="
  717. scope.row.isChild ||
  718. scope.row.isSubItem ||
  719. (scope.row.parentid &&
  720. scope.row.parentid != -1 &&
  721. scope.row.parentid != '-1')
  722. "
  723. type="success"
  724. size="small"
  725. >
  726. 子项
  727. </el-tag>
  728. <el-tag
  729. v-else-if="
  730. scope.row.parentid === -1 ||
  731. scope.row.parentid === '-1' ||
  732. !scope.row.parentid
  733. "
  734. type="primary"
  735. size="small"
  736. >
  737. 父项
  738. </el-tag>
  739. <el-tag v-else type="info" size="small">无</el-tag>
  740. </template>
  741. </el-table-column>
  742. <el-table-column label="序号" width="150" align="center">
  743. <template slot-scope="scope">
  744. <div
  745. class="row-indent-container"
  746. :style="getRowIndentStyle(scope.row)"
  747. >
  748. <el-input
  749. :value="
  750. scope.row.fixedValues
  751. ? scope.row.fixedValues['序号']
  752. : ''
  753. "
  754. size="small"
  755. placeholder="数字或中文"
  756. :disabled="dialogTitle == '查看成本核定模板'"
  757. @input="
  758. handleFixedValueChange(scope.row, '序号', $event)
  759. "
  760. ></el-input>
  761. </div>
  762. </template>
  763. </el-table-column>
  764. <el-table-column
  765. v-for="(item, index) in contentEditForm.fixedTable
  766. .fixedTableHeaders"
  767. :key="index"
  768. :label="item.rkey"
  769. align="center"
  770. >
  771. <template slot-scope="scope">
  772. <div class="row-indent-container">
  773. <el-input
  774. :value="
  775. scope.row.fixedValues
  776. ? scope.row.fixedValues[item.rkey]
  777. : ''
  778. "
  779. size="small"
  780. :disabled="dialogTitle == '查看成本核定模板'"
  781. @input="
  782. handleFixedValueChange(scope.row, item.rkey, $event)
  783. "
  784. ></el-input>
  785. </div>
  786. </template>
  787. </el-table-column>
  788. <el-table-column label="指标编号" width="100" align="center">
  789. <template slot-scope="scope">
  790. <div class="row-indent-container">
  791. <el-input
  792. :value="scope.row.cellCode"
  793. size="small"
  794. :disabled="dialogTitle == '查看成本核定模板'"
  795. @input="(val) => $set(scope.row, 'cellCode', val)"
  796. ></el-input>
  797. </div>
  798. </template>
  799. </el-table-column>
  800. <el-table-column
  801. label="计算公式"
  802. width="150"
  803. align="center"
  804. show-overflow-tooltip
  805. >
  806. <template slot-scope="scope">
  807. <div class="row-indent-container">
  808. <el-input
  809. :value="scope.row.calculationFormula"
  810. size="small"
  811. readonly
  812. :disabled="dialogTitle == '查看成本核定模板'"
  813. @click.native="
  814. openCalculationFormulaDialogVisible(
  815. scope.row,
  816. scope.$index
  817. )
  818. "
  819. ></el-input>
  820. </div>
  821. </template>
  822. </el-table-column>
  823. <el-table-column label="单位" width="80" align="center">
  824. <template slot-scope="scope">
  825. <div class="row-indent-container">
  826. <el-input
  827. :value="scope.row.unit"
  828. size="small"
  829. :disabled="dialogTitle == '查看成本核定模板'"
  830. @input="(val) => $set(scope.row, 'unit', val)"
  831. ></el-input>
  832. </div>
  833. </template>
  834. </el-table-column>
  835. <el-table-column
  836. label="操作"
  837. align="center"
  838. fixed="right"
  839. width="200"
  840. >
  841. <template slot-scope="scope">
  842. <div class="table-actions">
  843. <el-button
  844. v-if="!scope.row.isChild"
  845. type="text"
  846. size="mini"
  847. :disabled="dialogTitle == '查看成本核定模板'"
  848. @click="
  849. handleAddChildItem(
  850. scope.$index,
  851. '固定表项目',
  852. scope.row
  853. )
  854. "
  855. >
  856. 添加子项
  857. </el-button>
  858. <el-button
  859. type="text"
  860. size="mini"
  861. :disabled="dialogTitle == '查看成本核定模板'"
  862. @click="
  863. handleDeleteHeader(
  864. scope.$index,
  865. '固定表项目',
  866. scope.row
  867. )
  868. "
  869. >
  870. 删除
  871. </el-button>
  872. <el-button
  873. v-if="scope.$index !== 0"
  874. type="text"
  875. size="mini"
  876. :disabled="dialogTitle == '查看成本核定模板'"
  877. @click="handleMoveUp(scope.$index, '固定表', scope.row)"
  878. >
  879. 上升
  880. </el-button>
  881. <el-button
  882. v-if="
  883. scope.$index !==
  884. contentEditForm.fixedTable.fixedTables.length - 1
  885. "
  886. type="text"
  887. size="mini"
  888. :disabled="dialogTitle == '查看成本核定模板'"
  889. @click="handleMoveDown(scope.$index, '固定表')"
  890. >
  891. 下降
  892. </el-button>
  893. </div>
  894. </template>
  895. </el-table-column>
  896. </el-table>
  897. </div>
  898. </div>
  899. </div>
  900. </div>
  901. <!-- <div slot="footer" class="dialog-footer">
  902. <el-button type="primary" @click="handleSaveTemplate">确 认</el-button>
  903. <el-button @click="dialogVisible = false">取 消</el-button>
  904. </div> -->
  905. </el-dialog>
  906. <el-dialog
  907. title="计算公式"
  908. :visible.sync="calculationFormulaDialogVisible"
  909. width="500px"
  910. :before-close="handleDialogClose"
  911. :close-on-click-modal="false"
  912. >
  913. <!-- 单选按钮组:切换“当前指标项”/“其他模板指标项” -->
  914. <el-radio-group
  915. v-model="radioType"
  916. class="mb20"
  917. @change="handleRadioChange"
  918. >
  919. <el-radio label="current">当前指标项</el-radio>
  920. <el-radio label="other">其他模板指标项</el-radio>
  921. </el-radio-group>
  922. <!-- 「当前指标项」内容区域 -->
  923. <div v-if="radioType === 'current'" class="current-panel">
  924. <el-input
  925. v-model="formulaText"
  926. type="textarea"
  927. rows="4"
  928. placeholder="请输入公式(如 C1+C2+C3)"
  929. />
  930. </div>
  931. <!-- 「其他模板指标项」内容区域 -->
  932. <div v-else class="other-panel">
  933. <span>模板名称:</span>
  934. <el-select
  935. v-model="selectedTemplateId"
  936. style="width: 80%"
  937. placeholder="请选择模板"
  938. @change="handleTemplateChange"
  939. >
  940. <el-option
  941. v-for="(item, index) in templateList"
  942. :key="index"
  943. :label="item.surveyTemplateName"
  944. :value="item.pkVal"
  945. ></el-option>
  946. </el-select>
  947. <!-- 指标表格 -->
  948. <el-table
  949. ref="indicatorTable"
  950. :data="indicatorTableData"
  951. border
  952. style="width: 100%; margin-top: 10px"
  953. class="mb20"
  954. @row-click="handleRowClick"
  955. >
  956. <!-- @selection-change="selectionIndicatorChange" -->
  957. <el-table-column type="selection" label="选择" width="60">
  958. <template #default="scope">
  959. <el-checkbox
  960. v-model="scope.row.checked"
  961. @change="handleCheckboxChange(scope.row)"
  962. ></el-checkbox>
  963. </template>
  964. </el-table-column>
  965. <el-table-column
  966. prop="cellCode"
  967. label="指标编号"
  968. align="center"
  969. ></el-table-column>
  970. <!--循环表头 -->
  971. <el-table-column
  972. v-for="(item, index) in indicatorTableHeaders"
  973. :key="index"
  974. :label="item.rkey"
  975. align="center"
  976. show-overflow-tooltip
  977. >
  978. <template slot-scope="scope">
  979. {{
  980. scope.row.fixedValues ? scope.row.fixedValues[item.rkey] : ''
  981. }}
  982. </template>
  983. </el-table-column>
  984. </el-table>
  985. <el-input
  986. v-model="formulaText"
  987. type="textarea"
  988. rows="4"
  989. placeholder="请输入公式(如 C1+C2+C3)"
  990. @input="handleFormulaTextChange"
  991. />
  992. </div>
  993. <!-- 弹窗底部按钮 -->
  994. <div slot="footer" class="dialog-footer">
  995. <el-button type="primary" @click="handleConfirm">确定</el-button>
  996. <el-button @click="calculationFormulaDialogVisible = false">
  997. 取消
  998. </el-button>
  999. </div>
  1000. </el-dialog>
  1001. </div>
  1002. </template>
  1003. <script>
  1004. import {
  1005. getCostFormDataStorageTables,
  1006. deleteCostVerifyForm,
  1007. getActiveCostVerifyFormList,
  1008. getActiveCostVerifyFormListByType,
  1009. generateCostVerifyFormData,
  1010. generateCostVerifyForm,
  1011. addCostVerifyForm,
  1012. getCostFormVersionsByTemplateId,
  1013. batchSaveOrUpdate,
  1014. } from '@/api/costFormManage'
  1015. import {
  1016. getlistBySurveyTemplateId,
  1017. batchDeleteCostVerifyForm,
  1018. getlistBySurveyTemplateIdcurrentversion,
  1019. batchSave,
  1020. enable,
  1021. getListFixedEnabled,
  1022. listByVerifyTemplateId,
  1023. } from '@/api/costVerifyManage'
  1024. import { getCatalogDetail } from '@/api/catalogManage'
  1025. import { listByCurrentTemplateId } from '@/api/catalogManage.js'
  1026. import { catalogMixin, commonMixin } from '@/mixins/useDict'
  1027. import { getDictTypList } from '@/api/dictionaryManage.js'
  1028. export default {
  1029. name: 'SupervisionContent',
  1030. // 使用混入
  1031. mixins: [catalogMixin, commonMixin],
  1032. data() {
  1033. return {
  1034. loading: false,
  1035. searchForm: {
  1036. type: '',
  1037. catalogId: '',
  1038. keyword: '',
  1039. page: 1,
  1040. pageSize: 50,
  1041. },
  1042. props: {
  1043. filterable: true,
  1044. placeholder: '请选择监审类别',
  1045. style: 'width: 100%',
  1046. showAllLevels: false,
  1047. props: {
  1048. multiple: false,
  1049. children: 'children',
  1050. checkStrictly: false,
  1051. label: 'catalogName',
  1052. value: 'id',
  1053. emitPath: false,
  1054. },
  1055. },
  1056. tableData: [],
  1057. selectedRows: [],
  1058. pagination: {
  1059. currentPage: 1,
  1060. pageSize: 50,
  1061. total: 0,
  1062. },
  1063. dialogVisible: false,
  1064. detailDialogVisible: false,
  1065. dialogTitle: '',
  1066. contentEditForm: {
  1067. areaCode: '',
  1068. areaLevel: '',
  1069. catalogId: '',
  1070. contentType: '',
  1071. createBy: '',
  1072. createTime: '',
  1073. createmode: '',
  1074. createtemplateid: '',
  1075. createtemplateid1: '',
  1076. isDelete: '',
  1077. pkVal: '',
  1078. remarks: '',
  1079. status: '',
  1080. storageTable: '',
  1081. surveyTemplateId: '',
  1082. surveyTemplateName: '',
  1083. surveyTemplateNameYw: '',
  1084. templateType: '2',
  1085. type: '',
  1086. updateBy: '',
  1087. updateTime: '',
  1088. versionNo: '',
  1089. // 固定表列表
  1090. fixedTable: {
  1091. tableHeaders: [],
  1092. fixedTables: [],
  1093. fixedTablesTitle: [],
  1094. fixedTableHeaders: [],
  1095. },
  1096. },
  1097. dynamicTable: [],
  1098. contentEditFormRules: {
  1099. catalogId: [
  1100. { required: true, message: '请选择监审类别', trigger: 'change' },
  1101. ],
  1102. surveyTemplateName: [
  1103. { required: true, message: '请输入核定模板名称', trigger: 'blur' },
  1104. {
  1105. min: 1,
  1106. max: 30,
  1107. message: '核定模板名称长度应在1-30个字符之间',
  1108. trigger: 'blur',
  1109. },
  1110. ],
  1111. // createtemplateid: [
  1112. // { required: true, message: '请选择模板类型', trigger: 'change' },
  1113. // ],
  1114. },
  1115. // 成本核定表模板列表
  1116. contentEditFormList: [],
  1117. // 成本调查表模板列表
  1118. surveyFormList: [],
  1119. CatalogNameMap: {},
  1120. calculationFormulaDialogVisible: false,
  1121. currentEditingRow: null,
  1122. currentEditingRowIndex: -1,
  1123. radioType: 'current',
  1124. formulaText: 'C1+C2+C3',
  1125. templateName: '',
  1126. templateList: [],
  1127. indicatorTableData: [],
  1128. indicatorTableHeaders: [],
  1129. selectedIndicatorsPerTemplate: {},
  1130. selectedIndicatorCodes: [],
  1131. isAutoGeneratedFormula: false,
  1132. dictTypeList: [],
  1133. }
  1134. },
  1135. watch: {
  1136. // 监听目录数据变化,数据加载完成后处理回显
  1137. catalogListOptions: {
  1138. handler(newVal) {
  1139. if (newVal && newVal.length > 0) {
  1140. // 数据加载完成后,重新处理value
  1141. this.batchGetCatalogNames()
  1142. }
  1143. },
  1144. immediate: true,
  1145. },
  1146. indicatorTableData: {
  1147. handler(newVal) {
  1148. if (this.radioType === 'other' && this.selectedTemplateId) {
  1149. this.$set(
  1150. this.selectedIndicatorsPerTemplate,
  1151. this.selectedTemplateId,
  1152. newVal.filter((item) => item.checked)
  1153. )
  1154. }
  1155. this.updateSelectedIndicatorCodes()
  1156. },
  1157. deep: true,
  1158. },
  1159. selectedIndicatorCodes: {
  1160. handler(newVal) {
  1161. if (this.radioType === 'other') {
  1162. const allSelectedTemplateIds = [
  1163. ...new Set([
  1164. this.selectedTemplateId,
  1165. ...Object.keys(this.selectedIndicatorsPerTemplate).filter(
  1166. (id) =>
  1167. id !== this.selectedTemplateId &&
  1168. this.selectedIndicatorsPerTemplate[id].some(
  1169. (item) => item.checked
  1170. )
  1171. ),
  1172. ]),
  1173. ].filter((id) => id)
  1174. const isSingleTemplate = allSelectedTemplateIds.length === 1
  1175. if (isSingleTemplate && allSelectedTemplateIds[0]) {
  1176. const selectedTemplate = this.templateList.find(
  1177. (item) => item.pkVal === allSelectedTemplateIds[0]
  1178. )
  1179. const templateNameYw = selectedTemplate
  1180. ? selectedTemplate.surveyTemplateNameYw ||
  1181. selectedTemplate.surveyTemplateName ||
  1182. ''
  1183. : ''
  1184. let selectedItems = []
  1185. if (allSelectedTemplateIds[0] === this.selectedTemplateId) {
  1186. selectedItems = newVal
  1187. } else {
  1188. selectedItems = this.selectedIndicatorsPerTemplate[
  1189. allSelectedTemplateIds[0]
  1190. ]
  1191. .filter((item) => item.checked)
  1192. .map(
  1193. (item) => `${templateNameYw}.${item.code || item.cellCode}`
  1194. )
  1195. }
  1196. if (selectedItems.length > 0) {
  1197. this.formulaText = selectedItems.join('+')
  1198. this.isAutoGeneratedFormula = true
  1199. } else if (this.isAutoGeneratedFormula) {
  1200. this.formulaText = ''
  1201. }
  1202. } else {
  1203. let allSelectedCodes = []
  1204. if (newVal.length > 0 && this.selectedTemplateId) {
  1205. allSelectedCodes = [...newVal]
  1206. }
  1207. Object.keys(this.selectedIndicatorsPerTemplate).forEach(
  1208. (templateId) => {
  1209. if (templateId !== this.selectedTemplateId) {
  1210. const items = this.selectedIndicatorsPerTemplate[templateId]
  1211. const selectedTemplate = this.templateList.find(
  1212. (item) => item.pkVal === templateId
  1213. )
  1214. const templateName = selectedTemplate
  1215. ? selectedTemplate.surveyTemplateNameYw ||
  1216. selectedTemplate.surveyTemplateName ||
  1217. ''
  1218. : ''
  1219. items
  1220. .filter((item) => item.checked)
  1221. .forEach((item) => {
  1222. allSelectedCodes.push(
  1223. `${templateName}.${item.code || item.cellCode}`
  1224. )
  1225. })
  1226. }
  1227. }
  1228. )
  1229. if (allSelectedCodes.length > 0) {
  1230. this.formulaText = allSelectedCodes.join('+')
  1231. this.isAutoGeneratedFormula = true
  1232. } else if (this.isAutoGeneratedFormula) {
  1233. this.formulaText = ''
  1234. }
  1235. }
  1236. } else if (newVal.length > 0 && this.radioType === 'current') {
  1237. if (
  1238. !this.formulaText ||
  1239. this.formulaText === 'C1+C2+C3' ||
  1240. this.isAutoGeneratedFormula
  1241. ) {
  1242. this.formulaText = newVal.join('+')
  1243. this.isAutoGeneratedFormula = true
  1244. }
  1245. } else if (newVal.length === 0 && this.radioType === 'current') {
  1246. if (this.isAutoGeneratedFormula) {
  1247. this.formulaText = ''
  1248. }
  1249. }
  1250. },
  1251. deep: true,
  1252. },
  1253. },
  1254. mounted() {
  1255. this.handleSearch()
  1256. this.loadDictTypeList()
  1257. },
  1258. methods: {
  1259. async loadDictTypeList() {
  1260. try {
  1261. const res = await getDictTypList()
  1262. this.dictTypeList = res || []
  1263. } catch (error) {
  1264. console.error('加载字典类型失败:', error)
  1265. }
  1266. },
  1267. // 获取监审类别名称
  1268. batchGetCatalogNames() {
  1269. // 递归查找名称
  1270. this.CatalogNameMap = {}
  1271. this._recursiveCatalogMap(this.catalogListOptions)
  1272. },
  1273. // 递归遍历目录树并构建ID到名称的映射
  1274. _recursiveCatalogMap(catalogs) {
  1275. if (!Array.isArray(catalogs) || catalogs.length === 0) {
  1276. return
  1277. }
  1278. catalogs.forEach((item) => {
  1279. // 为当前目录项添加映射
  1280. this.CatalogNameMap[item.id] = item.catalogName
  1281. // 递归处理子目录
  1282. if (item.children && Array.isArray(item.children)) {
  1283. this._recursiveCatalogMap(item.children)
  1284. }
  1285. })
  1286. },
  1287. // 获取所有状态为启用的成本核定表模板数据
  1288. getActiveCostVerifyFormList() {
  1289. getActiveCostVerifyFormList().then((res) => {
  1290. if (res.code === 200) {
  1291. this.contentEditFormList = res.value
  1292. }
  1293. })
  1294. },
  1295. // 获取所有模板类型为固定表的所有启用成本调查表数据
  1296. getActiveCostVerifyFormListByType() {
  1297. getActiveCostVerifyFormListByType().then((res) => {
  1298. if (res.code === 200) {
  1299. this.surveyFormList = res.value
  1300. }
  1301. })
  1302. },
  1303. getCatalogNames(row) {
  1304. if (!row.catalogId) return ''
  1305. return row.catalogId
  1306. .split(',')
  1307. .map((id) => {
  1308. const trimId = id.trim()
  1309. return this.CatalogNameMap[trimId] || '未知名称'
  1310. })
  1311. .join(',')
  1312. },
  1313. // 删除成本核定表模板
  1314. handleDeleteRow(row) {
  1315. this.$confirm('确定删除该成本核定表模板吗?', '提示', {
  1316. confirmButtonText: '确定',
  1317. cancelButtonText: '取消',
  1318. type: 'warning',
  1319. }).then(() => {
  1320. deleteCostVerifyForm(row.pkVal).then((res) => {
  1321. if (res.code === 200) {
  1322. this.$message({
  1323. type: 'success',
  1324. message: '删除成功',
  1325. })
  1326. this.handleSearch()
  1327. } else {
  1328. this.$message({
  1329. type: 'error',
  1330. message: res.msg || '删除失败',
  1331. })
  1332. }
  1333. })
  1334. })
  1335. },
  1336. // 状态转换
  1337. handleStatusChange(row) {
  1338. enable({
  1339. id: row.surveyTemplateId,
  1340. }).then((res) => {
  1341. if (res.code === 200) {
  1342. this.$message.success(`${res.message}`)
  1343. this.handleSearch()
  1344. }
  1345. })
  1346. },
  1347. // 搜索
  1348. handleSearch() {
  1349. this.loading = true
  1350. getCostFormDataStorageTables(this.searchForm).then((res) => {
  1351. this.loading = false
  1352. if (res.rows.length > 0) {
  1353. this.tableData = res.rows || []
  1354. this.pagination.total = res.total || 0
  1355. }
  1356. })
  1357. },
  1358. // 重置
  1359. handleReset() {
  1360. this.searchForm = {
  1361. catalogId: '',
  1362. keyword: '',
  1363. page: 1,
  1364. pageSize: 50,
  1365. }
  1366. this.handleSearch()
  1367. },
  1368. // 添加
  1369. handleAdd() {
  1370. this.dialogTitle = '添加成本核定模板'
  1371. this.contentEditForm = {
  1372. areaCode: '',
  1373. areaLevel: '',
  1374. catalogId: '',
  1375. contentType: '',
  1376. createBy: '',
  1377. createTime: '',
  1378. createmode: '1',
  1379. createtemplateid: '',
  1380. createtemplateid1: '',
  1381. isDelete: '',
  1382. pkVal: '',
  1383. remarks: '',
  1384. status: '',
  1385. storageTable: '',
  1386. surveyTemplateId: '',
  1387. surveyTemplateName: '',
  1388. surveyTemplateNameYw: '',
  1389. templateType: '2',
  1390. type: '',
  1391. updateBy: '',
  1392. updateTime: '',
  1393. versionNo: '',
  1394. // 固定表列表
  1395. fixedTable: {
  1396. tableHeaders: [],
  1397. fixedTables: [],
  1398. fixedTablesTitle: [],
  1399. },
  1400. }
  1401. // 成本核定表模板列表
  1402. this.getActiveCostVerifyFormList()
  1403. // 成本调查表模板列表
  1404. this.getActiveCostVerifyFormListByType()
  1405. this.dialogVisible = true
  1406. // 清除表单校验
  1407. this.$nextTick(() => {
  1408. if (this.$refs.contentEditForm) {
  1409. this.$refs.contentEditForm.clearValidate()
  1410. }
  1411. })
  1412. console.log('this.contentEditForm', this.contentEditForm)
  1413. },
  1414. // 修改
  1415. handleEdit(row) {
  1416. this.dialogTitle = '修改成本核定模板'
  1417. this.contentEditForm = {
  1418. ...row,
  1419. // 固定表列表
  1420. fixedTable: {
  1421. tableHeaders: [],
  1422. fixedTables: [],
  1423. fixedTablesTitle: [],
  1424. },
  1425. }
  1426. if (row.createmode == '1') {
  1427. this.contentEditFormcreatetemplateid = row.createtemplateid || ''
  1428. this.contentEditForm.createtemplateid1 = ''
  1429. } else if (row.createmode == '2') {
  1430. this.contentEditForm.createtemplateid1 = row.createtemplateid || ''
  1431. this.contentEditForm.createtemplateid = ''
  1432. }
  1433. // 成本核定表模板列表
  1434. this.getActiveCostVerifyFormList()
  1435. // 成本调查表模板列表
  1436. this.getActiveCostVerifyFormListByType()
  1437. this.loadTemplateDataForEdit(this.contentEditForm.surveyTemplateId)
  1438. this.dialogVisible = true
  1439. },
  1440. // 查看详情
  1441. handleViewDetail(row) {
  1442. this.dialogTitle = '查看成本核定模板'
  1443. this.contentEditForm = {
  1444. ...row,
  1445. // 固定表列表
  1446. fixedTable: {
  1447. tableHeaders: [],
  1448. fixedTables: [],
  1449. fixedTablesTitle: [],
  1450. },
  1451. }
  1452. if (row.createmode == '1') {
  1453. this.contentEditFormcreatetemplateid = row.createtemplateid || ''
  1454. this.contentEditFormcreatetemplateid1 = ''
  1455. } else if (row.createmode == '2') {
  1456. this.contentEditForm.createtemplateid1 = row.createtemplateid1 || ''
  1457. this.contentEditFormcreatetemplateid = ''
  1458. }
  1459. // 成本核定表模板列表
  1460. this.getActiveCostVerifyFormList()
  1461. // 成本调查表模板列表
  1462. this.getActiveCostVerifyFormListByType()
  1463. this.loadTemplateDataForEdit(this.contentEditForm.surveyTemplateId)
  1464. this.dialogVisible = true
  1465. },
  1466. // 生成模板
  1467. handleGenerateTemplate() {
  1468. // 提示生成后不能修改
  1469. this.$confirm(
  1470. '生成后不能修改根据调查表生成还是根据历史核定模板生成,确定生成模板吗?',
  1471. '提示',
  1472. {
  1473. confirmButtonText: '确定',
  1474. cancelButtonText: '取消',
  1475. type: 'warning',
  1476. }
  1477. ).then(() => {
  1478. // 校验表单
  1479. this.$refs['contentEditForm'].validate((valid) => {
  1480. if (valid) {
  1481. if (this.contentEditForm.createmode == '1') {
  1482. if (!this.contentEditForm.createtemplateid) {
  1483. this.$message.error('请选择成本调查表模板')
  1484. return
  1485. }
  1486. this.generateFromSurveyTemplate()
  1487. } else if (this.contentEditForm.createmode == '2') {
  1488. if (!this.contentEditForm.createtemplateid1) {
  1489. this.$message.error('请选择历史核定模板')
  1490. return
  1491. }
  1492. this.generateFromHistoryTemplate()
  1493. }
  1494. } else {
  1495. this.$message.error('请填写表单数据')
  1496. return
  1497. }
  1498. })
  1499. })
  1500. },
  1501. async loadTemplateDataForEdit(surveyTemplateId) {
  1502. // 并行获取表头和表格数据
  1503. const [tableHeadersRes, tableDataRes] = await Promise.all([
  1504. getlistBySurveyTemplateId({
  1505. surveyTemplateId,
  1506. }),
  1507. getCostFormVersionsByTemplateId({
  1508. surveyTemplateId,
  1509. }),
  1510. ])
  1511. // 处理表头数据
  1512. if (tableHeadersRes.code == 200) {
  1513. this.contentEditForm.fixedTable.tableHeaders = Array.isArray(
  1514. tableHeadersRes.value
  1515. )
  1516. ? tableHeadersRes.value
  1517. : []
  1518. // 表头按照orderNum重新排序
  1519. this.contentEditForm.fixedTable.tableHeaders.sort(
  1520. (a, b) => a.orderNum - b.orderNum
  1521. )
  1522. // 检查是否有fieldName为"序号"的数据
  1523. const hasSerialNumber =
  1524. this.contentEditForm.fixedTable.tableHeaders.some(
  1525. (header) => header.fieldName === '序号'
  1526. )
  1527. // 如果没有序号数据,则添加一条默认的序号数据,并标记为不可编辑
  1528. if (!hasSerialNumber) {
  1529. this.contentEditForm.fixedTable.tableHeaders.unshift({
  1530. fieldName: '序号',
  1531. fieldType: 'string',
  1532. format: '30',
  1533. fieldTypelen: '',
  1534. fieldTypenointlen: '',
  1535. isRequired: 'false',
  1536. showVisible: '1',
  1537. isAuditPeriod: 'false',
  1538. tabtype: '2',
  1539. surveyTemplateId: this.contentEditForm.surveyTemplateId,
  1540. versionId: this.versionId,
  1541. isFixed: '1',
  1542. isReadOnly: true, // 标记为不可编辑
  1543. orderNum: 1,
  1544. })
  1545. } else {
  1546. this.contentEditForm.fixedTable.tableHeaders.forEach((item) => {
  1547. if (item.fieldName === '序号') {
  1548. item.isReadOnly = true // 确保序号字段不可编辑
  1549. }
  1550. })
  1551. }
  1552. }
  1553. // 处理表格数据
  1554. if (tableDataRes.code == 200) {
  1555. this.parseAndDisplayFixedTableData(tableDataRes)
  1556. }
  1557. },
  1558. // 根据调查表生成模板
  1559. async generateFromSurveyTemplate() {
  1560. try {
  1561. // 显示加载状态
  1562. this.loading = true
  1563. // 保存模板基本信息
  1564. let data = await generateCostVerifyForm({
  1565. catalogId: this.contentEditForm.catalogId,
  1566. templatename: this.contentEditForm.surveyTemplateName,
  1567. templateId: this.contentEditForm.createtemplateid,
  1568. })
  1569. this.contentEditForm.surveyTemplateId = data.value
  1570. ? data.value.surveyTemplateId
  1571. : ''
  1572. this.loadTemplateDataForEdit(this.contentEditForm.surveyTemplateId)
  1573. // // 并行获取表头和表格数据
  1574. // const [tableHeadersRes, tableDataRes] = await Promise.all([
  1575. // getlistBySurveyTemplateIdcurrentversion({
  1576. // surveyTemplateId: this.contentEditForm.createtemplateid,
  1577. // }),
  1578. // listByCurrentTemplateId({
  1579. // surveyTemplateId: this.contentEditForm.createtemplateid,
  1580. // }),
  1581. // ])
  1582. // // 处理表头数据
  1583. // if (tableHeadersRes.code == 200) {
  1584. // this.contentEditForm.fixedTable.tableHeaders = Array.isArray(
  1585. // tableHeadersRes.value
  1586. // )
  1587. // ? tableHeadersRes.value
  1588. // : []
  1589. // }
  1590. // // 处理表格数据
  1591. // if (tableDataRes.code == 200) {
  1592. // const fieldNamesString =
  1593. // this.contentEditForm.fixedTable.tableHeaders
  1594. // .map((header) => header.fieldName)
  1595. // .join(', ')
  1596. // this.contentEditForm.fixedTable.fixedTablesTitle = fieldNamesString
  1597. // this.parseAndDisplayFixedTableData(tableDataRes)
  1598. // // this.$message.success('生成模板成功')
  1599. // }
  1600. } catch (error) {
  1601. console.error('生成模板失败:', error)
  1602. } finally {
  1603. this.loading = false
  1604. }
  1605. },
  1606. // 根据历史核定模板生成
  1607. async generateFromHistoryTemplate() {
  1608. // 保存模板基本信息
  1609. let data = await generateCostVerifyFormData({
  1610. catalogId: this.contentEditForm.catalogId,
  1611. templatename: this.contentEditForm.surveyTemplateName,
  1612. templateId: this.contentEditForm.createtemplateid1,
  1613. })
  1614. this.contentEditForm.surveyTemplateId = data.value
  1615. ? data.value.surveyTemplateId
  1616. : ''
  1617. this.loadTemplateDataForEdit(this.contentEditForm.surveyTemplateId)
  1618. },
  1619. // 添加表头
  1620. handleAddTableHeader(type) {
  1621. switch (type) {
  1622. case '固定表表头':
  1623. this.contentEditForm.fixedTable.tableHeaders.push({
  1624. fieldName: '',
  1625. fieldType: 'string',
  1626. format: '255',
  1627. fieldTypelen: '',
  1628. fieldTypenointlen: '',
  1629. isRequired: 'false',
  1630. showVisible: '1',
  1631. isAuditPeriod: 'false',
  1632. tabtype: '2',
  1633. surveyTemplateId: this.contentEditForm.surveyTemplateId,
  1634. versionId: this.versionId,
  1635. orderNum: this.contentEditForm.fixedTable.tableHeaders.length + 1,
  1636. })
  1637. break
  1638. case '固定表项目':
  1639. let maxFixedOrderNum = 0
  1640. if (this.contentEditForm.fixedTable.fixedTables.length > 0) {
  1641. maxFixedOrderNum = Math.max(
  1642. ...this.contentEditForm.fixedTable.fixedTables.map(
  1643. (item) => item.orderNum || 0
  1644. )
  1645. )
  1646. }
  1647. const newRow = {
  1648. orderText: maxFixedOrderNum + 1,
  1649. orderNum: maxFixedOrderNum + 1,
  1650. cellCode: '',
  1651. calculationFormula: '',
  1652. unit: '',
  1653. tabtype: this.contentEditForm.templateType,
  1654. surveyTemplateId: this.contentEditForm.surveyTemplateId,
  1655. versionId: this.versionId,
  1656. fixedValues: {},
  1657. parentid: -1,
  1658. rowid: this.generateUUID(),
  1659. }
  1660. this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
  1661. (title) => {
  1662. newRow.fixedValues[title.rkey] = ''
  1663. }
  1664. )
  1665. this.contentEditForm.fixedTable.fixedTables.push(newRow)
  1666. break
  1667. default:
  1668. break
  1669. }
  1670. },
  1671. // 字段名称改变
  1672. handleFieldNameChange(row) {
  1673. console.log(row)
  1674. if (row.fieldName) {
  1675. // 检查是否已存在相同的fieldName
  1676. const existsInTableHeaders =
  1677. this.contentEditForm.fixedTable.tableHeaders.some(
  1678. (item) => item.fieldName === row.fieldName
  1679. )
  1680. // 跳过"序号"列
  1681. if (row.fieldName !== '序号' && !existsInTableHeaders) {
  1682. // 更新tableHeaders数组,这是关键的数据源
  1683. this.contentEditForm.fixedTable.tableHeaders.push({
  1684. fieldName: row.fieldName,
  1685. fieldType: 'string',
  1686. format: '255',
  1687. fieldTypelen: '',
  1688. fieldTypenointlen: '',
  1689. isRequired: 'false',
  1690. showVisible: '1',
  1691. isAuditPeriod: 'false',
  1692. tabtype: '2',
  1693. surveyTemplateId: this.contentEditForm.surveyTemplateId,
  1694. versionId: this.versionId || null,
  1695. orderNum: this.contentEditForm.fixedTable.tableHeaders.length + 1,
  1696. id: null,
  1697. })
  1698. // 同时更新fixedTablesTitle(这是源头数据)
  1699. const newTitle = {
  1700. rkey: row.fieldName,
  1701. rvalue: '',
  1702. }
  1703. this.contentEditForm.fixedTable.fixedTablesTitle.push(newTitle)
  1704. // 同时更新fixedTableHeaders
  1705. this.contentEditForm.fixedTable.fixedTableHeaders.push(newTitle)
  1706. // 为现有表格数据行添加对应的fixedValues属性
  1707. if (
  1708. this.contentEditForm.fixedTable.fixedTables &&
  1709. this.contentEditForm.fixedTable.fixedTables.length > 0
  1710. ) {
  1711. this.contentEditForm.fixedTable.fixedTables.forEach(
  1712. (tableRow) => {
  1713. // 确保fixedValues对象存在
  1714. if (!tableRow.fixedValues) {
  1715. tableRow.fixedValues = {}
  1716. }
  1717. // 为新字段设置默认值为空字符串
  1718. tableRow.fixedValues[row.fieldName] = ''
  1719. }
  1720. )
  1721. }
  1722. }
  1723. }
  1724. },
  1725. // 保存内容
  1726. handleSaveContent(type) {
  1727. try {
  1728. if (type === '固定表表头') {
  1729. var data = {
  1730. headersList: this.contentEditForm.fixedTable.tableHeaders,
  1731. }
  1732. batchSaveOrUpdate(data)
  1733. .then((res) => {
  1734. if (res.code === 200) {
  1735. // 如果后端返回了保存后的数据,更新本地数据
  1736. if (res.value && Array.isArray(res.value)) {
  1737. this.contentEditForm.fixedTable.tableHeaders =
  1738. res.value.map((item) => ({
  1739. ...item,
  1740. }))
  1741. }
  1742. this.loadTemplateDataForEdit(
  1743. this.contentEditForm.surveyTemplateId
  1744. )
  1745. this.contentEditForm.fixedTable.fixedTables.forEach((row) => {
  1746. this.initFixedTableRow(row)
  1747. })
  1748. }
  1749. })
  1750. .catch((error) => {
  1751. console.error('保存接口异常:', error)
  1752. })
  1753. .finally(() => {
  1754. this.loading = false
  1755. })
  1756. }
  1757. } catch (error) {
  1758. console.error('保存处理异常:', error)
  1759. }
  1760. },
  1761. initFixedTableRow(row) {
  1762. if (row.cellCode === undefined) {
  1763. this.$set(row, 'cellCode', '')
  1764. }
  1765. if (row.calculationFormula === undefined) {
  1766. this.$set(row, 'calculationFormula', '')
  1767. }
  1768. if (row.unit === undefined) {
  1769. this.$set(row, 'unit', '')
  1770. }
  1771. if (!row.fixedValues) {
  1772. this.$set(row, 'fixedValues', {})
  1773. }
  1774. // 初始化children数组,支持树形结构
  1775. if (!row.children) {
  1776. this.$set(row, 'children', [])
  1777. }
  1778. this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
  1779. (title, index) => {
  1780. if (!(title.rkey in row.fixedValues)) {
  1781. this.$set(row.fixedValues, title.rkey, '')
  1782. }
  1783. }
  1784. )
  1785. return row
  1786. },
  1787. // 删除表头
  1788. handleDeleteHeader(index, type, row) {
  1789. // 提取重复的删除逻辑为内部函数
  1790. const handleDelete = () => {
  1791. const data = {
  1792. deleteheadersList: [row],
  1793. }
  1794. batchSaveOrUpdate(data)
  1795. .then((res) => {
  1796. if (res.code === 200) {
  1797. this.$message.success('删除成功')
  1798. }
  1799. })
  1800. .catch((error) => {
  1801. console.error('删除接口异常:', error)
  1802. })
  1803. .finally(() => {})
  1804. }
  1805. switch (type) {
  1806. case '固定表表头':
  1807. if (this.contentEditForm.fixedTable.tableHeaders.length <= 1) {
  1808. this.$message.warning('至少保留一个表头')
  1809. return
  1810. }
  1811. this.contentEditForm.fixedTable.tableHeaders.splice(index, 1)
  1812. handleDelete()
  1813. break
  1814. case '固定表项目':
  1815. if (this.contentEditForm.fixedTable.fixedTables.length <= 1) {
  1816. this.$message.warning('至少保留一个项目')
  1817. return
  1818. }
  1819. this.contentEditForm.fixedTable.fixedTables.splice(index, 1)
  1820. handleDelete() // 执行删除逻辑
  1821. break
  1822. default:
  1823. break
  1824. }
  1825. },
  1826. /**
  1827. * 处理固定表项目字段值变化
  1828. */
  1829. handleFixedValueChange(row, rkey, value) {
  1830. if (!row.fixedValues) {
  1831. this.$set(row, 'fixedValues', {})
  1832. }
  1833. this.$set(row.fixedValues, rkey, value)
  1834. },
  1835. // 上升
  1836. handleMoveUp(index, tableType, row) {
  1837. if (tableType === '固定表') {
  1838. const fixedTableData = this.contentEditForm.fixedTable.fixedTables
  1839. const newFixedTableData = [...fixedTableData]
  1840. this.swamTableArr(newFixedTableData, row, true)
  1841. this.contentEditForm.fixedTable.fixedTables = newFixedTableData
  1842. } else {
  1843. // const tableHeaders = this.contentEditForm.fixedTable.tableHeaders
  1844. // const newTableHeaders = [...tableHeaders]
  1845. // this.swamTableArr(newTableHeaders, row, true, true)
  1846. // this.contentEditForm.tableHeaders = newTableHeaders
  1847. if (index > 0) {
  1848. const temp = this.contentEditForm.fixedTable.tableHeaders[index]
  1849. this.contentEditForm.fixedTable.tableHeaders.splice(index, 1)
  1850. this.contentEditForm.fixedTable.tableHeaders.splice(
  1851. index - 1,
  1852. 0,
  1853. temp
  1854. )
  1855. // 更新表头的序号
  1856. this.updateTableHeadersOrderNumbers()
  1857. }
  1858. }
  1859. },
  1860. // 下降
  1861. handleMoveDown(index, tableType, row) {
  1862. if (tableType === '固定表') {
  1863. const fixedTableData = this.contentEditForm.fixedTable.fixedTables
  1864. const newFixedTableData = [...fixedTableData]
  1865. this.swamTableArr(newFixedTableData, row, false)
  1866. this.contentEditForm.fixedTable.fixedTables = newFixedTableData
  1867. } else {
  1868. // const tableHeaders = this.contentEditForm.tableHeaders
  1869. // const newTableHeaders = [...tableHeaders]
  1870. // this.swamTableArr(newTableHeaders, row, false)
  1871. // this.contentEditForm.tableHeaders = newTableHeaders
  1872. if (index < this.contentEditForm.fixedTable.tableHeaders.length - 1) {
  1873. const temp = this.contentEditForm.fixedTable.tableHeaders[index]
  1874. this.contentEditForm.fixedTable.tableHeaders.splice(index, 1)
  1875. this.contentEditForm.fixedTable.tableHeaders.splice(
  1876. index + 1,
  1877. 0,
  1878. temp
  1879. )
  1880. // 更新表头的序号
  1881. this.updateTableHeadersOrderNumbers()
  1882. }
  1883. }
  1884. },
  1885. swamTableArr(arr, row, asc, isHeader) {
  1886. const isChild = row.isChild || row.isSubItem || false
  1887. if (isChild) {
  1888. // 子节点处理逻辑后续实现 parentid rowid
  1889. let child = arr.find((item) => item.rowid === row.parentid)
  1890. // const rowIndex = arr.indexOf(row);
  1891. // newFixedTableData[rowIndex]
  1892. this.doSwamTableArr(child.children, row, asc, isHeader)
  1893. } else {
  1894. // 创建数组副本以确保Vue能检测到变化
  1895. // 直接替换整个数组,确保Vue能检测到变化
  1896. this.doSwamTableArr(arr, row, asc, isHeader)
  1897. }
  1898. },
  1899. doSwamTableArr(arr, row, asc, isHeader) {
  1900. const rowIndex = arr.indexOf(row)
  1901. let swamIndex = 0
  1902. if (asc) {
  1903. // 正序
  1904. if (rowIndex < 1) {
  1905. return
  1906. }
  1907. swamIndex = rowIndex - 1
  1908. } else {
  1909. // 倒序
  1910. if (rowIndex >= arr.length - 1) {
  1911. return
  1912. }
  1913. swamIndex = rowIndex + 1
  1914. }
  1915. const curr = arr[rowIndex]
  1916. const swam = arr[swamIndex]
  1917. // 交换orderNum
  1918. const tempOrderNum = curr.orderNum
  1919. curr.orderNum = swam.orderNum
  1920. swam.orderNum = tempOrderNum
  1921. // row.isChild &&
  1922. if (!isHeader) {
  1923. // 获取当前项的序号值
  1924. let currIndex = curr.fixedValues
  1925. ? curr.fixedValues['序号']
  1926. : curr.dynamicValues['序号']
  1927. // 获取交换项的序号值
  1928. let swamIndex = swam.fixedValues
  1929. ? swam.fixedValues['序号']
  1930. : swam.dynamicValues['序号']
  1931. // 先保存交换项的值,再进行赋值,避免值被覆盖
  1932. if (curr.fixedValues) {
  1933. curr.fixedValues['序号'] = swamIndex
  1934. } else {
  1935. curr.dynamicValues['序号'] = swamIndex
  1936. }
  1937. if (swam.fixedValues) {
  1938. swam.fixedValues['序号'] = currIndex
  1939. } else {
  1940. swam.dynamicValues['序号'] = currIndex
  1941. }
  1942. }
  1943. // 交换数组中的位置
  1944. arr[rowIndex] = swam
  1945. arr[swamIndex] = curr
  1946. },
  1947. // 更新表头序号
  1948. updateTableHeadersOrderNumbers() {
  1949. // 更新固定表的表头序号
  1950. if (
  1951. this.contentEditForm.fixedTable &&
  1952. this.contentEditForm.fixedTable.tableHeaders
  1953. ) {
  1954. this.contentEditForm.fixedTable.tableHeaders.forEach(
  1955. (header, index) => {
  1956. header.orderNum = index + 1
  1957. }
  1958. )
  1959. }
  1960. },
  1961. // 添加子项方法
  1962. handleAddChildItem(index, type, parentRow) {
  1963. if (!parentRow.rowid) {
  1964. this.$set(parentRow, 'rowid', this.generateUUID())
  1965. }
  1966. switch (type) {
  1967. case '固定表项目':
  1968. let parentIndex1 =
  1969. this.contentEditForm.fixedTable.fixedTables.findIndex(
  1970. (item) => item.rowid == parentRow.rowid
  1971. )
  1972. if (
  1973. !this.contentEditForm.fixedTable.fixedTables[parentIndex1]
  1974. .children
  1975. ) {
  1976. this.$set(
  1977. this.contentEditForm.fixedTable.fixedTables[parentIndex1],
  1978. 'children',
  1979. []
  1980. )
  1981. }
  1982. let childOrderNum =
  1983. this.contentEditForm.fixedTable.fixedTables[parentIndex1].children
  1984. .length + 1
  1985. let fixedValues = {
  1986. ...parentRow.fixedValues,
  1987. }
  1988. for (const key in fixedValues) {
  1989. if (key == '序号') {
  1990. fixedValues[key] = childOrderNum
  1991. } else {
  1992. fixedValues[key] = ''
  1993. }
  1994. }
  1995. const fixedNewRow = {
  1996. orderText: this.contentEditForm.fixedTable.fixedTables.length + 1,
  1997. orderNum: this.contentEditForm.fixedTable.fixedTables.length + 1,
  1998. cellCode: '',
  1999. calculationFormula: '',
  2000. unit: '',
  2001. tabtype: this.contentEditForm.templateType,
  2002. surveyTemplateId: this.contentEditForm.surveyTemplateId,
  2003. versionId: this.versionId,
  2004. fixedValues: fixedValues,
  2005. parentid: parentRow.rowid,
  2006. isChild: true,
  2007. isSubItem: true,
  2008. rowid: this.generateUUID(),
  2009. }
  2010. this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
  2011. (title) => {
  2012. if (!(title.rkey in fixedNewRow.fixedValues)) {
  2013. fixedNewRow.fixedValues[title.rkey] = ''
  2014. }
  2015. }
  2016. )
  2017. this.contentEditForm.fixedTable.fixedTables[
  2018. parentIndex1
  2019. ].children.push(fixedNewRow)
  2020. // this.contentEditForm.fixedTable.fixedTables.splice(
  2021. // index + 1,
  2022. // 0,
  2023. // fixedNewRow
  2024. // )
  2025. break
  2026. }
  2027. this.$nextTick(() => {
  2028. const tableBody = document.querySelector('.el-table__body-wrapper')
  2029. if (tableBody) {
  2030. tableBody.scrollTop = tableBody.scrollHeight
  2031. }
  2032. })
  2033. },
  2034. handleCreateModeChange() {
  2035. if (this.contentEditForm.createmode == 1) {
  2036. this.contentEditForm.createtemplateid1 = ''
  2037. } else if (this.contentEditForm.createmode == 2) {
  2038. this.contentEditForm.createtemplateid = ''
  2039. }
  2040. },
  2041. openCalculationFormulaDialogVisible(row, index) {
  2042. this.currentEditingRow = row
  2043. this.currentEditingRowIndex = index
  2044. this.calculationFormulaDialogVisible = true
  2045. this.formulaText = row.calculationFormula || ''
  2046. this.selectedTemplateId = '' // 重置选中的模板
  2047. this.indicatorTableData = [] // 清空指标数据
  2048. this.getListFixedEnabled()
  2049. },
  2050. getListFixedEnabled() {
  2051. getListFixedEnabled({
  2052. surveyTemplateId: this.contentEditForm.surveyTemplateId,
  2053. }).then((res) => {
  2054. this.templateList = res.value
  2055. })
  2056. },
  2057. // 处理模板选择变化
  2058. handleTemplateChange(templateId) {
  2059. if (templateId) {
  2060. // 根据选中的模板ID查找对应的surveyTemplateId
  2061. const selectedTemplate = this.templateList.find(
  2062. (item) => item.pkVal === templateId
  2063. )
  2064. if (selectedTemplate && selectedTemplate.surveyTemplateId) {
  2065. this.getCellCodesByTemplateId(selectedTemplate.surveyTemplateId)
  2066. } else {
  2067. this.indicatorTableData = []
  2068. }
  2069. } else {
  2070. this.indicatorTableData = []
  2071. }
  2072. // 恢复该模板之前选中的指标项
  2073. this.$nextTick(() => {
  2074. if (this.selectedIndicatorsPerTemplate[templateId]) {
  2075. this.indicatorTableData.forEach((item) => {
  2076. const isSelected = this.selectedIndicatorsPerTemplate[
  2077. templateId
  2078. ].some((selectedItem) => selectedItem.code === item.code)
  2079. this.$set(item, 'checked', isSelected)
  2080. if (isSelected) {
  2081. this.formatRowCode(item)
  2082. }
  2083. })
  2084. }
  2085. // 更新选中的指标代码列表
  2086. this.updateSelectedIndicatorCodes()
  2087. })
  2088. },
  2089. getCellCodesByTemplateId(surveyTemplateId) {
  2090. listByVerifyTemplateId({
  2091. surveyTemplateId: surveyTemplateId,
  2092. })
  2093. .then((res) => {
  2094. // 将返回的数据转换为表格需要的格式
  2095. if (res.value && Array.isArray(res.value.itemlist)) {
  2096. let fixedTablesTitle = this.stringToObjects(
  2097. res.value.fixedFields || ''
  2098. )
  2099. this.indicatorTableHeaders = fixedTablesTitle
  2100. this.indicatorTableData = res.value.itemlist.map((item) => ({
  2101. ...item,
  2102. checked: false,
  2103. cellCode: item.cellCode || '',
  2104. name: res.value.fixedFields.split(',')[0] || '',
  2105. formattedCode: '', // 添加格式化代码字段
  2106. }))
  2107. } else {
  2108. this.indicatorTableData = []
  2109. }
  2110. })
  2111. .catch((error) => {
  2112. console.error('获取指标数据失败:', error)
  2113. this.indicatorTableData = []
  2114. })
  2115. },
  2116. updateSelectedIndicatorCodes() {
  2117. // 获取当前选中的行
  2118. const selectedRows = this.indicatorTableData.filter(
  2119. (item) => item.checked
  2120. )
  2121. // 更新选中的指标代码列表
  2122. this.selectedIndicatorCodes = selectedRows.map((item) => {
  2123. // 获取选中的模板信息
  2124. const selectedTemplate = this.templateList.find(
  2125. (template) => template.pkVal === this.selectedTemplateId
  2126. )
  2127. // 获取模板的 surveyTemplateNameYw
  2128. const templateName = selectedTemplate
  2129. ? selectedTemplate.surveyTemplateNameYw ||
  2130. selectedTemplate.surveyTemplateName ||
  2131. ''
  2132. : ''
  2133. return templateName
  2134. ? `${templateName}.${item.code || item.cellCode || ''}`
  2135. : item.code || item.cellCode || ''
  2136. })
  2137. },
  2138. formatRowCode(row) {
  2139. const selectedTemplate = this.templateList.find(
  2140. (item) => item.pkVal === this.selectedTemplateId
  2141. )
  2142. const surveyTemplateNameYw = selectedTemplate
  2143. ? selectedTemplate.surveyTemplateNameYw ||
  2144. selectedTemplate.surveyTemplateName ||
  2145. ''
  2146. : ''
  2147. const formattedCode = surveyTemplateNameYw
  2148. ? `${surveyTemplateNameYw}.${row.code || row.cellCode || ''}`
  2149. : row.code || row.cellCode || ''
  2150. this.$set(row, 'formattedCode', formattedCode)
  2151. const templateCode = surveyTemplateNameYw
  2152. ? `${surveyTemplateNameYw}_${row.code || row.cellCode || ''}`
  2153. : row.code || row.cellCode || ''
  2154. this.$set(
  2155. row,
  2156. 'jsonStr',
  2157. JSON.stringify([
  2158. {
  2159. [templateCode]: this.selectedTemplateId,
  2160. },
  2161. ])
  2162. )
  2163. },
  2164. handleRowClick(row, column, event) {
  2165. // 只有点击非 checkbox 列才触发
  2166. if (column && column.property !== 'checked') {
  2167. // 如果没有 cellCode,则不允许选中
  2168. if (!row.cellCode) {
  2169. // this.$message.warning('该数据没有指标编号,无法选择')
  2170. return
  2171. }
  2172. // 切换选中状态
  2173. this.toggleRowSelection(row)
  2174. }
  2175. },
  2176. toggleRowSelection(row) {
  2177. // 切换选中状态
  2178. this.$set(row, 'checked', !row.checked)
  2179. // 格式化代码并存储在行数据中
  2180. if (row.checked) {
  2181. this.formatRowCode(row)
  2182. }
  2183. // 触发选中状态更新
  2184. this.$forceUpdate()
  2185. },
  2186. selectionIndicatorChange(val) {
  2187. this.indicatorTableData.forEach((item) => {
  2188. item.checked = val.includes(item)
  2189. })
  2190. },
  2191. handleCheckboxChange(row) {
  2192. // 如果没有 cellCode,则不允许选中
  2193. if (!row.cellCode) {
  2194. this.$message.warning('该数据没有指标编号,无法选择')
  2195. this.$set(row, 'checked', false)
  2196. return
  2197. }
  2198. this.$set(row, 'checked', !row.checked)
  2199. if (row.checked) {
  2200. this.formatRowCode(row)
  2201. }
  2202. this.updateSelectedIndicatorCodes()
  2203. this.$forceUpdate()
  2204. },
  2205. handleFormulaTextChange(value) {
  2206. // 当用户手动修改公式文本时,标记为非自动生成
  2207. this.isAutoGeneratedFormula = false
  2208. },
  2209. handleDialogClose(done) {
  2210. this.selectedIndicatorsPerTemplate = {}
  2211. done()
  2212. },
  2213. handleRadioChange(value) {
  2214. this.formulaText = ''
  2215. },
  2216. handleConfirm() {
  2217. const result = {
  2218. type: this.radioType,
  2219. formula: this.formulaText,
  2220. selectedTemplate: this.selectedTemplateId,
  2221. selectedItems: this.indicatorTableData.filter((item) => item.checked),
  2222. }
  2223. let _data = []
  2224. if (this.radioType == 'current') {
  2225. // 使用递归函数扁平化树形结构
  2226. const flattenTree = (nodes) => {
  2227. let result = []
  2228. nodes.forEach((node) => {
  2229. result.push(node)
  2230. if (node.children && node.children.length > 0) {
  2231. result = result.concat(flattenTree(node.children))
  2232. }
  2233. })
  2234. return result
  2235. }
  2236. // 扁平化数据并提取cellCode
  2237. _data = flattenTree(this.contentEditForm.fixedTable.fixedTables)
  2238. .filter((item) => item.cellCode)
  2239. .map((item) => item.cellCode)
  2240. } else if (this.radioType == 'other') {
  2241. if (!result.selectedTemplate) {
  2242. this.$message.error('请选择指标编号')
  2243. return
  2244. }
  2245. _data = this.indicatorTableData
  2246. .filter((item) => item.cellCode)
  2247. .map((item) => item.cellCode)
  2248. }
  2249. if (!this.validateFormula(this.formulaText, _data).valid) {
  2250. this.$message.error(
  2251. this.validateFormula(this.formulaText, _data).errorMsg
  2252. )
  2253. return
  2254. }
  2255. // 生成 jsonstr 字段
  2256. const jsonStrArray = this.indicatorTableData
  2257. .filter((item) => item.checked)
  2258. .map((item) => {
  2259. if (item.jsonStr) {
  2260. try {
  2261. return JSON.parse(item.jsonStr)[0]
  2262. } catch (e) {
  2263. console.error('解析 jsonStr 失败:', e)
  2264. return {}
  2265. }
  2266. }
  2267. return {}
  2268. })
  2269. .filter((item) => Object.keys(item).length > 0)
  2270. const jsonstr = JSON.stringify(jsonStrArray)
  2271. // 更新当前编辑行的计算公式值
  2272. if (this.currentEditingRow) {
  2273. this.$set(
  2274. this.currentEditingRow,
  2275. 'calculationFormula',
  2276. this.formulaText
  2277. )
  2278. this.$set(this.currentEditingRow, 'jsonstr', jsonstr)
  2279. }
  2280. console.log('点击了确定,获取到的数据:', {
  2281. ...result,
  2282. jsonstr: jsonstr,
  2283. })
  2284. // 清空当前操作的状态
  2285. this.calculationFormulaDialogVisible = false
  2286. this.currentEditingRow = null
  2287. this.currentEditingRowIndex = -1
  2288. this.isAutoGeneratedFormula = false
  2289. this.selectedTemplateId = ''
  2290. this.indicatorTableData = []
  2291. this.selectedIndicatorsPerTemplate = {} // 清空模板选中记录
  2292. },
  2293. /**
  2294. * 解析并回显固定表项目数据
  2295. * @param {Object} responseData - listByCurrentTemplateId接口返回的数据
  2296. */
  2297. parseAndDisplayFixedTableData(responseData) {
  2298. if (responseData.value.fixedFields) {
  2299. this.contentEditForm.fixedTable.fixedTablesTitle =
  2300. this.stringToObjects(responseData.value.fixedFields || '')
  2301. } else {
  2302. let fixedFields = this.contentEditForm.fixedTable.tableHeaders
  2303. .map((item) => item.fieldName)
  2304. .join(',')
  2305. this.contentEditForm.fixedTable.fixedTablesTitle =
  2306. this.stringToObjects(fixedFields || '')
  2307. }
  2308. const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
  2309. this.contentEditForm.fixedTable.fixedTableHeaders = fixedTitles.filter(
  2310. (title) => title.rkey !== '序号'
  2311. )
  2312. if (
  2313. !responseData ||
  2314. !responseData.value ||
  2315. !responseData.value.itemlist
  2316. ) {
  2317. return
  2318. }
  2319. const itemList = responseData.value.itemlist
  2320. const allRows = []
  2321. const rowMap = new Map()
  2322. // 清空现有数据
  2323. this.contentEditForm.fixedTable.fixedTables = []
  2324. // 遍历itemList,为每个项目创建一行数据
  2325. itemList.forEach((item, index) => {
  2326. // 判断是否为子项(parentid不为-1且不为"-1")
  2327. const isSubItem =
  2328. item.parentid && item.parentid !== -1 && item.parentid !== '-1'
  2329. const newRow = {
  2330. orderText: item.orderNum || '', // 显示用序号
  2331. orderNum: item.orderNum || '', // 保留原始序号用于发送后端
  2332. surveyTemplateId: item.surveyTemplateId,
  2333. versionId: item.versionId,
  2334. cellCode: item.cellCode || '',
  2335. calculationFormula: item.calculationFormula || '',
  2336. unit: item.unit || '',
  2337. fixedValues: {},
  2338. itemId: item.id || null,
  2339. parentid: item.parentid || -1,
  2340. isChild: isSubItem,
  2341. isSubItem: isSubItem,
  2342. rowid: item.rowid || this.generateUUID(),
  2343. jsonstr: item.jsonstr || null,
  2344. children: [], // 添加children数组用于树形结构
  2345. }
  2346. // 确保orderNum是数字类型
  2347. if (item.orderNum) {
  2348. newRow.orderNum = parseInt(item.orderNum, 10) || 0
  2349. }
  2350. // 初始化fixedValues并填充实际值
  2351. fixedTitles.forEach((title) => {
  2352. newRow.fixedValues[title.rkey] = item[title.rkey] || ''
  2353. })
  2354. allRows.push(newRow)
  2355. // 构建rowMap用于快速查找
  2356. if (newRow.rowid) rowMap.set(String(newRow.rowid), newRow)
  2357. if (newRow.itemId) rowMap.set(String(newRow.itemId), newRow)
  2358. })
  2359. // 构建树形结构
  2360. const treeData = []
  2361. const parentItems = allRows.filter((item) => !item.isChild)
  2362. // 父级按orderNum正序排序
  2363. parentItems.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
  2364. // 将子项添加到对应的父项的children中
  2365. allRows.forEach((item) => {
  2366. if (item.isChild) {
  2367. const parentId = String(item.parentid)
  2368. const parent = rowMap.get(parentId)
  2369. if (parent) {
  2370. parent.children.push(item)
  2371. }
  2372. }
  2373. })
  2374. // 对子项进行排序
  2375. parentItems.forEach((parent) => {
  2376. parent.children.sort(
  2377. (a, b) =>
  2378. (a.fixedValues['序号'] || 0) - (b.fixedValues['序号'] || 0)
  2379. )
  2380. treeData.push(parent)
  2381. })
  2382. this.contentEditForm.fixedTable.fixedTables = treeData
  2383. },
  2384. /**
  2385. * 将固定表项目的数据根据固定列拆分成对应的数据结构
  2386. * @returns {Array} 拆分后的数据数组,每个固定列对应一行数据
  2387. */
  2388. splitFixedTableDataForSave() {
  2389. const fixedTables = this.contentEditForm.fixedTable.fixedTables
  2390. const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
  2391. const fixedHeaders = this.contentEditForm.fixedTable.tableHeaders
  2392. // 结果数组
  2393. const result = []
  2394. // 递归处理树形结构中的所有节点
  2395. const processNode = (node, parentRowIndex = 0) => {
  2396. // 确保node和fixedValues存在
  2397. if (!node) {
  2398. console.warn('遇到空节点,跳过处理')
  2399. return
  2400. }
  2401. // 确保fixedValues属性存在,如果不存在则初始化为空对象
  2402. if (!node.fixedValues) {
  2403. node.fixedValues = {}
  2404. }
  2405. // 为每个固定列创建一条记录
  2406. fixedTitles.forEach((title) => {
  2407. // 找到对应的表头信息
  2408. const correspondingHeader = fixedHeaders.find(
  2409. (header) => header.fieldName === title.rkey
  2410. )
  2411. const newItem = {
  2412. rkey: title.rkey,
  2413. rvalue: node.fixedValues[title.rkey] || '',
  2414. surveyTemplateId: node.surveyTemplateId || this.surveyTemplateId,
  2415. versionId: node.versionId || this.versionId,
  2416. tabtype: node.tabtype || this.templateType,
  2417. // 添加 headersId 字段(表头的id)
  2418. headersId: correspondingHeader ? correspondingHeader.id : null,
  2419. // 添加记录的id(itemlist中每条记录的id)
  2420. id: node.itemId || null,
  2421. // 添加父子关系字段
  2422. parentid: node.parentid || -1, // 父项ID,默认为-1表示无父项
  2423. isChild: node.isChild || false, // 是否为子项
  2424. // 添加 rowid 字段
  2425. rowid: node.rowid || null,
  2426. // 添加计算公式相关字段
  2427. calculationFormula: node.calculationFormula || null,
  2428. jsonstr: node.jsonstr || null,
  2429. orderNum:
  2430. typeof node.orderNum === 'number'
  2431. ? node.orderNum
  2432. : parseInt(node.orderNum, 10) || 0,
  2433. }
  2434. // 添加其他固定表特有的字段
  2435. if (!node.isSubItem) {
  2436. newItem.cellCode = node.cellCode || ''
  2437. newItem.unit = node.unit || ''
  2438. }
  2439. // 添加其他可能需要的字段,但排除特定字段
  2440. Object.keys(node).forEach((key) => {
  2441. if (
  2442. !(key in newItem) &&
  2443. key !== 'fixedValues' &&
  2444. key !== 'itemId' &&
  2445. key !== 'id' &&
  2446. key !== 'parentid' &&
  2447. key !== 'isChild' &&
  2448. key !== 'isSubItem' &&
  2449. key !== 'rowid' &&
  2450. key !== 'jsonstr' &&
  2451. key !== 'calculationFormula' &&
  2452. key !== 'children' // 排除children字段
  2453. ) {
  2454. newItem[key] = node[key]
  2455. }
  2456. })
  2457. result.push(newItem)
  2458. })
  2459. // 递归处理子节点
  2460. if (node.children && node.children.length > 0) {
  2461. node.children.forEach((childNode) => {
  2462. processNode(childNode)
  2463. })
  2464. }
  2465. }
  2466. // 遍历所有顶级节点
  2467. fixedTables.forEach((row) => {
  2468. processNode(row)
  2469. })
  2470. // 重新给子节点赋值orderNum 保证所有元素orderNum字段不重复
  2471. // 为所有子节点分配唯一的orderNum,但保持父节点的orderNum不变
  2472. // 计算所有已存在的orderNum中的最大值
  2473. let maxExistingOrderNum = 0
  2474. // 首先遍历结果数组找出当前最大的orderNum
  2475. result.forEach((item) => {
  2476. const orderNum =
  2477. typeof item.orderNum === 'number'
  2478. ? item.orderNum
  2479. : parseInt(item.orderNum, 10) || 0
  2480. if (orderNum > maxExistingOrderNum) {
  2481. maxExistingOrderNum = orderNum
  2482. }
  2483. })
  2484. // 子节点orderNum从当前最大orderNum + 1开始
  2485. let childOrderNumCounter = maxExistingOrderNum + 1
  2486. // 创建一个映射表,用于记录每个子节点对应的新orderNum
  2487. const childOrderMap = new Map()
  2488. // 第一次遍历:为每个子节点分配新的orderNum并存储映射关系
  2489. function assignChildOrderNums(nodes) {
  2490. nodes.forEach((node) => {
  2491. if (node.isChild || node.isSubItem) {
  2492. // 为每个子节点分配唯一的orderNum
  2493. childOrderMap.set(node.id || node.rowid, childOrderNumCounter++)
  2494. }
  2495. // 递归处理子节点
  2496. if (node.children && node.children.length > 0) {
  2497. assignChildOrderNums(node.children)
  2498. }
  2499. })
  2500. }
  2501. // 第二次遍历:更新结果数组中的orderNum
  2502. assignChildOrderNums(fixedTables)
  2503. // 应用新的orderNum到结果数组
  2504. result.forEach((item) => {
  2505. // 只更新子节点的orderNum
  2506. if (item.isChild || item.isSubItem) {
  2507. const newOrderNum =
  2508. childOrderMap.get(item.id) || childOrderMap.get(item.rowid)
  2509. if (newOrderNum) {
  2510. item.orderNum = newOrderNum
  2511. }
  2512. }
  2513. })
  2514. return result
  2515. },
  2516. //分割字符串
  2517. stringToObjects(str) {
  2518. const items = str.split(',')
  2519. return items.map((item) => ({
  2520. rkey: item,
  2521. rvalue: '',
  2522. }))
  2523. },
  2524. /**
  2525. * 获取行缩进样式,用于树形结构展示
  2526. * @param {Object} row - 表格行数据
  2527. * @returns {Object} 样式对象
  2528. */
  2529. getRowIndentStyle(row) {
  2530. // 为子项添加缩进
  2531. if (row.isChild) {
  2532. return {
  2533. marginLeft: '30px',
  2534. }
  2535. }
  2536. return {}
  2537. },
  2538. handleSaveTemplate() {
  2539. // 校验表单
  2540. this.$refs['contentEditForm'].validate((valid) => {
  2541. if (valid) {
  2542. if (this.dialogTitle == '修改成本核定模板') {
  2543. let data = {
  2544. ...this.contentEditForm,
  2545. }
  2546. delete data.fixedTable
  2547. // 修改表单数据
  2548. addCostVerifyForm(data).then((res) => {})
  2549. }
  2550. // 获取拆分后的数据
  2551. const splitData = this.splitFixedTableDataForSave()
  2552. const headersList =
  2553. this.contentEditForm.fixedTable.tableHeaders.map(
  2554. (header, index) => ({
  2555. ...header,
  2556. orderNum: header.orderNum || index + 1,
  2557. })
  2558. )
  2559. let data = {
  2560. costVerifyTemplateId: this.contentEditForm.surveyTemplateId,
  2561. headersList: headersList,
  2562. itemsList: splitData,
  2563. }
  2564. batchSaveOrUpdate(data)
  2565. .then((data) => {
  2566. this.dialogVisible = false
  2567. this.$message.success('保存成功')
  2568. this.handleSearch()
  2569. })
  2570. .catch((err) => {
  2571. console.log(err)
  2572. })
  2573. } else {
  2574. this.$message.error('请填写表单数据')
  2575. return
  2576. }
  2577. })
  2578. },
  2579. // 批量删除
  2580. handleBatchDelete() {
  2581. if (this.selectedRows.length === 0) {
  2582. this.$message.warning('请先选择要删除的数据')
  2583. return
  2584. }
  2585. this.$confirm(
  2586. `确定要删除选中的${this.selectedRows.length}条数据吗?`,
  2587. '提示',
  2588. {
  2589. type: 'warning',
  2590. }
  2591. )
  2592. .then(() => {
  2593. const ids = this.selectedRows.map((row) => row.surveyTemplateId)
  2594. batchDeleteCostVerifyForm(ids).then((res) => {
  2595. if (res.code === 200) {
  2596. this.selectedRows = []
  2597. this.$message.success('批量删除成功')
  2598. this.handleSearch()
  2599. }
  2600. })
  2601. })
  2602. .catch(() => {})
  2603. },
  2604. // 表格选择
  2605. handleSelectionChange(selection) {
  2606. this.selectedRows = selection
  2607. },
  2608. // 分页相关
  2609. handleSizeChange(val) {
  2610. this.searchForm.pageSize = val
  2611. this.handleSearch()
  2612. },
  2613. handleCurrentChange(val) {
  2614. this.searchForm.page = val
  2615. this.handleSearch()
  2616. },
  2617. // 获取或设置序号字段
  2618. getOrSetOrder(row, value) {
  2619. // 如果提供了value参数,则设置值
  2620. if (value !== undefined) {
  2621. // 使用this.$set确保响应式更新
  2622. if (row['序号'] === undefined) {
  2623. this.$set(row, '序号', value)
  2624. } else {
  2625. row['序号'] = value
  2626. }
  2627. }
  2628. // 如果没有提供value参数,则获取值
  2629. return row['序号'] !== undefined && row['序号'] !== null
  2630. ? row['序号']
  2631. : row.orderNum || ''
  2632. },
  2633. // 公式验证函数
  2634. validateFormula(formula, data) {
  2635. if (!formula || typeof formula !== 'string') {
  2636. return { valid: false, errorMsg: '公式不能为空' }
  2637. }
  2638. // 定义有效的操作符
  2639. const operators = ['+', '-', '*', '/', '(', ')']
  2640. // 检查是否包含至少一个操作符
  2641. const hasOperator = operators.some((operator) =>
  2642. formula.includes(operator)
  2643. )
  2644. if (!hasOperator) {
  2645. return { valid: false, errorMsg: '公式必须包含操作符' }
  2646. }
  2647. // 检查值是否在data中存在
  2648. function checkValueInData(value, data) {
  2649. if (!data) return false
  2650. if (Array.isArray(data)) {
  2651. return data.includes(value)
  2652. } else if (typeof data === 'object') {
  2653. return Object.values(data).includes(value)
  2654. }
  2655. return data === value
  2656. }
  2657. // 提取公式中的变量/值
  2658. function extractValues(formulaStr) {
  2659. // 改进实现:支持形如"CeShi3.C2"的格式,提取点后面的部分作为变量,同时保留普通变量
  2660. const result = new Set()
  2661. // 1. 首先提取带点格式中的变量部分(如CeShi3.C2中的C2)
  2662. const dotRegex = /[A-Za-z0-9]+\.([A-Za-z0-9]+)/g
  2663. let dotMatch
  2664. while ((dotMatch = dotRegex.exec(formulaStr)) !== null) {
  2665. result.add(dotMatch[1]) // 提取点后面的部分作为变量
  2666. }
  2667. // 2. 然后提取普通变量(C3等),但排除已经从带点格式中提取的部分
  2668. // 移除所有带点的部分,然后提取剩余的变量
  2669. const remainingFormula = formulaStr.replace(
  2670. /[A-Za-z0-9]+\.[A-Za-z0-9]+/g,
  2671. ''
  2672. )
  2673. const normalRegex = /[A-Za-z0-9]+/g
  2674. let normalMatch
  2675. while ((normalMatch = normalRegex.exec(remainingFormula)) !== null) {
  2676. // 跳过纯数字
  2677. if (
  2678. !isNaN(Number(normalMatch[0])) &&
  2679. Number(normalMatch[0]).toString() === normalMatch[0]
  2680. ) {
  2681. continue
  2682. }
  2683. result.add(normalMatch[0])
  2684. }
  2685. return Array.from(result)
  2686. }
  2687. function checkOperatorContext(formulaStr, data) {
  2688. for (let i = 0; i < formulaStr.length; i++) {
  2689. const char = formulaStr[i]
  2690. // 跳过括号
  2691. if (char === '(' || char === ')') continue
  2692. // 检查操作符
  2693. if (operators.includes(char)) {
  2694. // 检查操作符前是否有值(开头或不是操作符和左括号)
  2695. if (
  2696. i === 0 ||
  2697. (operators.includes(formulaStr[i - 1]) &&
  2698. formulaStr[i - 1] !== ')') ||
  2699. formulaStr[i - 1] === '('
  2700. ) {
  2701. return {
  2702. valid: false,
  2703. errorMsg: `位置 ${i + 1} 的操作符 '${char}' 前缺少值`,
  2704. }
  2705. }
  2706. // 检查操作符后是否有值(结尾或不是操作符和右括号)
  2707. if (
  2708. i === formulaStr.length - 1 ||
  2709. (operators.includes(formulaStr[i + 1]) &&
  2710. formulaStr[i + 1] !== '(') ||
  2711. formulaStr[i + 1] === ')'
  2712. ) {
  2713. return {
  2714. valid: false,
  2715. errorMsg: `位置 ${i + 1} 的操作符 '${char}' 后缺少值`,
  2716. }
  2717. }
  2718. }
  2719. }
  2720. // 验证通过后,检查公式中的值是否都在data中存在
  2721. if (data.length > 0) {
  2722. const values = extractValues(formulaStr)
  2723. for (const value of values) {
  2724. // 跳过纯数字(假设有值不在data中)
  2725. if (!isNaN(Number(value)) && Number(value).toString() === value) {
  2726. continue
  2727. }
  2728. if (!checkValueInData(value, data)) {
  2729. return {
  2730. valid: false,
  2731. errorMsg: `变量 '${value}' 在数据中不存在`,
  2732. }
  2733. }
  2734. }
  2735. }
  2736. return { valid: true }
  2737. }
  2738. // 执行验证
  2739. return checkOperatorContext(formula, data)
  2740. },
  2741. },
  2742. }
  2743. </script>
  2744. <style lang="scss" scoped>
  2745. .row-indent-container {
  2746. display: flex;
  2747. align-items: center;
  2748. position: relative;
  2749. }
  2750. .child-item {
  2751. padding-left: 30px; /* 增加子项缩进,为'子项'文字留出空间 */
  2752. }
  2753. .child-item-indicator {
  2754. position: absolute;
  2755. left: 0;
  2756. color: $base-color-default; /* 使用主题色,更醒目 */
  2757. font-size: 12px;
  2758. width: 30px;
  2759. text-align: left;
  2760. font-weight: 500;
  2761. }
  2762. @import '@/styles/costAudit.scss';
  2763. .supervision-content-container {
  2764. padding: 20px;
  2765. .operation-bar {
  2766. margin-bottom: 20px;
  2767. }
  2768. .table-container {
  2769. .table-name-link {
  2770. color: #409eff;
  2771. cursor: pointer;
  2772. &:hover {
  2773. color: #66b1ff;
  2774. text-decoration: underline;
  2775. }
  2776. }
  2777. .pagination-container {
  2778. margin-top: 20px;
  2779. text-align: right;
  2780. }
  2781. }
  2782. .content-form,
  2783. .detail-form {
  2784. ::v-deep .el-select {
  2785. width: 100%;
  2786. }
  2787. }
  2788. }
  2789. </style>