| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368 |
- <template>
- <div>
- <div class="top-wrapper">
- <el-button plain type="primary" icon="el-icon-back" @click="handleBack">
- 返回
- </el-button>
- <div class="title ml20">{{ surveyTemplateName }}内容维护</div>
- </div>
- <!-- 搜索面板 -->
- <div class="search-panel mt20">
- <el-form :inline="true" :model="searchForm" label-width="80px">
- <el-form-item label="状态:">
- <el-select
- v-model="searchForm.status"
- placeholder="请选择状态"
- style="width: 180px"
- >
- <el-option label="全部" value=""></el-option>
- <el-option label="草稿" value="-1"></el-option>
- <el-option label="现行版本" value="0"></el-option>
- <el-option label="历史版本" value="1"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" icon="el-icon-search" @click="handleSearch">
- 查询
- </el-button>
- <el-button
- plain
- type="primary"
- icon="el-icon-refresh"
- @click="handleReset"
- >
- 重置
- </el-button>
- </el-form-item>
- </el-form>
- </div>
- <!-- 操作栏 -->
- <div class="operation-bar">
- <el-button
- v-region-permission="{ category: 'costFormManage', action: 'add' }"
- plain
- type="success"
- icon="el-icon-circle-plus"
- @click="handleAdd"
- >
- 添加
- </el-button>
- <el-button
- v-region-permission="{
- category: 'costFormManage',
- action: 'delete',
- }"
- plain
- type="danger"
- icon="el-icon-delete"
- :disabled="selectedRows.length === 0"
- @click="handleBatchDelete"
- >
- 批量删除
- </el-button>
- </div>
- <!-- 表格 -->
- <div class="table-container">
- <CostAuditTable
- ref="costAuditTable"
- :table-data="tableData"
- :columns="tableColumns"
- :show-selection="true"
- :show-index="true"
- :show-pagination="true"
- :pagination="pagination"
- :loading="loading"
- @selection-change="handleSelectionChange"
- @pagination-change="handlePaginationChange"
- >
- <!-- 创建时间自定义单元格 -->
- <template #createTime="{ row }">
- <div>{{ row.createTime ? row.createTime.split(' ')[0] : '-' }}</div>
- <div>{{ row.createTime ? row.createTime.split(' ')[1] : '-' }}</div>
- </template>
- <!-- 操作列 -->
- <template #action="{ row }">
- <el-button
- v-region-permission="{
- category: 'costFormManage',
- action: 'view',
- }"
- type="text"
- size="small"
- @click="handleViewDetail(row)"
- >
- 详情
- </el-button>
- <el-button
- v-if="row.status === '-1'"
- v-region-permission="{
- category: 'costFormManage',
- action: 'edit',
- }"
- type="text"
- size="small"
- @click="handleEdit(row)"
- >
- 修改
- </el-button>
- <el-button
- v-if="row.status != '0'"
- v-region-permission="{
- category: 'costFormManage',
- action: 'delete',
- targetData: row,
- }"
- class="delete-btn"
- type="text"
- size="small"
- @click="handleDelete(row)"
- >
- 删除
- </el-button>
- <el-button
- v-if="row.status === '-1'"
- v-region-permission="{
- category: 'costFormManage',
- action: 'edit',
- }"
- type="text"
- size="small"
- @click="handleEditContent(row)"
- >
- 内容维护
- </el-button>
- <el-button
- v-if="row.status === '-1'"
- v-region-permission="{
- category: 'costFormManage',
- action: 'edit',
- }"
- type="text"
- size="small"
- @click="handleStatus(row)"
- >
- 启用
- </el-button>
- <el-button
- v-if="row.status === '0'"
- v-region-permission="{
- category: 'costFormManage',
- action: 'edit',
- }"
- type="text"
- size="small"
- @click="handleStatus(row)"
- >
- 停用
- </el-button>
- </template>
- </CostAuditTable>
- </div>
- <!-- 详情弹窗 -->
- <el-dialog title="详情" :visible.sync="detailDialogVisible" width="800px">
- <el-form :model="detailForm" label-width="120px" class="detail-form">
- <el-form-item label="ID:">{{ detailForm.id }}</el-form-item>
- <el-form-item label="版本号:">{{ detailForm.versionNo }}</el-form-item>
- <el-form-item label="状态:">
- {{ forStatus(detailForm.status) }}
- </el-form-item>
- <el-form-item label="创建人:">{{ detailForm.createBy }}</el-form-item>
- <el-form-item label="创建时间:">
- {{ detailForm.createTime }}
- </el-form-item>
- <el-form-item label="备注:">{{ detailForm.remarks }}</el-form-item>
- </el-form>
- <div slot="footer">
- <el-button @click="detailDialogVisible = false">关闭</el-button>
- </div>
- </el-dialog>
- <!-- 添加/修改弹窗 -->
- <el-dialog
- :title="dialogTitle"
- :visible.sync="dialogVisible"
- width="600px"
- :close-on-click-modal="false"
- >
- <el-form
- ref="dataForm"
- :model="dataForm"
- :rules="dataFormRules"
- label-width="120px"
- class="data-form"
- >
- <el-form-item label="创建人" prop="createBy">
- <el-input
- v-model="dataForm.createBy"
- placeholder="请输入创建人"
- ></el-input>
- </el-form-item>
- <el-form-item label="创建时间" prop="createTime">
- <el-date-picker
- v-model="dataForm.createTime"
- type="datetime"
- placeholder="选择日期时间"
- style="width: 100%"
- ></el-date-picker>
- </el-form-item>
- <el-form-item label="备注">
- <el-input
- v-model="dataForm.remarks"
- type="textarea"
- placeholder="请输入备注"
- rows="3"
- ></el-input>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="dialogVisible = false">取消</el-button>
- <el-button type="primary" @click="submitForm">确定</el-button>
- </div>
- </el-dialog>
- <!-- 内容修改弹窗 -->
- <el-dialog
- title="内容维护"
- :visible.sync="contentEditDialogVisible"
- width="75%"
- class="content-edit-dialog"
- :close-on-click-modal="false"
- >
- <div class="content-edit-container">
- <div class="table-header-info">
- <div class="table-name">
- 调查表名称:{{ contentEditForm.tableName }}
- </div>
- <div class="table-style">
- 表单样式:
- <el-radio-group
- v-model="contentEditForm.templateType"
- @change="handleFormStyleChange"
- >
- <el-radio v-if="contentEditForm.templateType === '1'" label="1">
- 单记录
- </el-radio>
- <el-radio v-if="contentEditForm.templateType === '2'" label="2">
- 固定表
- </el-radio>
- <el-radio v-if="contentEditForm.templateType === '3'" label="3">
- 动态表
- </el-radio>
- </el-radio-group>
- </div>
- <div v-if="viewDetail" class="detail-info-container">
- <div class="detail-item">
- <span class="detail-label">版本号:</span>
- <span class="detail-value">{{ detailForm.versionNo }}</span>
- </div>
- <div class="detail-item">
- <span class="detail-label">状态:</span>
- <span class="detail-value">
- {{ forStatus(detailForm.status) }}
- </span>
- </div>
- <div class="detail-item">
- <span class="detail-label">创建人:</span>
- <span class="detail-value">{{ detailForm.createBy }}</span>
- </div>
- <div class="detail-item">
- <span class="detail-label">创建时间:</span>
- <span class="detail-value">{{ detailForm.createTime }}</span>
- </div>
- <div class="detail-item">
- <span class="detail-label">备注:</span>
- <span class="detail-value">{{ detailForm.remarks }}</span>
- </div>
- </div>
- </div>
- <!-- 单记录列表 -->
- <div v-if="contentEditForm.templateType === '1'">
- <div class="button-group">
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleAddTableHeader('单记录')"
- >
- 添加项目
- </el-button>
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleSaveContent('单记录')"
- >
- 保存
- </el-button>
- </div>
- <div class="table-edit-container">
- <el-table
- :data="contentEditForm.tableHeaders"
- border
- style="width: 100%"
- >
- <el-table-column label="序号" width="80" align="center">
- <template slot-scope="scope">
- <span>{{ scope.$index + 1 }}</span>
- </template>
- </el-table-column>
- <el-table-column
- prop="fieldName"
- label="字段名称"
- min-width="150"
- >
- <template slot-scope="scope">
- <el-input
- v-model="scope.row.fieldName"
- placeholder="请输入字段名称"
- size="small"
- :disabled="viewDetail"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="fieldType" label="字段类型" width="220">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.fieldType"
- placeholder="请选择字段类型"
- size="small"
- :disabled="viewDetail"
- @change="handleFieldTypeChange(scope.row)"
- >
- <el-option label="字符串" value="string"></el-option>
- <el-option label="整数" value="integer"></el-option>
- <el-option label="小数" value="double"></el-option>
- <el-option label="日期" value="datetime"></el-option>
- <el-option label="布尔值" value="boolean"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="format" label="格式" width="220">
- <template slot-scope="scope">
- <!-- 字符串类型格式 -->
- <div
- v-if="scope.row.fieldType === 'string'"
- class="format-input"
- >
- <span class="format-prefix">长度</span>
- <el-input
- v-model="scope.row.format"
- placeholder="请输入长度"
- size="small"
- style="width: calc(100% - 80px)"
- :disabled="viewDetail"
- ></el-input>
- </div>
- <!-- 整数类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'integer'"
- class="format-input"
- >
- <span class="format-prefix">整数</span>
- <el-input
- v-model="scope.row.fieldTypelen"
- placeholder="整数位数"
- size="small"
- style="width: 80px; margin: 0 5px"
- :disabled="viewDetail"
- ></el-input>
- </div>
- <!-- 小数类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'double'"
- class="format-input"
- >
- <span class="format-prefix">小数</span>
- <el-input
- v-model="scope.row.fieldTypenointlen"
- placeholder="小数位数"
- size="small"
- style="width: 80px; margin-left: 5px"
- :disabled="viewDetail"
- ></el-input>
- </div>
- <!-- 日期类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'datetime'"
- class="format-input"
- >
- <el-select
- v-model="scope.row.format"
- placeholder="请选择日期格式"
- size="small"
- style="width: 100%"
- :disabled="viewDetail"
- >
- <el-option
- label="yyyy-MM-dd HH:mm:ss"
- value="yyyy-MM-dd HH:mm:ss"
- ></el-option>
- <el-option
- label="yyyy-MM-dd"
- value="yyyy-MM-dd"
- ></el-option>
- </el-select>
- </div>
- <!-- 布尔类型格式 -->
- <div v-else-if="scope.row.fieldType === 'boolean'">
- <el-select
- v-model="scope.row.format"
- placeholder="请选择布尔值格式"
- size="small"
- style="width: 100%"
- :disabled="viewDetail"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- </div>
- <!-- 默认情况 -->
- <el-input
- v-else
- v-model="scope.row.format"
- :placeholder="getFormatPlaceholder(scope.row.fieldType)"
- size="small"
- :disabled="viewDetail"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="isRequired" label="是否必填" width="120">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.isRequired"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="showVisible" label="是否显示" width="120">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.showVisible"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="1"></el-option>
- <el-option label="否" value="0"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="isDict" label="绑定字典" min-width="150">
- <template slot-scope="scope">
- <div class="bind-dict-column">
- <el-select
- v-model="scope.row.isDict"
- size="small"
- style="width: 80px"
- :disabled="scope.row.isDisabled || viewDetail"
- @change="handleBindDictChange(scope.row)"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- <el-select
- v-if="scope.row.isDict === 'true'"
- v-model="scope.row.dictid"
- placeholder="请选择字典"
- class="dict-select"
- size="small"
- style="width: 120px; margin-top: 5px"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option
- v-for="(item, index) in dictTypeList"
- :key="index"
- :label="item.name"
- :value="String(item.id)"
- ></el-option>
- </el-select>
- </div>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="150" fixed="right">
- <template slot-scope="scope">
- <div class="table-actions">
- <el-button
- type="text"
- size="mini"
- :disabled="viewDetail"
- class="delete-btn"
- @click="
- handleDeleteHeader(scope.$index, '单记录', scope.row)
- "
- >
- 删除
- </el-button>
- <el-button
- v-if="scope.$index !== 0"
- type="text"
- size="mini"
- :disabled="viewDetail"
- @click="
- handleMoveUp(scope.$index, '单记录表头', scope.row)
- "
- >
- 上升
- </el-button>
- <el-button
- v-if="
- scope.$index !== contentEditForm.tableHeaders.length - 1
- "
- type="text"
- size="mini"
- :disabled="viewDetail"
- @click="handleMoveDown(scope.$index)"
- >
- 下降
- </el-button>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </div>
- <!-- 固定表时显示 -->
- <div v-if="contentEditForm.templateType === '2'">
- <div class="button-group">
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleAddTableHeader('固定表表头')"
- >
- 添加表头
- </el-button>
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleSaveContent('固定表表头')"
- >
- 下一步
- </el-button>
- </div>
- <div class="table-edit-container">
- <el-table
- :data="contentEditForm.fixedTable.tableHeaders"
- border
- style="width: 100%"
- >
- <el-table-column label="序号" width="80" align="center">
- <template slot-scope="scope">
- <span>{{ scope.$index + 1 }}</span>
- </template>
- </el-table-column>
- <el-table-column
- prop="fieldName"
- label="字段名称"
- min-width="150"
- >
- <template slot-scope="scope">
- <el-input
- v-model="scope.row.fieldName"
- placeholder="请输入字段名称"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="fieldType" label="字段类型" width="120">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.fieldType"
- placeholder="请选择字段类型"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- @change="handleFieldTypeChange(scope.row)"
- >
- <el-option label="字符串" value="string"></el-option>
- <el-option label="整数" value="integer"></el-option>
- <el-option label="小数" value="double"></el-option>
- <el-option label="日期" value="datetime"></el-option>
- <el-option label="布尔值" value="boolean"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="format" label="格式" width="220">
- <template slot-scope="scope">
- <!-- 字符串类型格式 -->
- <div
- v-if="scope.row.fieldType === 'string'"
- class="format-input"
- >
- <span class="format-prefix">长度</span>
- <el-input
- v-model="scope.row.format"
- placeholder="请输入长度"
- size="small"
- style="width: calc(100% - 80px)"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </div>
- <!-- 整数类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'integer'"
- class="format-input"
- >
- <span class="format-prefix">整数</span>
- <el-input
- v-model="scope.row.fieldTypelen"
- placeholder="整数位数"
- size="small"
- style="width: 80px; margin: 0 5px"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </div>
- <!-- 小数类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'double'"
- class="format-input"
- >
- <span class="format-prefix">小数</span>
- <el-input
- v-model="scope.row.fieldTypenointlen"
- placeholder="小数位数"
- size="small"
- style="width: 80px; margin-left: 5px"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </div>
- <!-- 日期类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'datetime'"
- class="format-input"
- >
- <el-select
- v-model="scope.row.format"
- placeholder="请选择日期格式"
- size="small"
- style="width: 100%"
- :disabled="scope.row.isDisabled"
- >
- <el-option
- label="yyyy-MM-dd HH:mm:ss"
- value="yyyy-MM-dd HH:mm:ss"
- ></el-option>
- <el-option
- label="yyyy-MM-dd"
- value="yyyy-MM-dd"
- ></el-option>
- </el-select>
- </div>
- <!-- 布尔类型格式 -->
- <div v-else-if="scope.row.fieldType === 'boolean'">
- <el-select
- v-model="scope.row.format"
- placeholder="请选择布尔值格式"
- size="small"
- style="width: 100%"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- </div>
- <!-- 默认情况 -->
- <el-input
- v-else
- v-model="scope.row.format"
- :placeholder="getFormatPlaceholder(scope.row.fieldType)"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="isRequired" label="是否必填" width="120">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.isRequired"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="showVisible" label="是否显示" width="120">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.showVisible"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="1"></el-option>
- <el-option label="否" value="0"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column
- prop="isAuditPeriod"
- label="是否绑定监审期间"
- width="140"
- >
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.isAuditPeriod"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="isDict" label="绑定字典" min-width="150">
- <template slot-scope="scope">
- <div class="bind-dict-column">
- <el-select
- v-model="scope.row.isDict"
- size="small"
- style="width: 80px"
- :disabled="scope.row.isDisabled || viewDetail"
- @change="handleBindDictChange(scope.row)"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- <el-select
- v-if="scope.row.isDict === 'true'"
- v-model="scope.row.dictid"
- placeholder="请选择字典"
- class="dict-select"
- size="small"
- style="width: 120px; margin-top: 5px"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option
- v-for="(item, index) in dictTypeList"
- :key="index"
- :label="item.name"
- :value="String(item.id)"
- ></el-option>
- </el-select>
- </div>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="150" fixed="right">
- <template slot-scope="scope">
- <div class="table-actions">
- <el-button
- type="text"
- size="mini"
- :disabled="scope.row.isDisabled || viewDetail"
- class="delete-btn"
- @click="
- handleDeleteHeader(
- scope.$index,
- '固定表表头',
- scope.row
- )
- "
- >
- 删除
- </el-button>
- <el-button
- v-if="scope.$index !== 0"
- type="text"
- size="mini"
- :disabled="scope.row.isDisabled || viewDetail"
- @click="
- handleMoveUp(scope.$index, '固定表表头', scope.row)
- "
- >
- 上升
- </el-button>
- <el-button
- v-if="
- scope.$index !== contentEditForm.tableHeaders.length - 1
- "
- type="text"
- size="mini"
- :disabled="scope.row.isDisabled || viewDetail"
- @click="handleMoveDown(scope.$index)"
- >
- 下降
- </el-button>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div>
- <div class="button-group">
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleAddTableHeader('固定表项目')"
- >
- 添加项目
- </el-button>
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleSaveContent('固定表项目')"
- >
- 保存
- </el-button>
- </div>
- <div class="table-edit-container">
- <el-table
- :data="contentEditForm.fixedTable.fixedTables"
- border
- style="width: 100%"
- row-key="rowid"
- default-expand-all
- :tree-props="{
- children: 'children',
- hasChildren: 'hasChildren',
- }"
- @selection-change="handleSelectionChange"
- >
- <el-table-column label="父子节点" align="center" width="100">
- <template slot-scope="scope">
- <el-tag
- v-if="
- scope.row.isChild ||
- scope.row.isSubItem ||
- (scope.row.parentid &&
- scope.row.parentid != -1 &&
- scope.row.parentid != '-1')
- "
- type="success"
- size="small"
- >
- 子项
- </el-tag>
- <el-tag
- v-else-if="
- scope.row.parentid === -1 ||
- scope.row.parentid === '-1' ||
- !scope.row.parentid
- "
- type="primary"
- size="small"
- >
- 父项
- </el-tag>
- <el-tag v-else type="info" size="small">无</el-tag>
- </template>
- </el-table-column>
- <el-table-column label="序号" width="120" align="center">
- <template slot-scope="scope">
- <el-input
- :value="
- scope.row.fixedValues
- ? scope.row.fixedValues['序号']
- : ''
- "
- size="small"
- placeholder="数字或中文"
- :disabled="viewDetail"
- style="flex: 1; margin: 0"
- @input="handleFixedValueChange(scope.row, '序号', $event)"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- v-for="(item, index) in contentEditForm.fixedTable
- .fixedTableHeaders"
- :key="index"
- :label="item.rkey"
- align="center"
- >
- <template slot-scope="scope">
- <el-input
- :value="
- scope.row.fixedValues
- ? scope.row.fixedValues[item.rkey]
- : ''
- "
- size="small"
- :disabled="viewDetail"
- @input="
- handleFixedValueChange(scope.row, item.rkey, $event)
- "
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column label="指标编号" width="100" align="center">
- <template slot-scope="scope">
- <el-input
- :value="scope.row.cellCode"
- size="small"
- :disabled="viewDetail"
- @input="(val) => $set(scope.row, 'cellCode', val)"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column label="计算公式" width="100" align="center">
- <template slot-scope="scope">
- <el-input
- v-model="scope.row.calculationFormula"
- size="small"
- readonly
- :disabled="viewDetail"
- @click.native="
- openCalculationFormulaDialogVisible(
- scope.row,
- scope.$index
- )
- "
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column label="单位" width="100" align="center">
- <template slot-scope="scope">
- <el-input
- :value="scope.row.unit"
- size="small"
- :disabled="viewDetail"
- @input="(val) => $set(scope.row, 'unit', val)"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column label="操作" align="center" fixed="right">
- <template slot-scope="scope">
- <div class="table-actions">
- <el-button
- v-if="!scope.row.isChild"
- type="text"
- size="mini"
- :disabled="viewDetail"
- @click="
- handleAddChildItem(
- scope.$index,
- '固定表项目',
- scope.row
- )
- "
- >
- 添加子项
- </el-button>
- <el-button
- type="text"
- size="mini"
- :disabled="viewDetail"
- class="delete-btn"
- @click="
- handleDeleteHeader(
- scope.$index,
- '固定表项目',
- scope.row
- )
- "
- >
- 删除
- </el-button>
- <el-button
- v-if="scope.$index !== 0"
- type="text"
- size="mini"
- :disabled="viewDetail"
- @click="handleMoveUp(scope.$index, '固定表', scope.row)"
- >
- 上升
- </el-button>
- <el-button
- v-if="
- scope.$index !==
- contentEditForm.fixedTable.fixedTables.length - 1
- "
- type="text"
- size="mini"
- :disabled="viewDetail"
- @click="
- handleMoveDown(scope.$index, '固定表', scope.row)
- "
- >
- 下降
- </el-button>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </div>
- </div>
- <!-- 动态表时显示 -->
- <div v-if="contentEditForm.templateType === '3'">
- <div class="button-group">
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleAddTableHeader('动态表表头')"
- >
- 添加表头
- </el-button>
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleSaveContent('动态表表头')"
- >
- 下一步
- </el-button>
- </div>
- <div class="table-edit-container">
- <el-table
- :data="contentEditForm.dynamicTable.tableHeaders"
- border
- style="width: 100%"
- >
- <el-table-column label="序号" width="80" align="center">
- <template slot-scope="scope">
- <span>{{ scope.$index + 1 }}</span>
- </template>
- </el-table-column>
- <el-table-column
- prop="fieldName"
- label="字段名称"
- min-width="150"
- >
- <template slot-scope="scope">
- <el-input
- v-model="scope.row.fieldName"
- placeholder="请输入字段名称"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="fieldType" label="字段类型" width="120">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.fieldType"
- placeholder="请选择字段类型"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- @change="handleFieldTypeChange(scope.row)"
- >
- <el-option label="字符串" value="string"></el-option>
- <el-option label="整数" value="integer"></el-option>
- <el-option label="小数" value="double"></el-option>
- <el-option label="日期" value="datetime"></el-option>
- <el-option label="布尔值" value="boolean"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="format" label="格式" width="220">
- <template slot-scope="scope">
- <!-- 字符串类型格式 -->
- <div
- v-if="scope.row.fieldType === 'string'"
- class="format-input"
- >
- <span class="format-prefix">长度</span>
- <el-input
- v-model="scope.row.format"
- placeholder="请输入长度"
- size="small"
- style="width: calc(100% - 80px)"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </div>
- <!-- 整数类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'integer'"
- class="format-input"
- >
- <span class="format-prefix">整数</span>
- <el-input
- v-model="scope.row.fieldTypelen"
- placeholder="整数位数"
- size="small"
- style="width: 80px; margin: 0 5px"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </div>
- <!-- 小数类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'double'"
- class="format-input"
- >
- <span class="format-prefix">小数</span>
- <el-input
- v-model="scope.row.fieldTypenointlen"
- placeholder="小数位数"
- size="small"
- style="width: 80px; margin-left: 5px"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </div>
- <!-- 日期类型格式 -->
- <div
- v-else-if="scope.row.fieldType === 'datetime'"
- class="format-input"
- >
- <el-select
- v-model="scope.row.format"
- placeholder="请选择日期格式"
- size="small"
- style="width: 100%"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option
- label="yyyy-MM-dd HH:mm:ss"
- value="yyyy-MM-dd HH:mm:ss"
- ></el-option>
- <el-option
- label="yyyy-MM-dd"
- value="yyyy-MM-dd"
- ></el-option>
- </el-select>
- </div>
- <!-- 布尔类型格式 -->
- <div v-else-if="scope.row.fieldType === 'boolean'">
- <el-select
- v-model="scope.row.format"
- placeholder="请选择布尔值格式"
- size="small"
- style="width: 100%"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- </div>
- <!-- 默认情况 -->
- <el-input
- v-else
- v-model="scope.row.format"
- :placeholder="getFormatPlaceholder(scope.row.fieldType)"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="isRequired" label="是否必填" width="120">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.isRequired"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="showVisible" label="是否显示" width="120">
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.showVisible"
- size="small"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option label="是" value="1"></el-option>
- <el-option label="否" value="0"></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="isDict" label="绑定字典" min-width="150">
- <template slot-scope="scope">
- <div class="bind-dict-column">
- <el-select
- v-model="scope.row.isDict"
- size="small"
- style="width: 80px"
- :disabled="scope.row.isDisabled || viewDetail"
- @change="handleBindDictChange(scope.row)"
- >
- <el-option label="是" value="true"></el-option>
- <el-option label="否" value="false"></el-option>
- </el-select>
- <el-select
- v-if="scope.row.isDict === 'true'"
- v-model="scope.row.dictid"
- placeholder="请选择字典"
- class="dict-select"
- size="small"
- style="width: 120px; margin-top: 5px"
- :disabled="scope.row.isDisabled || viewDetail"
- >
- <el-option
- v-for="(item, index) in dictTypeList"
- :key="index"
- :label="item.name"
- :value="String(item.id)"
- ></el-option>
- </el-select>
- </div>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="150" fixed="right">
- <template slot-scope="scope">
- <div class="table-actions">
- <el-button
- type="text"
- size="mini"
- :disabled="scope.row.isDisabled || viewDetail"
- class="delete-btn"
- @click="
- handleDeleteHeader(
- scope.$index,
- '动态表表头',
- scope.row
- )
- "
- >
- 删除
- </el-button>
- <el-button
- v-if="scope.$index !== 0"
- type="text"
- size="mini"
- :disabled="scope.row.isDisabled || viewDetail"
- @click="
- handleMoveUp(scope.$index, '动态表表头', scope.row)
- "
- >
- 上升
- </el-button>
- <el-button
- v-if="
- scope.$index !== contentEditForm.tableHeaders.length - 1
- "
- type="text"
- size="mini"
- :disabled="scope.row.isDisabled || viewDetail"
- @click="handleMoveDown(scope.$index)"
- >
- 下降
- </el-button>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div>
- <div class="button-group">
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleAddTableHeader('动态表项目')"
- >
- 添加项目
- </el-button>
- <el-button
- v-if="!viewDetail"
- type="primary"
- @click="handleSaveContent('动态表项目')"
- >
- 保存
- </el-button>
- </div>
- <div class="table-edit-container">
- <el-table
- :data="contentEditForm.dynamicTable.dynamicTables"
- border
- style="width: 100%"
- row-key="rowid"
- default-expand-all
- :tree-props="{
- children: 'children',
- hasChildren: 'hasChildren',
- }"
- @selection-change="handleSelectionChange"
- >
- <el-table-column label="父子节点" align="center" width="100">
- <template slot-scope="scope">
- <el-tag
- v-if="
- scope.row.isChild ||
- scope.row.isSubItem ||
- (scope.row.parentid &&
- scope.row.parentid != -1 &&
- scope.row.parentid != '-1')
- "
- type="success"
- size="small"
- >
- 子项
- </el-tag>
- <el-tag
- v-else-if="
- scope.row.parentid === -1 ||
- scope.row.parentid === '-1' ||
- !scope.row.parentid
- "
- type="primary"
- size="small"
- >
- 父项
- </el-tag>
- <el-tag v-else type="info" size="small">无</el-tag>
- </template>
- </el-table-column>
- <el-table-column label="序号" width="120" align="center">
- <template slot-scope="scope">
- <div
- style="
- display: flex;
- align-items: center;
- min-height: 32px;
- "
- >
- <el-input
- :value="
- scope.row.dynamicValues
- ? scope.row.dynamicValues['序号']
- : ''
- "
- size="small"
- placeholder="数字或中文"
- :disabled="viewDetail"
- style="flex: 1; margin: 0"
- @input="
- handleDynamicValueChange(scope.row, '序号', $event)
- "
- ></el-input>
- </div>
- </template>
- </el-table-column>
- <el-table-column
- v-for="(item, index) in contentEditForm.dynamicTable
- .dynamicTableHeaders"
- :key="index"
- :label="item.rkey"
- align="center"
- >
- <template slot-scope="scope">
- <el-input
- :value="
- scope.row.dynamicValues
- ? scope.row.dynamicValues[item.rkey]
- : ''
- "
- size="small"
- :disabled="viewDetail"
- @input="
- handleDynamicValueChange(scope.row, item.rkey, $event)
- "
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- label="操作"
- align="center"
- fixed="right"
- width="200"
- >
- <template slot-scope="scope">
- <div class="table-actions">
- <el-button
- v-if="!scope.row.isChild"
- type="text"
- size="mini"
- :disabled="viewDetail"
- @click="
- handleAddChildItem(
- scope.$index,
- '动态表项目',
- scope.row
- )
- "
- >
- 添加子项
- </el-button>
- <el-button
- type="text"
- size="mini"
- :disabled="viewDetail"
- class="delete-btn"
- @click="
- handleDeleteHeader(
- scope.$index,
- '动态表项目',
- scope.row
- )
- "
- >
- 删除
- </el-button>
- <el-button
- v-if="scope.$index !== 0"
- type="text"
- size="mini"
- :disabled="viewDetail"
- @click="handleMoveUp(scope.$index, '动态表', scope.row)"
- >
- 上升
- </el-button>
- <el-button
- v-if="
- scope.$index !==
- contentEditForm.tableHeaders.length - 1
- "
- type="text"
- size="mini"
- :disabled="viewDetail"
- @click="
- handleMoveDown(scope.$index, '动态表', scope.row)
- "
- >
- 下降
- </el-button>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </div>
- </div>
- </div>
- </el-dialog>
- <el-dialog
- title="计算公式"
- :visible.sync="calculationFormulaDialogVisible"
- width="500px"
- :before-close="handleDialogClose"
- :close-on-click-modal="false"
- >
- <!-- 单选按钮组:切换“当前指标项”/“其他模板指标项” -->
- <el-radio-group
- v-model="radioType"
- class="mb20"
- @change="handleRadioChange"
- >
- <el-radio label="current">当前指标项</el-radio>
- <el-radio label="other">其他模板指标项</el-radio>
- </el-radio-group>
- <!-- 「当前指标项」内容区域 -->
- <div v-if="radioType === 'current'" class="current-panel">
- <el-input
- v-model="formulaText"
- type="textarea"
- rows="4"
- placeholder="请输入公式(如 C1+C2+C3)"
- />
- </div>
- <!-- 「其他模板指标项」内容区域 -->
- <div v-else class="other-panel">
- <span>版本号:</span>
- <el-select
- v-model="selectedTemplateId"
- placeholder="请选择版本号"
- @change="handleTemplateChange"
- >
- <el-option
- v-for="(item, index) in templateList"
- :key="index"
- :label="item.versionNo"
- :value="item.pkVal"
- ></el-option>
- </el-select>
- <!-- 指标表格 -->
- <el-table
- ref="indicatorTable"
- :data="indicatorTableData"
- border
- style="width: 100%; margin-top: 10px"
- @row-click="handleRowClick"
- >
- <el-table-column label="选择" width="60">
- <template #default="scope">
- <el-checkbox
- v-model="scope.row.checked"
- @change="handleCheckboxChange(scope.row)"
- @click.stop
- ></el-checkbox>
- </template>
- </el-table-column>
- <el-table-column
- label="指标编号"
- prop="cellCode"
- align="center"
- ></el-table-column>
- <!--循环表头 -->
- <el-table-column
- v-for="(item, index) in indicatorTableHeaders"
- :key="index"
- :label="item.rkey"
- align="center"
- show-overflow-tooltip
- >
- <template slot-scope="scope">
- {{
- scope.row.fixedValues ? scope.row.fixedValues[item.rkey] : ''
- }}
- </template>
- </el-table-column>
- </el-table>
- <el-input
- v-model="formulaText"
- type="textarea"
- rows="4"
- placeholder="请输入公式(如 C1+C2+C3)"
- @input="handleFormulaTextChange"
- />
- </div>
- <!-- 弹窗底部按钮 -->
- <template #footer>
- <span class="dialog-footer">
- <el-button type="primary" @click="handleConfirm">确定</el-button>
- <el-button @click="calculationFormulaDialogVisible = false">
- 取消
- </el-button>
- </span>
- </template>
- </el-dialog>
- </div>
- </template>
- <script>
- // 导入API模块
- import {
- getCostFormList,
- addCostForm,
- editCostForm,
- deleteCostForm,
- getDataStorageTableOptions,
- } from '@/api/costFormManage'
- import CostAuditTable from '@/components/costAudit/CostAuditTable.vue'
- import { getDictTypList } from '@/api/dictionaryManage.js'
- import {
- listByTemplateIdAndVersion,
- getCellCodesByTemplateId,
- } from '@/api/costSurveyTemplateItems'
- import {
- addSurveyTemplateVersion,
- delSurveyTemplateVersionById,
- putSurveyTemplatePublishVersion,
- getCostSurveyTemplateVersionsByTemplateId,
- batchDeleteCostForm,
- } from '@/api/costSurveyTemplateVersion'
- import { getListFixedEnabled } from '@/api/costSurveyTemplate'
- import { listByCurrentTemplateId } from '@/api/catalogManage.js'
- import {
- getListBySurveyTemplateId,
- getListBySurveyTemplateIdAndVersion,
- getBatchSaveOrUpdate,
- } from '@/api/costSurveyTemplateHeaders'
- import { commonMixin } from '@/mixins/useDict'
- import { mapState } from 'vuex'
- export default {
- name: 'InfoMaintain',
- components: {
- CostAuditTable,
- },
- mixins: [commonMixin],
- data() {
- return {
- surveyTemplateName: '',
- loading: false,
- searchForm: {
- status: '',
- },
- tableData: [],
- currentRow: null,
- selectedRows: [],
- pagination: {
- currentPage: 1,
- pageSize: 50,
- total: 0, // 初始化为0
- },
- dialogVisible: false,
- detailDialogVisible: false,
- viewDetail: false,
- contentEditDialogVisible: false,
- calculationFormulaDialogVisible: false,
- currentEditingRow: null,
- currentEditingRowIndex: -1,
- radioType: 'current',
- formulaText: 'C1+C2+C3',
- templateName: '',
- templateList: [],
- indicatorTableData: [],
- indicatorTableHeaders: [],
- selectedIndicatorCodes: [],
- selectedIndicatorsPerTemplate: {},
- dialogTitle: '',
- dataForm: {
- id: null,
- version: '',
- status: '',
- createBy: '',
- createTime: '',
- remark: '',
- },
- detailForm: {
- id: null,
- version: '',
- status: '',
- createBy: '',
- createTime: '',
- remark: '',
- },
- contentEditForm: {
- tableName: '',
- templateType: '1',
- versionId: '',
- // 单记录列表
- tableHeaders: [],
- // 固定表列表
- fixedTable: {
- tableHeaders: [],
- fixedTables: [],
- fixedTablesTitle: [],
- fixedTableHeaders: [],
- },
- // 动态表列表
- dynamicTable: {
- tableHeaders: [],
- dynamicTables: [],
- dynamicTablesTitle: [],
- dynamicTableHeaders: [],
- },
- isDynamicTables: false,
- isFixedTables: false,
- },
- tableKey: 0, // 用于强制刷新表格
- dataFormRules: {
- status: [
- { required: true, message: '请选择状态', trigger: 'change' },
- ],
- createBy: [
- { required: true, message: '请输入创建人', trigger: 'blur' },
- ],
- createTime: [
- { required: true, message: '请选择创建时间', trigger: 'change' },
- ],
- },
- id: '', // 从路由获取的ID
- dataStorageTableOptions: [], // 数据存储库表选项
- surveyTemplateId: '', // 成本调查表ID
- versionId: '',
- dictTypeList: [],
- }
- },
- computed: {
- ...mapState('user', ['userInfo', 'username']),
- formatter: (status) => {
- return status === '-1' ? '草稿' : status === '0' ? '现行' : '历史'
- },
- tableColumns() {
- return [
- {
- prop: 'versionNo',
- label: '版本号',
- align: 'center',
- showOverflowTooltip: true,
- },
- {
- prop: 'status',
- label: '状态',
- align: 'center',
- formatter: (row) => {
- return row.status == '-1'
- ? '草稿'
- : row.status == '0'
- ? '现行'
- : '历史'
- },
- },
- {
- prop: 'createBy',
- label: '创建人',
- align: 'center',
- },
- {
- prop: 'createTime',
- label: '创建时间',
- showOverflowTooltip: true,
- slotName: 'createTime',
- },
- {
- prop: 'remarks',
- label: '备注',
- align: 'center',
- showOverflowTooltip: true,
- },
- {
- prop: 'action',
- width: '270',
- label: '操作',
- align: 'center',
- fixed: 'right',
- slotName: 'action',
- },
- ]
- },
- },
- watch: {
- indicatorTableData: {
- handler(newVal) {
- if (this.radioType === 'other' && this.selectedTemplateId) {
- this.$set(
- this.selectedIndicatorsPerTemplate,
- this.selectedTemplateId,
- newVal.filter((item) => item.checked)
- )
- }
- this.updateSelectedIndicatorCodes()
- },
- deep: true,
- },
- selectedIndicatorCodes: {
- handler(newVal) {
- if (this.radioType === 'other') {
- const allSelectedTemplateIds = [
- ...new Set([
- this.selectedTemplateId,
- ...Object.keys(this.selectedIndicatorsPerTemplate).filter(
- (id) =>
- id !== this.selectedTemplateId &&
- this.selectedIndicatorsPerTemplate[id].some(
- (item) => item.checked
- )
- ),
- ]),
- ].filter((id) => id)
- const isSingleTemplate = allSelectedTemplateIds.length === 1
- if (isSingleTemplate && allSelectedTemplateIds[0]) {
- const selectedTemplate = this.templateList.find(
- (item) => item.pkVal === allSelectedTemplateIds[0]
- )
- const templateNameYw = selectedTemplate
- ? selectedTemplate.surveyTemplateNameYw ||
- selectedTemplate.surveyTemplateName ||
- ''
- : ''
- let selectedItems = []
- if (allSelectedTemplateIds[0] === this.selectedTemplateId) {
- selectedItems = newVal
- } else {
- selectedItems = this.selectedIndicatorsPerTemplate[
- allSelectedTemplateIds[0]
- ]
- .filter((item) => item.checked)
- .map(
- (item) => `${templateNameYw}.${item.code || item.cellCode}`
- )
- }
- if (selectedItems.length > 0) {
- this.formulaText = selectedItems.join('+')
- this.isAutoGeneratedFormula = true
- } else if (this.isAutoGeneratedFormula) {
- this.formulaText = ''
- }
- } else {
- let allSelectedCodes = []
- if (newVal.length > 0 && this.selectedTemplateId) {
- allSelectedCodes = [...newVal]
- }
- Object.keys(this.selectedIndicatorsPerTemplate).forEach(
- (templateId) => {
- if (templateId !== this.selectedTemplateId) {
- const items = this.selectedIndicatorsPerTemplate[templateId]
- const selectedTemplate = this.templateList.find(
- (item) => item.pkVal === templateId
- )
- const templateName = selectedTemplate
- ? selectedTemplate.surveyTemplateNameYw ||
- selectedTemplate.surveyTemplateName ||
- ''
- : ''
- items
- .filter((item) => item.checked)
- .forEach((item) => {
- allSelectedCodes.push(
- `${templateName}.${item.code || item.cellCode}`
- )
- })
- }
- }
- )
- if (allSelectedCodes.length > 0) {
- this.formulaText = allSelectedCodes.join('+')
- this.isAutoGeneratedFormula = true
- } else if (this.isAutoGeneratedFormula) {
- this.formulaText = ''
- }
- }
- } else if (newVal.length > 0 && this.radioType === 'current') {
- if (
- !this.formulaText ||
- this.formulaText === 'C1+C2+C3' ||
- this.isAutoGeneratedFormula
- ) {
- this.formulaText = newVal.join('+')
- this.isAutoGeneratedFormula = true
- }
- } else if (newVal.length === 0 && this.radioType === 'current') {
- if (this.isAutoGeneratedFormula) {
- this.formulaText = ''
- }
- }
- },
- deep: true,
- },
- },
- mounted() {
- this.isAutoGeneratedFormula = false
- },
- methods: {
- async loadDictTypeList() {
- try {
- const res = await getDictTypList()
- this.dictTypeList = res || []
- } catch (error) {
- console.error('加载字典类型失败:', error)
- }
- },
- getTemplateRow(row) {
- this.currentRow = row
- this.surveyTemplateId = row.surveyTemplateId
- this.templateType = row.templateType
- this.contentEditForm.tableName = row.surveyTemplateName
- this.surveyTemplateName = row.surveyTemplateName
- this.contentEditForm.templateType = row.templateType
- this.handleSearch()
- this.loadDictTypeList()
- },
- handleBack() {
- this.$emit('back', 'list')
- },
- // 查询
- handleSearch() {
- this.loading = true
- const params = {
- surveyTemplateId: this.surveyTemplateId,
- status: this.searchForm.status,
- // pageNum: this.pagination.currentPage,
- // pageSize: this.pagination.pageSize,
- }
- // 根据成本调查表ID获取所有版本数据
- getCostSurveyTemplateVersionsByTemplateId(params)
- .then((response) => {
- this.tableData = response.value || []
- this.pagination.total = response.total || 0
- this.loading = false
- })
- .catch((error) => {
- console.error('查询失败:', error)
- this.loading = false
- })
- },
- // 重置
- handleReset() {
- this.searchForm = {
- status: '',
- }
- this.pagination.currentPage = 1
- this.handleSearch()
- },
- handleRowClick(row, column, event) {
- // 只有点击非 checkbox 列才触发
- if (column && column.property !== 'checked') {
- // 如果没有 cellCode,则不允许选中
- if (!row.cellCode) {
- // this.$message.warning('该数据没有指标编号,无法选择')
- return
- }
- // 切换选中状态
- this.toggleRowSelection(row)
- }
- },
- toggleRowSelection(row) {
- // 切换选中状态
- this.$set(row, 'checked', !row.checked)
- // 格式化代码并存储在行数据中
- if (row.checked) {
- this.formatRowCode(row)
- }
- // 触发选中状态更新
- this.$forceUpdate()
- },
- handleCheckboxChange(row) {
- // 如果没有 cellCode,则不允许选中
- if (!row.cellCode) {
- this.$message.warning('该数据没有指标编号,无法选择')
- this.$set(row, 'checked', false)
- return
- }
- this.$set(row, 'checked', !row.checked)
- if (row.checked) {
- this.formatRowCode(row)
- }
- this.updateSelectedIndicatorCodes()
- this.$forceUpdate()
- },
- updateSelectedIndicatorCodes() {
- // 获取当前选中的行
- const selectedRows = this.indicatorTableData.filter(
- (item) => item.checked
- )
- // 更新选中的指标代码列表
- this.selectedIndicatorCodes = selectedRows.map((item) => {
- // 获取选中的模板信息
- const selectedTemplate = this.templateList.find(
- (template) => template.pkVal === this.selectedTemplateId
- )
- // 获取模板的 surveyTemplateNameYw
- const templateName = selectedTemplate
- ? selectedTemplate.surveyTemplateNameYw ||
- selectedTemplate.surveyTemplateName ||
- ''
- : ''
- return templateName
- ? `${templateName}.${item.code || item.cellCode || ''}`
- : item.code || item.cellCode || ''
- })
- },
- formatRowCode(row) {
- const selectedTemplate = this.templateList.find(
- (item) => item.pkVal === this.selectedTemplateId
- )
- const surveyTemplateNameYw = selectedTemplate
- ? selectedTemplate.surveyTemplateNameYw ||
- selectedTemplate.surveyTemplateName ||
- ''
- : ''
- const formattedCode = surveyTemplateNameYw
- ? `${surveyTemplateNameYw}.${row.code || row.cellCode || ''}`
- : row.code || row.cellCode || ''
- this.$set(row, 'formattedCode', formattedCode)
- const templateCode = surveyTemplateNameYw
- ? `${surveyTemplateNameYw}_${row.code || row.cellCode || ''}`
- : row.code || row.cellCode || ''
- this.$set(
- row,
- 'jsonStr',
- JSON.stringify([
- {
- [templateCode]: this.selectedTemplateId,
- },
- ])
- )
- },
- openCalculationFormulaDialogVisible(row, index) {
- this.currentEditingRow = row
- this.currentEditingRowIndex = index
- this.calculationFormulaDialogVisible = true
- this.formulaText = row.calculationFormula || ''
- this.selectedTemplateId = '' // 重置选中的模板
- this.indicatorTableData = [] // 清空指标数据
- this.getListFixedEnabled()
- },
- getListFixedEnabled() {
- // 修改为调用状态为现行的数据
- const params = {
- surveyTemplateId: this.surveyTemplateId,
- status: '0',
- // pageNum: this.pagination.currentPage,
- // pageSize: this.pagination.pageSize,
- }
- // 根据成本调查表ID获取所有版本数据
- getCostSurveyTemplateVersionsByTemplateId(params)
- .then((response) => {
- this.templateList = response.value || []
- })
- .catch((error) => {
- console.error('查询失败:', error)
- })
- // getListFixedEnabled().then((res) => {
- // this.templateList = res.value
- // })
- },
- // 处理模板选择变化
- handleTemplateChange(templateId) {
- if (templateId) {
- // 根据选中的模板ID查找对应的surveyTemplateId
- const selectedTemplate = this.templateList.find(
- (item) => item.pkVal === templateId
- )
- if (selectedTemplate && selectedTemplate.surveyTemplateId) {
- // this.getCellCodesByTemplateId(selectedTemplate.surveyTemplateId)
- listByCurrentTemplateId({
- surveyTemplateId: selectedTemplate.surveyTemplateId,
- }).then((responseData) => {
- //解析并显示数据
- if (responseData.value && responseData.value.itemlist) {
- const itemList = responseData.value.itemlist
- let fixedTablesTitle = this.stringToObjects(
- responseData.value.fixedFields || ''
- )
- this.indicatorTableHeaders = fixedTablesTitle
- // 遍历itemList,为每个项目创建一行数据
- itemList.forEach((item, index) => {
- const newRow = {
- ...item,
- checked: false,
- cellCode: item.cellCode || '',
- fixedValues: {},
- }
- // 初始化fixedValues并填充实际值
- fixedTablesTitle.forEach((title) => {
- newRow.fixedValues[title.rkey] = item[title.rkey] || ''
- })
- this.indicatorTableData.push(newRow)
- })
- }
- })
- } else {
- this.indicatorTableData = []
- }
- } else {
- this.indicatorTableData = []
- }
- // 恢复该模板之前选中的指标项
- this.$nextTick(() => {
- if (this.selectedIndicatorsPerTemplate[templateId]) {
- this.indicatorTableData.forEach((item) => {
- const isSelected = this.selectedIndicatorsPerTemplate[
- templateId
- ].some((selectedItem) => selectedItem.code === item.code)
- this.$set(item, 'checked', isSelected)
- if (isSelected) {
- this.formatRowCode(item)
- }
- })
- }
- // 更新选中的指标代码列表
- this.updateSelectedIndicatorCodes()
- })
- },
- handleDialogClose(done) {
- this.selectedIndicatorsPerTemplate = {}
- done()
- },
- handleRadioChange(value) {
- this.formulaText = ''
- },
- handleConfirm() {
- const result = {
- type: this.radioType,
- formula: this.formulaText,
- selectedTemplate: this.selectedTemplateId,
- selectedItems: this.indicatorTableData.filter((item) => item.checked),
- }
- let _data = []
- if (this.radioType == 'current') {
- // 使用递归函数扁平化树形结构
- const flattenTree = (nodes) => {
- let result = []
- nodes.forEach((node) => {
- result.push(node)
- if (node.children && node.children.length > 0) {
- result = result.concat(flattenTree(node.children))
- }
- })
- return result
- }
- // 扁平化数据并提取cellCode
- _data = flattenTree(this.contentEditForm.fixedTable.fixedTables)
- .filter((item) => item.cellCode)
- .map((item) => item.cellCode)
- } else if (this.radioType == 'other') {
- if (!result.selectedTemplate) {
- this.$message.error('请选择指标编号')
- return
- }
- _data = this.indicatorTableData
- .filter((item) => item.cellCode)
- .map((item) => item.cellCode)
- }
- if (!this.validateFormula(this.formulaText, _data).valid) {
- this.$message.error(
- this.validateFormula(this.formulaText, _data).errorMsg
- )
- return
- }
- // 生成 jsonstr 字段
- const jsonStrArray = this.indicatorTableData
- .filter((item) => item.checked)
- .map((item) => {
- if (item.jsonStr) {
- try {
- return JSON.parse(item.jsonStr)[0]
- } catch (e) {
- console.error('解析 jsonStr 失败:', e)
- return {}
- }
- }
- return {}
- })
- .filter((item) => Object.keys(item).length > 0)
- const jsonstr = JSON.stringify(jsonStrArray)
- // 更新当前编辑行的计算公式值
- if (this.currentEditingRow) {
- this.$set(
- this.currentEditingRow,
- 'calculationFormula',
- this.formulaText
- )
- this.$set(this.currentEditingRow, 'jsonstr', jsonstr)
- }
- console.log('点击了确定,获取到的数据:', {
- ...result,
- jsonstr: jsonstr,
- })
- // 清空当前操作的状态
- this.calculationFormulaDialogVisible = false
- this.currentEditingRow = null
- this.currentEditingRowIndex = -1
- this.isAutoGeneratedFormula = false
- this.selectedTemplateId = ''
- this.indicatorTableData = []
- this.selectedIndicatorsPerTemplate = {} // 清空模板选中记录
- },
- // 获取单元格代码
- getCellCodesByTemplateId(surveyTemplateId) {
- getCellCodesByTemplateId(surveyTemplateId)
- .then((res) => {
- // 将返回的数据转换为表格需要的格式
- if (res.value && Array.isArray(res.value)) {
- this.indicatorTableData = res.value.map((item) => ({
- ...item,
- checked: false,
- code: item.cellCode || '',
- name: item.rvalue || '',
- formattedCode: '', // 添加格式化代码字段
- }))
- } else {
- this.indicatorTableData = []
- }
- })
- .catch((error) => {
- console.error('获取指标数据失败:', error)
- this.$message.error('获取指标数据失败')
- this.indicatorTableData = []
- })
- },
- handleFormulaTextChange(value) {
- // 当用户手动修改公式文本时,标记为非自动生成
- this.isAutoGeneratedFormula = false
- },
- handleAdd() {
- this.dialogTitle = '添加'
- // 获取当前时间
- const now = new Date()
- // 格式化时间为YYYY-MM-DD HH:mm:ss
- const formattedDate = `${now.getFullYear()}-${String(
- now.getMonth() + 1
- ).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(
- now.getHours()
- ).padStart(2, '0')}:${String(now.getMinutes()).padStart(
- 2,
- '0'
- )}:${String(now.getSeconds()).padStart(2, '0')}`
- this.dataForm = {
- id: null,
- version: '',
- status: '',
- createBy: this.username,
- createTime: formattedDate,
- remarks: '',
- }
- this.dialogVisible = true
- },
- // 修改
- handleEdit(row) {
- this.dialogTitle = '修改'
- this.dataForm = { ...row }
- this.dialogVisible = true
- },
- //状态格式化
- forStatus(status) {
- return status === '-1' ? '草稿' : status === '0' ? '现行' : '历史'
- },
- // 查看详情
- handleViewDetail(row) {
- this.viewDetail = true
- this.detailForm = { ...row }
- // this.detailDialogVisible = true
- this.handleEditContent(row, this.viewDetail)
- },
- // 添加子项方法
- handleAddChildItem(index, type, parentRow) {
- if (!parentRow.rowid) {
- this.$set(parentRow, 'rowid', this.generateUUID())
- }
- switch (type) {
- case '固定表项目':
- let parentIndex1 =
- this.contentEditForm.fixedTable.fixedTables.findIndex(
- (item) => item.rowid == parentRow.rowid
- )
- if (
- !this.contentEditForm.fixedTable.fixedTables[parentIndex1]
- .children
- ) {
- this.$set(
- this.contentEditForm.fixedTable.fixedTables[parentIndex1],
- 'children',
- []
- )
- }
- let childOrderNum =
- this.contentEditForm.fixedTable.fixedTables[parentIndex1].children
- .length + 1
- let fixedValues = {
- ...parentRow.fixedValues,
- }
- for (const key in fixedValues) {
- if (key == '序号') {
- fixedValues[key] = childOrderNum
- } else {
- fixedValues[key] = ''
- }
- }
- const fixedNewRow = {
- orderText: this.contentEditForm.fixedTable.fixedTables.length + 1,
- orderNum: this.contentEditForm.fixedTable.fixedTables.length + 1,
- cellCode: '',
- calculationFormula: '',
- unit: '',
- tabtype: this.templateType,
- surveyTemplateId: this.surveyTemplateId,
- versionId: this.versionId,
- fixedValues: fixedValues,
- parentid: parentRow.rowid,
- isChild: true,
- isSubItem: true,
- rowid: this.generateUUID(),
- }
- this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
- (title) => {
- if (!(title.rkey in fixedNewRow.fixedValues)) {
- fixedNewRow.fixedValues[title.rkey] = ''
- }
- }
- )
- // 先将子项添加到children数组
- this.contentEditForm.fixedTable.fixedTables[
- parentIndex1
- ].children.push(fixedNewRow)
- // this.contentEditForm.fixedTable.fixedTables.splice(
- // index + 1,
- // 0,
- // fixedNewRow
- // )
- break
- case '动态表项目':
- let parentIndex2 =
- this.contentEditForm.dynamicTable.dynamicTables.findIndex(
- (item) => item.rowid == parentRow.rowid
- )
- if (
- !this.contentEditForm.dynamicTable.dynamicTables[parentIndex2]
- .children
- ) {
- this.$set(
- this.contentEditForm.dynamicTable.dynamicTables[parentIndex2],
- 'children',
- []
- )
- }
- let dynamicChildOrderNum =
- this.contentEditForm.dynamicTable.dynamicTables[parentIndex2]
- .children.length + 1
- let dynamicValues = { ...parentRow.dynamicValues }
- for (const key in dynamicValues) {
- if (key == '序号') {
- dynamicValues[key] = dynamicChildOrderNum
- } else {
- dynamicValues[key] = ''
- }
- }
- const dynamicNewRow = {
- orderText: dynamicChildOrderNum,
- orderNum: dynamicChildOrderNum,
- tabtype: this.templateType,
- surveyTemplateId: this.surveyTemplateId,
- versionId: this.versionId,
- dynamicValues: dynamicValues,
- parentid: parentRow.rowid,
- isChild: true,
- isSubItem: true,
- rowid: Date.now() + Math.random() + 1,
- }
- this.contentEditForm.dynamicTable.dynamicTablesTitle.forEach(
- (title) => {
- if (!(title.rkey in dynamicNewRow.dynamicValues)) {
- dynamicNewRow.dynamicValues[title.rkey] = ''
- }
- }
- )
- this.contentEditForm.dynamicTable.dynamicTables[
- parentIndex2
- ].children.push(dynamicNewRow)
- // this.contentEditForm.dynamicTable.dynamicTables.splice(
- // index + 1,
- // 0,
- // dynamicNewRow
- // )
- break
- }
- this.$nextTick(() => {
- const tableBody = document.querySelector('.el-table__body-wrapper')
- if (tableBody) {
- tableBody.scrollTop = tableBody.scrollHeight
- }
- })
- },
- handleFormStyleChange() {},
- getListBySurveyTemplateIdAndVersion(surveyTemplateId, versionId) {
- return getListBySurveyTemplateIdAndVersion({
- surveyTemplateId: surveyTemplateId,
- versionId: versionId,
- })
- .then((res) => {
- // 确保表头数据包含所有必要的字段,包括 id
- this.contentEditForm.tableHeaders =
- res.value.map((item) => ({
- ...item,
- fieldKey: item.fieldEname
- ? item.fieldEname.toLowerCase()
- : `field_${Date.now()}_${Math.random()
- .toString(36)
- .substr(2, 9)}`,
- })) || []
- // 检查并添加序号字段(固定表和动态表需要)
- if (['2', '3'].includes(this.contentEditForm.templateType)) {
- const hasSerialNumber = this.contentEditForm.tableHeaders.some(
- (item) => item.fieldName === '序号'
- )
- if (!hasSerialNumber) {
- this.contentEditForm.tableHeaders.unshift({
- fieldName: '序号',
- fieldType: 'string',
- format: '255',
- fieldTypelen: '',
- fieldTypenointlen: '',
- isRequired: 'false',
- showVisible: '1',
- isAuditPeriod: 'false',
- tabtype: this.templateType,
- surveyTemplateId: this.surveyTemplateId,
- versionId: this.versionId,
- isDisabled: true,
- orderNum: 1,
- })
- } else {
- // 如果已存在序号字段,确保其不可编辑
- const serialNumberIndex =
- this.contentEditForm.tableHeaders.findIndex(
- (item) => item.fieldName === '序号'
- )
- if (serialNumberIndex !== -1) {
- this.contentEditForm.tableHeaders[
- serialNumberIndex
- ].isDisabled = true
- }
- }
- }
- this.contentEditForm.dynamicTable.tableHeaders =
- this.contentEditForm.tableHeaders
- this.contentEditForm.fixedTable.tableHeaders =
- this.contentEditForm.tableHeaders
- // 表头按照orderNum重新排序
- this.contentEditForm.tableHeaders.sort(
- (a, b) => a.orderNum - b.orderNum
- )
- this.contentEditForm.dynamicTable.tableHeaders.sort(
- (a, b) => a.orderNum - b.orderNum
- )
- this.contentEditForm.fixedTable.tableHeaders.sort(
- (a, b) => a.orderNum - b.orderNum
- )
- // 同时获取表头标题信息
- listByTemplateIdAndVersion(surveyTemplateId, versionId)
- .then((response) => {
- if (response.code === 200) {
- if (this.contentEditForm.templateType === '2') {
- this.contentEditForm.fixedTable.fixedTablesTitle =
- this.stringToObjects(response.value.fixedFields || '')
- } else if (this.contentEditForm.templateType === '3') {
- this.contentEditForm.dynamicTable.dynamicTablesTitle =
- this.stringToObjects(response.value.fixedFields || '')
- }
- }
- return response
- })
- .catch((error) => {
- console.error('获取表头标题信息失败:', error)
- throw error
- })
- })
- .catch((error) => {
- console.error('查询失败:', error)
- this.loading = false
- throw error
- })
- },
- initFixedTableRow(row) {
- if (row.cellCode === undefined) {
- this.$set(row, 'cellCode', '')
- }
- if (row.calculationFormula === undefined) {
- this.$set(row, 'calculationFormula', '')
- }
- if (row.unit === undefined) {
- this.$set(row, 'unit', '')
- }
- if (!row.fixedValues) {
- this.$set(row, 'fixedValues', {})
- }
- this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
- (title, index) => {
- if (!(title.rkey in row.fixedValues)) {
- this.$set(row.fixedValues, title.rkey, '')
- }
- }
- )
- return row
- },
- initDynamicTableRow(row) {
- // 为当前行创建一个与 dynamicTablesTitle 对应的值对象
- if (!row.dynamicValues) {
- this.$set(row, 'dynamicValues', {})
- }
- // 确保每个动态列在当前行都有对应的值
- this.contentEditForm.dynamicTable.dynamicTablesTitle.forEach(
- (title) => {
- if (!(title.rkey in row.dynamicValues)) {
- this.$set(row.dynamicValues, title.rkey, '')
- }
- }
- )
- return row
- },
- /**
- * 处理固定表项目字段值变化
- */
- handleFixedValueChange(row, rkey, value) {
- if (!row.fixedValues) {
- this.$set(row, 'fixedValues', {})
- }
- this.$set(row.fixedValues, rkey, value)
- },
- // 获取或设置序号字段
- getOrSetOrder(row, value) {
- // 如果提供了value参数,则设置值
- if (value !== undefined) {
- // 使用this.$set确保响应式更新
- if (row['序号'] === undefined) {
- this.$set(row, '序号', value)
- } else {
- row['序号'] = value
- }
- }
- // 如果没有提供value参数,则获取值
- return row['序号'] !== undefined && row['序号'] !== null
- ? row['序号']
- : row.orderNum || ''
- },
- /**
- * 处理动态表项目字段值变化
- */
- handleDynamicValueChange(row, rkey, value) {
- if (!row.dynamicValues) {
- this.$set(row, 'dynamicValues', {})
- }
- this.$set(row.dynamicValues, rkey, value)
- },
- // 内容维护
- handleEditContent(row, viewDetail) {
- this.viewDetail = viewDetail || false
- this.versionId = row.id
- // 显示加载状态
- this.loading = true
- // 获取所有需要的数据
- this.getListBySurveyTemplateIdAndVersion(row.surveyTemplateId, row.id)
- .then(() => {
- // 获取项目数据用于回显
- return listByTemplateIdAndVersion(row.surveyTemplateId, row.id)
- })
- .then((res) => {
- if (res.code === 200) {
- // 根据模板类型解析并显示数据
- if (this.contentEditForm.templateType === '2') {
- // 解析并显示固定表项目数据
- setTimeout(() => {
- this.parseAndDisplayFixedTableData(res)
- }, 1000)
- } else if (this.contentEditForm.templateType === '3') {
- // 解析并显示动态表项目数据
- setTimeout(() => {
- this.parseAndDisplayDynamicTableData(res)
- }, 1000)
- }
- }
- this.loading = false
- this.contentEditDialogVisible = true
- })
- .catch((error) => {
- console.error('获取数据失败:', error)
- // this.$message.error('获取数据失败')
- this.contentEditDialogVisible = true
- this.loading = false
- })
- },
- // 字段类型变化处理
- handleFieldTypeChange(row) {
- // 重置格式相关字段
- row.format = ''
- row.integerDigits = ''
- row.decimalDigits = ''
- },
- // 添加表头
- handleAddTableHeader(type) {
- switch (type) {
- case '单记录':
- this.contentEditForm.tableHeaders.push({
- fieldName: '',
- fieldType: 'string',
- format: '255',
- fieldTypelen: '',
- fieldTypenointlen: '',
- isRequired: 'false',
- showVisible: '1',
- isDict: 'false',
- dictid: '',
- dictValue: '',
- tabtype: this.templateType,
- surveyTemplateId: this.surveyTemplateId,
- versionId: this.versionId,
- orderNum: this.contentEditForm.tableHeaders.length + 1,
- })
- break
- case '固定表表头':
- this.contentEditForm.fixedTable.tableHeaders.push({
- fieldName: '',
- fieldType: 'string',
- format: '255',
- fieldTypelen: '',
- fieldTypenointlen: '',
- isRequired: 'false',
- showVisible: '1',
- isAuditPeriod: 'false',
- tabtype: this.templateType,
- surveyTemplateId: this.surveyTemplateId,
- versionId: this.versionId,
- orderNum: this.contentEditForm.fixedTable.tableHeaders.length + 1,
- })
- // 确保添加后顺序正确
- this.updateTableHeadersOrderNumbers()
- break
- case '固定表项目':
- let maxFixedOrderNum = 0
- if (this.contentEditForm.fixedTable.fixedTables.length > 0) {
- maxFixedOrderNum = Math.max(
- ...this.contentEditForm.fixedTable.fixedTables.map(
- (item) => item.orderNum || 0
- )
- )
- }
- const newRow = {
- orderText: maxFixedOrderNum + 1,
- orderNum: maxFixedOrderNum + 1,
- cellCode: '',
- calculationFormula: '',
- unit: '',
- tabtype: this.templateType,
- surveyTemplateId: this.surveyTemplateId,
- versionId: this.versionId,
- fixedValues: {},
- parentid: -1,
- rowid: this.generateUUID(),
- children: [],
- }
- this.contentEditForm.fixedTable.fixedTablesTitle.forEach(
- (title) => {
- newRow.fixedValues[title.rkey] = ''
- }
- )
- this.contentEditForm.fixedTable.fixedTables.push(newRow)
- break
- case '动态表表头':
- this.contentEditForm.dynamicTable.tableHeaders.push({
- fieldName: '',
- fieldType: 'string',
- format: '255',
- fieldTypelen: '',
- fieldTypenointlen: '',
- isRequired: 'false',
- showVisible: '1',
- tabtype: this.templateType,
- surveyTemplateId: this.surveyTemplateId,
- versionId: this.versionId,
- orderNum:
- this.contentEditForm.dynamicTable.tableHeaders.length + 1,
- })
- break
- case '动态表项目':
- let maxDynamicOrderNum = 0
- if (this.contentEditForm.dynamicTable.dynamicTables.length > 0) {
- maxDynamicOrderNum = Math.max(
- ...this.contentEditForm.dynamicTable.dynamicTables.map(
- (item) => item.orderNum || 0
- )
- )
- }
- const dynamicRow = {
- orderText: maxDynamicOrderNum + 1,
- orderNum: maxDynamicOrderNum + 1,
- tabtype: this.templateType,
- surveyTemplateId: this.surveyTemplateId,
- versionId: this.versionId,
- dynamicValues: {},
- parentid: -1,
- rowid: this.generateUUID(),
- children: [],
- }
- this.contentEditForm.dynamicTable.dynamicTablesTitle.forEach(
- (title) => {
- dynamicRow.dynamicValues[title.rkey] = ''
- }
- )
- this.contentEditForm.dynamicTable.dynamicTables.push(dynamicRow)
- break
- default:
- break
- }
- this.$nextTick(() => {
- const tableBody = document.querySelector('.el-table__body-wrapper')
- if (tableBody) {
- tableBody.scrollTop = tableBody.scrollHeight
- }
- })
- },
- // 删除表头
- handleDeleteHeader(index, type, row) {
- const handleDelete = () => {
- const data = {
- deleteheadersList: [row],
- }
- getBatchSaveOrUpdate(data)
- .then((res) => {
- if (res.code === 200) {
- this.$message.success('删除成功')
- } else {
- this.$message.error(`删除失败:${res.message || '未知错误'}`)
- }
- })
- .catch((error) => {
- console.error('删除接口异常:', error)
- // this.$message.error('删除接口异常,请重试')
- })
- .finally(() => {})
- }
- switch (type) {
- case '固定表表头':
- if (this.contentEditForm.fixedTable.tableHeaders.length <= 1) {
- this.$message.warning('至少保留一个表头')
- return
- }
- this.contentEditForm.fixedTable.tableHeaders.splice(index, 1)
- let fixedFields = this.contentEditForm.fixedTable.tableHeaders
- .map((item) => item.fieldName)
- .join(',')
- this.contentEditForm.fixedTable.fixedTablesTitle =
- this.stringToObjects(fixedFields || '')
- this.contentEditForm.fixedTable.fixedTableHeaders =
- this.contentEditForm.fixedTable.fixedTablesTitle.filter(
- (title) => title.rkey !== '序号'
- )
- handleDelete()
- // 重新排序
- this.updateTableHeadersOrderNumbers()
- break
- case '固定表项目':
- this.$confirm(
- '确定要删除此行数据吗?如果删除的是父项,将同时删除其所有子项。',
- '确认删除',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- }
- )
- .then(() => {
- // 检查是否是删除子项
- const isChildItem = row.isChild || row.isSubItem || false
- console.log('isChildItem', isChildItem)
- console.log('row', row)
- if (isChildItem) {
- // 查找父项
- const parentItem =
- this.contentEditForm.fixedTable.fixedTables.find(
- (item) =>
- item.children &&
- item.children.some((child) => child.rowid === row.rowid)
- )
- if (parentItem && parentItem.children) {
- // 从父项的children数组中删除子项
- const childIndex = parentItem.children.findIndex(
- (child) => child.rowid === row.rowid
- )
- if (childIndex > -1) {
- parentItem.children.splice(childIndex, 1)
- // 如果children数组为空,将hasChildren设为false
- if (parentItem.children.length === 0) {
- this.$set(parentItem, 'hasChildren', false)
- } else {
- // 重新计算子项序号
- parentItem.children.forEach((child, idx) => {
- child.orderText = idx + 1
- child.orderNum = idx + 1
- })
- }
- // 确保Vue响应式系统检测到变化
- const children = [...parentItem.children]
- this.$set(parentItem, 'children', children)
- this.handleSaveContent('固定表项目', 'delete') // 保存数据
- }
- }
- } else {
- // 处理删除父项的情况
- if (this.contentEditForm.fixedTable.fixedTables.length <= 1) {
- this.$message.warning('至少保留一个项目')
- return
- }
- // 获取要删除的行
- index =
- this.contentEditForm.fixedTable.fixedTables.indexOf(row)
- const rowToDelete =
- this.contentEditForm.fixedTable.fixedTables[index]
- // 先删除所有子项(parentid等于当前行的rowid或itemId的项)
- // 从后往前删除,避免索引偏移
- const rowsToDelete = []
- // 找出所有需要删除的行(包括父项和子项)
- for (
- let i = 0;
- i < this.contentEditForm.fixedTable.fixedTables.length;
- i++
- ) {
- const currentRow =
- this.contentEditForm.fixedTable.fixedTables[i]
- // 是当前行或其子项(子项的parentid等于当前行的rowid或itemId)
- if (
- i === index ||
- (currentRow.parentid &&
- (currentRow.parentid === rowToDelete.rowid ||
- currentRow.parentid === rowToDelete.itemId))
- ) {
- rowsToDelete.push(i)
- }
- }
- // 从后往前删除,避免索引偏移
- for (let i = rowsToDelete.length - 1; i >= 0; i--) {
- this.contentEditForm.fixedTable.fixedTables.splice(
- rowsToDelete[i],
- 1
- )
- }
- this.handleSaveContent('固定表项目', 'delete') // 保存数据
- }
- })
- .catch(() => {})
- break
- case '动态表表头':
- if (this.contentEditForm.dynamicTable.tableHeaders.length <= 1) {
- this.$message.warning('至少保留一个表头')
- return
- }
- this.contentEditForm.dynamicTable.tableHeaders.splice(index, 1)
- let dynamicFields = this.contentEditForm.dynamicTable.tableHeaders
- .map((item) => item.fieldName)
- .join(',')
- this.contentEditForm.dynamicTable.dynamicTablesTitle =
- this.stringToObjects(dynamicFields || '')
- this.contentEditForm.dynamicTable.dynamicTableHeaders =
- this.contentEditForm.dynamicTable.dynamicTablesTitle.filter(
- (title) => title.rkey !== '序号'
- )
- handleDelete()
- // 重新排序
- this.updateTableHeadersOrderNumbers()
- break
- case '动态表项目':
- if (this.contentEditForm.dynamicTable.dynamicTables.length <= 1) {
- this.$message.warning('至少保留一个项目')
- return
- }
- this.$confirm(
- '确定要删除此行数据吗?如果删除的是父项,将同时删除其所有子项。',
- '确认删除',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- }
- )
- .then(() => {
- // 检查是否是删除子项
- const isChildItem = row.isChild || row.isSubItem || false
- if (isChildItem) {
- // 查找父项
- const parentItem =
- this.contentEditForm.dynamicTable.dynamicTables.find(
- (item) =>
- item.children &&
- item.children.some((child) => child.rowid === row.rowid)
- )
- if (parentItem && parentItem.children) {
- // 从父项的children数组中删除子项
- const childIndex = parentItem.children.findIndex(
- (child) => child.rowid === row.rowid
- )
- if (childIndex > -1) {
- parentItem.children.splice(childIndex, 1)
- // 如果children数组为空,将hasChildren设为false
- if (parentItem.children.length === 0) {
- this.$set(parentItem, 'hasChildren', false)
- } else {
- // 重新计算子项序号
- parentItem.children.forEach((child, idx) => {
- child.orderText = idx + 1
- child.orderNum = idx + 1
- })
- }
- // 确保Vue响应式系统检测到变化
- const children = [...parentItem.children]
- this.$set(parentItem, 'children', children)
- this.handleSaveContent('动态表项目', 'delete') // 保存数据
- }
- }
- } else {
- // 处理删除父项的情况
- if (
- this.contentEditForm.dynamicTable.dynamicTables.length <= 1
- ) {
- this.$message.warning('至少保留一个项目')
- return
- }
- // 获取要删除的行
- index =
- this.contentEditForm.dynamicTable.dynamicTables.indexOf(row)
- const rowToDelete =
- this.contentEditForm.dynamicTable.dynamicTables[index]
- // 先删除所有子项(parentid等于当前行的rowid或itemId的项)
- // 从后往前删除,避免索引偏移
- const rowsToDelete = []
- // 找出所有需要删除的行(包括父项和子项)
- for (
- let i = 0;
- i < this.contentEditForm.dynamicTable.dynamicTables.length;
- i++
- ) {
- const currentRow =
- this.contentEditForm.dynamicTable.dynamicTables[i]
- // 是当前行或其子项(子项的parentid等于当前行的rowid或itemId)
- if (
- i === index ||
- (currentRow.parentid &&
- (currentRow.parentid === rowToDelete.rowid ||
- currentRow.parentid === rowToDelete.itemId))
- ) {
- rowsToDelete.push(i)
- }
- }
- // 从后往前删除,避免索引偏移
- for (let i = rowsToDelete.length - 1; i >= 0; i--) {
- this.contentEditForm.dynamicTable.dynamicTables.splice(
- rowsToDelete[i],
- 1
- )
- }
- this.handleSaveContent('动态表项目', 'delete') // 保存数据
- }
- })
- .catch(() => {})
- break
- case '单记录':
- if (this.contentEditForm.tableHeaders.length <= 1) {
- this.$message.warning('至少保留一个表头')
- return
- }
- this.contentEditForm.tableHeaders.splice(index, 1)
- handleDelete()
- break
- default:
- break
- }
- },
- // 上升
- handleMoveUp(index, tableType, row) {
- if (tableType === '固定表') {
- const fixedTableData = this.contentEditForm.fixedTable.fixedTables
- const newFixedTableData = [...fixedTableData]
- this.swamTableArr(newFixedTableData, row, true)
- this.contentEditForm.fixedTable.fixedTables = newFixedTableData
- } else if (tableType === '动态表') {
- const dynamicTableData =
- this.contentEditForm.dynamicTable.dynamicTables
- const newDynamicTableData = [...dynamicTableData]
- this.swamTableArr(newDynamicTableData, row, true)
- this.contentEditForm.dynamicTable.dynamicTables = newDynamicTableData
- } else {
- // const tableHeaders = this.contentEditForm.tableHeaders
- // const newTableHeaders = [...tableHeaders]
- // this.swamTableArr(newTableHeaders, row, true, true)
- // this.contentEditForm.tableHeaders = newTableHeaders
- // console.log('newTableHeaders', newTableHeaders)
- if (index > 0) {
- const temp = this.contentEditForm.tableHeaders[index]
- this.contentEditForm.tableHeaders.splice(index, 1)
- this.contentEditForm.tableHeaders.splice(index - 1, 0, temp)
- // 更新表头的序号
- this.updateTableHeadersOrderNumbers()
- }
- }
- },
- // 下降
- handleMoveDown(index, tableType, row) {
- if (tableType === '固定表') {
- const fixedTableData = this.contentEditForm.fixedTable.fixedTables
- const newFixedTableData = [...fixedTableData]
- this.swamTableArr(newFixedTableData, row, false)
- this.contentEditForm.fixedTable.fixedTables = newFixedTableData
- } else if (tableType === '动态表') {
- const dynamicTableData =
- this.contentEditForm.dynamicTable.dynamicTables
- const newDynamicTableData = [...dynamicTableData]
- this.swamTableArr(newDynamicTableData, row, false)
- this.contentEditForm.dynamicTable.dynamicTables = newDynamicTableData
- } else {
- // const tableHeaders = this.contentEditForm.tableHeaders
- // const newTableHeaders = [...tableHeaders]
- // this.swamTableArr(newTableHeaders, row, false)
- // this.contentEditForm.tableHeaders = newTableHeaders
- if (index < this.contentEditForm.tableHeaders.length - 1) {
- const temp = this.contentEditForm.tableHeaders[index]
- this.contentEditForm.tableHeaders.splice(index, 1)
- this.contentEditForm.tableHeaders.splice(index + 1, 0, temp)
- // 更新表头的序号
- this.updateTableHeadersOrderNumbers()
- }
- }
- },
- swamTableArr(arr, row, asc, isHeader) {
- if (isHeader) {
- // 创建数组副本以确保Vue能检测到变化
- // 直接替换整个数组,确保Vue能检测到变化
- this.doSwamTableArr(arr, row, asc, isHeader)
- } else {
- const isChild = row.isChild || row.isSubItem || false
- if (isChild) {
- // 子节点处理逻辑后续实现 parentid rowid
- let child = arr.find((item) => item.rowid === row.parentid)
- // const rowIndex = arr.indexOf(row);
- // newFixedTableData[rowIndex]
- this.doSwamTableArr(child.children, row, asc, isHeader)
- } else {
- this.doSwamTableArr(arr, row, asc, isHeader)
- }
- }
- },
- // 更新表头序号
- updateTableHeadersOrderNumbers() {
- if (!this.contentEditForm || !this.contentEditForm.tableHeaders) return
- // 更新主表头的orderNum
- this.contentEditForm.tableHeaders.forEach((header, index) => {
- header.orderNum = index + 1
- })
- // 同步更新固定表和动态表的表头序号
- if (
- this.contentEditForm.fixedTable &&
- this.contentEditForm.fixedTable.tableHeaders
- ) {
- this.contentEditForm.fixedTable.tableHeaders.forEach(
- (header, index) => {
- header.orderNum = index + 1
- }
- )
- }
- if (
- this.contentEditForm.dynamicTable &&
- this.contentEditForm.dynamicTable.tableHeaders
- ) {
- this.contentEditForm.dynamicTable.tableHeaders.forEach(
- (header, index) => {
- header.orderNum = index + 1
- }
- )
- }
- },
- doSwamTableArr(arr, row, asc, isHeader) {
- const rowIndex = arr.indexOf(row)
- let swamIndex = 0
- if (asc) {
- // 正序
- if (rowIndex < 1) {
- return
- }
- swamIndex = rowIndex - 1
- } else {
- // 倒序
- if (rowIndex >= arr.length - 1) {
- return
- }
- swamIndex = rowIndex + 1
- }
- const curr = arr[rowIndex]
- const swam = arr[swamIndex]
- // 交换orderNum
- const tempOrderNum = curr.orderNum
- curr.orderNum = swam.orderNum
- swam.orderNum = tempOrderNum
- // row.isChild &&
- if (!isHeader) {
- // 获取当前项的序号值
- let currIndex = curr.fixedValues
- ? curr.fixedValues['序号']
- : curr.dynamicValues['序号']
- // 获取交换项的序号值
- let swamIndex = swam.fixedValues
- ? swam.fixedValues['序号']
- : swam.dynamicValues['序号']
- // 先保存交换项的值,再进行赋值,避免值被覆盖
- if (curr.fixedValues) {
- curr.fixedValues['序号'] = swamIndex
- } else {
- curr.dynamicValues['序号'] = swamIndex
- }
- if (swam.fixedValues) {
- swam.fixedValues['序号'] = currIndex
- } else {
- swam.dynamicValues['序号'] = currIndex
- }
- }
- // 交换数组中的位置
- arr[rowIndex] = swam
- arr[swamIndex] = curr
- },
- // 启动/停用状态
- handleStatus(row) {
- const action = row.status === '启用' ? '停用' : '启用'
- if (row.status === '0') {
- this.$confirm(`确认要停用该数据吗?`, '操作确认', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- })
- .then(() => {
- row.status = '-1'
- putSurveyTemplatePublishVersion(row).then((res) => {
- if (res.code === 200) {
- this.$message.success(`停用成功`)
- this.handleSearch()
- }
- })
- })
- .catch(() => {
- this.$message({
- type: 'info',
- message: '已取消操作',
- })
- })
- } else if (row.status === '-1') {
- this.$confirm(`确认要启用该数据吗?`, '操作确认', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- })
- .then(() => {
- row.status = '0'
- putSurveyTemplatePublishVersion(row).then((res) => {
- if (res.code === 200) {
- this.$message.success(`启用成功`)
- this.handleSearch()
- }
- })
- })
- .catch(() => {
- this.$message({
- type: 'info',
- message: '已取消操作',
- })
- })
- }
- },
- // 更新固定表行序号
- updateFixedTableOrderNumbers() {
- this.contentEditForm.fixedTable.fixedTables.forEach((row, index) => {
- // 更新显示序号
- this.$set(row, 'orderText', index + 1)
- // 更新后端序号
- this.$set(row, 'orderNum', index + 1)
- })
- },
- // 更新动态表行序号
- updateDynamicTableOrderNumbers() {
- this.contentEditForm.dynamicTable.dynamicTables.forEach(
- (row, index) => {
- // 更新显示序号
- this.$set(row, 'orderText', index + 1)
- // 更新后端序号
- this.$set(row, 'orderNum', index + 1)
- }
- )
- },
- // 绑定字典变化
- handleBindDictChange(row) {
- if (row.isDict === 'false') {
- row.dictid = ''
- }
- },
- // 获取格式占位符
- getFormatPlaceholder(fieldType) {
- switch (fieldType) {
- case '日期':
- return '如:yyyy-MM-dd'
- case '数字':
- return '如:#,##0.00'
- default:
- return '请输入格式'
- }
- },
- // 滚动到错误行
- scrollToErrorRow(rowIndex) {
- this.$nextTick(() => {
- const tableBody = document.querySelector(
- '.table-edit-container .el-table__body-wrapper'
- )
- if (tableBody) {
- const scrollTop = rowIndex * 48
- tableBody.scrollTop = scrollTop
- }
- })
- },
- // 保存内容
- handleSaveContent(type, action) {
- this.loading = true
- let isValid = false
- try {
- if (type === '单记录') {
- var data = {
- headersList: this.contentEditForm.tableHeaders,
- }
- getBatchSaveOrUpdate(data)
- .then((res) => {
- if (res.code === 200) {
- if (action != 'delete') {
- this.$message.success('保存成功')
- this.contentEditDialogVisible = false
- }
- } else {
- this.$message.error(`保存失败:${res.message || '未知错误'}`)
- }
- })
- .catch((error) => {
- console.error('保存接口异常:', error)
- // this.$message.error('保存接口异常,请重试')
- })
- .finally(() => {
- this.loading = false
- })
- } else if (type === '固定表表头') {
- var data = {
- headersList: this.contentEditForm.fixedTable.tableHeaders,
- }
- getBatchSaveOrUpdate(data)
- .then((res) => {
- if (res.code === 200) {
- this.contentEditForm.isFixedTables = true
- this.loading = true
- // 如果后端返回了保存后的数据,更新本地数据
- if (res.value && Array.isArray(res.value)) {
- this.contentEditForm.fixedTable.tableHeaders =
- res.value.map((item) => ({
- ...item,
- }))
- // 确保保存后的数据也按正确顺序显示
- this.updateTableHeadersOrderNumbers()
- }
- this.getListBySurveyTemplateIdAndVersion(
- this.surveyTemplateId,
- this.versionId
- )
- listByTemplateIdAndVersion(
- this.surveyTemplateId,
- this.versionId
- )
- .then((res) => {
- this.loading = false
- this.contentEditForm.fixedTable.fixedTablesTitle =
- this.stringToObjects(res.value.fixedFields)
- this.contentEditForm.fixedTable.fixedTables.forEach(
- (row) => {
- this.initFixedTableRow(row)
- }
- )
- this.contentEditForm.fixedTable.fixedTableHeaders =
- this.contentEditForm.fixedTable.fixedTablesTitle.filter(
- (title) => title.rkey !== '序号'
- )
- })
- .catch((error) => {
- console.error('查询失败:', error)
- this.loading = false
- })
- } else {
- this.$message.error(`保存失败:${res.message || '未知错误'}`)
- }
- })
- .catch((error) => {
- console.error('保存接口异常:', error)
- // this.$message.error('保存接口异常,请重试')
- })
- .finally(() => {
- this.loading = false
- })
- } else if (type === '固定表项目') {
- this.saveFixedTableData(action)
- } else if (type === '动态表表头') {
- var data = {
- headersList: this.contentEditForm.dynamicTable.tableHeaders,
- }
- getBatchSaveOrUpdate(data)
- .then((res) => {
- if (res.code === 200) {
- this.contentEditForm.isDynamicTables = true
- this.loading = true
- // 如果后端返回了保存后的数据,更新本地数据
- if (res.value && Array.isArray(res.value)) {
- this.contentEditForm.dynamicTable.tableHeaders =
- res.value.map((item) => ({
- ...item,
- fieldKey: item.fieldEname
- ? item.fieldEname.toLowerCase()
- : `field_${Date.now()}_${Math.random()
- .toString(36)
- .substr(2, 9)}`,
- }))
- // 确保保存后的数据也按正确顺序显示
- this.updateTableHeadersOrderNumbers()
- }
- this.getListBySurveyTemplateIdAndVersion(
- this.surveyTemplateId,
- this.versionId
- )
- listByTemplateIdAndVersion(
- this.surveyTemplateId,
- this.versionId
- )
- .then((res) => {
- this.loading = false
- this.contentEditForm.dynamicTable.dynamicTablesTitle =
- this.stringToObjects(res.value.fixedFields || '')
- // 初始化所有已有行的 dynamicValues
- this.contentEditForm.dynamicTable.dynamicTables.forEach(
- (row) => {
- this.initDynamicTableRow(row)
- }
- )
- this.contentEditForm.dynamicTable.dynamicTableHeaders =
- this.contentEditForm.dynamicTable.dynamicTablesTitle.filter(
- (title) => title.rkey !== '序号'
- )
- })
- .catch((error) => {
- console.error('查询失败:', error)
- this.loading = false
- })
- } else {
- this.$message.error(`保存失败:${res.message || '未知错误'}`)
- }
- })
- .catch((error) => {
- console.error('保存接口异常:', error)
- // this.$message.error('保存接口异常,请重试')
- })
- .finally(() => {
- this.loading = false
- })
- } else if (type === '动态表项目') {
- this.saveDynamicTableData(action)
- }
- } catch (error) {
- console.error('保存处理异常:', error)
- // this.$message.error('保存过程中发生错误,请重试')
- this.loading = false
- }
- },
- // 公式验证函数
- validateFormula(formula, data) {
- if (!formula || typeof formula !== 'string') {
- return { valid: false, errorMsg: '公式不能为空' }
- }
- // 定义有效的操作符
- const operators = ['+', '-', '*', '/', '(', ')']
- // 检查是否包含至少一个操作符
- const hasOperator = operators.some((operator) =>
- formula.includes(operator)
- )
- if (!hasOperator) {
- return { valid: false, errorMsg: '公式必须包含操作符' }
- }
- // 检查值是否在data中存在
- function checkValueInData(value, data) {
- if (!data) return false
- if (Array.isArray(data)) {
- return data.includes(value)
- } else if (typeof data === 'object') {
- return Object.values(data).includes(value)
- }
- return data === value
- }
- // 提取公式中的变量/值
- function extractValues(formulaStr) {
- // 改进实现:支持形如"CeShi3.C2"的格式,提取点后面的部分作为变量,同时保留普通变量
- const result = new Set()
- // 1. 首先提取带点格式中的变量部分(如CeShi3.C2中的C2)
- const dotRegex = /[A-Za-z0-9]+\.([A-Za-z0-9]+)/g
- let dotMatch
- while ((dotMatch = dotRegex.exec(formulaStr)) !== null) {
- result.add(dotMatch[1]) // 提取点后面的部分作为变量
- }
- // 2. 然后提取普通变量(C3等),但排除已经从带点格式中提取的部分
- // 移除所有带点的部分,然后提取剩余的变量
- const remainingFormula = formulaStr.replace(
- /[A-Za-z0-9]+\.[A-Za-z0-9]+/g,
- ''
- )
- const normalRegex = /[A-Za-z0-9]+/g
- let normalMatch
- while ((normalMatch = normalRegex.exec(remainingFormula)) !== null) {
- // 跳过纯数字
- if (
- !isNaN(Number(normalMatch[0])) &&
- Number(normalMatch[0]).toString() === normalMatch[0]
- ) {
- continue
- }
- result.add(normalMatch[0])
- }
- return Array.from(result)
- }
- function checkOperatorContext(formulaStr, data) {
- for (let i = 0; i < formulaStr.length; i++) {
- const char = formulaStr[i]
- // 跳过括号
- if (char === '(' || char === ')') continue
- // 检查操作符
- if (operators.includes(char)) {
- // 检查操作符前是否有值(开头或不是操作符和左括号)
- if (
- i === 0 ||
- (operators.includes(formulaStr[i - 1]) &&
- formulaStr[i - 1] !== ')') ||
- formulaStr[i - 1] === '('
- ) {
- return {
- valid: false,
- errorMsg: `位置 ${i + 1} 的操作符 '${char}' 前缺少值`,
- }
- }
- // 检查操作符后是否有值(结尾或不是操作符和右括号)
- if (
- i === formulaStr.length - 1 ||
- (operators.includes(formulaStr[i + 1]) &&
- formulaStr[i + 1] !== '(') ||
- formulaStr[i + 1] === ')'
- ) {
- return {
- valid: false,
- errorMsg: `位置 ${i + 1} 的操作符 '${char}' 后缺少值`,
- }
- }
- }
- }
- // 验证通过后,检查公式中的值是否都在data中存在
- if (data.length > 0) {
- const values = extractValues(formulaStr)
- for (const value of values) {
- // 跳过纯数字(假设有值不在data中)
- if (!isNaN(Number(value)) && Number(value).toString() === value) {
- continue
- }
- if (!checkValueInData(value, data)) {
- return {
- valid: false,
- errorMsg: `变量 '${value}' 在数据中不存在`,
- }
- }
- }
- }
- return { valid: true }
- }
- // 执行验证
- return checkOperatorContext(formula, data)
- },
- /**
- * 将固定表项目的数据根据固定列拆分成对应的数据结构
- * @returns {Array} 拆分后的数据数组,每个固定列对应一行数据
- */
- splitFixedTableDataForSave() {
- const fixedTables = this.contentEditForm.fixedTable.fixedTables
- const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
- const fixedHeaders = this.contentEditForm.fixedTable.tableHeaders
- // 结果数组
- const result = []
- // 递归处理树形结构中的所有节点
- const processNode = (node, parentRowIndex = 0) => {
- // 确保node和fixedValues存在
- if (!node) {
- console.warn('遇到空节点,跳过处理')
- return
- }
- // 确保fixedValues属性存在,如果不存在则初始化为空对象
- if (!node.fixedValues) {
- node.fixedValues = {}
- }
- // 为每个固定列创建一条记录
- fixedTitles.forEach((title) => {
- // 找到对应的表头信息
- const correspondingHeader = fixedHeaders.find(
- (header) => header.fieldName === title.rkey
- )
- const newItem = {
- rkey: title.rkey,
- rvalue: node.fixedValues[title.rkey] || '',
- surveyTemplateId: node.surveyTemplateId || this.surveyTemplateId,
- versionId: node.versionId || this.versionId,
- tabtype: node.tabtype || this.templateType,
- // 添加 headersId 字段(表头的id)
- headersId: correspondingHeader ? correspondingHeader.id : null,
- // 添加记录的id(itemlist中每条记录的id)
- id: node.itemId || null,
- // 添加父子关系字段
- parentid: node.parentid || -1, // 父项ID,默认为-1表示无父项
- isChild: node.isChild || false, // 是否为子项
- // 添加 rowid 字段
- rowid: node.rowid || null,
- // 添加计算公式相关字段
- calculationFormula: node.calculationFormula || null,
- jsonstr: node.jsonstr || null,
- orderNum:
- typeof node.orderNum === 'number'
- ? node.orderNum
- : parseInt(node.orderNum, 10) || 0,
- }
- // 添加其他固定表特有的字段
- if (!node.isSubItem) {
- newItem.cellCode = node.cellCode || ''
- newItem.unit = node.unit || ''
- }
- // 添加其他可能需要的字段,但排除特定字段
- Object.keys(node).forEach((key) => {
- if (
- !(key in newItem) &&
- key !== 'fixedValues' &&
- key !== 'itemId' &&
- key !== 'id' &&
- key !== 'parentid' &&
- key !== 'isChild' &&
- key !== 'isSubItem' &&
- key !== 'rowid' &&
- key !== 'jsonstr' &&
- key !== 'calculationFormula' &&
- key !== 'children' // 排除children字段
- ) {
- newItem[key] = node[key]
- }
- })
- result.push(newItem)
- })
- // 递归处理子节点
- if (node.children && node.children.length > 0) {
- node.children.forEach((childNode) => {
- processNode(childNode)
- })
- }
- }
- // 遍历所有顶级节点
- fixedTables.forEach((row) => {
- processNode(row)
- })
- // 重新给子节点赋值orderNum 保证所有元素orderNum字段不重复
- // 为所有子节点分配唯一的orderNum,但保持父节点的orderNum不变
- // 计算所有已存在的orderNum中的最大值
- let maxExistingOrderNum = 0
- // 首先遍历结果数组找出当前最大的orderNum
- result.forEach((item) => {
- const orderNum =
- typeof item.orderNum === 'number'
- ? item.orderNum
- : parseInt(item.orderNum, 10) || 0
- if (orderNum > maxExistingOrderNum) {
- maxExistingOrderNum = orderNum
- }
- })
- // 子节点orderNum从当前最大orderNum + 1开始
- let childOrderNumCounter = maxExistingOrderNum + 1
- // 创建一个映射表,用于记录每个子节点对应的新orderNum
- const childOrderMap = new Map()
- // 第一次遍历:为每个子节点分配新的orderNum并存储映射关系
- function assignChildOrderNums(nodes) {
- nodes.forEach((node) => {
- if (node.isChild || node.isSubItem) {
- // 为每个子节点分配唯一的orderNum
- childOrderMap.set(node.id || node.rowid, childOrderNumCounter++)
- }
- // 递归处理子节点
- if (node.children && node.children.length > 0) {
- assignChildOrderNums(node.children)
- }
- })
- }
- // 第二次遍历:更新结果数组中的orderNum
- assignChildOrderNums(fixedTables)
- // 应用新的orderNum到结果数组
- result.forEach((item) => {
- // 只更新子节点的orderNum
- if (item.isChild || item.isSubItem) {
- const newOrderNum =
- childOrderMap.get(item.id) || childOrderMap.get(item.rowid)
- if (newOrderNum) {
- item.orderNum = newOrderNum
- }
- }
- })
- return result
- },
- /**
- * 将动态表项目的数据根据动态列拆分成对应的数据结构
- * @returns {Array} 拆分后的数据数组,每个动态列对应一行数据
- */
- splitDynamicTableDataForSave() {
- const dynamicTables = this.contentEditForm.dynamicTable.dynamicTables
- const dynamicTitles =
- this.contentEditForm.dynamicTable.dynamicTablesTitle
- const dynamicHeaders = this.contentEditForm.dynamicTable.tableHeaders
- // 结果数组
- const result = []
- // 递归处理树形结构中的所有节点
- const processNode = (node) => {
- // 确保node和dynamicValues存在
- if (!node) {
- console.warn('遇到空节点,跳过处理')
- return
- }
- // 确保dynamicValues属性存在,如果不存在则初始化为空对象
- if (!node.dynamicValues) {
- node.dynamicValues = {}
- }
- // 为每个固定列创建一条记录
- dynamicTitles.forEach((title) => {
- // 找到对应的表头信息
- const correspondingHeader = dynamicHeaders.find(
- (header) => header.fieldName === title.rkey
- )
- const newItem = {
- rkey: title.rkey,
- rvalue: node.dynamicValues[title.rkey] || '',
- surveyTemplateId: node.surveyTemplateId,
- versionId: node.versionId,
- tabtype: node.tabtype,
- // 添加 headersId 字段(表头的id)
- headersId: correspondingHeader ? correspondingHeader.id : null,
- // 添加记录的id(itemlist中每条记录的id)
- id: node.itemId || null,
- // 添加父子关系字段
- parentid: node.parentid || -1, // 父项ID,默认为-1表示无父项
- isChild: node.isChild || false, // 是否为子项
- // 添加 rowid 字段
- rowid: node.rowid || null,
- // 添加计算公式相关字段
- calculationFormula: node.calculationFormula || null,
- jsonstr: node.jsonstr || null,
- orderNum:
- typeof node.orderNum === 'number'
- ? node.orderNum
- : parseInt(node.orderNum, 10) || 0,
- }
- // 添加其他可能需要的字段,但排除特定字段
- Object.keys(node).forEach((key) => {
- if (
- !(key in newItem) &&
- key !== 'dynamicValues' &&
- key !== 'itemId' &&
- key !== 'id' &&
- key !== 'parentid' &&
- key !== 'isChild' &&
- key !== 'isSubItem' &&
- key !== 'rowid' &&
- key !== 'jsonstr' &&
- key !== 'calculationFormula' &&
- key !== 'children' // 排除children字段
- ) {
- newItem[key] = node[key]
- }
- })
- result.push(newItem)
- })
- // 递归处理子节点
- if (node.children && node.children.length > 0) {
- node.children.forEach((childNode) => {
- processNode(childNode)
- })
- }
- }
- // 遍历所有顶级节点
- dynamicTables.forEach((row) => {
- processNode(row)
- })
- // 重新给子节点赋值orderNum 保证所有元素orderNum字段不重复
- // 为所有子节点分配唯一的orderNum,但保持父节点的orderNum不变
- // 计算所有已存在的orderNum中的最大值
- let maxExistingOrderNum = 0
- // 首先遍历结果数组找出当前最大的orderNum
- result.forEach((item) => {
- const orderNum =
- typeof item.orderNum === 'number'
- ? item.orderNum
- : parseInt(item.orderNum, 10) || 0
- if (orderNum > maxExistingOrderNum) {
- maxExistingOrderNum = orderNum
- }
- })
- // 子节点orderNum从当前最大orderNum + 1开始
- let childOrderNumCounter = maxExistingOrderNum + 1
- // 创建一个映射表,用于记录每个子节点对应的新orderNum
- const childOrderMap = new Map()
- // 第一次遍历:为每个子节点分配新的orderNum并存储映射关系
- function assignChildOrderNums(nodes) {
- nodes.forEach((node) => {
- if (node.isChild || node.isSubItem) {
- // 为每个子节点分配唯一的orderNum
- childOrderMap.set(node.id || node.rowid, childOrderNumCounter++)
- }
- // 递归处理子节点
- if (node.children && node.children.length > 0) {
- assignChildOrderNums(node.children)
- }
- })
- }
- // 第二次遍历:更新结果数组中的orderNum
- assignChildOrderNums(dynamicTables)
- // 应用新的orderNum到结果数组
- result.forEach((item) => {
- // 只更新子节点的orderNum
- if (item.isChild || item.isSubItem) {
- const newOrderNum =
- childOrderMap.get(item.id) || childOrderMap.get(item.rowid)
- if (newOrderNum) {
- item.orderNum = newOrderNum
- }
- }
- })
- return result
- },
- //保存固定表项目数据
- saveFixedTableData(action = '') {
- try {
- // 获取拆分后的数据
- const splitData = this.splitFixedTableDataForSave()
- // 构造保存数据的结构
- const saveData = {
- itemsList: splitData,
- }
- // 调用保存接口
- getBatchSaveOrUpdate(saveData)
- .then((res) => {
- if (res.code === 200) {
- // 如果是删除操作,不显示成功提示且不关闭对话框
- if (action !== 'delete') {
- this.$message.success('固定表数据保存成功')
- this.contentEditDialogVisible = false
- }
- // 刷新数据以确保UI更新
- this.getListBySurveyTemplateIdAndVersion(
- this.surveyTemplateId,
- this.versionId
- )
- } else {
- this.$message.error(`保存失败:${res.message || '未知错误'}`)
- }
- })
- .catch((error) => {
- console.error('保存固定表数据接口异常:', error)
- // this.$message.error('保存固定表数据失败,请重试')
- })
- .finally(() => {
- this.loading = false
- })
- return splitData
- } catch (error) {
- console.error('处理固定表数据保存时出错:', error)
- // this.$message.error('保存过程中发生错误,请重试')
- this.loading = false
- }
- },
- //保存动态表项目数据
- saveDynamicTableData() {
- try {
- // 获取拆分后的数据
- const splitData = this.splitDynamicTableDataForSave()
- // 构造保存数据的结构
- const saveData = {
- itemsList: splitData,
- }
- // 调用保存接口
- getBatchSaveOrUpdate(saveData)
- .then((res) => {
- if (res.code === 200) {
- if (action != 'delete') {
- this.$message.success('动态表数据保存成功')
- this.contentEditDialogVisible = false
- }
- } else {
- this.$message.error(`保存失败:${res.message || '未知错误'}`)
- }
- })
- .catch((error) => {
- console.error('保存动态表数据接口异常:', error)
- // this.$message.error('保存动态表数据失败,请重试')
- })
- .finally(() => {
- this.loading = false
- })
- return splitData
- } catch (error) {
- console.error('处理动态表数据保存时出错:', error)
- // this.$message.error('保存过程中发生错误,请重试')
- this.loading = false
- }
- },
- /**
- * 解析并回显固定表项目数据
- * @param {Object} responseData - listByTemplateIdAndVersion接口返回的数据
- */
- parseAndDisplayFixedTableData(responseData) {
- if (responseData.value.fixedFields) {
- this.contentEditForm.fixedTable.fixedTablesTitle =
- this.stringToObjects(responseData.value.fixedFields || '')
- } else {
- let fixedFields = this.contentEditForm.fixedTable.tableHeaders
- .map((item) => item.fieldName)
- .join(',')
- this.contentEditForm.fixedTable.fixedTablesTitle =
- this.stringToObjects(fixedFields || '')
- }
- const fixedTitles = this.contentEditForm.fixedTable.fixedTablesTitle
- this.contentEditForm.fixedTable.fixedTableHeaders = fixedTitles.filter(
- (title) => title.rkey !== '序号'
- )
- if (
- !responseData ||
- !responseData.value ||
- !responseData.value.itemlist
- ) {
- return
- }
- const itemList = responseData.value.itemlist
- const allRows = []
- const rowMap = new Map()
- // 清空现有数据
- this.contentEditForm.fixedTable.fixedTables = []
- // 遍历itemList,为每个项目创建一行数据
- itemList.forEach((item, index) => {
- // 判断是否为子项(parentid不为-1且不为"-1")
- const isSubItem =
- item.parentid && item.parentid !== -1 && item.parentid !== '-1'
- const newRow = {
- orderText: item.orderNum || '', // 显示用序号
- orderNum: item.orderNum || '', // 保留原始序号用于发送后端
- surveyTemplateId: item.surveyTemplateId,
- versionId: item.versionId,
- cellCode: item.cellCode || '',
- calculationFormula: item.calculationFormula || '',
- unit: item.unit || '',
- fixedValues: {},
- itemId: item.id || null,
- parentid: item.parentid || -1,
- isChild: isSubItem,
- isSubItem: isSubItem,
- rowid: item.rowid || this.generateUUID(),
- jsonstr: item.jsonstr || null,
- children: [], // 添加children数组用于树形结构
- }
- // 确保orderNum是数字类型
- if (item.orderNum) {
- newRow.orderNum = parseInt(item.orderNum, 10) || 0
- }
- // 初始化fixedValues并填充实际值
- fixedTitles.forEach((title) => {
- newRow.fixedValues[title.rkey] = item[title.rkey] || ''
- })
- allRows.push(newRow)
- // 构建rowMap用于快速查找
- if (newRow.rowid) rowMap.set(String(newRow.rowid), newRow)
- if (newRow.itemId) rowMap.set(String(newRow.itemId), newRow)
- })
- // 构建树形结构
- const treeData = []
- const parentItems = allRows.filter((item) => !item.isChild)
- // 父级按orderNum正序排序
- parentItems.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
- // 将子项添加到对应的父项的children中
- allRows.forEach((item) => {
- if (item.isChild) {
- const parentId = String(item.parentid)
- const parent = rowMap.get(parentId)
- if (parent) {
- parent.children.push(item)
- }
- }
- })
- // 对子项进行排序
- parentItems.forEach((parent) => {
- parent.children.sort(
- (a, b) =>
- (a.fixedValues['序号'] || 0) - (b.fixedValues['序号'] || 0)
- )
- treeData.push(parent)
- })
- this.contentEditForm.fixedTable.fixedTables = treeData
- },
- /**
- * 解析并回显动态表项目数据
- * @param {Object} responseData - listByTemplateIdAndVersion接口返回的数据
- */
- parseAndDisplayDynamicTableData(responseData) {
- if (responseData.value.fixedFields) {
- this.contentEditForm.dynamicTable.dynamicTablesTitle =
- this.stringToObjects(responseData.value.fixedFields || '')
- } else {
- let fixedFields = this.contentEditForm.dynamicTable.tableHeaders
- .map((item) => item.fieldName)
- .join(',')
- this.contentEditForm.dynamicTable.dynamicTablesTitle =
- this.stringToObjects(fixedFields || '')
- }
- const dynamicTitles =
- this.contentEditForm.dynamicTable.dynamicTablesTitle
- this.contentEditForm.dynamicTable.dynamicTableHeaders =
- dynamicTitles.filter((title) => title.rkey !== '序号')
- if (
- !responseData ||
- !responseData.value ||
- !responseData.value.itemlist
- ) {
- return
- }
- const itemList = responseData.value.itemlist
- const allRows = []
- const rowMap = new Map()
- // 清空现有数据
- this.contentEditForm.dynamicTable.dynamicTables = []
- // 遍历itemList,为每个项目创建一行数据
- itemList.forEach((item, index) => {
- // 判断是否为子项(parentid不为-1且不为"-1")
- const isSubItem =
- item.parentid && item.parentid !== -1 && item.parentid !== '-1'
- const newRow = {
- orderText: item.orderNum || '', // 显示用序号
- orderNum: item.orderNum || '', // 保留原始序号用于发送后端
- surveyTemplateId: item.surveyTemplateId,
- dynamicValues: {},
- itemId: item.id || null,
- parentid: item.parentid || -1,
- isChild: isSubItem,
- isSubItem: isSubItem,
- rowid: item.rowid || this.generateUUID(),
- jsonstr: item.jsonstr || null,
- children: [], // 添加children数组用于树形结构
- }
- // 确保orderNum是数字类型
- if (item.orderNum) {
- newRow.orderNum = parseInt(item.orderNum, 10) || 0
- }
- // 初始化dynamicValues并填充实际值
- dynamicTitles.forEach((title) => {
- // 特殊处理序号字段,需要保存到dynamicValues中供输入框使用
- if (title.rkey === '序号') {
- // 优先使用item中的序号值,如果没有则保持为空
- newRow.dynamicValues[title.rkey] = item[title.rkey] || ''
- }
- // 排除其他序号相关字段,避免重复显示
- else if (title.rkey !== 'ordernum' && title.rkey !== 'orderText') {
- newRow.dynamicValues[title.rkey] = item[title.rkey] || ''
- }
- })
- allRows.push(newRow)
- // 构建rowMap用于快速查找
- if (newRow.rowid) rowMap.set(String(newRow.rowid), newRow)
- if (newRow.itemId) rowMap.set(String(newRow.itemId), newRow)
- })
- // 构建树形结构
- const treeData = []
- const parentItems = allRows.filter((item) => !item.isChild)
- // 父级按orderNum正序排序
- parentItems.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
- // 将子项添加到对应的父项的children中
- allRows.forEach((item) => {
- if (item.isChild) {
- const parentId = String(item.parentid)
- const parent = rowMap.get(parentId)
- if (parent) {
- parent.children.push(item)
- }
- }
- })
- // 对子项进行排序
- parentItems.forEach((parent) => {
- parent.children.sort(
- (a, b) =>
- (Number(a.dynamicValues['序号']) || 0) -
- (Number(b.dynamicValues['序号']) || 0)
- )
- treeData.push(parent)
- })
- this.contentEditForm.dynamicTable.dynamicTables = treeData
- console.log('树形结构数据:', treeData)
- },
- //分割字符串
- stringToObjects(str) {
- const items = str.split(',')
- return items.map((item) => ({
- rkey: item,
- rvalue: '',
- }))
- },
- // 删除
- handleDelete(row) {
- this.$confirm('确定要删除该数据吗?', '提示', {
- type: 'warning',
- })
- .then(() => {
- this.loading = true
- delSurveyTemplateVersionById(row.id)
- .then((res) => {
- if (res.code === 200) {
- this.$message.success(res.message || '删除成功')
- this.handleSearch()
- this.loading = false
- }
- })
- .catch((error) => {
- console.error('删除失败:', error)
- this.loading = false
- })
- })
- .catch(() => {})
- },
- // 批量删除
- handleBatchDelete() {
- if (this.selectedRows.length === 0) {
- this.$message.warning('请先选择要删除的数据')
- return
- }
- this.$confirm(
- `确定要删除选中的${this.selectedRows.length}条数据吗?`,
- '提示',
- {
- type: 'warning',
- }
- )
- .then(() => {
- this.loading = true
- const ids = this.selectedRows.map((row) => row.id)
- batchDeleteCostForm(ids)
- .then((res) => {
- this.selectedRows = []
- this.$message.success(res.message || '删除成功')
- this.handleSearch()
- this.loading = false
- })
- .catch((error) => {
- console.error('批量删除失败:', error)
- this.loading = false
- })
- })
- .catch(() => {})
- },
- // 表格选择
- handleSelectionChange(selection) {
- this.selectedRows = selection
- },
- // 分页变化处理
- handlePaginationChange({ currentPage, pageSize }) {
- this.pagination.currentPage = currentPage
- this.pagination.pageSize = pageSize
- this.handleSearch()
- },
- // 提交表单
- submitForm() {
- this.$refs.dataForm.validate((valid) => {
- if (valid) {
- this.loading = true
- const submitData = {
- versionNo: this.dataForm.version,
- status: this.dataForm.status,
- createBy: this.dataForm.createBy,
- createTime: this.dataForm.createTime,
- remarks: this.dataForm.remarks,
- templateType: this.currentRow.templateType,
- surveyTemplateName: this.currentRow.surveyTemplateName,
- surveyTemplateId: this.currentRow.surveyTemplateId,
- }
- if (this.dataForm.id) {
- // 修改
- submitData.formId = this.dataForm.id
- editCostForm(submitData)
- .then(() => {
- this.loading = false
- this.$message.success('修改成功')
- this.dialogVisible = false
- this.handleSearch() // 重新加载数据
- })
- .catch((error) => {
- console.error('修改失败:', error)
- // this.$message.error('修改失败,请重试')
- this.loading = false
- })
- } else {
- addSurveyTemplateVersion(submitData)
- .then(() => {
- this.loading = false
- this.$message.success('添加成功')
- this.dialogVisible = false
- this.handleSearch() // 重新加载数据
- })
- .catch((error) => {
- console.error('添加失败:', error)
- // this.$message.error('添加失败,请重试')
- this.loading = false
- })
- }
- }
- })
- },
- // 获取数据存储库表选项
- loadDataStorageTableOptions() {
- getDataStorageTableOptions()
- .then((response) => {
- this.dataStorageTableOptions = response.data || []
- })
- .catch((error) => {
- console.error('获取数据存储库表选项失败:', error)
- })
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- @import '@/styles/costAudit.scss';
- .top-wrapper {
- display: flex;
- align-items: center;
- }
- .data-form,
- .detail-form {
- ::v-deep .el-select {
- width: 100%;
- }
- }
- .content-edit-container {
- overflow-y: auto;
- .button-group {
- margin: 10px 0;
- .el-button {
- margin-right: 10px;
- }
- }
- .table-edit-container {
- margin-top: 10px;
- ::v-deep .el-table {
- transition: height 0.3s ease;
- }
- ::v-deep .el-table__body-wrapper {
- transition: scrollTop 0.3s ease;
- }
- }
- .bind-dict-column {
- display: flex;
- flex-direction: column;
- }
- .table-actions {
- display: flex;
- justify-content: center;
- align-items: center;
- .el-button {
- padding: 4px;
- margin: 0 2px;
- }
- }
- .format-input {
- display: flex;
- align-items: center;
- .format-prefix {
- font-size: 12px;
- color: #606266;
- margin-right: 5px;
- white-space: nowrap;
- }
- }
- }
- .detail-info-container {
- margin: 20px 0;
- border-radius: 4px;
- .detail-item {
- display: inline-block;
- margin-right: 30px;
- margin-bottom: 10px;
- .detail-label {
- font-weight: bold;
- color: #606266;
- }
- .detail-value {
- color: #303133;
- }
- }
- }
- </style>
|