infoMaintain.vue 153 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368
  1. <template>
  2. <div>
  3. <div class="top-wrapper">
  4. <el-button plain type="primary" icon="el-icon-back" @click="handleBack">
  5. 返回
  6. </el-button>
  7. <div class="title ml20">{{ surveyTemplateName }}内容维护</div>
  8. </div>
  9. <!-- 搜索面板 -->
  10. <div class="search-panel mt20">
  11. <el-form :inline="true" :model="searchForm" label-width="80px">
  12. <el-form-item label="状态:">
  13. <el-select
  14. v-model="searchForm.status"
  15. placeholder="请选择状态"
  16. style="width: 180px"
  17. >
  18. <el-option label="全部" value=""></el-option>
  19. <el-option label="草稿" value="-1"></el-option>
  20. <el-option label="现行版本" value="0"></el-option>
  21. <el-option label="历史版本" value="1"></el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="primary" icon="el-icon-search" @click="handleSearch">
  26. 查询
  27. </el-button>
  28. <el-button
  29. plain
  30. type="primary"
  31. icon="el-icon-refresh"
  32. @click="handleReset"
  33. >
  34. 重置
  35. </el-button>
  36. </el-form-item>
  37. </el-form>
  38. </div>
  39. <!-- 操作栏 -->
  40. <div class="operation-bar">
  41. <el-button
  42. v-region-permission="{ category: 'costFormManage', action: 'add' }"
  43. plain
  44. type="success"
  45. icon="el-icon-circle-plus"
  46. @click="handleAdd"
  47. >
  48. 添加
  49. </el-button>
  50. <el-button
  51. v-region-permission="{
  52. category: 'costFormManage',
  53. action: 'delete',
  54. }"
  55. plain
  56. type="danger"
  57. icon="el-icon-delete"
  58. :disabled="selectedRows.length === 0"
  59. @click="handleBatchDelete"
  60. >
  61. 批量删除
  62. </el-button>
  63. </div>
  64. <!-- 表格 -->
  65. <div class="table-container">
  66. <CostAuditTable
  67. ref="costAuditTable"
  68. :table-data="tableData"
  69. :columns="tableColumns"
  70. :show-selection="true"
  71. :show-index="true"
  72. :show-pagination="true"
  73. :pagination="pagination"
  74. :loading="loading"
  75. @selection-change="handleSelectionChange"
  76. @pagination-change="handlePaginationChange"
  77. >
  78. <!-- 创建时间自定义单元格 -->
  79. <template #createTime="{ row }">
  80. <div>{{ row.createTime ? row.createTime.split(' ')[0] : '-' }}</div>
  81. <div>{{ row.createTime ? row.createTime.split(' ')[1] : '-' }}</div>
  82. </template>
  83. <!-- 操作列 -->
  84. <template #action="{ row }">
  85. <el-button
  86. v-region-permission="{
  87. category: 'costFormManage',
  88. action: 'view',
  89. }"
  90. type="text"
  91. size="small"
  92. @click="handleViewDetail(row)"
  93. >
  94. 详情
  95. </el-button>
  96. <el-button
  97. v-if="row.status === '-1'"
  98. v-region-permission="{
  99. category: 'costFormManage',
  100. action: 'edit',
  101. }"
  102. type="text"
  103. size="small"
  104. @click="handleEdit(row)"
  105. >
  106. 修改
  107. </el-button>
  108. <el-button
  109. v-if="row.status != '0'"
  110. v-region-permission="{
  111. category: 'costFormManage',
  112. action: 'delete',
  113. targetData: row,
  114. }"
  115. class="delete-btn"
  116. type="text"
  117. size="small"
  118. @click="handleDelete(row)"
  119. >
  120. 删除
  121. </el-button>
  122. <el-button
  123. v-if="row.status === '-1'"
  124. v-region-permission="{
  125. category: 'costFormManage',
  126. action: 'edit',
  127. }"
  128. type="text"
  129. size="small"
  130. @click="handleEditContent(row)"
  131. >
  132. 内容维护
  133. </el-button>
  134. <el-button
  135. v-if="row.status === '-1'"
  136. v-region-permission="{
  137. category: 'costFormManage',
  138. action: 'edit',
  139. }"
  140. type="text"
  141. size="small"
  142. @click="handleStatus(row)"
  143. >
  144. 启用
  145. </el-button>
  146. <el-button
  147. v-if="row.status === '0'"
  148. v-region-permission="{
  149. category: 'costFormManage',
  150. action: 'edit',
  151. }"
  152. type="text"
  153. size="small"
  154. @click="handleStatus(row)"
  155. >
  156. 停用
  157. </el-button>
  158. </template>
  159. </CostAuditTable>
  160. </div>
  161. <!-- 详情弹窗 -->
  162. <el-dialog title="详情" :visible.sync="detailDialogVisible" width="800px">
  163. <el-form :model="detailForm" label-width="120px" class="detail-form">
  164. <el-form-item label="ID:">{{ detailForm.id }}</el-form-item>
  165. <el-form-item label="版本号:">{{ detailForm.versionNo }}</el-form-item>
  166. <el-form-item label="状态:">
  167. {{ forStatus(detailForm.status) }}
  168. </el-form-item>
  169. <el-form-item label="创建人:">{{ detailForm.createBy }}</el-form-item>
  170. <el-form-item label="创建时间:">
  171. {{ detailForm.createTime }}
  172. </el-form-item>
  173. <el-form-item label="备注:">{{ detailForm.remarks }}</el-form-item>
  174. </el-form>
  175. <div slot="footer">
  176. <el-button @click="detailDialogVisible = false">关闭</el-button>
  177. </div>
  178. </el-dialog>
  179. <!-- 添加/修改弹窗 -->
  180. <el-dialog
  181. :title="dialogTitle"
  182. :visible.sync="dialogVisible"
  183. width="600px"
  184. :close-on-click-modal="false"
  185. >
  186. <el-form
  187. ref="dataForm"
  188. :model="dataForm"
  189. :rules="dataFormRules"
  190. label-width="120px"
  191. class="data-form"
  192. >
  193. <el-form-item label="创建人" prop="createBy">
  194. <el-input
  195. v-model="dataForm.createBy"
  196. placeholder="请输入创建人"
  197. ></el-input>
  198. </el-form-item>
  199. <el-form-item label="创建时间" prop="createTime">
  200. <el-date-picker
  201. v-model="dataForm.createTime"
  202. type="datetime"
  203. placeholder="选择日期时间"
  204. style="width: 100%"
  205. ></el-date-picker>
  206. </el-form-item>
  207. <el-form-item label="备注">
  208. <el-input
  209. v-model="dataForm.remarks"
  210. type="textarea"
  211. placeholder="请输入备注"
  212. rows="3"
  213. ></el-input>
  214. </el-form-item>
  215. </el-form>
  216. <div slot="footer" class="dialog-footer">
  217. <el-button @click="dialogVisible = false">取消</el-button>
  218. <el-button type="primary" @click="submitForm">确定</el-button>
  219. </div>
  220. </el-dialog>
  221. <!-- 内容修改弹窗 -->
  222. <el-dialog
  223. title="内容维护"
  224. :visible.sync="contentEditDialogVisible"
  225. width="75%"
  226. class="content-edit-dialog"
  227. :close-on-click-modal="false"
  228. >
  229. <div class="content-edit-container">
  230. <div class="table-header-info">
  231. <div class="table-name">
  232. 调查表名称:{{ contentEditForm.tableName }}
  233. </div>
  234. <div class="table-style">
  235. 表单样式:
  236. <el-radio-group
  237. v-model="contentEditForm.templateType"
  238. @change="handleFormStyleChange"
  239. >
  240. <el-radio v-if="contentEditForm.templateType === '1'" label="1">
  241. 单记录
  242. </el-radio>
  243. <el-radio v-if="contentEditForm.templateType === '2'" label="2">
  244. 固定表
  245. </el-radio>
  246. <el-radio v-if="contentEditForm.templateType === '3'" label="3">
  247. 动态表
  248. </el-radio>
  249. </el-radio-group>
  250. </div>
  251. <div v-if="viewDetail" class="detail-info-container">
  252. <div class="detail-item">
  253. <span class="detail-label">版本号:</span>
  254. <span class="detail-value">{{ detailForm.versionNo }}</span>
  255. </div>
  256. <div class="detail-item">
  257. <span class="detail-label">状态:</span>
  258. <span class="detail-value">
  259. {{ forStatus(detailForm.status) }}
  260. </span>
  261. </div>
  262. <div class="detail-item">
  263. <span class="detail-label">创建人:</span>
  264. <span class="detail-value">{{ detailForm.createBy }}</span>
  265. </div>
  266. <div class="detail-item">
  267. <span class="detail-label">创建时间:</span>
  268. <span class="detail-value">{{ detailForm.createTime }}</span>
  269. </div>
  270. <div class="detail-item">
  271. <span class="detail-label">备注:</span>
  272. <span class="detail-value">{{ detailForm.remarks }}</span>
  273. </div>
  274. </div>
  275. </div>
  276. <!-- 单记录列表 -->
  277. <div v-if="contentEditForm.templateType === '1'">
  278. <div class="button-group">
  279. <el-button
  280. v-if="!viewDetail"
  281. type="primary"
  282. @click="handleAddTableHeader('单记录')"
  283. >
  284. 添加项目
  285. </el-button>
  286. <el-button
  287. v-if="!viewDetail"
  288. type="primary"
  289. @click="handleSaveContent('单记录')"
  290. >
  291. 保存
  292. </el-button>
  293. </div>
  294. <div class="table-edit-container">
  295. <el-table
  296. :data="contentEditForm.tableHeaders"
  297. border
  298. style="width: 100%"
  299. >
  300. <el-table-column label="序号" width="80" align="center">
  301. <template slot-scope="scope">
  302. <span>{{ scope.$index + 1 }}</span>
  303. </template>
  304. </el-table-column>
  305. <el-table-column
  306. prop="fieldName"
  307. label="字段名称"
  308. min-width="150"
  309. >
  310. <template slot-scope="scope">
  311. <el-input
  312. v-model="scope.row.fieldName"
  313. placeholder="请输入字段名称"
  314. size="small"
  315. :disabled="viewDetail"
  316. ></el-input>
  317. </template>
  318. </el-table-column>
  319. <el-table-column prop="fieldType" label="字段类型" width="220">
  320. <template slot-scope="scope">
  321. <el-select
  322. v-model="scope.row.fieldType"
  323. placeholder="请选择字段类型"
  324. size="small"
  325. :disabled="viewDetail"
  326. @change="handleFieldTypeChange(scope.row)"
  327. >
  328. <el-option label="字符串" value="string"></el-option>
  329. <el-option label="整数" value="integer"></el-option>
  330. <el-option label="小数" value="double"></el-option>
  331. <el-option label="日期" value="datetime"></el-option>
  332. <el-option label="布尔值" value="boolean"></el-option>
  333. </el-select>
  334. </template>
  335. </el-table-column>
  336. <el-table-column prop="format" label="格式" width="220">
  337. <template slot-scope="scope">
  338. <!-- 字符串类型格式 -->
  339. <div
  340. v-if="scope.row.fieldType === 'string'"
  341. class="format-input"
  342. >
  343. <span class="format-prefix">长度</span>
  344. <el-input
  345. v-model="scope.row.format"
  346. placeholder="请输入长度"
  347. size="small"
  348. style="width: calc(100% - 80px)"
  349. :disabled="viewDetail"
  350. ></el-input>
  351. </div>
  352. <!-- 整数类型格式 -->
  353. <div
  354. v-else-if="scope.row.fieldType === 'integer'"
  355. class="format-input"
  356. >
  357. <span class="format-prefix">整数</span>
  358. <el-input
  359. v-model="scope.row.fieldTypelen"
  360. placeholder="整数位数"
  361. size="small"
  362. style="width: 80px; margin: 0 5px"
  363. :disabled="viewDetail"
  364. ></el-input>
  365. </div>
  366. <!-- 小数类型格式 -->
  367. <div
  368. v-else-if="scope.row.fieldType === 'double'"
  369. class="format-input"
  370. >
  371. <span class="format-prefix">小数</span>
  372. <el-input
  373. v-model="scope.row.fieldTypenointlen"
  374. placeholder="小数位数"
  375. size="small"
  376. style="width: 80px; margin-left: 5px"
  377. :disabled="viewDetail"
  378. ></el-input>
  379. </div>
  380. <!-- 日期类型格式 -->
  381. <div
  382. v-else-if="scope.row.fieldType === 'datetime'"
  383. class="format-input"
  384. >
  385. <el-select
  386. v-model="scope.row.format"
  387. placeholder="请选择日期格式"
  388. size="small"
  389. style="width: 100%"
  390. :disabled="viewDetail"
  391. >
  392. <el-option
  393. label="yyyy-MM-dd HH:mm:ss"
  394. value="yyyy-MM-dd HH:mm:ss"
  395. ></el-option>
  396. <el-option
  397. label="yyyy-MM-dd"
  398. value="yyyy-MM-dd"
  399. ></el-option>
  400. </el-select>
  401. </div>
  402. <!-- 布尔类型格式 -->
  403. <div v-else-if="scope.row.fieldType === 'boolean'">
  404. <el-select
  405. v-model="scope.row.format"
  406. placeholder="请选择布尔值格式"
  407. size="small"
  408. style="width: 100%"
  409. :disabled="viewDetail"
  410. >
  411. <el-option label="是" value="true"></el-option>
  412. <el-option label="否" value="false"></el-option>
  413. </el-select>
  414. </div>
  415. <!-- 默认情况 -->
  416. <el-input
  417. v-else
  418. v-model="scope.row.format"
  419. :placeholder="getFormatPlaceholder(scope.row.fieldType)"
  420. size="small"
  421. :disabled="viewDetail"
  422. ></el-input>
  423. </template>
  424. </el-table-column>
  425. <el-table-column prop="isRequired" label="是否必填" width="120">
  426. <template slot-scope="scope">
  427. <el-select
  428. v-model="scope.row.isRequired"
  429. size="small"
  430. :disabled="scope.row.isDisabled || viewDetail"
  431. >
  432. <el-option label="是" value="true"></el-option>
  433. <el-option label="否" value="false"></el-option>
  434. </el-select>
  435. </template>
  436. </el-table-column>
  437. <el-table-column prop="showVisible" label="是否显示" width="120">
  438. <template slot-scope="scope">
  439. <el-select
  440. v-model="scope.row.showVisible"
  441. size="small"
  442. :disabled="scope.row.isDisabled || viewDetail"
  443. >
  444. <el-option label="是" value="1"></el-option>
  445. <el-option label="否" value="0"></el-option>
  446. </el-select>
  447. </template>
  448. </el-table-column>
  449. <el-table-column prop="isDict" label="绑定字典" min-width="150">
  450. <template slot-scope="scope">
  451. <div class="bind-dict-column">
  452. <el-select
  453. v-model="scope.row.isDict"
  454. size="small"
  455. style="width: 80px"
  456. :disabled="scope.row.isDisabled || viewDetail"
  457. @change="handleBindDictChange(scope.row)"
  458. >
  459. <el-option label="是" value="true"></el-option>
  460. <el-option label="否" value="false"></el-option>
  461. </el-select>
  462. <el-select
  463. v-if="scope.row.isDict === 'true'"
  464. v-model="scope.row.dictid"
  465. placeholder="请选择字典"
  466. class="dict-select"
  467. size="small"
  468. style="width: 120px; margin-top: 5px"
  469. :disabled="scope.row.isDisabled || viewDetail"
  470. >
  471. <el-option
  472. v-for="(item, index) in dictTypeList"
  473. :key="index"
  474. :label="item.name"
  475. :value="String(item.id)"
  476. ></el-option>
  477. </el-select>
  478. </div>
  479. </template>
  480. </el-table-column>
  481. <el-table-column label="操作" width="150" fixed="right">
  482. <template slot-scope="scope">
  483. <div class="table-actions">
  484. <el-button
  485. type="text"
  486. size="mini"
  487. :disabled="viewDetail"
  488. class="delete-btn"
  489. @click="
  490. handleDeleteHeader(scope.$index, '单记录', scope.row)
  491. "
  492. >
  493. 删除
  494. </el-button>
  495. <el-button
  496. v-if="scope.$index !== 0"
  497. type="text"
  498. size="mini"
  499. :disabled="viewDetail"
  500. @click="
  501. handleMoveUp(scope.$index, '单记录表头', scope.row)
  502. "
  503. >
  504. 上升
  505. </el-button>
  506. <el-button
  507. v-if="
  508. scope.$index !== contentEditForm.tableHeaders.length - 1
  509. "
  510. type="text"
  511. size="mini"
  512. :disabled="viewDetail"
  513. @click="handleMoveDown(scope.$index)"
  514. >
  515. 下降
  516. </el-button>
  517. </div>
  518. </template>
  519. </el-table-column>
  520. </el-table>
  521. </div>
  522. </div>
  523. <!-- 固定表时显示 -->
  524. <div v-if="contentEditForm.templateType === '2'">
  525. <div class="button-group">
  526. <el-button
  527. v-if="!viewDetail"
  528. type="primary"
  529. @click="handleAddTableHeader('固定表表头')"
  530. >
  531. 添加表头
  532. </el-button>
  533. <el-button
  534. v-if="!viewDetail"
  535. type="primary"
  536. @click="handleSaveContent('固定表表头')"
  537. >
  538. 下一步
  539. </el-button>
  540. </div>
  541. <div class="table-edit-container">
  542. <el-table
  543. :data="contentEditForm.fixedTable.tableHeaders"
  544. border
  545. style="width: 100%"
  546. >
  547. <el-table-column label="序号" width="80" align="center">
  548. <template slot-scope="scope">
  549. <span>{{ scope.$index + 1 }}</span>
  550. </template>
  551. </el-table-column>
  552. <el-table-column
  553. prop="fieldName"
  554. label="字段名称"
  555. min-width="150"
  556. >
  557. <template slot-scope="scope">
  558. <el-input
  559. v-model="scope.row.fieldName"
  560. placeholder="请输入字段名称"
  561. size="small"
  562. :disabled="scope.row.isDisabled || viewDetail"
  563. ></el-input>
  564. </template>
  565. </el-table-column>
  566. <el-table-column prop="fieldType" label="字段类型" width="120">
  567. <template slot-scope="scope">
  568. <el-select
  569. v-model="scope.row.fieldType"
  570. placeholder="请选择字段类型"
  571. size="small"
  572. :disabled="scope.row.isDisabled || viewDetail"
  573. @change="handleFieldTypeChange(scope.row)"
  574. >
  575. <el-option label="字符串" value="string"></el-option>
  576. <el-option label="整数" value="integer"></el-option>
  577. <el-option label="小数" value="double"></el-option>
  578. <el-option label="日期" value="datetime"></el-option>
  579. <el-option label="布尔值" value="boolean"></el-option>
  580. </el-select>
  581. </template>
  582. </el-table-column>
  583. <el-table-column prop="format" label="格式" width="220">
  584. <template slot-scope="scope">
  585. <!-- 字符串类型格式 -->
  586. <div
  587. v-if="scope.row.fieldType === 'string'"
  588. class="format-input"
  589. >
  590. <span class="format-prefix">长度</span>
  591. <el-input
  592. v-model="scope.row.format"
  593. placeholder="请输入长度"
  594. size="small"
  595. style="width: calc(100% - 80px)"
  596. :disabled="scope.row.isDisabled || viewDetail"
  597. ></el-input>
  598. </div>
  599. <!-- 整数类型格式 -->
  600. <div
  601. v-else-if="scope.row.fieldType === 'integer'"
  602. class="format-input"
  603. >
  604. <span class="format-prefix">整数</span>
  605. <el-input
  606. v-model="scope.row.fieldTypelen"
  607. placeholder="整数位数"
  608. size="small"
  609. style="width: 80px; margin: 0 5px"
  610. :disabled="scope.row.isDisabled || viewDetail"
  611. ></el-input>
  612. </div>
  613. <!-- 小数类型格式 -->
  614. <div
  615. v-else-if="scope.row.fieldType === 'double'"
  616. class="format-input"
  617. >
  618. <span class="format-prefix">小数</span>
  619. <el-input
  620. v-model="scope.row.fieldTypenointlen"
  621. placeholder="小数位数"
  622. size="small"
  623. style="width: 80px; margin-left: 5px"
  624. :disabled="scope.row.isDisabled || viewDetail"
  625. ></el-input>
  626. </div>
  627. <!-- 日期类型格式 -->
  628. <div
  629. v-else-if="scope.row.fieldType === 'datetime'"
  630. class="format-input"
  631. >
  632. <el-select
  633. v-model="scope.row.format"
  634. placeholder="请选择日期格式"
  635. size="small"
  636. style="width: 100%"
  637. :disabled="scope.row.isDisabled"
  638. >
  639. <el-option
  640. label="yyyy-MM-dd HH:mm:ss"
  641. value="yyyy-MM-dd HH:mm:ss"
  642. ></el-option>
  643. <el-option
  644. label="yyyy-MM-dd"
  645. value="yyyy-MM-dd"
  646. ></el-option>
  647. </el-select>
  648. </div>
  649. <!-- 布尔类型格式 -->
  650. <div v-else-if="scope.row.fieldType === 'boolean'">
  651. <el-select
  652. v-model="scope.row.format"
  653. placeholder="请选择布尔值格式"
  654. size="small"
  655. style="width: 100%"
  656. :disabled="scope.row.isDisabled || viewDetail"
  657. >
  658. <el-option label="是" value="true"></el-option>
  659. <el-option label="否" value="false"></el-option>
  660. </el-select>
  661. </div>
  662. <!-- 默认情况 -->
  663. <el-input
  664. v-else
  665. v-model="scope.row.format"
  666. :placeholder="getFormatPlaceholder(scope.row.fieldType)"
  667. size="small"
  668. :disabled="scope.row.isDisabled || viewDetail"
  669. ></el-input>
  670. </template>
  671. </el-table-column>
  672. <el-table-column prop="isRequired" label="是否必填" width="120">
  673. <template slot-scope="scope">
  674. <el-select
  675. v-model="scope.row.isRequired"
  676. size="small"
  677. :disabled="scope.row.isDisabled || viewDetail"
  678. >
  679. <el-option label="是" value="true"></el-option>
  680. <el-option label="否" value="false"></el-option>
  681. </el-select>
  682. </template>
  683. </el-table-column>
  684. <el-table-column prop="showVisible" label="是否显示" width="120">
  685. <template slot-scope="scope">
  686. <el-select
  687. v-model="scope.row.showVisible"
  688. size="small"
  689. :disabled="scope.row.isDisabled || viewDetail"
  690. >
  691. <el-option label="是" value="1"></el-option>
  692. <el-option label="否" value="0"></el-option>
  693. </el-select>
  694. </template>
  695. </el-table-column>
  696. <el-table-column
  697. prop="isAuditPeriod"
  698. label="是否绑定监审期间"
  699. width="140"
  700. >
  701. <template slot-scope="scope">
  702. <el-select
  703. v-model="scope.row.isAuditPeriod"
  704. size="small"
  705. :disabled="scope.row.isDisabled || viewDetail"
  706. >
  707. <el-option label="是" value="true"></el-option>
  708. <el-option label="否" value="false"></el-option>
  709. </el-select>
  710. </template>
  711. </el-table-column>
  712. <el-table-column prop="isDict" label="绑定字典" min-width="150">
  713. <template slot-scope="scope">
  714. <div class="bind-dict-column">
  715. <el-select
  716. v-model="scope.row.isDict"
  717. size="small"
  718. style="width: 80px"
  719. :disabled="scope.row.isDisabled || viewDetail"
  720. @change="handleBindDictChange(scope.row)"
  721. >
  722. <el-option label="是" value="true"></el-option>
  723. <el-option label="否" value="false"></el-option>
  724. </el-select>
  725. <el-select
  726. v-if="scope.row.isDict === 'true'"
  727. v-model="scope.row.dictid"
  728. placeholder="请选择字典"
  729. class="dict-select"
  730. size="small"
  731. style="width: 120px; margin-top: 5px"
  732. :disabled="scope.row.isDisabled || viewDetail"
  733. >
  734. <el-option
  735. v-for="(item, index) in dictTypeList"
  736. :key="index"
  737. :label="item.name"
  738. :value="String(item.id)"
  739. ></el-option>
  740. </el-select>
  741. </div>
  742. </template>
  743. </el-table-column>
  744. <el-table-column label="操作" width="150" fixed="right">
  745. <template slot-scope="scope">
  746. <div class="table-actions">
  747. <el-button
  748. type="text"
  749. size="mini"
  750. :disabled="scope.row.isDisabled || viewDetail"
  751. class="delete-btn"
  752. @click="
  753. handleDeleteHeader(
  754. scope.$index,
  755. '固定表表头',
  756. scope.row
  757. )
  758. "
  759. >
  760. 删除
  761. </el-button>
  762. <el-button
  763. v-if="scope.$index !== 0"
  764. type="text"
  765. size="mini"
  766. :disabled="scope.row.isDisabled || viewDetail"
  767. @click="
  768. handleMoveUp(scope.$index, '固定表表头', scope.row)
  769. "
  770. >
  771. 上升
  772. </el-button>
  773. <el-button
  774. v-if="
  775. scope.$index !== contentEditForm.tableHeaders.length - 1
  776. "
  777. type="text"
  778. size="mini"
  779. :disabled="scope.row.isDisabled || viewDetail"
  780. @click="handleMoveDown(scope.$index)"
  781. >
  782. 下降
  783. </el-button>
  784. </div>
  785. </template>
  786. </el-table-column>
  787. </el-table>
  788. </div>
  789. <div>
  790. <div class="button-group">
  791. <el-button
  792. v-if="!viewDetail"
  793. type="primary"
  794. @click="handleAddTableHeader('固定表项目')"
  795. >
  796. 添加项目
  797. </el-button>
  798. <el-button
  799. v-if="!viewDetail"
  800. type="primary"
  801. @click="handleSaveContent('固定表项目')"
  802. >
  803. 保存
  804. </el-button>
  805. </div>
  806. <div class="table-edit-container">
  807. <el-table
  808. :data="contentEditForm.fixedTable.fixedTables"
  809. border
  810. style="width: 100%"
  811. row-key="rowid"
  812. default-expand-all
  813. :tree-props="{
  814. children: 'children',
  815. hasChildren: 'hasChildren',
  816. }"
  817. @selection-change="handleSelectionChange"
  818. >
  819. <el-table-column label="父子节点" align="center" width="100">
  820. <template slot-scope="scope">
  821. <el-tag
  822. v-if="
  823. scope.row.isChild ||
  824. scope.row.isSubItem ||
  825. (scope.row.parentid &&
  826. scope.row.parentid != -1 &&
  827. scope.row.parentid != '-1')
  828. "
  829. type="success"
  830. size="small"
  831. >
  832. 子项
  833. </el-tag>
  834. <el-tag
  835. v-else-if="
  836. scope.row.parentid === -1 ||
  837. scope.row.parentid === '-1' ||
  838. !scope.row.parentid
  839. "
  840. type="primary"
  841. size="small"
  842. >
  843. 父项
  844. </el-tag>
  845. <el-tag v-else type="info" size="small">无</el-tag>
  846. </template>
  847. </el-table-column>
  848. <el-table-column label="序号" width="120" align="center">
  849. <template slot-scope="scope">
  850. <el-input
  851. :value="
  852. scope.row.fixedValues
  853. ? scope.row.fixedValues['序号']
  854. : ''
  855. "
  856. size="small"
  857. placeholder="数字或中文"
  858. :disabled="viewDetail"
  859. style="flex: 1; margin: 0"
  860. @input="handleFixedValueChange(scope.row, '序号', $event)"
  861. ></el-input>
  862. </template>
  863. </el-table-column>
  864. <el-table-column
  865. v-for="(item, index) in contentEditForm.fixedTable
  866. .fixedTableHeaders"
  867. :key="index"
  868. :label="item.rkey"
  869. align="center"
  870. >
  871. <template slot-scope="scope">
  872. <el-input
  873. :value="
  874. scope.row.fixedValues
  875. ? scope.row.fixedValues[item.rkey]
  876. : ''
  877. "
  878. size="small"
  879. :disabled="viewDetail"
  880. @input="
  881. handleFixedValueChange(scope.row, item.rkey, $event)
  882. "
  883. ></el-input>
  884. </template>
  885. </el-table-column>
  886. <el-table-column label="指标编号" width="100" align="center">
  887. <template slot-scope="scope">
  888. <el-input
  889. :value="scope.row.cellCode"
  890. size="small"
  891. :disabled="viewDetail"
  892. @input="(val) => $set(scope.row, 'cellCode', val)"
  893. ></el-input>
  894. </template>
  895. </el-table-column>
  896. <el-table-column label="计算公式" width="100" align="center">
  897. <template slot-scope="scope">
  898. <el-input
  899. v-model="scope.row.calculationFormula"
  900. size="small"
  901. readonly
  902. :disabled="viewDetail"
  903. @click.native="
  904. openCalculationFormulaDialogVisible(
  905. scope.row,
  906. scope.$index
  907. )
  908. "
  909. ></el-input>
  910. </template>
  911. </el-table-column>
  912. <el-table-column label="单位" width="100" align="center">
  913. <template slot-scope="scope">
  914. <el-input
  915. :value="scope.row.unit"
  916. size="small"
  917. :disabled="viewDetail"
  918. @input="(val) => $set(scope.row, 'unit', val)"
  919. ></el-input>
  920. </template>
  921. </el-table-column>
  922. <el-table-column label="操作" align="center" fixed="right">
  923. <template slot-scope="scope">
  924. <div class="table-actions">
  925. <el-button
  926. v-if="!scope.row.isChild"
  927. type="text"
  928. size="mini"
  929. :disabled="viewDetail"
  930. @click="
  931. handleAddChildItem(
  932. scope.$index,
  933. '固定表项目',
  934. scope.row
  935. )
  936. "
  937. >
  938. 添加子项
  939. </el-button>
  940. <el-button
  941. type="text"
  942. size="mini"
  943. :disabled="viewDetail"
  944. class="delete-btn"
  945. @click="
  946. handleDeleteHeader(
  947. scope.$index,
  948. '固定表项目',
  949. scope.row
  950. )
  951. "
  952. >
  953. 删除
  954. </el-button>
  955. <el-button
  956. v-if="scope.$index !== 0"
  957. type="text"
  958. size="mini"
  959. :disabled="viewDetail"
  960. @click="handleMoveUp(scope.$index, '固定表', scope.row)"
  961. >
  962. 上升
  963. </el-button>
  964. <el-button
  965. v-if="
  966. scope.$index !==
  967. contentEditForm.fixedTable.fixedTables.length - 1
  968. "
  969. type="text"
  970. size="mini"
  971. :disabled="viewDetail"
  972. @click="
  973. handleMoveDown(scope.$index, '固定表', scope.row)
  974. "
  975. >
  976. 下降
  977. </el-button>
  978. </div>
  979. </template>
  980. </el-table-column>
  981. </el-table>
  982. </div>
  983. </div>
  984. </div>
  985. <!-- 动态表时显示 -->
  986. <div v-if="contentEditForm.templateType === '3'">
  987. <div class="button-group">
  988. <el-button
  989. v-if="!viewDetail"
  990. type="primary"
  991. @click="handleAddTableHeader('动态表表头')"
  992. >
  993. 添加表头
  994. </el-button>
  995. <el-button
  996. v-if="!viewDetail"
  997. type="primary"
  998. @click="handleSaveContent('动态表表头')"
  999. >
  1000. 下一步
  1001. </el-button>
  1002. </div>
  1003. <div class="table-edit-container">
  1004. <el-table
  1005. :data="contentEditForm.dynamicTable.tableHeaders"
  1006. border
  1007. style="width: 100%"
  1008. >
  1009. <el-table-column label="序号" width="80" align="center">
  1010. <template slot-scope="scope">
  1011. <span>{{ scope.$index + 1 }}</span>
  1012. </template>
  1013. </el-table-column>
  1014. <el-table-column
  1015. prop="fieldName"
  1016. label="字段名称"
  1017. min-width="150"
  1018. >
  1019. <template slot-scope="scope">
  1020. <el-input
  1021. v-model="scope.row.fieldName"
  1022. placeholder="请输入字段名称"
  1023. size="small"
  1024. :disabled="scope.row.isDisabled || viewDetail"
  1025. ></el-input>
  1026. </template>
  1027. </el-table-column>
  1028. <el-table-column prop="fieldType" label="字段类型" width="120">
  1029. <template slot-scope="scope">
  1030. <el-select
  1031. v-model="scope.row.fieldType"
  1032. placeholder="请选择字段类型"
  1033. size="small"
  1034. :disabled="scope.row.isDisabled || viewDetail"
  1035. @change="handleFieldTypeChange(scope.row)"
  1036. >
  1037. <el-option label="字符串" value="string"></el-option>
  1038. <el-option label="整数" value="integer"></el-option>
  1039. <el-option label="小数" value="double"></el-option>
  1040. <el-option label="日期" value="datetime"></el-option>
  1041. <el-option label="布尔值" value="boolean"></el-option>
  1042. </el-select>
  1043. </template>
  1044. </el-table-column>
  1045. <el-table-column prop="format" label="格式" width="220">
  1046. <template slot-scope="scope">
  1047. <!-- 字符串类型格式 -->
  1048. <div
  1049. v-if="scope.row.fieldType === 'string'"
  1050. class="format-input"
  1051. >
  1052. <span class="format-prefix">长度</span>
  1053. <el-input
  1054. v-model="scope.row.format"
  1055. placeholder="请输入长度"
  1056. size="small"
  1057. style="width: calc(100% - 80px)"
  1058. :disabled="scope.row.isDisabled || viewDetail"
  1059. ></el-input>
  1060. </div>
  1061. <!-- 整数类型格式 -->
  1062. <div
  1063. v-else-if="scope.row.fieldType === 'integer'"
  1064. class="format-input"
  1065. >
  1066. <span class="format-prefix">整数</span>
  1067. <el-input
  1068. v-model="scope.row.fieldTypelen"
  1069. placeholder="整数位数"
  1070. size="small"
  1071. style="width: 80px; margin: 0 5px"
  1072. :disabled="scope.row.isDisabled || viewDetail"
  1073. ></el-input>
  1074. </div>
  1075. <!-- 小数类型格式 -->
  1076. <div
  1077. v-else-if="scope.row.fieldType === 'double'"
  1078. class="format-input"
  1079. >
  1080. <span class="format-prefix">小数</span>
  1081. <el-input
  1082. v-model="scope.row.fieldTypenointlen"
  1083. placeholder="小数位数"
  1084. size="small"
  1085. style="width: 80px; margin-left: 5px"
  1086. :disabled="scope.row.isDisabled || viewDetail"
  1087. ></el-input>
  1088. </div>
  1089. <!-- 日期类型格式 -->
  1090. <div
  1091. v-else-if="scope.row.fieldType === 'datetime'"
  1092. class="format-input"
  1093. >
  1094. <el-select
  1095. v-model="scope.row.format"
  1096. placeholder="请选择日期格式"
  1097. size="small"
  1098. style="width: 100%"
  1099. :disabled="scope.row.isDisabled || viewDetail"
  1100. >
  1101. <el-option
  1102. label="yyyy-MM-dd HH:mm:ss"
  1103. value="yyyy-MM-dd HH:mm:ss"
  1104. ></el-option>
  1105. <el-option
  1106. label="yyyy-MM-dd"
  1107. value="yyyy-MM-dd"
  1108. ></el-option>
  1109. </el-select>
  1110. </div>
  1111. <!-- 布尔类型格式 -->
  1112. <div v-else-if="scope.row.fieldType === 'boolean'">
  1113. <el-select
  1114. v-model="scope.row.format"
  1115. placeholder="请选择布尔值格式"
  1116. size="small"
  1117. style="width: 100%"
  1118. :disabled="scope.row.isDisabled || viewDetail"
  1119. >
  1120. <el-option label="是" value="true"></el-option>
  1121. <el-option label="否" value="false"></el-option>
  1122. </el-select>
  1123. </div>
  1124. <!-- 默认情况 -->
  1125. <el-input
  1126. v-else
  1127. v-model="scope.row.format"
  1128. :placeholder="getFormatPlaceholder(scope.row.fieldType)"
  1129. size="small"
  1130. :disabled="scope.row.isDisabled || viewDetail"
  1131. ></el-input>
  1132. </template>
  1133. </el-table-column>
  1134. <el-table-column prop="isRequired" label="是否必填" width="120">
  1135. <template slot-scope="scope">
  1136. <el-select
  1137. v-model="scope.row.isRequired"
  1138. size="small"
  1139. :disabled="scope.row.isDisabled || viewDetail"
  1140. >
  1141. <el-option label="是" value="true"></el-option>
  1142. <el-option label="否" value="false"></el-option>
  1143. </el-select>
  1144. </template>
  1145. </el-table-column>
  1146. <el-table-column prop="showVisible" label="是否显示" width="120">
  1147. <template slot-scope="scope">
  1148. <el-select
  1149. v-model="scope.row.showVisible"
  1150. size="small"
  1151. :disabled="scope.row.isDisabled || viewDetail"
  1152. >
  1153. <el-option label="是" value="1"></el-option>
  1154. <el-option label="否" value="0"></el-option>
  1155. </el-select>
  1156. </template>
  1157. </el-table-column>
  1158. <el-table-column prop="isDict" label="绑定字典" min-width="150">
  1159. <template slot-scope="scope">
  1160. <div class="bind-dict-column">
  1161. <el-select
  1162. v-model="scope.row.isDict"
  1163. size="small"
  1164. style="width: 80px"
  1165. :disabled="scope.row.isDisabled || viewDetail"
  1166. @change="handleBindDictChange(scope.row)"
  1167. >
  1168. <el-option label="是" value="true"></el-option>
  1169. <el-option label="否" value="false"></el-option>
  1170. </el-select>
  1171. <el-select
  1172. v-if="scope.row.isDict === 'true'"
  1173. v-model="scope.row.dictid"
  1174. placeholder="请选择字典"
  1175. class="dict-select"
  1176. size="small"
  1177. style="width: 120px; margin-top: 5px"
  1178. :disabled="scope.row.isDisabled || viewDetail"
  1179. >
  1180. <el-option
  1181. v-for="(item, index) in dictTypeList"
  1182. :key="index"
  1183. :label="item.name"
  1184. :value="String(item.id)"
  1185. ></el-option>
  1186. </el-select>
  1187. </div>
  1188. </template>
  1189. </el-table-column>
  1190. <el-table-column label="操作" width="150" fixed="right">
  1191. <template slot-scope="scope">
  1192. <div class="table-actions">
  1193. <el-button
  1194. type="text"
  1195. size="mini"
  1196. :disabled="scope.row.isDisabled || viewDetail"
  1197. class="delete-btn"
  1198. @click="
  1199. handleDeleteHeader(
  1200. scope.$index,
  1201. '动态表表头',
  1202. scope.row
  1203. )
  1204. "
  1205. >
  1206. 删除
  1207. </el-button>
  1208. <el-button
  1209. v-if="scope.$index !== 0"
  1210. type="text"
  1211. size="mini"
  1212. :disabled="scope.row.isDisabled || viewDetail"
  1213. @click="
  1214. handleMoveUp(scope.$index, '动态表表头', scope.row)
  1215. "
  1216. >
  1217. 上升
  1218. </el-button>
  1219. <el-button
  1220. v-if="
  1221. scope.$index !== contentEditForm.tableHeaders.length - 1
  1222. "
  1223. type="text"
  1224. size="mini"
  1225. :disabled="scope.row.isDisabled || viewDetail"
  1226. @click="handleMoveDown(scope.$index)"
  1227. >
  1228. 下降
  1229. </el-button>
  1230. </div>
  1231. </template>
  1232. </el-table-column>
  1233. </el-table>
  1234. </div>
  1235. <div>
  1236. <div class="button-group">
  1237. <el-button
  1238. v-if="!viewDetail"
  1239. type="primary"
  1240. @click="handleAddTableHeader('动态表项目')"
  1241. >
  1242. 添加项目
  1243. </el-button>
  1244. <el-button
  1245. v-if="!viewDetail"
  1246. type="primary"
  1247. @click="handleSaveContent('动态表项目')"
  1248. >
  1249. 保存
  1250. </el-button>
  1251. </div>
  1252. <div class="table-edit-container">
  1253. <el-table
  1254. :data="contentEditForm.dynamicTable.dynamicTables"
  1255. border
  1256. style="width: 100%"
  1257. row-key="rowid"
  1258. default-expand-all
  1259. :tree-props="{
  1260. children: 'children',
  1261. hasChildren: 'hasChildren',
  1262. }"
  1263. @selection-change="handleSelectionChange"
  1264. >
  1265. <el-table-column label="父子节点" align="center" width="100">
  1266. <template slot-scope="scope">
  1267. <el-tag
  1268. v-if="
  1269. scope.row.isChild ||
  1270. scope.row.isSubItem ||
  1271. (scope.row.parentid &&
  1272. scope.row.parentid != -1 &&
  1273. scope.row.parentid != '-1')
  1274. "
  1275. type="success"
  1276. size="small"
  1277. >
  1278. 子项
  1279. </el-tag>
  1280. <el-tag
  1281. v-else-if="
  1282. scope.row.parentid === -1 ||
  1283. scope.row.parentid === '-1' ||
  1284. !scope.row.parentid
  1285. "
  1286. type="primary"
  1287. size="small"
  1288. >
  1289. 父项
  1290. </el-tag>
  1291. <el-tag v-else type="info" size="small">无</el-tag>
  1292. </template>
  1293. </el-table-column>
  1294. <el-table-column label="序号" width="120" align="center">
  1295. <template slot-scope="scope">
  1296. <div
  1297. style="
  1298. display: flex;
  1299. align-items: center;
  1300. min-height: 32px;
  1301. "
  1302. >
  1303. <el-input
  1304. :value="
  1305. scope.row.dynamicValues
  1306. ? scope.row.dynamicValues['序号']
  1307. : ''
  1308. "
  1309. size="small"
  1310. placeholder="数字或中文"
  1311. :disabled="viewDetail"
  1312. style="flex: 1; margin: 0"
  1313. @input="
  1314. handleDynamicValueChange(scope.row, '序号', $event)
  1315. "
  1316. ></el-input>
  1317. </div>
  1318. </template>
  1319. </el-table-column>
  1320. <el-table-column
  1321. v-for="(item, index) in contentEditForm.dynamicTable
  1322. .dynamicTableHeaders"
  1323. :key="index"
  1324. :label="item.rkey"
  1325. align="center"
  1326. >
  1327. <template slot-scope="scope">
  1328. <el-input
  1329. :value="
  1330. scope.row.dynamicValues
  1331. ? scope.row.dynamicValues[item.rkey]
  1332. : ''
  1333. "
  1334. size="small"
  1335. :disabled="viewDetail"
  1336. @input="
  1337. handleDynamicValueChange(scope.row, item.rkey, $event)
  1338. "
  1339. ></el-input>
  1340. </template>
  1341. </el-table-column>
  1342. <el-table-column
  1343. label="操作"
  1344. align="center"
  1345. fixed="right"
  1346. width="200"
  1347. >
  1348. <template slot-scope="scope">
  1349. <div class="table-actions">
  1350. <el-button
  1351. v-if="!scope.row.isChild"
  1352. type="text"
  1353. size="mini"
  1354. :disabled="viewDetail"
  1355. @click="
  1356. handleAddChildItem(
  1357. scope.$index,
  1358. '动态表项目',
  1359. scope.row
  1360. )
  1361. "
  1362. >
  1363. 添加子项
  1364. </el-button>
  1365. <el-button
  1366. type="text"
  1367. size="mini"
  1368. :disabled="viewDetail"
  1369. class="delete-btn"
  1370. @click="
  1371. handleDeleteHeader(
  1372. scope.$index,
  1373. '动态表项目',
  1374. scope.row
  1375. )
  1376. "
  1377. >
  1378. 删除
  1379. </el-button>
  1380. <el-button
  1381. v-if="scope.$index !== 0"
  1382. type="text"
  1383. size="mini"
  1384. :disabled="viewDetail"
  1385. @click="handleMoveUp(scope.$index, '动态表', scope.row)"
  1386. >
  1387. 上升
  1388. </el-button>
  1389. <el-button
  1390. v-if="
  1391. scope.$index !==
  1392. contentEditForm.tableHeaders.length - 1
  1393. "
  1394. type="text"
  1395. size="mini"
  1396. :disabled="viewDetail"
  1397. @click="
  1398. handleMoveDown(scope.$index, '动态表', scope.row)
  1399. "
  1400. >
  1401. 下降
  1402. </el-button>
  1403. </div>
  1404. </template>
  1405. </el-table-column>
  1406. </el-table>
  1407. </div>
  1408. </div>
  1409. </div>
  1410. </div>
  1411. </el-dialog>
  1412. <el-dialog
  1413. title="计算公式"
  1414. :visible.sync="calculationFormulaDialogVisible"
  1415. width="500px"
  1416. :before-close="handleDialogClose"
  1417. :close-on-click-modal="false"
  1418. >
  1419. <!-- 单选按钮组:切换“当前指标项”/“其他模板指标项” -->
  1420. <el-radio-group
  1421. v-model="radioType"
  1422. class="mb20"
  1423. @change="handleRadioChange"
  1424. >
  1425. <el-radio label="current">当前指标项</el-radio>
  1426. <el-radio label="other">其他模板指标项</el-radio>
  1427. </el-radio-group>
  1428. <!-- 「当前指标项」内容区域 -->
  1429. <div v-if="radioType === 'current'" class="current-panel">
  1430. <el-input
  1431. v-model="formulaText"
  1432. type="textarea"
  1433. rows="4"
  1434. placeholder="请输入公式(如 C1+C2+C3)"
  1435. />
  1436. </div>
  1437. <!-- 「其他模板指标项」内容区域 -->
  1438. <div v-else class="other-panel">
  1439. <span>版本号:</span>
  1440. <el-select
  1441. v-model="selectedTemplateId"
  1442. placeholder="请选择版本号"
  1443. @change="handleTemplateChange"
  1444. >
  1445. <el-option
  1446. v-for="(item, index) in templateList"
  1447. :key="index"
  1448. :label="item.versionNo"
  1449. :value="item.pkVal"
  1450. ></el-option>
  1451. </el-select>
  1452. <!-- 指标表格 -->
  1453. <el-table
  1454. ref="indicatorTable"
  1455. :data="indicatorTableData"
  1456. border
  1457. style="width: 100%; margin-top: 10px"
  1458. @row-click="handleRowClick"
  1459. >
  1460. <el-table-column label="选择" width="60">
  1461. <template #default="scope">
  1462. <el-checkbox
  1463. v-model="scope.row.checked"
  1464. @change="handleCheckboxChange(scope.row)"
  1465. @click.stop
  1466. ></el-checkbox>
  1467. </template>
  1468. </el-table-column>
  1469. <el-table-column
  1470. label="指标编号"
  1471. prop="cellCode"
  1472. align="center"
  1473. ></el-table-column>
  1474. <!--循环表头 -->
  1475. <el-table-column
  1476. v-for="(item, index) in indicatorTableHeaders"
  1477. :key="index"
  1478. :label="item.rkey"
  1479. align="center"
  1480. show-overflow-tooltip
  1481. >
  1482. <template slot-scope="scope">
  1483. {{
  1484. scope.row.fixedValues ? scope.row.fixedValues[item.rkey] : ''
  1485. }}
  1486. </template>
  1487. </el-table-column>
  1488. </el-table>
  1489. <el-input
  1490. v-model="formulaText"
  1491. type="textarea"
  1492. rows="4"
  1493. placeholder="请输入公式(如 C1+C2+C3)"
  1494. @input="handleFormulaTextChange"
  1495. />
  1496. </div>
  1497. <!-- 弹窗底部按钮 -->
  1498. <template #footer>
  1499. <span class="dialog-footer">
  1500. <el-button type="primary" @click="handleConfirm">确定</el-button>
  1501. <el-button @click="calculationFormulaDialogVisible = false">
  1502. 取消
  1503. </el-button>
  1504. </span>
  1505. </template>
  1506. </el-dialog>
  1507. </div>
  1508. </template>
  1509. <script>
  1510. // 导入API模块
  1511. import {
  1512. getCostFormList,
  1513. addCostForm,
  1514. editCostForm,
  1515. deleteCostForm,
  1516. getDataStorageTableOptions,
  1517. } from '@/api/costFormManage'
  1518. import CostAuditTable from '@/components/costAudit/CostAuditTable.vue'
  1519. import { getDictTypList } from '@/api/dictionaryManage.js'
  1520. import {
  1521. listByTemplateIdAndVersion,
  1522. getCellCodesByTemplateId,
  1523. } from '@/api/costSurveyTemplateItems'
  1524. import {
  1525. addSurveyTemplateVersion,
  1526. delSurveyTemplateVersionById,
  1527. putSurveyTemplatePublishVersion,
  1528. getCostSurveyTemplateVersionsByTemplateId,
  1529. batchDeleteCostForm,
  1530. } from '@/api/costSurveyTemplateVersion'
  1531. import { getListFixedEnabled } from '@/api/costSurveyTemplate'
  1532. import { listByCurrentTemplateId } from '@/api/catalogManage.js'
  1533. import {
  1534. getListBySurveyTemplateId,
  1535. getListBySurveyTemplateIdAndVersion,
  1536. getBatchSaveOrUpdate,
  1537. } from '@/api/costSurveyTemplateHeaders'
  1538. import { commonMixin } from '@/mixins/useDict'
  1539. import { mapState } from 'vuex'
  1540. export default {
  1541. name: 'InfoMaintain',
  1542. components: {
  1543. CostAuditTable,
  1544. },
  1545. mixins: [commonMixin],
  1546. data() {
  1547. return {
  1548. surveyTemplateName: '',
  1549. loading: false,
  1550. searchForm: {
  1551. status: '',
  1552. },
  1553. tableData: [],
  1554. currentRow: null,
  1555. selectedRows: [],
  1556. pagination: {
  1557. currentPage: 1,
  1558. pageSize: 50,
  1559. total: 0, // 初始化为0
  1560. },
  1561. dialogVisible: false,
  1562. detailDialogVisible: false,
  1563. viewDetail: false,
  1564. contentEditDialogVisible: false,
  1565. calculationFormulaDialogVisible: false,
  1566. currentEditingRow: null,
  1567. currentEditingRowIndex: -1,
  1568. radioType: 'current',
  1569. formulaText: 'C1+C2+C3',
  1570. templateName: '',
  1571. templateList: [],
  1572. indicatorTableData: [],
  1573. indicatorTableHeaders: [],
  1574. selectedIndicatorCodes: [],
  1575. selectedIndicatorsPerTemplate: {},
  1576. dialogTitle: '',
  1577. dataForm: {
  1578. id: null,
  1579. version: '',
  1580. status: '',
  1581. createBy: '',
  1582. createTime: '',
  1583. remark: '',
  1584. },
  1585. detailForm: {
  1586. id: null,
  1587. version: '',
  1588. status: '',
  1589. createBy: '',
  1590. createTime: '',
  1591. remark: '',
  1592. },
  1593. contentEditForm: {
  1594. tableName: '',
  1595. templateType: '1',
  1596. versionId: '',
  1597. // 单记录列表
  1598. tableHeaders: [],
  1599. // 固定表列表
  1600. fixedTable: {
  1601. tableHeaders: [],
  1602. fixedTables: [],
  1603. fixedTablesTitle: [],
  1604. fixedTableHeaders: [],
  1605. },
  1606. // 动态表列表
  1607. dynamicTable: {
  1608. tableHeaders: [],
  1609. dynamicTables: [],
  1610. dynamicTablesTitle: [],
  1611. dynamicTableHeaders: [],
  1612. },
  1613. isDynamicTables: false,
  1614. isFixedTables: false,
  1615. },
  1616. tableKey: 0, // 用于强制刷新表格
  1617. dataFormRules: {
  1618. status: [
  1619. { required: true, message: '请选择状态', trigger: 'change' },
  1620. ],
  1621. createBy: [
  1622. { required: true, message: '请输入创建人', trigger: 'blur' },
  1623. ],
  1624. createTime: [
  1625. { required: true, message: '请选择创建时间', trigger: 'change' },
  1626. ],
  1627. },
  1628. id: '', // 从路由获取的ID
  1629. dataStorageTableOptions: [], // 数据存储库表选项
  1630. surveyTemplateId: '', // 成本调查表ID
  1631. versionId: '',
  1632. dictTypeList: [],
  1633. }
  1634. },
  1635. computed: {
  1636. ...mapState('user', ['userInfo', 'username']),
  1637. formatter: (status) => {
  1638. return status === '-1' ? '草稿' : status === '0' ? '现行' : '历史'
  1639. },
  1640. tableColumns() {
  1641. return [
  1642. {
  1643. prop: 'versionNo',
  1644. label: '版本号',
  1645. align: 'center',
  1646. showOverflowTooltip: true,
  1647. },
  1648. {
  1649. prop: 'status',
  1650. label: '状态',
  1651. align: 'center',
  1652. formatter: (row) => {
  1653. return row.status == '-1'
  1654. ? '草稿'
  1655. : row.status == '0'
  1656. ? '现行'
  1657. : '历史'
  1658. },
  1659. },
  1660. {
  1661. prop: 'createBy',
  1662. label: '创建人',
  1663. align: 'center',
  1664. },
  1665. {
  1666. prop: 'createTime',
  1667. label: '创建时间',
  1668. showOverflowTooltip: true,
  1669. slotName: 'createTime',
  1670. },
  1671. {
  1672. prop: 'remarks',
  1673. label: '备注',
  1674. align: 'center',
  1675. showOverflowTooltip: true,
  1676. },
  1677. {
  1678. prop: 'action',
  1679. width: '270',
  1680. label: '操作',
  1681. align: 'center',
  1682. fixed: 'right',
  1683. slotName: 'action',
  1684. },
  1685. ]
  1686. },
  1687. },
  1688. watch: {
  1689. indicatorTableData: {
  1690. handler(newVal) {
  1691. if (this.radioType === 'other' && this.selectedTemplateId) {
  1692. this.$set(
  1693. this.selectedIndicatorsPerTemplate,
  1694. this.selectedTemplateId,
  1695. newVal.filter((item) => item.checked)
  1696. )
  1697. }
  1698. this.updateSelectedIndicatorCodes()
  1699. },
  1700. deep: true,
  1701. },
  1702. selectedIndicatorCodes: {
  1703. handler(newVal) {
  1704. if (this.radioType === 'other') {
  1705. const allSelectedTemplateIds = [
  1706. ...new Set([
  1707. this.selectedTemplateId,
  1708. ...Object.keys(this.selectedIndicatorsPerTemplate).filter(
  1709. (id) =>
  1710. id !== this.selectedTemplateId &&
  1711. this.selectedIndicatorsPerTemplate[id].some(
  1712. (item) => item.checked
  1713. )
  1714. ),
  1715. ]),
  1716. ].filter((id) => id)
  1717. const isSingleTemplate = allSelectedTemplateIds.length === 1
  1718. if (isSingleTemplate && allSelectedTemplateIds[0]) {
  1719. const selectedTemplate = this.templateList.find(
  1720. (item) => item.pkVal === allSelectedTemplateIds[0]
  1721. )
  1722. const templateNameYw = selectedTemplate
  1723. ? selectedTemplate.surveyTemplateNameYw ||
  1724. selectedTemplate.surveyTemplateName ||
  1725. ''
  1726. : ''
  1727. let selectedItems = []
  1728. if (allSelectedTemplateIds[0] === this.selectedTemplateId) {
  1729. selectedItems = newVal
  1730. } else {
  1731. selectedItems = this.selectedIndicatorsPerTemplate[
  1732. allSelectedTemplateIds[0]
  1733. ]
  1734. .filter((item) => item.checked)
  1735. .map(
  1736. (item) => `${templateNameYw}.${item.code || item.cellCode}`
  1737. )
  1738. }
  1739. if (selectedItems.length > 0) {
  1740. this.formulaText = selectedItems.join('+')
  1741. this.isAutoGeneratedFormula = true
  1742. } else if (this.isAutoGeneratedFormula) {
  1743. this.formulaText = ''
  1744. }
  1745. } else {
  1746. let allSelectedCodes = []
  1747. if (newVal.length > 0 && this.selectedTemplateId) {
  1748. allSelectedCodes = [...newVal]
  1749. }
  1750. Object.keys(this.selectedIndicatorsPerTemplate).forEach(
  1751. (templateId) => {
  1752. if (templateId !== this.selectedTemplateId) {
  1753. const items = this.selectedIndicatorsPerTemplate[templateId]
  1754. const selectedTemplate = this.templateList.find(
  1755. (item) => item.pkVal === templateId
  1756. )
  1757. const templateName = selectedTemplate
  1758. ? selectedTemplate.surveyTemplateNameYw ||
  1759. selectedTemplate.surveyTemplateName ||
  1760. ''
  1761. : ''
  1762. items
  1763. .filter((item) => item.checked)
  1764. .forEach((item) => {
  1765. allSelectedCodes.push(
  1766. `${templateName}.${item.code || item.cellCode}`
  1767. )
  1768. })
  1769. }
  1770. }
  1771. )
  1772. if (allSelectedCodes.length > 0) {
  1773. this.formulaText = allSelectedCodes.join('+')
  1774. this.isAutoGeneratedFormula = true
  1775. } else if (this.isAutoGeneratedFormula) {
  1776. this.formulaText = ''
  1777. }
  1778. }
  1779. } else if (newVal.length > 0 && this.radioType === 'current') {
  1780. if (
  1781. !this.formulaText ||
  1782. this.formulaText === 'C1+C2+C3' ||
  1783. this.isAutoGeneratedFormula
  1784. ) {
  1785. this.formulaText = newVal.join('+')
  1786. this.isAutoGeneratedFormula = true
  1787. }
  1788. } else if (newVal.length === 0 && this.radioType === 'current') {
  1789. if (this.isAutoGeneratedFormula) {
  1790. this.formulaText = ''
  1791. }
  1792. }
  1793. },
  1794. deep: true,
  1795. },
  1796. },
  1797. mounted() {
  1798. this.isAutoGeneratedFormula = false
  1799. },
  1800. methods: {
  1801. async loadDictTypeList() {
  1802. try {
  1803. const res = await getDictTypList()
  1804. this.dictTypeList = res || []
  1805. } catch (error) {
  1806. console.error('加载字典类型失败:', error)
  1807. }
  1808. },
  1809. getTemplateRow(row) {
  1810. this.currentRow = row
  1811. this.surveyTemplateId = row.surveyTemplateId
  1812. this.templateType = row.templateType
  1813. this.contentEditForm.tableName = row.surveyTemplateName
  1814. this.surveyTemplateName = row.surveyTemplateName
  1815. this.contentEditForm.templateType = row.templateType
  1816. this.handleSearch()
  1817. this.loadDictTypeList()
  1818. },
  1819. handleBack() {
  1820. this.$emit('back', 'list')
  1821. },
  1822. // 查询
  1823. handleSearch() {
  1824. this.loading = true
  1825. const params = {
  1826. surveyTemplateId: this.surveyTemplateId,
  1827. status: this.searchForm.status,
  1828. // pageNum: this.pagination.currentPage,
  1829. // pageSize: this.pagination.pageSize,
  1830. }
  1831. // 根据成本调查表ID获取所有版本数据
  1832. getCostSurveyTemplateVersionsByTemplateId(params)
  1833. .then((response) => {
  1834. this.tableData = response.value || []
  1835. this.pagination.total = response.total || 0
  1836. this.loading = false
  1837. })
  1838. .catch((error) => {
  1839. console.error('查询失败:', error)
  1840. this.loading = false
  1841. })
  1842. },
  1843. // 重置
  1844. handleReset() {
  1845. this.searchForm = {
  1846. status: '',
  1847. }
  1848. this.pagination.currentPage = 1
  1849. this.handleSearch()
  1850. },
  1851. handleRowClick(row, column, event) {
  1852. // 只有点击非 checkbox 列才触发
  1853. if (column && column.property !== 'checked') {
  1854. // 如果没有 cellCode,则不允许选中
  1855. if (!row.cellCode) {
  1856. // this.$message.warning('该数据没有指标编号,无法选择')
  1857. return
  1858. }
  1859. // 切换选中状态
  1860. this.toggleRowSelection(row)
  1861. }
  1862. },
  1863. toggleRowSelection(row) {
  1864. // 切换选中状态
  1865. this.$set(row, 'checked', !row.checked)
  1866. // 格式化代码并存储在行数据中
  1867. if (row.checked) {
  1868. this.formatRowCode(row)
  1869. }
  1870. // 触发选中状态更新
  1871. this.$forceUpdate()
  1872. },
  1873. handleCheckboxChange(row) {
  1874. // 如果没有 cellCode,则不允许选中
  1875. if (!row.cellCode) {
  1876. this.$message.warning('该数据没有指标编号,无法选择')
  1877. this.$set(row, 'checked', false)
  1878. return
  1879. }
  1880. this.$set(row, 'checked', !row.checked)
  1881. if (row.checked) {
  1882. this.formatRowCode(row)
  1883. }
  1884. this.updateSelectedIndicatorCodes()
  1885. this.$forceUpdate()
  1886. },
  1887. updateSelectedIndicatorCodes() {
  1888. // 获取当前选中的行
  1889. const selectedRows = this.indicatorTableData.filter(
  1890. (item) => item.checked
  1891. )
  1892. // 更新选中的指标代码列表
  1893. this.selectedIndicatorCodes = selectedRows.map((item) => {
  1894. // 获取选中的模板信息
  1895. const selectedTemplate = this.templateList.find(
  1896. (template) => template.pkVal === this.selectedTemplateId
  1897. )
  1898. // 获取模板的 surveyTemplateNameYw
  1899. const templateName = selectedTemplate
  1900. ? selectedTemplate.surveyTemplateNameYw ||
  1901. selectedTemplate.surveyTemplateName ||
  1902. ''
  1903. : ''
  1904. return templateName
  1905. ? `${templateName}.${item.code || item.cellCode || ''}`
  1906. : item.code || item.cellCode || ''
  1907. })
  1908. },
  1909. formatRowCode(row) {
  1910. const selectedTemplate = this.templateList.find(
  1911. (item) => item.pkVal === this.selectedTemplateId
  1912. )
  1913. const surveyTemplateNameYw = selectedTemplate
  1914. ? selectedTemplate.surveyTemplateNameYw ||
  1915. selectedTemplate.surveyTemplateName ||
  1916. ''
  1917. : ''
  1918. const formattedCode = surveyTemplateNameYw
  1919. ? `${surveyTemplateNameYw}.${row.code || row.cellCode || ''}`
  1920. : row.code || row.cellCode || ''
  1921. this.$set(row, 'formattedCode', formattedCode)
  1922. const templateCode = surveyTemplateNameYw
  1923. ? `${surveyTemplateNameYw}_${row.code || row.cellCode || ''}`
  1924. : row.code || row.cellCode || ''
  1925. this.$set(
  1926. row,
  1927. 'jsonStr',
  1928. JSON.stringify([
  1929. {
  1930. [templateCode]: this.selectedTemplateId,
  1931. },
  1932. ])
  1933. )
  1934. },
  1935. openCalculationFormulaDialogVisible(row, index) {
  1936. this.currentEditingRow = row
  1937. this.currentEditingRowIndex = index
  1938. this.calculationFormulaDialogVisible = true
  1939. this.formulaText = row.calculationFormula || ''
  1940. this.selectedTemplateId = '' // 重置选中的模板
  1941. this.indicatorTableData = [] // 清空指标数据
  1942. this.getListFixedEnabled()
  1943. },
  1944. getListFixedEnabled() {
  1945. // 修改为调用状态为现行的数据
  1946. const params = {
  1947. surveyTemplateId: this.surveyTemplateId,
  1948. status: '0',
  1949. // pageNum: this.pagination.currentPage,
  1950. // pageSize: this.pagination.pageSize,
  1951. }
  1952. // 根据成本调查表ID获取所有版本数据
  1953. getCostSurveyTemplateVersionsByTemplateId(params)
  1954. .then((response) => {
  1955. this.templateList = response.value || []
  1956. })
  1957. .catch((error) => {
  1958. console.error('查询失败:', error)
  1959. })
  1960. // getListFixedEnabled().then((res) => {
  1961. // this.templateList = res.value
  1962. // })
  1963. },
  1964. // 处理模板选择变化
  1965. handleTemplateChange(templateId) {
  1966. if (templateId) {
  1967. // 根据选中的模板ID查找对应的surveyTemplateId
  1968. const selectedTemplate = this.templateList.find(
  1969. (item) => item.pkVal === templateId
  1970. )
  1971. if (selectedTemplate && selectedTemplate.surveyTemplateId) {
  1972. // this.getCellCodesByTemplateId(selectedTemplate.surveyTemplateId)
  1973. listByCurrentTemplateId({
  1974. surveyTemplateId: selectedTemplate.surveyTemplateId,
  1975. }).then((responseData) => {
  1976. //解析并显示数据
  1977. if (responseData.value && responseData.value.itemlist) {
  1978. const itemList = responseData.value.itemlist
  1979. let fixedTablesTitle = this.stringToObjects(
  1980. responseData.value.fixedFields || ''
  1981. )
  1982. this.indicatorTableHeaders = fixedTablesTitle
  1983. // 遍历itemList,为每个项目创建一行数据
  1984. itemList.forEach((item, index) => {
  1985. const newRow = {
  1986. ...item,
  1987. checked: false,
  1988. cellCode: item.cellCode || '',
  1989. fixedValues: {},
  1990. }
  1991. // 初始化fixedValues并填充实际值
  1992. fixedTablesTitle.forEach((title) => {
  1993. newRow.fixedValues[title.rkey] = item[title.rkey] || ''
  1994. })
  1995. this.indicatorTableData.push(newRow)
  1996. })
  1997. }
  1998. })
  1999. } else {
  2000. this.indicatorTableData = []
  2001. }
  2002. } else {
  2003. this.indicatorTableData = []
  2004. }
  2005. // 恢复该模板之前选中的指标项
  2006. this.$nextTick(() => {
  2007. if (this.selectedIndicatorsPerTemplate[templateId]) {
  2008. this.indicatorTableData.forEach((item) => {
  2009. const isSelected = this.selectedIndicatorsPerTemplate[
  2010. templateId
  2011. ].some((selectedItem) => selectedItem.code === item.code)
  2012. this.$set(item, 'checked', isSelected)
  2013. if (isSelected) {
  2014. this.formatRowCode(item)
  2015. }
  2016. })
  2017. }
  2018. // 更新选中的指标代码列表
  2019. this.updateSelectedIndicatorCodes()
  2020. })
  2021. },
  2022. handleDialogClose(done) {
  2023. this.selectedIndicatorsPerTemplate = {}
  2024. done()
  2025. },
  2026. handleRadioChange(value) {
  2027. this.formulaText = ''
  2028. },
  2029. handleConfirm() {
  2030. const result = {
  2031. type: this.radioType,
  2032. formula: this.formulaText,
  2033. selectedTemplate: this.selectedTemplateId,
  2034. selectedItems: this.indicatorTableData.filter((item) => item.checked),
  2035. }
  2036. let _data = []
  2037. if (this.radioType == 'current') {
  2038. // 使用递归函数扁平化树形结构
  2039. const flattenTree = (nodes) => {
  2040. let result = []
  2041. nodes.forEach((node) => {
  2042. result.push(node)
  2043. if (node.children && node.children.length > 0) {
  2044. result = result.concat(flattenTree(node.children))
  2045. }
  2046. })
  2047. return result
  2048. }
  2049. // 扁平化数据并提取cellCode
  2050. _data = flattenTree(this.contentEditForm.fixedTable.fixedTables)
  2051. .filter((item) => item.cellCode)
  2052. .map((item) => item.cellCode)
  2053. } else if (this.radioType == 'other') {
  2054. if (!result.selectedTemplate) {
  2055. this.$message.error('请选择指标编号')
  2056. return
  2057. }
  2058. _data = this.indicatorTableData
  2059. .filter((item) => item.cellCode)
  2060. .map((item) => item.cellCode)
  2061. }
  2062. if (!this.validateFormula(this.formulaText, _data).valid) {
  2063. this.$message.error(
  2064. this.validateFormula(this.formulaText, _data).errorMsg
  2065. )
  2066. return
  2067. }
  2068. // 生成 jsonstr 字段
  2069. const jsonStrArray = this.indicatorTableData
  2070. .filter((item) => item.checked)
  2071. .map((item) => {
  2072. if (item.jsonStr) {
  2073. try {
  2074. return JSON.parse(item.jsonStr)[0]
  2075. } catch (e) {
  2076. console.error('解析 jsonStr 失败:', e)
  2077. return {}
  2078. }
  2079. }
  2080. return {}
  2081. })
  2082. .filter((item) => Object.keys(item).length > 0)
  2083. const jsonstr = JSON.stringify(jsonStrArray)
  2084. // 更新当前编辑行的计算公式值
  2085. if (this.currentEditingRow) {
  2086. this.$set(
  2087. this.currentEditingRow,
  2088. 'calculationFormula',
  2089. this.formulaText
  2090. )
  2091. this.$set(this.currentEditingRow, 'jsonstr', jsonstr)
  2092. }
  2093. console.log('点击了确定,获取到的数据:', {
  2094. ...result,
  2095. jsonstr: jsonstr,
  2096. })
  2097. // 清空当前操作的状态
  2098. this.calculationFormulaDialogVisible = false
  2099. this.currentEditingRow = null
  2100. this.currentEditingRowIndex = -1
  2101. this.isAutoGeneratedFormula = false
  2102. this.selectedTemplateId = ''
  2103. this.indicatorTableData = []
  2104. this.selectedIndicatorsPerTemplate = {} // 清空模板选中记录
  2105. },
  2106. // 获取单元格代码
  2107. getCellCodesByTemplateId(surveyTemplateId) {
  2108. getCellCodesByTemplateId(surveyTemplateId)
  2109. .then((res) => {
  2110. // 将返回的数据转换为表格需要的格式
  2111. if (res.value && Array.isArray(res.value)) {
  2112. this.indicatorTableData = res.value.map((item) => ({
  2113. ...item,
  2114. checked: false,
  2115. code: item.cellCode || '',
  2116. name: item.rvalue || '',
  2117. formattedCode: '', // 添加格式化代码字段
  2118. }))
  2119. } else {
  2120. this.indicatorTableData = []
  2121. }
  2122. })
  2123. .catch((error) => {
  2124. console.error('获取指标数据失败:', error)
  2125. this.$message.error('获取指标数据失败')
  2126. this.indicatorTableData = []
  2127. })
  2128. },
  2129. handleFormulaTextChange(value) {
  2130. // 当用户手动修改公式文本时,标记为非自动生成
  2131. this.isAutoGeneratedFormula = false
  2132. },
  2133. handleAdd() {
  2134. this.dialogTitle = '添加'
  2135. // 获取当前时间
  2136. const now = new Date()
  2137. // 格式化时间为YYYY-MM-DD HH:mm:ss
  2138. const formattedDate = `${now.getFullYear()}-${String(
  2139. now.getMonth() + 1
  2140. ).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(
  2141. now.getHours()
  2142. ).padStart(2, '0')}:${String(now.getMinutes()).padStart(
  2143. 2,
  2144. '0'
  2145. )}:${String(now.getSeconds()).padStart(2, '0')}`
  2146. this.dataForm = {
  2147. id: null,
  2148. version: '',
  2149. status: '',
  2150. createBy: this.username,
  2151. createTime: formattedDate,
  2152. remarks: '',
  2153. }
  2154. this.dialogVisible = true
  2155. },
  2156. // 修改
  2157. handleEdit(row) {
  2158. this.dialogTitle = '修改'
  2159. this.dataForm = { ...row }
  2160. this.dialogVisible = true
  2161. },
  2162. //状态格式化
  2163. forStatus(status) {
  2164. return status === '-1' ? '草稿' : status === '0' ? '现行' : '历史'
  2165. },
  2166. // 查看详情
  2167. handleViewDetail(row) {
  2168. this.viewDetail = true
  2169. this.detailForm = { ...row }
  2170. // this.detailDialogVisible = true
  2171. this.handleEditContent(row, this.viewDetail)
  2172. },
  2173. // 添加子项方法
  2174. handleAddChildItem(index, type, parentRow) {
  2175. if (!parentRow.rowid) {
  2176. this.$set(parentRow, 'rowid', this.generateUUID())
  2177. }
  2178. switch (type) {
  2179. case '固定表项目':
  2180. let parentIndex1 =
  2181. this.contentEditForm.fixedTable.fixedTables.findIndex(
  2182. (item) => item.rowid == parentRow.rowid
  2183. )
  2184. if (
  2185. !this.contentEditForm.fixedTable.fixedTables[parentIndex1]
  2186. .children
  2187. ) {
  2188. this.$set(
  2189. this.contentEditForm.fixedTable.fixedTables[parentIndex1],
  2190. 'children',
  2191. []
  2192. )
  2193. }
  2194. let childOrderNum =
  2195. this.contentEditForm.fixedTable.fixedTables[parentIndex1].children
  2196. .length + 1
  2197. let fixedValues = {
  2198. ...parentRow.fixedValues,
  2199. }
  2200. for (const key in fixedValues) {
  2201. if (key == '序号') {
  2202. fixedValues[key] = childOrderNum
  2203. } else {
  2204. fixedValues[key] = ''
  2205. }
  2206. }
  2207. const fixedNewRow = {
  2208. orderText: this.contentEditForm.fixedTable.fixedTables.length + 1,
  2209. orderNum: this.contentEditForm.fixedTable.fixedTables.length + 1,
  2210. cellCode: '',
  2211. calculationFormula: '',
  2212. unit: '',
  2213. tabtype: this.templateType,
  2214. surveyTemplateId: this.surveyTemplateId,
  2215. versionId: this.versionId,
  2216. fixedValues: fixedValues,
  2217. parentid: parentRow.rowid,
  2218. isChild: true,
  2219. isSubItem: true,
  2220. rowid: this.generateUUID(),
  2221. }
  2222. this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
  2223. (title) => {
  2224. if (!(title.rkey in fixedNewRow.fixedValues)) {
  2225. fixedNewRow.fixedValues[title.rkey] = ''
  2226. }
  2227. }
  2228. )
  2229. // 先将子项添加到children数组
  2230. this.contentEditForm.fixedTable.fixedTables[
  2231. parentIndex1
  2232. ].children.push(fixedNewRow)
  2233. // this.contentEditForm.fixedTable.fixedTables.splice(
  2234. // index + 1,
  2235. // 0,
  2236. // fixedNewRow
  2237. // )
  2238. break
  2239. case '动态表项目':
  2240. let parentIndex2 =
  2241. this.contentEditForm.dynamicTable.dynamicTables.findIndex(
  2242. (item) => item.rowid == parentRow.rowid
  2243. )
  2244. if (
  2245. !this.contentEditForm.dynamicTable.dynamicTables[parentIndex2]
  2246. .children
  2247. ) {
  2248. this.$set(
  2249. this.contentEditForm.dynamicTable.dynamicTables[parentIndex2],
  2250. 'children',
  2251. []
  2252. )
  2253. }
  2254. let dynamicChildOrderNum =
  2255. this.contentEditForm.dynamicTable.dynamicTables[parentIndex2]
  2256. .children.length + 1
  2257. let dynamicValues = { ...parentRow.dynamicValues }
  2258. for (const key in dynamicValues) {
  2259. if (key == '序号') {
  2260. dynamicValues[key] = dynamicChildOrderNum
  2261. } else {
  2262. dynamicValues[key] = ''
  2263. }
  2264. }
  2265. const dynamicNewRow = {
  2266. orderText: dynamicChildOrderNum,
  2267. orderNum: dynamicChildOrderNum,
  2268. tabtype: this.templateType,
  2269. surveyTemplateId: this.surveyTemplateId,
  2270. versionId: this.versionId,
  2271. dynamicValues: dynamicValues,
  2272. parentid: parentRow.rowid,
  2273. isChild: true,
  2274. isSubItem: true,
  2275. rowid: Date.now() + Math.random() + 1,
  2276. }
  2277. this.contentEditForm.dynamicTable.dynamicTablesTitle.forEach(
  2278. (title) => {
  2279. if (!(title.rkey in dynamicNewRow.dynamicValues)) {
  2280. dynamicNewRow.dynamicValues[title.rkey] = ''
  2281. }
  2282. }
  2283. )
  2284. this.contentEditForm.dynamicTable.dynamicTables[
  2285. parentIndex2
  2286. ].children.push(dynamicNewRow)
  2287. // this.contentEditForm.dynamicTable.dynamicTables.splice(
  2288. // index + 1,
  2289. // 0,
  2290. // dynamicNewRow
  2291. // )
  2292. break
  2293. }
  2294. this.$nextTick(() => {
  2295. const tableBody = document.querySelector('.el-table__body-wrapper')
  2296. if (tableBody) {
  2297. tableBody.scrollTop = tableBody.scrollHeight
  2298. }
  2299. })
  2300. },
  2301. handleFormStyleChange() {},
  2302. getListBySurveyTemplateIdAndVersion(surveyTemplateId, versionId) {
  2303. return getListBySurveyTemplateIdAndVersion({
  2304. surveyTemplateId: surveyTemplateId,
  2305. versionId: versionId,
  2306. })
  2307. .then((res) => {
  2308. // 确保表头数据包含所有必要的字段,包括 id
  2309. this.contentEditForm.tableHeaders =
  2310. res.value.map((item) => ({
  2311. ...item,
  2312. fieldKey: item.fieldEname
  2313. ? item.fieldEname.toLowerCase()
  2314. : `field_${Date.now()}_${Math.random()
  2315. .toString(36)
  2316. .substr(2, 9)}`,
  2317. })) || []
  2318. // 检查并添加序号字段(固定表和动态表需要)
  2319. if (['2', '3'].includes(this.contentEditForm.templateType)) {
  2320. const hasSerialNumber = this.contentEditForm.tableHeaders.some(
  2321. (item) => item.fieldName === '序号'
  2322. )
  2323. if (!hasSerialNumber) {
  2324. this.contentEditForm.tableHeaders.unshift({
  2325. fieldName: '序号',
  2326. fieldType: 'string',
  2327. format: '255',
  2328. fieldTypelen: '',
  2329. fieldTypenointlen: '',
  2330. isRequired: 'false',
  2331. showVisible: '1',
  2332. isAuditPeriod: 'false',
  2333. tabtype: this.templateType,
  2334. surveyTemplateId: this.surveyTemplateId,
  2335. versionId: this.versionId,
  2336. isDisabled: true,
  2337. orderNum: 1,
  2338. })
  2339. } else {
  2340. // 如果已存在序号字段,确保其不可编辑
  2341. const serialNumberIndex =
  2342. this.contentEditForm.tableHeaders.findIndex(
  2343. (item) => item.fieldName === '序号'
  2344. )
  2345. if (serialNumberIndex !== -1) {
  2346. this.contentEditForm.tableHeaders[
  2347. serialNumberIndex
  2348. ].isDisabled = true
  2349. }
  2350. }
  2351. }
  2352. this.contentEditForm.dynamicTable.tableHeaders =
  2353. this.contentEditForm.tableHeaders
  2354. this.contentEditForm.fixedTable.tableHeaders =
  2355. this.contentEditForm.tableHeaders
  2356. // 表头按照orderNum重新排序
  2357. this.contentEditForm.tableHeaders.sort(
  2358. (a, b) => a.orderNum - b.orderNum
  2359. )
  2360. this.contentEditForm.dynamicTable.tableHeaders.sort(
  2361. (a, b) => a.orderNum - b.orderNum
  2362. )
  2363. this.contentEditForm.fixedTable.tableHeaders.sort(
  2364. (a, b) => a.orderNum - b.orderNum
  2365. )
  2366. // 同时获取表头标题信息
  2367. listByTemplateIdAndVersion(surveyTemplateId, versionId)
  2368. .then((response) => {
  2369. if (response.code === 200) {
  2370. if (this.contentEditForm.templateType === '2') {
  2371. this.contentEditForm.fixedTable.fixedTablesTitle =
  2372. this.stringToObjects(response.value.fixedFields || '')
  2373. } else if (this.contentEditForm.templateType === '3') {
  2374. this.contentEditForm.dynamicTable.dynamicTablesTitle =
  2375. this.stringToObjects(response.value.fixedFields || '')
  2376. }
  2377. }
  2378. return response
  2379. })
  2380. .catch((error) => {
  2381. console.error('获取表头标题信息失败:', error)
  2382. throw error
  2383. })
  2384. })
  2385. .catch((error) => {
  2386. console.error('查询失败:', error)
  2387. this.loading = false
  2388. throw error
  2389. })
  2390. },
  2391. initFixedTableRow(row) {
  2392. if (row.cellCode === undefined) {
  2393. this.$set(row, 'cellCode', '')
  2394. }
  2395. if (row.calculationFormula === undefined) {
  2396. this.$set(row, 'calculationFormula', '')
  2397. }
  2398. if (row.unit === undefined) {
  2399. this.$set(row, 'unit', '')
  2400. }
  2401. if (!row.fixedValues) {
  2402. this.$set(row, 'fixedValues', {})
  2403. }
  2404. this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
  2405. (title, index) => {
  2406. if (!(title.rkey in row.fixedValues)) {
  2407. this.$set(row.fixedValues, title.rkey, '')
  2408. }
  2409. }
  2410. )
  2411. return row
  2412. },
  2413. initDynamicTableRow(row) {
  2414. // 为当前行创建一个与 dynamicTablesTitle 对应的值对象
  2415. if (!row.dynamicValues) {
  2416. this.$set(row, 'dynamicValues', {})
  2417. }
  2418. // 确保每个动态列在当前行都有对应的值
  2419. this.contentEditForm.dynamicTable.dynamicTablesTitle.forEach(
  2420. (title) => {
  2421. if (!(title.rkey in row.dynamicValues)) {
  2422. this.$set(row.dynamicValues, title.rkey, '')
  2423. }
  2424. }
  2425. )
  2426. return row
  2427. },
  2428. /**
  2429. * 处理固定表项目字段值变化
  2430. */
  2431. handleFixedValueChange(row, rkey, value) {
  2432. if (!row.fixedValues) {
  2433. this.$set(row, 'fixedValues', {})
  2434. }
  2435. this.$set(row.fixedValues, rkey, value)
  2436. },
  2437. // 获取或设置序号字段
  2438. getOrSetOrder(row, value) {
  2439. // 如果提供了value参数,则设置值
  2440. if (value !== undefined) {
  2441. // 使用this.$set确保响应式更新
  2442. if (row['序号'] === undefined) {
  2443. this.$set(row, '序号', value)
  2444. } else {
  2445. row['序号'] = value
  2446. }
  2447. }
  2448. // 如果没有提供value参数,则获取值
  2449. return row['序号'] !== undefined && row['序号'] !== null
  2450. ? row['序号']
  2451. : row.orderNum || ''
  2452. },
  2453. /**
  2454. * 处理动态表项目字段值变化
  2455. */
  2456. handleDynamicValueChange(row, rkey, value) {
  2457. if (!row.dynamicValues) {
  2458. this.$set(row, 'dynamicValues', {})
  2459. }
  2460. this.$set(row.dynamicValues, rkey, value)
  2461. },
  2462. // 内容维护
  2463. handleEditContent(row, viewDetail) {
  2464. this.viewDetail = viewDetail || false
  2465. this.versionId = row.id
  2466. // 显示加载状态
  2467. this.loading = true
  2468. // 获取所有需要的数据
  2469. this.getListBySurveyTemplateIdAndVersion(row.surveyTemplateId, row.id)
  2470. .then(() => {
  2471. // 获取项目数据用于回显
  2472. return listByTemplateIdAndVersion(row.surveyTemplateId, row.id)
  2473. })
  2474. .then((res) => {
  2475. if (res.code === 200) {
  2476. // 根据模板类型解析并显示数据
  2477. if (this.contentEditForm.templateType === '2') {
  2478. // 解析并显示固定表项目数据
  2479. setTimeout(() => {
  2480. this.parseAndDisplayFixedTableData(res)
  2481. }, 1000)
  2482. } else if (this.contentEditForm.templateType === '3') {
  2483. // 解析并显示动态表项目数据
  2484. setTimeout(() => {
  2485. this.parseAndDisplayDynamicTableData(res)
  2486. }, 1000)
  2487. }
  2488. }
  2489. this.loading = false
  2490. this.contentEditDialogVisible = true
  2491. })
  2492. .catch((error) => {
  2493. console.error('获取数据失败:', error)
  2494. // this.$message.error('获取数据失败')
  2495. this.contentEditDialogVisible = true
  2496. this.loading = false
  2497. })
  2498. },
  2499. // 字段类型变化处理
  2500. handleFieldTypeChange(row) {
  2501. // 重置格式相关字段
  2502. row.format = ''
  2503. row.integerDigits = ''
  2504. row.decimalDigits = ''
  2505. },
  2506. // 添加表头
  2507. handleAddTableHeader(type) {
  2508. switch (type) {
  2509. case '单记录':
  2510. this.contentEditForm.tableHeaders.push({
  2511. fieldName: '',
  2512. fieldType: 'string',
  2513. format: '255',
  2514. fieldTypelen: '',
  2515. fieldTypenointlen: '',
  2516. isRequired: 'false',
  2517. showVisible: '1',
  2518. isDict: 'false',
  2519. dictid: '',
  2520. dictValue: '',
  2521. tabtype: this.templateType,
  2522. surveyTemplateId: this.surveyTemplateId,
  2523. versionId: this.versionId,
  2524. orderNum: this.contentEditForm.tableHeaders.length + 1,
  2525. })
  2526. break
  2527. case '固定表表头':
  2528. this.contentEditForm.fixedTable.tableHeaders.push({
  2529. fieldName: '',
  2530. fieldType: 'string',
  2531. format: '255',
  2532. fieldTypelen: '',
  2533. fieldTypenointlen: '',
  2534. isRequired: 'false',
  2535. showVisible: '1',
  2536. isAuditPeriod: 'false',
  2537. tabtype: this.templateType,
  2538. surveyTemplateId: this.surveyTemplateId,
  2539. versionId: this.versionId,
  2540. orderNum: this.contentEditForm.fixedTable.tableHeaders.length + 1,
  2541. })
  2542. // 确保添加后顺序正确
  2543. this.updateTableHeadersOrderNumbers()
  2544. break
  2545. case '固定表项目':
  2546. let maxFixedOrderNum = 0
  2547. if (this.contentEditForm.fixedTable.fixedTables.length > 0) {
  2548. maxFixedOrderNum = Math.max(
  2549. ...this.contentEditForm.fixedTable.fixedTables.map(
  2550. (item) => item.orderNum || 0
  2551. )
  2552. )
  2553. }
  2554. const newRow = {
  2555. orderText: maxFixedOrderNum + 1,
  2556. orderNum: maxFixedOrderNum + 1,
  2557. cellCode: '',
  2558. calculationFormula: '',
  2559. unit: '',
  2560. tabtype: this.templateType,
  2561. surveyTemplateId: this.surveyTemplateId,
  2562. versionId: this.versionId,
  2563. fixedValues: {},
  2564. parentid: -1,
  2565. rowid: this.generateUUID(),
  2566. children: [],
  2567. }
  2568. this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
  2569. (title) => {
  2570. newRow.fixedValues[title.rkey] = ''
  2571. }
  2572. )
  2573. this.contentEditForm.fixedTable.fixedTables.push(newRow)
  2574. break
  2575. case '动态表表头':
  2576. this.contentEditForm.dynamicTable.tableHeaders.push({
  2577. fieldName: '',
  2578. fieldType: 'string',
  2579. format: '255',
  2580. fieldTypelen: '',
  2581. fieldTypenointlen: '',
  2582. isRequired: 'false',
  2583. showVisible: '1',
  2584. tabtype: this.templateType,
  2585. surveyTemplateId: this.surveyTemplateId,
  2586. versionId: this.versionId,
  2587. orderNum:
  2588. this.contentEditForm.dynamicTable.tableHeaders.length + 1,
  2589. })
  2590. break
  2591. case '动态表项目':
  2592. let maxDynamicOrderNum = 0
  2593. if (this.contentEditForm.dynamicTable.dynamicTables.length > 0) {
  2594. maxDynamicOrderNum = Math.max(
  2595. ...this.contentEditForm.dynamicTable.dynamicTables.map(
  2596. (item) => item.orderNum || 0
  2597. )
  2598. )
  2599. }
  2600. const dynamicRow = {
  2601. orderText: maxDynamicOrderNum + 1,
  2602. orderNum: maxDynamicOrderNum + 1,
  2603. tabtype: this.templateType,
  2604. surveyTemplateId: this.surveyTemplateId,
  2605. versionId: this.versionId,
  2606. dynamicValues: {},
  2607. parentid: -1,
  2608. rowid: this.generateUUID(),
  2609. children: [],
  2610. }
  2611. this.contentEditForm.dynamicTable.dynamicTablesTitle.forEach(
  2612. (title) => {
  2613. dynamicRow.dynamicValues[title.rkey] = ''
  2614. }
  2615. )
  2616. this.contentEditForm.dynamicTable.dynamicTables.push(dynamicRow)
  2617. break
  2618. default:
  2619. break
  2620. }
  2621. this.$nextTick(() => {
  2622. const tableBody = document.querySelector('.el-table__body-wrapper')
  2623. if (tableBody) {
  2624. tableBody.scrollTop = tableBody.scrollHeight
  2625. }
  2626. })
  2627. },
  2628. // 删除表头
  2629. handleDeleteHeader(index, type, row) {
  2630. const handleDelete = () => {
  2631. const data = {
  2632. deleteheadersList: [row],
  2633. }
  2634. getBatchSaveOrUpdate(data)
  2635. .then((res) => {
  2636. if (res.code === 200) {
  2637. this.$message.success('删除成功')
  2638. } else {
  2639. this.$message.error(`删除失败:${res.message || '未知错误'}`)
  2640. }
  2641. })
  2642. .catch((error) => {
  2643. console.error('删除接口异常:', error)
  2644. // this.$message.error('删除接口异常,请重试')
  2645. })
  2646. .finally(() => {})
  2647. }
  2648. switch (type) {
  2649. case '固定表表头':
  2650. if (this.contentEditForm.fixedTable.tableHeaders.length <= 1) {
  2651. this.$message.warning('至少保留一个表头')
  2652. return
  2653. }
  2654. this.contentEditForm.fixedTable.tableHeaders.splice(index, 1)
  2655. let fixedFields = this.contentEditForm.fixedTable.tableHeaders
  2656. .map((item) => item.fieldName)
  2657. .join(',')
  2658. this.contentEditForm.fixedTable.fixedTablesTitle =
  2659. this.stringToObjects(fixedFields || '')
  2660. this.contentEditForm.fixedTable.fixedTableHeaders =
  2661. this.contentEditForm.fixedTable.fixedTablesTitle.filter(
  2662. (title) => title.rkey !== '序号'
  2663. )
  2664. handleDelete()
  2665. // 重新排序
  2666. this.updateTableHeadersOrderNumbers()
  2667. break
  2668. case '固定表项目':
  2669. this.$confirm(
  2670. '确定要删除此行数据吗?如果删除的是父项,将同时删除其所有子项。',
  2671. '确认删除',
  2672. {
  2673. confirmButtonText: '确定',
  2674. cancelButtonText: '取消',
  2675. type: 'warning',
  2676. }
  2677. )
  2678. .then(() => {
  2679. // 检查是否是删除子项
  2680. const isChildItem = row.isChild || row.isSubItem || false
  2681. console.log('isChildItem', isChildItem)
  2682. console.log('row', row)
  2683. if (isChildItem) {
  2684. // 查找父项
  2685. const parentItem =
  2686. this.contentEditForm.fixedTable.fixedTables.find(
  2687. (item) =>
  2688. item.children &&
  2689. item.children.some((child) => child.rowid === row.rowid)
  2690. )
  2691. if (parentItem && parentItem.children) {
  2692. // 从父项的children数组中删除子项
  2693. const childIndex = parentItem.children.findIndex(
  2694. (child) => child.rowid === row.rowid
  2695. )
  2696. if (childIndex > -1) {
  2697. parentItem.children.splice(childIndex, 1)
  2698. // 如果children数组为空,将hasChildren设为false
  2699. if (parentItem.children.length === 0) {
  2700. this.$set(parentItem, 'hasChildren', false)
  2701. } else {
  2702. // 重新计算子项序号
  2703. parentItem.children.forEach((child, idx) => {
  2704. child.orderText = idx + 1
  2705. child.orderNum = idx + 1
  2706. })
  2707. }
  2708. // 确保Vue响应式系统检测到变化
  2709. const children = [...parentItem.children]
  2710. this.$set(parentItem, 'children', children)
  2711. this.handleSaveContent('固定表项目', 'delete') // 保存数据
  2712. }
  2713. }
  2714. } else {
  2715. // 处理删除父项的情况
  2716. if (this.contentEditForm.fixedTable.fixedTables.length <= 1) {
  2717. this.$message.warning('至少保留一个项目')
  2718. return
  2719. }
  2720. // 获取要删除的行
  2721. index =
  2722. this.contentEditForm.fixedTable.fixedTables.indexOf(row)
  2723. const rowToDelete =
  2724. this.contentEditForm.fixedTable.fixedTables[index]
  2725. // 先删除所有子项(parentid等于当前行的rowid或itemId的项)
  2726. // 从后往前删除,避免索引偏移
  2727. const rowsToDelete = []
  2728. // 找出所有需要删除的行(包括父项和子项)
  2729. for (
  2730. let i = 0;
  2731. i < this.contentEditForm.fixedTable.fixedTables.length;
  2732. i++
  2733. ) {
  2734. const currentRow =
  2735. this.contentEditForm.fixedTable.fixedTables[i]
  2736. // 是当前行或其子项(子项的parentid等于当前行的rowid或itemId)
  2737. if (
  2738. i === index ||
  2739. (currentRow.parentid &&
  2740. (currentRow.parentid === rowToDelete.rowid ||
  2741. currentRow.parentid === rowToDelete.itemId))
  2742. ) {
  2743. rowsToDelete.push(i)
  2744. }
  2745. }
  2746. // 从后往前删除,避免索引偏移
  2747. for (let i = rowsToDelete.length - 1; i >= 0; i--) {
  2748. this.contentEditForm.fixedTable.fixedTables.splice(
  2749. rowsToDelete[i],
  2750. 1
  2751. )
  2752. }
  2753. this.handleSaveContent('固定表项目', 'delete') // 保存数据
  2754. }
  2755. })
  2756. .catch(() => {})
  2757. break
  2758. case '动态表表头':
  2759. if (this.contentEditForm.dynamicTable.tableHeaders.length <= 1) {
  2760. this.$message.warning('至少保留一个表头')
  2761. return
  2762. }
  2763. this.contentEditForm.dynamicTable.tableHeaders.splice(index, 1)
  2764. let dynamicFields = this.contentEditForm.dynamicTable.tableHeaders
  2765. .map((item) => item.fieldName)
  2766. .join(',')
  2767. this.contentEditForm.dynamicTable.dynamicTablesTitle =
  2768. this.stringToObjects(dynamicFields || '')
  2769. this.contentEditForm.dynamicTable.dynamicTableHeaders =
  2770. this.contentEditForm.dynamicTable.dynamicTablesTitle.filter(
  2771. (title) => title.rkey !== '序号'
  2772. )
  2773. handleDelete()
  2774. // 重新排序
  2775. this.updateTableHeadersOrderNumbers()
  2776. break
  2777. case '动态表项目':
  2778. if (this.contentEditForm.dynamicTable.dynamicTables.length <= 1) {
  2779. this.$message.warning('至少保留一个项目')
  2780. return
  2781. }
  2782. this.$confirm(
  2783. '确定要删除此行数据吗?如果删除的是父项,将同时删除其所有子项。',
  2784. '确认删除',
  2785. {
  2786. confirmButtonText: '确定',
  2787. cancelButtonText: '取消',
  2788. type: 'warning',
  2789. }
  2790. )
  2791. .then(() => {
  2792. // 检查是否是删除子项
  2793. const isChildItem = row.isChild || row.isSubItem || false
  2794. if (isChildItem) {
  2795. // 查找父项
  2796. const parentItem =
  2797. this.contentEditForm.dynamicTable.dynamicTables.find(
  2798. (item) =>
  2799. item.children &&
  2800. item.children.some((child) => child.rowid === row.rowid)
  2801. )
  2802. if (parentItem && parentItem.children) {
  2803. // 从父项的children数组中删除子项
  2804. const childIndex = parentItem.children.findIndex(
  2805. (child) => child.rowid === row.rowid
  2806. )
  2807. if (childIndex > -1) {
  2808. parentItem.children.splice(childIndex, 1)
  2809. // 如果children数组为空,将hasChildren设为false
  2810. if (parentItem.children.length === 0) {
  2811. this.$set(parentItem, 'hasChildren', false)
  2812. } else {
  2813. // 重新计算子项序号
  2814. parentItem.children.forEach((child, idx) => {
  2815. child.orderText = idx + 1
  2816. child.orderNum = idx + 1
  2817. })
  2818. }
  2819. // 确保Vue响应式系统检测到变化
  2820. const children = [...parentItem.children]
  2821. this.$set(parentItem, 'children', children)
  2822. this.handleSaveContent('动态表项目', 'delete') // 保存数据
  2823. }
  2824. }
  2825. } else {
  2826. // 处理删除父项的情况
  2827. if (
  2828. this.contentEditForm.dynamicTable.dynamicTables.length <= 1
  2829. ) {
  2830. this.$message.warning('至少保留一个项目')
  2831. return
  2832. }
  2833. // 获取要删除的行
  2834. index =
  2835. this.contentEditForm.dynamicTable.dynamicTables.indexOf(row)
  2836. const rowToDelete =
  2837. this.contentEditForm.dynamicTable.dynamicTables[index]
  2838. // 先删除所有子项(parentid等于当前行的rowid或itemId的项)
  2839. // 从后往前删除,避免索引偏移
  2840. const rowsToDelete = []
  2841. // 找出所有需要删除的行(包括父项和子项)
  2842. for (
  2843. let i = 0;
  2844. i < this.contentEditForm.dynamicTable.dynamicTables.length;
  2845. i++
  2846. ) {
  2847. const currentRow =
  2848. this.contentEditForm.dynamicTable.dynamicTables[i]
  2849. // 是当前行或其子项(子项的parentid等于当前行的rowid或itemId)
  2850. if (
  2851. i === index ||
  2852. (currentRow.parentid &&
  2853. (currentRow.parentid === rowToDelete.rowid ||
  2854. currentRow.parentid === rowToDelete.itemId))
  2855. ) {
  2856. rowsToDelete.push(i)
  2857. }
  2858. }
  2859. // 从后往前删除,避免索引偏移
  2860. for (let i = rowsToDelete.length - 1; i >= 0; i--) {
  2861. this.contentEditForm.dynamicTable.dynamicTables.splice(
  2862. rowsToDelete[i],
  2863. 1
  2864. )
  2865. }
  2866. this.handleSaveContent('动态表项目', 'delete') // 保存数据
  2867. }
  2868. })
  2869. .catch(() => {})
  2870. break
  2871. case '单记录':
  2872. if (this.contentEditForm.tableHeaders.length <= 1) {
  2873. this.$message.warning('至少保留一个表头')
  2874. return
  2875. }
  2876. this.contentEditForm.tableHeaders.splice(index, 1)
  2877. handleDelete()
  2878. break
  2879. default:
  2880. break
  2881. }
  2882. },
  2883. // 上升
  2884. handleMoveUp(index, tableType, row) {
  2885. if (tableType === '固定表') {
  2886. const fixedTableData = this.contentEditForm.fixedTable.fixedTables
  2887. const newFixedTableData = [...fixedTableData]
  2888. this.swamTableArr(newFixedTableData, row, true)
  2889. this.contentEditForm.fixedTable.fixedTables = newFixedTableData
  2890. } else if (tableType === '动态表') {
  2891. const dynamicTableData =
  2892. this.contentEditForm.dynamicTable.dynamicTables
  2893. const newDynamicTableData = [...dynamicTableData]
  2894. this.swamTableArr(newDynamicTableData, row, true)
  2895. this.contentEditForm.dynamicTable.dynamicTables = newDynamicTableData
  2896. } else {
  2897. // const tableHeaders = this.contentEditForm.tableHeaders
  2898. // const newTableHeaders = [...tableHeaders]
  2899. // this.swamTableArr(newTableHeaders, row, true, true)
  2900. // this.contentEditForm.tableHeaders = newTableHeaders
  2901. // console.log('newTableHeaders', newTableHeaders)
  2902. if (index > 0) {
  2903. const temp = this.contentEditForm.tableHeaders[index]
  2904. this.contentEditForm.tableHeaders.splice(index, 1)
  2905. this.contentEditForm.tableHeaders.splice(index - 1, 0, temp)
  2906. // 更新表头的序号
  2907. this.updateTableHeadersOrderNumbers()
  2908. }
  2909. }
  2910. },
  2911. // 下降
  2912. handleMoveDown(index, tableType, row) {
  2913. if (tableType === '固定表') {
  2914. const fixedTableData = this.contentEditForm.fixedTable.fixedTables
  2915. const newFixedTableData = [...fixedTableData]
  2916. this.swamTableArr(newFixedTableData, row, false)
  2917. this.contentEditForm.fixedTable.fixedTables = newFixedTableData
  2918. } else if (tableType === '动态表') {
  2919. const dynamicTableData =
  2920. this.contentEditForm.dynamicTable.dynamicTables
  2921. const newDynamicTableData = [...dynamicTableData]
  2922. this.swamTableArr(newDynamicTableData, row, false)
  2923. this.contentEditForm.dynamicTable.dynamicTables = newDynamicTableData
  2924. } else {
  2925. // const tableHeaders = this.contentEditForm.tableHeaders
  2926. // const newTableHeaders = [...tableHeaders]
  2927. // this.swamTableArr(newTableHeaders, row, false)
  2928. // this.contentEditForm.tableHeaders = newTableHeaders
  2929. if (index < this.contentEditForm.tableHeaders.length - 1) {
  2930. const temp = this.contentEditForm.tableHeaders[index]
  2931. this.contentEditForm.tableHeaders.splice(index, 1)
  2932. this.contentEditForm.tableHeaders.splice(index + 1, 0, temp)
  2933. // 更新表头的序号
  2934. this.updateTableHeadersOrderNumbers()
  2935. }
  2936. }
  2937. },
  2938. swamTableArr(arr, row, asc, isHeader) {
  2939. if (isHeader) {
  2940. // 创建数组副本以确保Vue能检测到变化
  2941. // 直接替换整个数组,确保Vue能检测到变化
  2942. this.doSwamTableArr(arr, row, asc, isHeader)
  2943. } else {
  2944. const isChild = row.isChild || row.isSubItem || false
  2945. if (isChild) {
  2946. // 子节点处理逻辑后续实现 parentid rowid
  2947. let child = arr.find((item) => item.rowid === row.parentid)
  2948. // const rowIndex = arr.indexOf(row);
  2949. // newFixedTableData[rowIndex]
  2950. this.doSwamTableArr(child.children, row, asc, isHeader)
  2951. } else {
  2952. this.doSwamTableArr(arr, row, asc, isHeader)
  2953. }
  2954. }
  2955. },
  2956. // 更新表头序号
  2957. updateTableHeadersOrderNumbers() {
  2958. if (!this.contentEditForm || !this.contentEditForm.tableHeaders) return
  2959. // 更新主表头的orderNum
  2960. this.contentEditForm.tableHeaders.forEach((header, index) => {
  2961. header.orderNum = index + 1
  2962. })
  2963. // 同步更新固定表和动态表的表头序号
  2964. if (
  2965. this.contentEditForm.fixedTable &&
  2966. this.contentEditForm.fixedTable.tableHeaders
  2967. ) {
  2968. this.contentEditForm.fixedTable.tableHeaders.forEach(
  2969. (header, index) => {
  2970. header.orderNum = index + 1
  2971. }
  2972. )
  2973. }
  2974. if (
  2975. this.contentEditForm.dynamicTable &&
  2976. this.contentEditForm.dynamicTable.tableHeaders
  2977. ) {
  2978. this.contentEditForm.dynamicTable.tableHeaders.forEach(
  2979. (header, index) => {
  2980. header.orderNum = index + 1
  2981. }
  2982. )
  2983. }
  2984. },
  2985. doSwamTableArr(arr, row, asc, isHeader) {
  2986. const rowIndex = arr.indexOf(row)
  2987. let swamIndex = 0
  2988. if (asc) {
  2989. // 正序
  2990. if (rowIndex < 1) {
  2991. return
  2992. }
  2993. swamIndex = rowIndex - 1
  2994. } else {
  2995. // 倒序
  2996. if (rowIndex >= arr.length - 1) {
  2997. return
  2998. }
  2999. swamIndex = rowIndex + 1
  3000. }
  3001. const curr = arr[rowIndex]
  3002. const swam = arr[swamIndex]
  3003. // 交换orderNum
  3004. const tempOrderNum = curr.orderNum
  3005. curr.orderNum = swam.orderNum
  3006. swam.orderNum = tempOrderNum
  3007. // row.isChild &&
  3008. if (!isHeader) {
  3009. // 获取当前项的序号值
  3010. let currIndex = curr.fixedValues
  3011. ? curr.fixedValues['序号']
  3012. : curr.dynamicValues['序号']
  3013. // 获取交换项的序号值
  3014. let swamIndex = swam.fixedValues
  3015. ? swam.fixedValues['序号']
  3016. : swam.dynamicValues['序号']
  3017. // 先保存交换项的值,再进行赋值,避免值被覆盖
  3018. if (curr.fixedValues) {
  3019. curr.fixedValues['序号'] = swamIndex
  3020. } else {
  3021. curr.dynamicValues['序号'] = swamIndex
  3022. }
  3023. if (swam.fixedValues) {
  3024. swam.fixedValues['序号'] = currIndex
  3025. } else {
  3026. swam.dynamicValues['序号'] = currIndex
  3027. }
  3028. }
  3029. // 交换数组中的位置
  3030. arr[rowIndex] = swam
  3031. arr[swamIndex] = curr
  3032. },
  3033. // 启动/停用状态
  3034. handleStatus(row) {
  3035. const action = row.status === '启用' ? '停用' : '启用'
  3036. if (row.status === '0') {
  3037. this.$confirm(`确认要停用该数据吗?`, '操作确认', {
  3038. confirmButtonText: '确定',
  3039. cancelButtonText: '取消',
  3040. type: 'warning',
  3041. })
  3042. .then(() => {
  3043. row.status = '-1'
  3044. putSurveyTemplatePublishVersion(row).then((res) => {
  3045. if (res.code === 200) {
  3046. this.$message.success(`停用成功`)
  3047. this.handleSearch()
  3048. }
  3049. })
  3050. })
  3051. .catch(() => {
  3052. this.$message({
  3053. type: 'info',
  3054. message: '已取消操作',
  3055. })
  3056. })
  3057. } else if (row.status === '-1') {
  3058. this.$confirm(`确认要启用该数据吗?`, '操作确认', {
  3059. confirmButtonText: '确定',
  3060. cancelButtonText: '取消',
  3061. type: 'warning',
  3062. })
  3063. .then(() => {
  3064. row.status = '0'
  3065. putSurveyTemplatePublishVersion(row).then((res) => {
  3066. if (res.code === 200) {
  3067. this.$message.success(`启用成功`)
  3068. this.handleSearch()
  3069. }
  3070. })
  3071. })
  3072. .catch(() => {
  3073. this.$message({
  3074. type: 'info',
  3075. message: '已取消操作',
  3076. })
  3077. })
  3078. }
  3079. },
  3080. // 更新固定表行序号
  3081. updateFixedTableOrderNumbers() {
  3082. this.contentEditForm.fixedTable.fixedTables.forEach((row, index) => {
  3083. // 更新显示序号
  3084. this.$set(row, 'orderText', index + 1)
  3085. // 更新后端序号
  3086. this.$set(row, 'orderNum', index + 1)
  3087. })
  3088. },
  3089. // 更新动态表行序号
  3090. updateDynamicTableOrderNumbers() {
  3091. this.contentEditForm.dynamicTable.dynamicTables.forEach(
  3092. (row, index) => {
  3093. // 更新显示序号
  3094. this.$set(row, 'orderText', index + 1)
  3095. // 更新后端序号
  3096. this.$set(row, 'orderNum', index + 1)
  3097. }
  3098. )
  3099. },
  3100. // 绑定字典变化
  3101. handleBindDictChange(row) {
  3102. if (row.isDict === 'false') {
  3103. row.dictid = ''
  3104. }
  3105. },
  3106. // 获取格式占位符
  3107. getFormatPlaceholder(fieldType) {
  3108. switch (fieldType) {
  3109. case '日期':
  3110. return '如:yyyy-MM-dd'
  3111. case '数字':
  3112. return '如:#,##0.00'
  3113. default:
  3114. return '请输入格式'
  3115. }
  3116. },
  3117. // 滚动到错误行
  3118. scrollToErrorRow(rowIndex) {
  3119. this.$nextTick(() => {
  3120. const tableBody = document.querySelector(
  3121. '.table-edit-container .el-table__body-wrapper'
  3122. )
  3123. if (tableBody) {
  3124. const scrollTop = rowIndex * 48
  3125. tableBody.scrollTop = scrollTop
  3126. }
  3127. })
  3128. },
  3129. // 保存内容
  3130. handleSaveContent(type, action) {
  3131. this.loading = true
  3132. let isValid = false
  3133. try {
  3134. if (type === '单记录') {
  3135. var data = {
  3136. headersList: this.contentEditForm.tableHeaders,
  3137. }
  3138. getBatchSaveOrUpdate(data)
  3139. .then((res) => {
  3140. if (res.code === 200) {
  3141. if (action != 'delete') {
  3142. this.$message.success('保存成功')
  3143. this.contentEditDialogVisible = false
  3144. }
  3145. } else {
  3146. this.$message.error(`保存失败:${res.message || '未知错误'}`)
  3147. }
  3148. })
  3149. .catch((error) => {
  3150. console.error('保存接口异常:', error)
  3151. // this.$message.error('保存接口异常,请重试')
  3152. })
  3153. .finally(() => {
  3154. this.loading = false
  3155. })
  3156. } else if (type === '固定表表头') {
  3157. var data = {
  3158. headersList: this.contentEditForm.fixedTable.tableHeaders,
  3159. }
  3160. getBatchSaveOrUpdate(data)
  3161. .then((res) => {
  3162. if (res.code === 200) {
  3163. this.contentEditForm.isFixedTables = true
  3164. this.loading = true
  3165. // 如果后端返回了保存后的数据,更新本地数据
  3166. if (res.value && Array.isArray(res.value)) {
  3167. this.contentEditForm.fixedTable.tableHeaders =
  3168. res.value.map((item) => ({
  3169. ...item,
  3170. }))
  3171. // 确保保存后的数据也按正确顺序显示
  3172. this.updateTableHeadersOrderNumbers()
  3173. }
  3174. this.getListBySurveyTemplateIdAndVersion(
  3175. this.surveyTemplateId,
  3176. this.versionId
  3177. )
  3178. listByTemplateIdAndVersion(
  3179. this.surveyTemplateId,
  3180. this.versionId
  3181. )
  3182. .then((res) => {
  3183. this.loading = false
  3184. this.contentEditForm.fixedTable.fixedTablesTitle =
  3185. this.stringToObjects(res.value.fixedFields)
  3186. this.contentEditForm.fixedTable.fixedTables.forEach(
  3187. (row) => {
  3188. this.initFixedTableRow(row)
  3189. }
  3190. )
  3191. this.contentEditForm.fixedTable.fixedTableHeaders =
  3192. this.contentEditForm.fixedTable.fixedTablesTitle.filter(
  3193. (title) => title.rkey !== '序号'
  3194. )
  3195. })
  3196. .catch((error) => {
  3197. console.error('查询失败:', error)
  3198. this.loading = false
  3199. })
  3200. } else {
  3201. this.$message.error(`保存失败:${res.message || '未知错误'}`)
  3202. }
  3203. })
  3204. .catch((error) => {
  3205. console.error('保存接口异常:', error)
  3206. // this.$message.error('保存接口异常,请重试')
  3207. })
  3208. .finally(() => {
  3209. this.loading = false
  3210. })
  3211. } else if (type === '固定表项目') {
  3212. this.saveFixedTableData(action)
  3213. } else if (type === '动态表表头') {
  3214. var data = {
  3215. headersList: this.contentEditForm.dynamicTable.tableHeaders,
  3216. }
  3217. getBatchSaveOrUpdate(data)
  3218. .then((res) => {
  3219. if (res.code === 200) {
  3220. this.contentEditForm.isDynamicTables = true
  3221. this.loading = true
  3222. // 如果后端返回了保存后的数据,更新本地数据
  3223. if (res.value && Array.isArray(res.value)) {
  3224. this.contentEditForm.dynamicTable.tableHeaders =
  3225. res.value.map((item) => ({
  3226. ...item,
  3227. fieldKey: item.fieldEname
  3228. ? item.fieldEname.toLowerCase()
  3229. : `field_${Date.now()}_${Math.random()
  3230. .toString(36)
  3231. .substr(2, 9)}`,
  3232. }))
  3233. // 确保保存后的数据也按正确顺序显示
  3234. this.updateTableHeadersOrderNumbers()
  3235. }
  3236. this.getListBySurveyTemplateIdAndVersion(
  3237. this.surveyTemplateId,
  3238. this.versionId
  3239. )
  3240. listByTemplateIdAndVersion(
  3241. this.surveyTemplateId,
  3242. this.versionId
  3243. )
  3244. .then((res) => {
  3245. this.loading = false
  3246. this.contentEditForm.dynamicTable.dynamicTablesTitle =
  3247. this.stringToObjects(res.value.fixedFields || '')
  3248. // 初始化所有已有行的 dynamicValues
  3249. this.contentEditForm.dynamicTable.dynamicTables.forEach(
  3250. (row) => {
  3251. this.initDynamicTableRow(row)
  3252. }
  3253. )
  3254. this.contentEditForm.dynamicTable.dynamicTableHeaders =
  3255. this.contentEditForm.dynamicTable.dynamicTablesTitle.filter(
  3256. (title) => title.rkey !== '序号'
  3257. )
  3258. })
  3259. .catch((error) => {
  3260. console.error('查询失败:', error)
  3261. this.loading = false
  3262. })
  3263. } else {
  3264. this.$message.error(`保存失败:${res.message || '未知错误'}`)
  3265. }
  3266. })
  3267. .catch((error) => {
  3268. console.error('保存接口异常:', error)
  3269. // this.$message.error('保存接口异常,请重试')
  3270. })
  3271. .finally(() => {
  3272. this.loading = false
  3273. })
  3274. } else if (type === '动态表项目') {
  3275. this.saveDynamicTableData(action)
  3276. }
  3277. } catch (error) {
  3278. console.error('保存处理异常:', error)
  3279. // this.$message.error('保存过程中发生错误,请重试')
  3280. this.loading = false
  3281. }
  3282. },
  3283. // 公式验证函数
  3284. validateFormula(formula, data) {
  3285. if (!formula || typeof formula !== 'string') {
  3286. return { valid: false, errorMsg: '公式不能为空' }
  3287. }
  3288. // 定义有效的操作符
  3289. const operators = ['+', '-', '*', '/', '(', ')']
  3290. // 检查是否包含至少一个操作符
  3291. const hasOperator = operators.some((operator) =>
  3292. formula.includes(operator)
  3293. )
  3294. if (!hasOperator) {
  3295. return { valid: false, errorMsg: '公式必须包含操作符' }
  3296. }
  3297. // 检查值是否在data中存在
  3298. function checkValueInData(value, data) {
  3299. if (!data) return false
  3300. if (Array.isArray(data)) {
  3301. return data.includes(value)
  3302. } else if (typeof data === 'object') {
  3303. return Object.values(data).includes(value)
  3304. }
  3305. return data === value
  3306. }
  3307. // 提取公式中的变量/值
  3308. function extractValues(formulaStr) {
  3309. // 改进实现:支持形如"CeShi3.C2"的格式,提取点后面的部分作为变量,同时保留普通变量
  3310. const result = new Set()
  3311. // 1. 首先提取带点格式中的变量部分(如CeShi3.C2中的C2)
  3312. const dotRegex = /[A-Za-z0-9]+\.([A-Za-z0-9]+)/g
  3313. let dotMatch
  3314. while ((dotMatch = dotRegex.exec(formulaStr)) !== null) {
  3315. result.add(dotMatch[1]) // 提取点后面的部分作为变量
  3316. }
  3317. // 2. 然后提取普通变量(C3等),但排除已经从带点格式中提取的部分
  3318. // 移除所有带点的部分,然后提取剩余的变量
  3319. const remainingFormula = formulaStr.replace(
  3320. /[A-Za-z0-9]+\.[A-Za-z0-9]+/g,
  3321. ''
  3322. )
  3323. const normalRegex = /[A-Za-z0-9]+/g
  3324. let normalMatch
  3325. while ((normalMatch = normalRegex.exec(remainingFormula)) !== null) {
  3326. // 跳过纯数字
  3327. if (
  3328. !isNaN(Number(normalMatch[0])) &&
  3329. Number(normalMatch[0]).toString() === normalMatch[0]
  3330. ) {
  3331. continue
  3332. }
  3333. result.add(normalMatch[0])
  3334. }
  3335. return Array.from(result)
  3336. }
  3337. function checkOperatorContext(formulaStr, data) {
  3338. for (let i = 0; i < formulaStr.length; i++) {
  3339. const char = formulaStr[i]
  3340. // 跳过括号
  3341. if (char === '(' || char === ')') continue
  3342. // 检查操作符
  3343. if (operators.includes(char)) {
  3344. // 检查操作符前是否有值(开头或不是操作符和左括号)
  3345. if (
  3346. i === 0 ||
  3347. (operators.includes(formulaStr[i - 1]) &&
  3348. formulaStr[i - 1] !== ')') ||
  3349. formulaStr[i - 1] === '('
  3350. ) {
  3351. return {
  3352. valid: false,
  3353. errorMsg: `位置 ${i + 1} 的操作符 '${char}' 前缺少值`,
  3354. }
  3355. }
  3356. // 检查操作符后是否有值(结尾或不是操作符和右括号)
  3357. if (
  3358. i === formulaStr.length - 1 ||
  3359. (operators.includes(formulaStr[i + 1]) &&
  3360. formulaStr[i + 1] !== '(') ||
  3361. formulaStr[i + 1] === ')'
  3362. ) {
  3363. return {
  3364. valid: false,
  3365. errorMsg: `位置 ${i + 1} 的操作符 '${char}' 后缺少值`,
  3366. }
  3367. }
  3368. }
  3369. }
  3370. // 验证通过后,检查公式中的值是否都在data中存在
  3371. if (data.length > 0) {
  3372. const values = extractValues(formulaStr)
  3373. for (const value of values) {
  3374. // 跳过纯数字(假设有值不在data中)
  3375. if (!isNaN(Number(value)) && Number(value).toString() === value) {
  3376. continue
  3377. }
  3378. if (!checkValueInData(value, data)) {
  3379. return {
  3380. valid: false,
  3381. errorMsg: `变量 '${value}' 在数据中不存在`,
  3382. }
  3383. }
  3384. }
  3385. }
  3386. return { valid: true }
  3387. }
  3388. // 执行验证
  3389. return checkOperatorContext(formula, data)
  3390. },
  3391. /**
  3392. * 将固定表项目的数据根据固定列拆分成对应的数据结构
  3393. * @returns {Array} 拆分后的数据数组,每个固定列对应一行数据
  3394. */
  3395. splitFixedTableDataForSave() {
  3396. const fixedTables = this.contentEditForm.fixedTable.fixedTables
  3397. const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
  3398. const fixedHeaders = this.contentEditForm.fixedTable.tableHeaders
  3399. // 结果数组
  3400. const result = []
  3401. // 递归处理树形结构中的所有节点
  3402. const processNode = (node, parentRowIndex = 0) => {
  3403. // 确保node和fixedValues存在
  3404. if (!node) {
  3405. console.warn('遇到空节点,跳过处理')
  3406. return
  3407. }
  3408. // 确保fixedValues属性存在,如果不存在则初始化为空对象
  3409. if (!node.fixedValues) {
  3410. node.fixedValues = {}
  3411. }
  3412. // 为每个固定列创建一条记录
  3413. fixedTitles.forEach((title) => {
  3414. // 找到对应的表头信息
  3415. const correspondingHeader = fixedHeaders.find(
  3416. (header) => header.fieldName === title.rkey
  3417. )
  3418. const newItem = {
  3419. rkey: title.rkey,
  3420. rvalue: node.fixedValues[title.rkey] || '',
  3421. surveyTemplateId: node.surveyTemplateId || this.surveyTemplateId,
  3422. versionId: node.versionId || this.versionId,
  3423. tabtype: node.tabtype || this.templateType,
  3424. // 添加 headersId 字段(表头的id)
  3425. headersId: correspondingHeader ? correspondingHeader.id : null,
  3426. // 添加记录的id(itemlist中每条记录的id)
  3427. id: node.itemId || null,
  3428. // 添加父子关系字段
  3429. parentid: node.parentid || -1, // 父项ID,默认为-1表示无父项
  3430. isChild: node.isChild || false, // 是否为子项
  3431. // 添加 rowid 字段
  3432. rowid: node.rowid || null,
  3433. // 添加计算公式相关字段
  3434. calculationFormula: node.calculationFormula || null,
  3435. jsonstr: node.jsonstr || null,
  3436. orderNum:
  3437. typeof node.orderNum === 'number'
  3438. ? node.orderNum
  3439. : parseInt(node.orderNum, 10) || 0,
  3440. }
  3441. // 添加其他固定表特有的字段
  3442. if (!node.isSubItem) {
  3443. newItem.cellCode = node.cellCode || ''
  3444. newItem.unit = node.unit || ''
  3445. }
  3446. // 添加其他可能需要的字段,但排除特定字段
  3447. Object.keys(node).forEach((key) => {
  3448. if (
  3449. !(key in newItem) &&
  3450. key !== 'fixedValues' &&
  3451. key !== 'itemId' &&
  3452. key !== 'id' &&
  3453. key !== 'parentid' &&
  3454. key !== 'isChild' &&
  3455. key !== 'isSubItem' &&
  3456. key !== 'rowid' &&
  3457. key !== 'jsonstr' &&
  3458. key !== 'calculationFormula' &&
  3459. key !== 'children' // 排除children字段
  3460. ) {
  3461. newItem[key] = node[key]
  3462. }
  3463. })
  3464. result.push(newItem)
  3465. })
  3466. // 递归处理子节点
  3467. if (node.children && node.children.length > 0) {
  3468. node.children.forEach((childNode) => {
  3469. processNode(childNode)
  3470. })
  3471. }
  3472. }
  3473. // 遍历所有顶级节点
  3474. fixedTables.forEach((row) => {
  3475. processNode(row)
  3476. })
  3477. // 重新给子节点赋值orderNum 保证所有元素orderNum字段不重复
  3478. // 为所有子节点分配唯一的orderNum,但保持父节点的orderNum不变
  3479. // 计算所有已存在的orderNum中的最大值
  3480. let maxExistingOrderNum = 0
  3481. // 首先遍历结果数组找出当前最大的orderNum
  3482. result.forEach((item) => {
  3483. const orderNum =
  3484. typeof item.orderNum === 'number'
  3485. ? item.orderNum
  3486. : parseInt(item.orderNum, 10) || 0
  3487. if (orderNum > maxExistingOrderNum) {
  3488. maxExistingOrderNum = orderNum
  3489. }
  3490. })
  3491. // 子节点orderNum从当前最大orderNum + 1开始
  3492. let childOrderNumCounter = maxExistingOrderNum + 1
  3493. // 创建一个映射表,用于记录每个子节点对应的新orderNum
  3494. const childOrderMap = new Map()
  3495. // 第一次遍历:为每个子节点分配新的orderNum并存储映射关系
  3496. function assignChildOrderNums(nodes) {
  3497. nodes.forEach((node) => {
  3498. if (node.isChild || node.isSubItem) {
  3499. // 为每个子节点分配唯一的orderNum
  3500. childOrderMap.set(node.id || node.rowid, childOrderNumCounter++)
  3501. }
  3502. // 递归处理子节点
  3503. if (node.children && node.children.length > 0) {
  3504. assignChildOrderNums(node.children)
  3505. }
  3506. })
  3507. }
  3508. // 第二次遍历:更新结果数组中的orderNum
  3509. assignChildOrderNums(fixedTables)
  3510. // 应用新的orderNum到结果数组
  3511. result.forEach((item) => {
  3512. // 只更新子节点的orderNum
  3513. if (item.isChild || item.isSubItem) {
  3514. const newOrderNum =
  3515. childOrderMap.get(item.id) || childOrderMap.get(item.rowid)
  3516. if (newOrderNum) {
  3517. item.orderNum = newOrderNum
  3518. }
  3519. }
  3520. })
  3521. return result
  3522. },
  3523. /**
  3524. * 将动态表项目的数据根据动态列拆分成对应的数据结构
  3525. * @returns {Array} 拆分后的数据数组,每个动态列对应一行数据
  3526. */
  3527. splitDynamicTableDataForSave() {
  3528. const dynamicTables = this.contentEditForm.dynamicTable.dynamicTables
  3529. const dynamicTitles =
  3530. this.contentEditForm.dynamicTable.dynamicTablesTitle
  3531. const dynamicHeaders = this.contentEditForm.dynamicTable.tableHeaders
  3532. // 结果数组
  3533. const result = []
  3534. // 递归处理树形结构中的所有节点
  3535. const processNode = (node) => {
  3536. // 确保node和dynamicValues存在
  3537. if (!node) {
  3538. console.warn('遇到空节点,跳过处理')
  3539. return
  3540. }
  3541. // 确保dynamicValues属性存在,如果不存在则初始化为空对象
  3542. if (!node.dynamicValues) {
  3543. node.dynamicValues = {}
  3544. }
  3545. // 为每个固定列创建一条记录
  3546. dynamicTitles.forEach((title) => {
  3547. // 找到对应的表头信息
  3548. const correspondingHeader = dynamicHeaders.find(
  3549. (header) => header.fieldName === title.rkey
  3550. )
  3551. const newItem = {
  3552. rkey: title.rkey,
  3553. rvalue: node.dynamicValues[title.rkey] || '',
  3554. surveyTemplateId: node.surveyTemplateId,
  3555. versionId: node.versionId,
  3556. tabtype: node.tabtype,
  3557. // 添加 headersId 字段(表头的id)
  3558. headersId: correspondingHeader ? correspondingHeader.id : null,
  3559. // 添加记录的id(itemlist中每条记录的id)
  3560. id: node.itemId || null,
  3561. // 添加父子关系字段
  3562. parentid: node.parentid || -1, // 父项ID,默认为-1表示无父项
  3563. isChild: node.isChild || false, // 是否为子项
  3564. // 添加 rowid 字段
  3565. rowid: node.rowid || null,
  3566. // 添加计算公式相关字段
  3567. calculationFormula: node.calculationFormula || null,
  3568. jsonstr: node.jsonstr || null,
  3569. orderNum:
  3570. typeof node.orderNum === 'number'
  3571. ? node.orderNum
  3572. : parseInt(node.orderNum, 10) || 0,
  3573. }
  3574. // 添加其他可能需要的字段,但排除特定字段
  3575. Object.keys(node).forEach((key) => {
  3576. if (
  3577. !(key in newItem) &&
  3578. key !== 'dynamicValues' &&
  3579. key !== 'itemId' &&
  3580. key !== 'id' &&
  3581. key !== 'parentid' &&
  3582. key !== 'isChild' &&
  3583. key !== 'isSubItem' &&
  3584. key !== 'rowid' &&
  3585. key !== 'jsonstr' &&
  3586. key !== 'calculationFormula' &&
  3587. key !== 'children' // 排除children字段
  3588. ) {
  3589. newItem[key] = node[key]
  3590. }
  3591. })
  3592. result.push(newItem)
  3593. })
  3594. // 递归处理子节点
  3595. if (node.children && node.children.length > 0) {
  3596. node.children.forEach((childNode) => {
  3597. processNode(childNode)
  3598. })
  3599. }
  3600. }
  3601. // 遍历所有顶级节点
  3602. dynamicTables.forEach((row) => {
  3603. processNode(row)
  3604. })
  3605. // 重新给子节点赋值orderNum 保证所有元素orderNum字段不重复
  3606. // 为所有子节点分配唯一的orderNum,但保持父节点的orderNum不变
  3607. // 计算所有已存在的orderNum中的最大值
  3608. let maxExistingOrderNum = 0
  3609. // 首先遍历结果数组找出当前最大的orderNum
  3610. result.forEach((item) => {
  3611. const orderNum =
  3612. typeof item.orderNum === 'number'
  3613. ? item.orderNum
  3614. : parseInt(item.orderNum, 10) || 0
  3615. if (orderNum > maxExistingOrderNum) {
  3616. maxExistingOrderNum = orderNum
  3617. }
  3618. })
  3619. // 子节点orderNum从当前最大orderNum + 1开始
  3620. let childOrderNumCounter = maxExistingOrderNum + 1
  3621. // 创建一个映射表,用于记录每个子节点对应的新orderNum
  3622. const childOrderMap = new Map()
  3623. // 第一次遍历:为每个子节点分配新的orderNum并存储映射关系
  3624. function assignChildOrderNums(nodes) {
  3625. nodes.forEach((node) => {
  3626. if (node.isChild || node.isSubItem) {
  3627. // 为每个子节点分配唯一的orderNum
  3628. childOrderMap.set(node.id || node.rowid, childOrderNumCounter++)
  3629. }
  3630. // 递归处理子节点
  3631. if (node.children && node.children.length > 0) {
  3632. assignChildOrderNums(node.children)
  3633. }
  3634. })
  3635. }
  3636. // 第二次遍历:更新结果数组中的orderNum
  3637. assignChildOrderNums(dynamicTables)
  3638. // 应用新的orderNum到结果数组
  3639. result.forEach((item) => {
  3640. // 只更新子节点的orderNum
  3641. if (item.isChild || item.isSubItem) {
  3642. const newOrderNum =
  3643. childOrderMap.get(item.id) || childOrderMap.get(item.rowid)
  3644. if (newOrderNum) {
  3645. item.orderNum = newOrderNum
  3646. }
  3647. }
  3648. })
  3649. return result
  3650. },
  3651. //保存固定表项目数据
  3652. saveFixedTableData(action = '') {
  3653. try {
  3654. // 获取拆分后的数据
  3655. const splitData = this.splitFixedTableDataForSave()
  3656. // 构造保存数据的结构
  3657. const saveData = {
  3658. itemsList: splitData,
  3659. }
  3660. // 调用保存接口
  3661. getBatchSaveOrUpdate(saveData)
  3662. .then((res) => {
  3663. if (res.code === 200) {
  3664. // 如果是删除操作,不显示成功提示且不关闭对话框
  3665. if (action !== 'delete') {
  3666. this.$message.success('固定表数据保存成功')
  3667. this.contentEditDialogVisible = false
  3668. }
  3669. // 刷新数据以确保UI更新
  3670. this.getListBySurveyTemplateIdAndVersion(
  3671. this.surveyTemplateId,
  3672. this.versionId
  3673. )
  3674. } else {
  3675. this.$message.error(`保存失败:${res.message || '未知错误'}`)
  3676. }
  3677. })
  3678. .catch((error) => {
  3679. console.error('保存固定表数据接口异常:', error)
  3680. // this.$message.error('保存固定表数据失败,请重试')
  3681. })
  3682. .finally(() => {
  3683. this.loading = false
  3684. })
  3685. return splitData
  3686. } catch (error) {
  3687. console.error('处理固定表数据保存时出错:', error)
  3688. // this.$message.error('保存过程中发生错误,请重试')
  3689. this.loading = false
  3690. }
  3691. },
  3692. //保存动态表项目数据
  3693. saveDynamicTableData() {
  3694. try {
  3695. // 获取拆分后的数据
  3696. const splitData = this.splitDynamicTableDataForSave()
  3697. // 构造保存数据的结构
  3698. const saveData = {
  3699. itemsList: splitData,
  3700. }
  3701. // 调用保存接口
  3702. getBatchSaveOrUpdate(saveData)
  3703. .then((res) => {
  3704. if (res.code === 200) {
  3705. if (action != 'delete') {
  3706. this.$message.success('动态表数据保存成功')
  3707. this.contentEditDialogVisible = false
  3708. }
  3709. } else {
  3710. this.$message.error(`保存失败:${res.message || '未知错误'}`)
  3711. }
  3712. })
  3713. .catch((error) => {
  3714. console.error('保存动态表数据接口异常:', error)
  3715. // this.$message.error('保存动态表数据失败,请重试')
  3716. })
  3717. .finally(() => {
  3718. this.loading = false
  3719. })
  3720. return splitData
  3721. } catch (error) {
  3722. console.error('处理动态表数据保存时出错:', error)
  3723. // this.$message.error('保存过程中发生错误,请重试')
  3724. this.loading = false
  3725. }
  3726. },
  3727. /**
  3728. * 解析并回显固定表项目数据
  3729. * @param {Object} responseData - listByTemplateIdAndVersion接口返回的数据
  3730. */
  3731. parseAndDisplayFixedTableData(responseData) {
  3732. if (responseData.value.fixedFields) {
  3733. this.contentEditForm.fixedTable.fixedTablesTitle =
  3734. this.stringToObjects(responseData.value.fixedFields || '')
  3735. } else {
  3736. let fixedFields = this.contentEditForm.fixedTable.tableHeaders
  3737. .map((item) => item.fieldName)
  3738. .join(',')
  3739. this.contentEditForm.fixedTable.fixedTablesTitle =
  3740. this.stringToObjects(fixedFields || '')
  3741. }
  3742. const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
  3743. this.contentEditForm.fixedTable.fixedTableHeaders = fixedTitles.filter(
  3744. (title) => title.rkey !== '序号'
  3745. )
  3746. if (
  3747. !responseData ||
  3748. !responseData.value ||
  3749. !responseData.value.itemlist
  3750. ) {
  3751. return
  3752. }
  3753. const itemList = responseData.value.itemlist
  3754. const allRows = []
  3755. const rowMap = new Map()
  3756. // 清空现有数据
  3757. this.contentEditForm.fixedTable.fixedTables = []
  3758. // 遍历itemList,为每个项目创建一行数据
  3759. itemList.forEach((item, index) => {
  3760. // 判断是否为子项(parentid不为-1且不为"-1")
  3761. const isSubItem =
  3762. item.parentid && item.parentid !== -1 && item.parentid !== '-1'
  3763. const newRow = {
  3764. orderText: item.orderNum || '', // 显示用序号
  3765. orderNum: item.orderNum || '', // 保留原始序号用于发送后端
  3766. surveyTemplateId: item.surveyTemplateId,
  3767. versionId: item.versionId,
  3768. cellCode: item.cellCode || '',
  3769. calculationFormula: item.calculationFormula || '',
  3770. unit: item.unit || '',
  3771. fixedValues: {},
  3772. itemId: item.id || null,
  3773. parentid: item.parentid || -1,
  3774. isChild: isSubItem,
  3775. isSubItem: isSubItem,
  3776. rowid: item.rowid || this.generateUUID(),
  3777. jsonstr: item.jsonstr || null,
  3778. children: [], // 添加children数组用于树形结构
  3779. }
  3780. // 确保orderNum是数字类型
  3781. if (item.orderNum) {
  3782. newRow.orderNum = parseInt(item.orderNum, 10) || 0
  3783. }
  3784. // 初始化fixedValues并填充实际值
  3785. fixedTitles.forEach((title) => {
  3786. newRow.fixedValues[title.rkey] = item[title.rkey] || ''
  3787. })
  3788. allRows.push(newRow)
  3789. // 构建rowMap用于快速查找
  3790. if (newRow.rowid) rowMap.set(String(newRow.rowid), newRow)
  3791. if (newRow.itemId) rowMap.set(String(newRow.itemId), newRow)
  3792. })
  3793. // 构建树形结构
  3794. const treeData = []
  3795. const parentItems = allRows.filter((item) => !item.isChild)
  3796. // 父级按orderNum正序排序
  3797. parentItems.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
  3798. // 将子项添加到对应的父项的children中
  3799. allRows.forEach((item) => {
  3800. if (item.isChild) {
  3801. const parentId = String(item.parentid)
  3802. const parent = rowMap.get(parentId)
  3803. if (parent) {
  3804. parent.children.push(item)
  3805. }
  3806. }
  3807. })
  3808. // 对子项进行排序
  3809. parentItems.forEach((parent) => {
  3810. parent.children.sort(
  3811. (a, b) =>
  3812. (a.fixedValues['序号'] || 0) - (b.fixedValues['序号'] || 0)
  3813. )
  3814. treeData.push(parent)
  3815. })
  3816. this.contentEditForm.fixedTable.fixedTables = treeData
  3817. },
  3818. /**
  3819. * 解析并回显动态表项目数据
  3820. * @param {Object} responseData - listByTemplateIdAndVersion接口返回的数据
  3821. */
  3822. parseAndDisplayDynamicTableData(responseData) {
  3823. if (responseData.value.fixedFields) {
  3824. this.contentEditForm.dynamicTable.dynamicTablesTitle =
  3825. this.stringToObjects(responseData.value.fixedFields || '')
  3826. } else {
  3827. let fixedFields = this.contentEditForm.dynamicTable.tableHeaders
  3828. .map((item) => item.fieldName)
  3829. .join(',')
  3830. this.contentEditForm.dynamicTable.dynamicTablesTitle =
  3831. this.stringToObjects(fixedFields || '')
  3832. }
  3833. const dynamicTitles =
  3834. this.contentEditForm.dynamicTable.dynamicTablesTitle
  3835. this.contentEditForm.dynamicTable.dynamicTableHeaders =
  3836. dynamicTitles.filter((title) => title.rkey !== '序号')
  3837. if (
  3838. !responseData ||
  3839. !responseData.value ||
  3840. !responseData.value.itemlist
  3841. ) {
  3842. return
  3843. }
  3844. const itemList = responseData.value.itemlist
  3845. const allRows = []
  3846. const rowMap = new Map()
  3847. // 清空现有数据
  3848. this.contentEditForm.dynamicTable.dynamicTables = []
  3849. // 遍历itemList,为每个项目创建一行数据
  3850. itemList.forEach((item, index) => {
  3851. // 判断是否为子项(parentid不为-1且不为"-1")
  3852. const isSubItem =
  3853. item.parentid && item.parentid !== -1 && item.parentid !== '-1'
  3854. const newRow = {
  3855. orderText: item.orderNum || '', // 显示用序号
  3856. orderNum: item.orderNum || '', // 保留原始序号用于发送后端
  3857. surveyTemplateId: item.surveyTemplateId,
  3858. dynamicValues: {},
  3859. itemId: item.id || null,
  3860. parentid: item.parentid || -1,
  3861. isChild: isSubItem,
  3862. isSubItem: isSubItem,
  3863. rowid: item.rowid || this.generateUUID(),
  3864. jsonstr: item.jsonstr || null,
  3865. children: [], // 添加children数组用于树形结构
  3866. }
  3867. // 确保orderNum是数字类型
  3868. if (item.orderNum) {
  3869. newRow.orderNum = parseInt(item.orderNum, 10) || 0
  3870. }
  3871. // 初始化dynamicValues并填充实际值
  3872. dynamicTitles.forEach((title) => {
  3873. // 特殊处理序号字段,需要保存到dynamicValues中供输入框使用
  3874. if (title.rkey === '序号') {
  3875. // 优先使用item中的序号值,如果没有则保持为空
  3876. newRow.dynamicValues[title.rkey] = item[title.rkey] || ''
  3877. }
  3878. // 排除其他序号相关字段,避免重复显示
  3879. else if (title.rkey !== 'ordernum' && title.rkey !== 'orderText') {
  3880. newRow.dynamicValues[title.rkey] = item[title.rkey] || ''
  3881. }
  3882. })
  3883. allRows.push(newRow)
  3884. // 构建rowMap用于快速查找
  3885. if (newRow.rowid) rowMap.set(String(newRow.rowid), newRow)
  3886. if (newRow.itemId) rowMap.set(String(newRow.itemId), newRow)
  3887. })
  3888. // 构建树形结构
  3889. const treeData = []
  3890. const parentItems = allRows.filter((item) => !item.isChild)
  3891. // 父级按orderNum正序排序
  3892. parentItems.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
  3893. // 将子项添加到对应的父项的children中
  3894. allRows.forEach((item) => {
  3895. if (item.isChild) {
  3896. const parentId = String(item.parentid)
  3897. const parent = rowMap.get(parentId)
  3898. if (parent) {
  3899. parent.children.push(item)
  3900. }
  3901. }
  3902. })
  3903. // 对子项进行排序
  3904. parentItems.forEach((parent) => {
  3905. parent.children.sort(
  3906. (a, b) =>
  3907. (Number(a.dynamicValues['序号']) || 0) -
  3908. (Number(b.dynamicValues['序号']) || 0)
  3909. )
  3910. treeData.push(parent)
  3911. })
  3912. this.contentEditForm.dynamicTable.dynamicTables = treeData
  3913. console.log('树形结构数据:', treeData)
  3914. },
  3915. //分割字符串
  3916. stringToObjects(str) {
  3917. const items = str.split(',')
  3918. return items.map((item) => ({
  3919. rkey: item,
  3920. rvalue: '',
  3921. }))
  3922. },
  3923. // 删除
  3924. handleDelete(row) {
  3925. this.$confirm('确定要删除该数据吗?', '提示', {
  3926. type: 'warning',
  3927. })
  3928. .then(() => {
  3929. this.loading = true
  3930. delSurveyTemplateVersionById(row.id)
  3931. .then((res) => {
  3932. if (res.code === 200) {
  3933. this.$message.success(res.message || '删除成功')
  3934. this.handleSearch()
  3935. this.loading = false
  3936. }
  3937. })
  3938. .catch((error) => {
  3939. console.error('删除失败:', error)
  3940. this.loading = false
  3941. })
  3942. })
  3943. .catch(() => {})
  3944. },
  3945. // 批量删除
  3946. handleBatchDelete() {
  3947. if (this.selectedRows.length === 0) {
  3948. this.$message.warning('请先选择要删除的数据')
  3949. return
  3950. }
  3951. this.$confirm(
  3952. `确定要删除选中的${this.selectedRows.length}条数据吗?`,
  3953. '提示',
  3954. {
  3955. type: 'warning',
  3956. }
  3957. )
  3958. .then(() => {
  3959. this.loading = true
  3960. const ids = this.selectedRows.map((row) => row.id)
  3961. batchDeleteCostForm(ids)
  3962. .then((res) => {
  3963. this.selectedRows = []
  3964. this.$message.success(res.message || '删除成功')
  3965. this.handleSearch()
  3966. this.loading = false
  3967. })
  3968. .catch((error) => {
  3969. console.error('批量删除失败:', error)
  3970. this.loading = false
  3971. })
  3972. })
  3973. .catch(() => {})
  3974. },
  3975. // 表格选择
  3976. handleSelectionChange(selection) {
  3977. this.selectedRows = selection
  3978. },
  3979. // 分页变化处理
  3980. handlePaginationChange({ currentPage, pageSize }) {
  3981. this.pagination.currentPage = currentPage
  3982. this.pagination.pageSize = pageSize
  3983. this.handleSearch()
  3984. },
  3985. // 提交表单
  3986. submitForm() {
  3987. this.$refs.dataForm.validate((valid) => {
  3988. if (valid) {
  3989. this.loading = true
  3990. const submitData = {
  3991. versionNo: this.dataForm.version,
  3992. status: this.dataForm.status,
  3993. createBy: this.dataForm.createBy,
  3994. createTime: this.dataForm.createTime,
  3995. remarks: this.dataForm.remarks,
  3996. templateType: this.currentRow.templateType,
  3997. surveyTemplateName: this.currentRow.surveyTemplateName,
  3998. surveyTemplateId: this.currentRow.surveyTemplateId,
  3999. }
  4000. if (this.dataForm.id) {
  4001. // 修改
  4002. submitData.formId = this.dataForm.id
  4003. editCostForm(submitData)
  4004. .then(() => {
  4005. this.loading = false
  4006. this.$message.success('修改成功')
  4007. this.dialogVisible = false
  4008. this.handleSearch() // 重新加载数据
  4009. })
  4010. .catch((error) => {
  4011. console.error('修改失败:', error)
  4012. // this.$message.error('修改失败,请重试')
  4013. this.loading = false
  4014. })
  4015. } else {
  4016. addSurveyTemplateVersion(submitData)
  4017. .then(() => {
  4018. this.loading = false
  4019. this.$message.success('添加成功')
  4020. this.dialogVisible = false
  4021. this.handleSearch() // 重新加载数据
  4022. })
  4023. .catch((error) => {
  4024. console.error('添加失败:', error)
  4025. // this.$message.error('添加失败,请重试')
  4026. this.loading = false
  4027. })
  4028. }
  4029. }
  4030. })
  4031. },
  4032. // 获取数据存储库表选项
  4033. loadDataStorageTableOptions() {
  4034. getDataStorageTableOptions()
  4035. .then((response) => {
  4036. this.dataStorageTableOptions = response.data || []
  4037. })
  4038. .catch((error) => {
  4039. console.error('获取数据存储库表选项失败:', error)
  4040. })
  4041. },
  4042. },
  4043. }
  4044. </script>
  4045. <style lang="scss" scoped>
  4046. @import '@/styles/costAudit.scss';
  4047. .top-wrapper {
  4048. display: flex;
  4049. align-items: center;
  4050. }
  4051. .data-form,
  4052. .detail-form {
  4053. ::v-deep .el-select {
  4054. width: 100%;
  4055. }
  4056. }
  4057. .content-edit-container {
  4058. overflow-y: auto;
  4059. .button-group {
  4060. margin: 10px 0;
  4061. .el-button {
  4062. margin-right: 10px;
  4063. }
  4064. }
  4065. .table-edit-container {
  4066. margin-top: 10px;
  4067. ::v-deep .el-table {
  4068. transition: height 0.3s ease;
  4069. }
  4070. ::v-deep .el-table__body-wrapper {
  4071. transition: scrollTop 0.3s ease;
  4072. }
  4073. }
  4074. .bind-dict-column {
  4075. display: flex;
  4076. flex-direction: column;
  4077. }
  4078. .table-actions {
  4079. display: flex;
  4080. justify-content: center;
  4081. align-items: center;
  4082. .el-button {
  4083. padding: 4px;
  4084. margin: 0 2px;
  4085. }
  4086. }
  4087. .format-input {
  4088. display: flex;
  4089. align-items: center;
  4090. .format-prefix {
  4091. font-size: 12px;
  4092. color: #606266;
  4093. margin-right: 5px;
  4094. white-space: nowrap;
  4095. }
  4096. }
  4097. }
  4098. .detail-info-container {
  4099. margin: 20px 0;
  4100. border-radius: 4px;
  4101. .detail-item {
  4102. display: inline-block;
  4103. margin-right: 30px;
  4104. margin-bottom: 10px;
  4105. .detail-label {
  4106. font-weight: bold;
  4107. color: #606266;
  4108. }
  4109. .detail-value {
  4110. color: #303133;
  4111. }
  4112. }
  4113. }
  4114. </style>