infoMaintain.vue 150 KB

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