IotProjectTaskForm.vue 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331
  1. <template>
  2. <ContentWrap v-loading="formLoading">
  3. <el-form
  4. ref="formRef"
  5. :model="formData"
  6. :rules="formRules"
  7. label-width="100px"
  8. v-loading="formLoading"
  9. >
  10. <el-row>
  11. <el-col :span="12">
  12. <el-form-item label="合同名称" prop="contractName">
  13. <el-select
  14. v-model="formData.contractId"
  15. placeholder="请选择"
  16. @change="getProjectInfo"
  17. disabled
  18. >
  19. <el-option
  20. v-for="item in projectList"
  21. :key="item.id"
  22. :label="item.contractName"
  23. :value="item.id"
  24. clearable
  25. />
  26. </el-select>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="12">
  30. <el-form-item label="合同编号" prop="contractCode">
  31. <el-input v-model="formData.contractCode" placeholder="请输入合同编号" disabled />
  32. </el-form-item>
  33. </el-col>
  34. </el-row>
  35. <el-row>
  36. <el-col :span="12">
  37. <el-form-item label="客户名称" prop="manufacturerId">
  38. <el-select
  39. clearable
  40. @clear="zzClear"
  41. v-model="formData.manufacturerId"
  42. :placeholder="t('deviceForm.mfgHolder')"
  43. disabled
  44. >
  45. <el-option :label="formData.manufactureName" :value="formData.manufacturerId" />
  46. </el-select>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="12">
  50. <el-form-item :label="t('project.payment')" prop="payment">
  51. <el-select v-model="formData.payment" placeholder="请选择" disabled>
  52. <el-option
  53. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_PROJECT_SETTLEMENT)"
  54. :key="dict.id"
  55. :label="dict.label"
  56. :value="dict.value"
  57. />
  58. </el-select>
  59. </el-form-item>
  60. </el-col>
  61. </el-row>
  62. <el-row>
  63. <el-col :span="12">
  64. <el-form-item label="开始时间" prop="startTime">
  65. <el-date-picker
  66. style="width: 150%"
  67. v-model="formData.startTime"
  68. type="date"
  69. value-format="x"
  70. placeholder="选择开始时间"
  71. disabled
  72. />
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="12">
  76. <el-form-item label="完成时间" prop="endTime">
  77. <el-date-picker
  78. style="width: 150%"
  79. v-model="formData.endTime"
  80. type="date"
  81. value-format="x"
  82. placeholder="选择完成时间"
  83. disabled
  84. />
  85. </el-form-item>
  86. </el-col>
  87. </el-row>
  88. <el-form-item label="备注" prop="remark">
  89. <el-input v-model="formData.remark" placeholder="请输入备注" type="textarea" disabled />
  90. </el-form-item>
  91. </el-form>
  92. </ContentWrap>
  93. <ContentWrap v-if="false">
  94. <div class="content">
  95. <div class="toolbar">
  96. <div class="actions">
  97. <!-- 操作按钮已移动到表单区域 -->
  98. </div>
  99. </div>
  100. <div class="table-container">
  101. <el-table
  102. :data="tableData"
  103. empty-text="暂无数据"
  104. highlight-current-row
  105. @current-change="handleRowClick"
  106. >
  107. <el-table-column prop="wellName" label="井号" />
  108. <el-table-column prop="wellType" label="井型">
  109. <template #default="{ row }">
  110. {{ getWellTypeLabel(row.wellType) }}
  111. </template>
  112. </el-table-column>
  113. <el-table-column prop="wellCategory" label="井别">
  114. <template #default="{ row }">
  115. {{ getWellCategoryLabel(row.wellCategory) }}
  116. </template>
  117. </el-table-column>
  118. <el-table-column prop="location" label="施工地点" />
  119. <el-table-column :label="t('project.technology')">
  120. <template #default="{ row }">
  121. {{ getTechniqueLabel(row.technique) }}
  122. </template>
  123. </el-table-column>
  124. <el-table-column prop="workloadDesign" label="设计工作量" />
  125. <el-table-column :label="t('project.unit')">
  126. <template #default="{ row }">
  127. {{ getWorkloadUnitLabel(row.workloadUnit) }}
  128. </template>
  129. </el-table-column>
  130. <el-table-column prop="deptIds" label="施工队伍">
  131. <template #default="{ row }">
  132. <el-tooltip
  133. effect="dark"
  134. :content="getAllDeptNames(row.deptIds)"
  135. placement="top"
  136. :disabled="!row.deptIds || row.deptIds.length <= 1"
  137. >
  138. <span class="dept-names">
  139. {{ getDeptNames(row.deptIds) }}
  140. </span>
  141. </el-tooltip>
  142. </template>
  143. </el-table-column>
  144. <el-table-column prop="deviceIds" label="施工设备">
  145. <template #default="{ row }">
  146. <el-tooltip
  147. :content="getAllDeviceNames(row.deviceIds)"
  148. placement="top"
  149. :disabled="row.deviceIds && row.deviceIds.length <= 1"
  150. >
  151. <span class="device-names">
  152. {{ getDeviceNames(row.deviceIds) }}
  153. </span>
  154. </el-tooltip>
  155. </template>
  156. </el-table-column>
  157. <el-table-column prop="responsiblePerson" label="责任人">
  158. <template #default="{ row }">
  159. <el-tooltip
  160. :content="getAllResponsiblePersonNames(row.responsiblePerson)"
  161. placement="top"
  162. :disabled="!row.responsiblePerson || row.responsiblePerson.length <= 1"
  163. >
  164. <span class="responsible-names">
  165. {{ getResponsiblePersonNames(row.responsiblePerson) }}
  166. </span>
  167. </el-tooltip>
  168. </template>
  169. </el-table-column>
  170. <el-table-column prop="remark" label="备注" />
  171. </el-table>
  172. </div>
  173. </div>
  174. </ContentWrap>
  175. <!-- 新增任务详情编辑表单 -->
  176. <ContentWrap>
  177. <h3 style="margin-bottom: 20px">任务详情</h3>
  178. <el-form
  179. ref="taskFormRef"
  180. :model="currentTask"
  181. :rules="taskFormRules"
  182. label-width="120px"
  183. class="task-edit-form"
  184. >
  185. <el-row>
  186. <el-col :span="8">
  187. <el-form-item label="井号" prop="wellName">
  188. <el-input
  189. v-model="currentTask.wellName"
  190. placeholder="请输入井号"
  191. :disabled="currentTask.platformWell === '1'"
  192. />
  193. </el-form-item>
  194. </el-col>
  195. <el-col :span="8">
  196. <el-form-item :label="t('project.workArea')" prop="location">
  197. <el-autocomplete
  198. ref="workAreaAutocomplete"
  199. v-model="currentTask.location"
  200. :fetch-suggestions="querySearch"
  201. :trigger-on-focus="true"
  202. placeholder="请输入施工区域"
  203. @focus="handleWorkAreaFocus"
  204. @select="handleSelect"
  205. :disabled="!workAreaOptions.length"
  206. popper-class="work-area-autocomplete"
  207. >
  208. <template #prefix>
  209. <el-icon v-if="loadingWorkAreaOptions" class="is-loading">
  210. <Loading />
  211. </el-icon>
  212. </template>
  213. </el-autocomplete>
  214. <div v-if="!workAreaOptions.length" class="el-form-item__error">
  215. 暂无可用施工区域选项,请手动输入
  216. </div>
  217. </el-form-item>
  218. </el-col>
  219. <el-col :span="8">
  220. <el-form-item :label="t('project.technology')" prop="technique">
  221. <el-select
  222. v-model="currentTask.technique"
  223. placeholder="请选择施工工艺"
  224. clearable
  225. :loading="loadingTechnologyOptions"
  226. >
  227. <el-option
  228. v-for="dict in technologyOptions"
  229. :key="dict.value"
  230. :label="dict.label"
  231. :value="dict.value"
  232. />
  233. </el-select>
  234. <div
  235. v-if="!technologyOptions.length && !loadingTechnologyOptions"
  236. class="el-form-item__error"
  237. >
  238. 暂无可用施工工艺选项
  239. </div>
  240. </el-form-item>
  241. </el-col>
  242. </el-row>
  243. <el-row>
  244. <el-col :span="8">
  245. <el-form-item label="设计工作量" prop="workloadDesign">
  246. <el-tooltip
  247. :disabled="!workloadDesignError"
  248. :content="workloadDesignError"
  249. placement="top"
  250. effect="light"
  251. popper-class="workload-design-tooltip"
  252. :show-after="0"
  253. >
  254. <el-input
  255. v-model="currentTask.workloadDesign"
  256. placeholder="请输入设计工作量"
  257. :disabled="currentTask.platformWell === '1'"
  258. class="workload-input-with-button"
  259. :class="{ 'error-input': workloadDesignError }"
  260. @blur="validateWorkloadDesign"
  261. >
  262. <template #append>
  263. <el-tooltip content="添加多个设计工作量" placement="top">
  264. <el-button
  265. class="workload-add-btn"
  266. @click="openWorkloadDialog"
  267. :disabled="getWorkloadAddBtnDisabled"
  268. >
  269. <span class="btn-text">+</span>
  270. </el-button>
  271. </el-tooltip>
  272. </template>
  273. </el-input>
  274. </el-tooltip>
  275. </el-form-item>
  276. </el-col>
  277. <el-col :span="8">
  278. <el-form-item :label="t('project.unit')" prop="workloadUnit">
  279. <el-select
  280. v-model="currentTask.workloadUnit"
  281. placeholder="请选择工作量单位"
  282. clearable
  283. :disabled="currentTask.platformWell === '1'"
  284. >
  285. <el-option
  286. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_PROJECT_WORKLOAD_UNIT)"
  287. :key="dict.value"
  288. :label="dict.label"
  289. :value="dict.value"
  290. :disabled="
  291. getFormSelectedWorkloadUnits().includes(dict.value) &&
  292. dict.value !== currentTask.workloadUnit
  293. "
  294. />
  295. </el-select>
  296. </el-form-item>
  297. </el-col>
  298. <el-col :span="8">
  299. <el-form-item label="施工队伍" prop="deptIds">
  300. <el-tree-select
  301. multiple
  302. :multiple-limit="formData.deptId === 157 ? 1 : 0"
  303. v-model="currentTask.deptIds"
  304. :data="deptList"
  305. :props="treeSelectProps"
  306. :default-expanded-keys="defaultExpandedKeys"
  307. check-strictly
  308. node-key="id"
  309. filterable
  310. placeholder="请选择施工队伍"
  311. clearable
  312. @visible-change="handleTreeVisibleChange"
  313. collapse-tags
  314. collapse-tags-tooltip
  315. :max-collapse-tags="1"
  316. class="department-tree-select single-line-tree-select"
  317. />
  318. </el-form-item>
  319. </el-col>
  320. </el-row>
  321. <el-row>
  322. <el-col :span="8">
  323. <el-form-item label="施工设备" prop="deviceIds">
  324. <el-button @click="openDeviceDialogForForm" type="primary" size="small">
  325. 选择设备
  326. </el-button>
  327. <!--
  328. <span v-if="currentTask.deviceIds && currentTask.deviceIds.length > 0" style="margin-left: 10px;">
  329. 已选 {{ currentTask.deviceIds.length }} 台设备
  330. </span> -->
  331. <el-tooltip
  332. v-if="currentTask.deviceIds && currentTask.deviceIds.length > 0"
  333. :content="getAllDeviceNamesForForm(currentTask.deviceIds)"
  334. placement="top"
  335. >
  336. <span style="margin-left: 10px">
  337. {{ formatDevicesForForm(currentTask.deviceIds) }}
  338. </span>
  339. </el-tooltip>
  340. </el-form-item>
  341. </el-col>
  342. <el-col :span="8">
  343. <el-form-item :label="isSpecialDept ? '带班干部' : '责任人'" prop="responsiblePerson">
  344. <el-button @click="openResponsiblePersonDialogForForm" type="primary" size="small">
  345. 选择{{ isSpecialDept ? '带班干部' : '责任人' }}
  346. </el-button>
  347. <el-tooltip
  348. v-if="currentTask.responsiblePerson && currentTask.responsiblePerson.length > 0"
  349. :content="getAllResponsiblePersonNamesForForm(currentTask.responsiblePerson)"
  350. placement="top"
  351. >
  352. <span style="margin-left: 10px">
  353. {{ formatResponsiblePersonsForForm(currentTask.responsiblePerson) }}
  354. </span>
  355. </el-tooltip>
  356. </el-form-item>
  357. </el-col>
  358. <el-col :span="8" v-if="isSpecialDept">
  359. <el-form-item label="填报人" prop="submitter">
  360. <el-button @click="openSubmitterDialogForForm" type="primary" size="small">
  361. 选择填报人
  362. </el-button>
  363. <el-tooltip
  364. v-if="currentTask.submitter && currentTask.submitter.length > 0"
  365. :content="getAllSubmitterNamesForForm(currentTask.submitter)"
  366. placement="top"
  367. >
  368. <span style="margin-left: 10px">
  369. {{ formatSubmittersForForm(currentTask.submitter) }}
  370. </span>
  371. </el-tooltip>
  372. </el-form-item>
  373. </el-col>
  374. </el-row>
  375. <el-row>
  376. <el-col :span="8" v-if="isSpecialDept">
  377. <el-form-item label="平台井" prop="platformWell">
  378. <el-switch
  379. v-model="currentTask.platformWell"
  380. active-value="1"
  381. inactive-value="0"
  382. @change="handlePlatformWellChange"
  383. />
  384. </el-form-item>
  385. </el-col>
  386. </el-row>
  387. <!-- 动态属性部分 -->
  388. <el-row v-if="dynamicAttrs.length > 0">
  389. <el-col
  390. v-for="attr in dynamicAttrs"
  391. :key="attr.id"
  392. :span="attr.dataType === 'textarea' ? 24 : 8"
  393. >
  394. <el-form-item
  395. :label="attr.name + (attr.unit ? `(${attr.unit})` : '')"
  396. :prop="attr.identifier"
  397. :rules="getDynamicAttrRules(attr)"
  398. >
  399. <!-- 文本类型 -->
  400. <el-input
  401. v-if="attr.dataType === 'text'"
  402. v-model="currentTask[attr.identifier]"
  403. :placeholder="`请输入${attr.name}`"
  404. />
  405. <!-- 文本域类型 -->
  406. <el-input
  407. v-else-if="attr.dataType === 'textarea'"
  408. v-model="currentTask[attr.identifier]"
  409. :placeholder="`请输入${attr.name}`"
  410. type="textarea"
  411. :rows="3"
  412. />
  413. <!-- 数字类型 -->
  414. <el-input
  415. v-else-if="attr.dataType === 'double'"
  416. v-model="currentTask[attr.identifier]"
  417. :placeholder="`请输入${attr.name}`"
  418. type="number"
  419. :min="attr.minValue || undefined"
  420. :max="attr.maxValue || undefined"
  421. />
  422. <!-- 日期类型 -->
  423. <el-date-picker
  424. v-else-if="attr.dataType === 'date'"
  425. v-model="currentTask[attr.identifier]"
  426. type="date"
  427. value-format="x"
  428. :placeholder="`选择${attr.name}`"
  429. style="width: 100%"
  430. />
  431. <!-- 默认文本输入 -->
  432. <el-input
  433. v-else
  434. v-model="currentTask[attr.identifier]"
  435. :placeholder="`请输入${attr.name}`"
  436. />
  437. </el-form-item>
  438. </el-col>
  439. </el-row>
  440. <el-row>
  441. <el-col :span="24">
  442. <el-form-item label="备注" prop="remark">
  443. <el-input v-model="currentTask.remark" placeholder="请输入备注" type="textarea" />
  444. </el-form-item>
  445. </el-col>
  446. </el-row>
  447. <el-form-item>
  448. <el-button @click="resetTaskForm" v-if="isNewTask">重置</el-button>
  449. </el-form-item>
  450. </el-form>
  451. </ContentWrap>
  452. <div
  453. v-if="companyName === 'ry'"
  454. class="my-6 bg-white p-4 border-1 border-solid border-[var(--el-border-color-light)]"
  455. >
  456. <h3 style="margin-bottom: 20px">附件</h3>
  457. <el-form-item size="default" label="工程设计">
  458. <el-upload
  459. v-model:file-list="constructionFiles"
  460. :action="uploadUrl"
  461. multiple
  462. :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
  463. name="files"
  464. class="w-50%"
  465. @preview="handlePreview"
  466. >
  467. <el-button type="primary">上传工程设计</el-button>
  468. <template #tip>
  469. <div class="el-upload__tip">文件大小不能超过50MB </div>
  470. </template>
  471. </el-upload>
  472. </el-form-item>
  473. <el-form-item size="default" label="地质设计">
  474. <el-upload
  475. v-model:file-list="geologicalFiles"
  476. :action="uploadUrl"
  477. multiple
  478. :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
  479. name="files"
  480. class="w-50%"
  481. @preview="handlePreview"
  482. >
  483. <el-button type="primary">上传地质设计</el-button>
  484. <template #tip>
  485. <div class="el-upload__tip">文件大小不能超过50MB </div>
  486. </template>
  487. </el-upload>
  488. </el-form-item>
  489. <el-form-item size="default" label="完井报告">
  490. <el-upload
  491. v-model:file-list="completionFiles"
  492. :action="uploadUrl"
  493. multiple
  494. :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
  495. name="files"
  496. class="w-50%"
  497. @preview="handlePreview"
  498. >
  499. <el-button :disabled="tableData[0].status !== 'wg'" type="primary">上传完井报告</el-button>
  500. <template #tip>
  501. <div class="el-upload__tip">文件大小不能超过50MB </div>
  502. </template>
  503. </el-upload>
  504. </el-form-item>
  505. </div>
  506. <ContentWrap v-if="currentTask.platformWell === '1'">
  507. <h3 style="margin-bottom: 20px">平台井</h3>
  508. <el-table :data="currentTask.platformWellDetails" style="width: 100%">
  509. <el-table-column prop="wellName" label="井号">
  510. <template #default="{ $index }">
  511. <el-input
  512. v-model="currentTask.platformWellDetails[$index].wellName"
  513. placeholder="请输入井号"
  514. />
  515. </template>
  516. </el-table-column>
  517. <el-table-column label="工作量单位" width="150">
  518. <template #default="{ $index }">
  519. <el-select
  520. v-model="currentTask.platformWellDetails[$index].workloadUnit"
  521. placeholder="请选择工作量单位"
  522. clearable
  523. :disabled="
  524. getPlatformWellWorkloadUnits($index).includes(
  525. currentTask.platformWellDetails[$index].workloadUnit
  526. ) && currentTask.platformWellDetails[$index].workloadUnit !== currentTask.workloadUnit
  527. "
  528. >
  529. <el-option
  530. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_PROJECT_WORKLOAD_UNIT)"
  531. :key="dict.value"
  532. :label="dict.label"
  533. :value="dict.value"
  534. :disabled="
  535. getPlatformWellWorkloadUnits($index).includes(dict.value) &&
  536. dict.value !== currentTask.platformWellDetails[$index].workloadUnit
  537. "
  538. />
  539. </el-select>
  540. </template>
  541. </el-table-column>
  542. <el-table-column prop="workloadDesign" label="设计工作量">
  543. <template #default="{ $index }">
  544. <el-tooltip
  545. :disabled="!currentTask.platformWellDetails[$index].workloadDesignError"
  546. :content="currentTask.platformWellDetails[$index].workloadDesignError"
  547. placement="top"
  548. effect="light"
  549. popper-class="workload-design-tooltip"
  550. :show-after="0"
  551. >
  552. <el-input
  553. v-model="currentTask.platformWellDetails[$index].workloadDesign"
  554. placeholder="请输入设计工作量"
  555. class="workload-input-with-button"
  556. :class="{
  557. 'error-input': currentTask.platformWellDetails[$index].workloadDesignError
  558. }"
  559. @blur="validatePlatformWellWorkloadDesign($index)"
  560. >
  561. <template #append>
  562. <el-tooltip content="添加多个设计工作量" placement="top">
  563. <el-button
  564. class="workload-add-btn"
  565. @click="openPlatformWellWorkloadDialog($index)"
  566. :disabled="getPlatformWellWorkloadAddBtnDisabled($index)"
  567. >
  568. <span class="btn-text">+</span>
  569. </el-button>
  570. </el-tooltip>
  571. </template>
  572. </el-input>
  573. </el-tooltip>
  574. </template>
  575. </el-table-column>
  576. <el-table-column label="操作" width="100">
  577. <template #default="{ $index }">
  578. <el-button
  579. type="danger"
  580. size="small"
  581. @click="removePlatformWellDetail($index)"
  582. :disabled="isMainPlatformWellDetail($index)"
  583. >
  584. 删除
  585. </el-button>
  586. </template>
  587. </el-table-column>
  588. </el-table>
  589. <el-button type="primary" size="small" @click="addPlatformWellDetail" style="margin-top: 10px">
  590. 添加一行
  591. </el-button>
  592. </ContentWrap>
  593. <ContentWrap>
  594. <el-form style="float: right">
  595. <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
  596. <el-button @click="close">取 消</el-button>
  597. </el-form>
  598. </ContentWrap>
  599. <!-- 设备选择对话框 -->
  600. <el-dialog
  601. v-model="deviceDialogVisible"
  602. title="选择施工设备"
  603. width="1000px"
  604. :before-close="handleDeviceDialogClose"
  605. class="device-select-dialog"
  606. >
  607. <div class="transfer-container">
  608. <el-transfer
  609. v-model="selectedDeviceIds"
  610. :data="filteredDeviceList"
  611. :titles="['可选设备', '已选设备']"
  612. :props="{ key: 'id', label: 'deviceCode' }"
  613. filterable
  614. :filter-method="filterDeviceMethod"
  615. class="transfer-component"
  616. @change="handleTransferChange"
  617. >
  618. <template #default="{ option }">
  619. <el-tooltip
  620. effect="dark"
  621. placement="top"
  622. :content="`${option.deviceCode || ''} - ${option.deviceName || ''}`"
  623. :disabled="!option.deviceCode && !option.deviceName"
  624. transition="fade-in-linear"
  625. >
  626. <span class="transfer-option-text">
  627. {{ option.deviceCode }} - {{ option.deviceName }}
  628. </span>
  629. </el-tooltip>
  630. </template>
  631. </el-transfer>
  632. </div>
  633. <template #footer>
  634. <span class="dialog-footer">
  635. <el-button @click="handleDeviceDialogClose">取消</el-button>
  636. <el-button type="primary" @click="confirmDeviceSelection">确定</el-button>
  637. </span>
  638. </template>
  639. </el-dialog>
  640. <!-- 责任人选择对话框 -->
  641. <el-dialog
  642. v-model="responsiblePersonDialogVisible"
  643. title="选择责任人"
  644. width="1000px"
  645. :before-close="handleResponsiblePersonDialogClose"
  646. class="responsible-person-select-dialog"
  647. >
  648. <div class="transfer-container">
  649. <el-transfer
  650. v-model="selectedResponsiblePersonIds"
  651. :data="responsiblePersonList"
  652. :titles="['可选人员', '已选人员']"
  653. :props="{ key: 'id', label: 'nickname' }"
  654. filterable
  655. class="transfer-component"
  656. >
  657. <template #default="{ option }">
  658. <el-tooltip
  659. effect="dark"
  660. placement="top"
  661. :content="`${option.nickname} - ${option.deptName || '未分配部门'}`"
  662. >
  663. <span class="transfer-option-text">
  664. {{ option.nickname }} - {{ option.deptName || '未分配部门' }}
  665. </span>
  666. </el-tooltip>
  667. </template>
  668. </el-transfer>
  669. </div>
  670. <template #footer>
  671. <span class="dialog-footer">
  672. <el-button @click="handleResponsiblePersonDialogClose">取消</el-button>
  673. <el-button type="primary" @click="confirmResponsiblePersonSelection">确定</el-button>
  674. </span>
  675. </template>
  676. </el-dialog>
  677. <!-- 填报人选择对话框 -->
  678. <el-dialog
  679. v-model="submitterDialogVisible"
  680. title="选择填报人"
  681. width="1000px"
  682. :before-close="handleSubmitterDialogClose"
  683. class="responsible-person-select-dialog"
  684. >
  685. <div class="transfer-container">
  686. <el-transfer
  687. v-model="selectedSubmitterIds"
  688. :data="submitterList"
  689. :titles="['可选人员', '已选人员']"
  690. :props="{ key: 'id', label: 'nickname' }"
  691. filterable
  692. class="transfer-component"
  693. >
  694. <template #default="{ option }">
  695. <el-tooltip
  696. effect="dark"
  697. placement="top"
  698. :content="`${option.nickname} - ${option.deptName || '未分配部门'}`"
  699. >
  700. <span class="transfer-option-text">
  701. {{ option.nickname }} - {{ option.deptName || '未分配部门' }}
  702. </span>
  703. </el-tooltip>
  704. </template>
  705. </el-transfer>
  706. </div>
  707. <template #footer>
  708. <span class="dialog-footer">
  709. <el-button @click="handleSubmitterDialogClose">取消</el-button>
  710. <el-button type="primary" @click="confirmSubmitterSelection">确定</el-button>
  711. </span>
  712. </template>
  713. </el-dialog>
  714. <!-- 工作量维护对话框 -->
  715. <el-dialog v-model="workloadDialogVisible" title="设计工作量" width="600px">
  716. <el-table :data="workloadList" style="width: 100%">
  717. <el-table-column prop="workloadUnit" label="工作量单位" width="200">
  718. <template #default="{ $index }">
  719. <el-select
  720. v-model="workloadList[$index].workloadUnit"
  721. placeholder="请选择工作量单位"
  722. :disabled="$index === 0 && hasInitialWorkload"
  723. >
  724. <el-option
  725. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_PROJECT_WORKLOAD_UNIT)"
  726. :key="dict.value"
  727. :label="dict.label"
  728. :value="dict.value"
  729. :disabled="getSelectedWorkloadUnits($index).includes(dict.value)"
  730. />
  731. </el-select>
  732. </template>
  733. </el-table-column>
  734. <el-table-column prop="workloadDesign" label="工作量">
  735. <template #default="{ $index }">
  736. <el-tooltip
  737. :disabled="!workloadList[$index].workloadDesignError"
  738. :content="workloadList[$index].workloadDesignError"
  739. placement="top"
  740. effect="light"
  741. popper-class="workload-design-tooltip"
  742. :show-after="0"
  743. >
  744. <el-input
  745. v-model="workloadList[$index].workloadDesign"
  746. placeholder="请输入工作量"
  747. :disabled="$index === 0 && hasInitialWorkload"
  748. :class="{ 'error-input': workloadList[$index].workloadDesignError }"
  749. @blur="validateWorkloadDialogDesign($index)"
  750. />
  751. </el-tooltip>
  752. </template>
  753. </el-table-column>
  754. <el-table-column label="操作" width="80">
  755. <template #default="{ $index }">
  756. <el-button
  757. type="danger"
  758. size="small"
  759. @click="removeWorkloadItem($index)"
  760. :disabled="$index === 0 && hasInitialWorkload"
  761. >
  762. 删除
  763. </el-button>
  764. </template>
  765. </el-table-column>
  766. </el-table>
  767. <el-button type="primary" size="small" @click="addWorkloadItem" style="margin-top: 10px">
  768. 添加一行
  769. </el-button>
  770. <template #footer>
  771. <span class="dialog-footer">
  772. <el-button @click="workloadDialogVisible = false">取消</el-button>
  773. <el-button type="primary" @click="confirmWorkloadSelection">确定</el-button>
  774. </span>
  775. </template>
  776. </el-dialog>
  777. </template>
  778. <script setup lang="ts">
  779. // 导入部分保持不变,与原始代码相同
  780. import { IotProjectInfoApi, IotProjectInfoVO } from '@/api/pms/iotprojectinfo'
  781. import { handleTree } from '@/utils/tree'
  782. import * as DeptApi from '@/api/system/dept'
  783. import { ref, reactive, computed, onMounted, watch } from 'vue'
  784. import { useUserStore } from '@/store/modules/user'
  785. import { IotProjectTaskApi, IotProjectTaskVO } from '@/api/pms/iotprojecttask'
  786. import { ElMessage } from 'element-plus'
  787. import { useTagsViewStore } from '@/store/modules/tagsView'
  788. import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
  789. import * as UserApi from '@/api/system/user'
  790. import { IotProjectTaskAttrsApi } from '@/api/pms/iotprojecttaskattrs'
  791. import { DICT_TYPE, getStrDictOptions, getDictLabel } from '@/utils/dict'
  792. import { IotOpeationFillApi } from '@/api/pms/iotopeationfill'
  793. import { Base64 } from 'js-base64'
  794. // 在导入部分添加Plus图标
  795. // import { Plus } from '@element-plus/icons-vue'
  796. const { query, params, name } = useRoute() // 查询参数
  797. const id = params.id
  798. const uploadUrl = import.meta.env.VITE_BASE_URL + '/admin-api/rq/file/upload'
  799. const constructionFiles = ref<any>([])
  800. const geologicalFiles = ref<any>([])
  801. const completionFiles = ref<any>([])
  802. // 修改projectId获取逻辑:优先使用params.projectId,其次使用query.projectId
  803. const projectId = ref<string>('')
  804. // 获取projectId的逻辑
  805. if (params.projectId) {
  806. projectId.value = Array.isArray(params.projectId) ? params.projectId[0] : params.projectId
  807. } else if (query.projectId) {
  808. projectId.value = Array.isArray(query.projectId as any)
  809. ? query.projectId[0]
  810. : (query.projectId as string)
  811. }
  812. function handlePreview(file: any) {
  813. if (!file.response) {
  814. message.error('附件路径不存在')
  815. return
  816. }
  817. try {
  818. const filePath = file.response.data.filePath ?? file.response.data.files[0].filePath
  819. const encodedPath = encodeURIComponent(Base64.encode(filePath))
  820. window.open(`http://doc.deepoil.cc:8012/onlinePreview?url=${encodedPath}`)
  821. } catch (error) {
  822. console.error('预览附件失败:', error)
  823. message.error('预览附件失败')
  824. }
  825. }
  826. // 施工队伍 选择树 响应式变量
  827. const defaultExpandedKeys = ref<number[]>([]) // 默认展开的部门节点keys
  828. const treeSelectRef = ref() // 树选择组件的引用
  829. const { delView } = useTagsViewStore() // 视图操作
  830. const { currentRoute, push } = useRouter()
  831. const { t } = useI18n() // 国际化
  832. const message = useMessage() // 消息弹窗
  833. const deptList = ref<Tree[]>([]) // 树形结构
  834. const deviceList = ref<IotDeviceVO[]>([]) // 设备列表
  835. // 设备映射表(ID->设备对象)
  836. const deviceMap = ref<Record<number, IotDeviceVO>>({})
  837. const dialogVisible = ref(true) // 弹窗的是否展示
  838. const dialogTitle = ref('') // 弹窗的标题
  839. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  840. const taskList = ref<IotProjectTaskVO[]>([]) // 列表的数据
  841. const projectList = ref<IotProjectInfoVO[]>([])
  842. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  843. const loading = ref(true) // 列表的加载中
  844. // 设备选择相关变量
  845. const deviceDialogVisible = ref(false)
  846. const filteredDeviceList = ref<IotDeviceVO[]>([]) // 过滤后的设备列表
  847. const selectedDeviceIds = ref<number[]>([]) // 选中的设备ID
  848. // 责任人相关变量
  849. const responsiblePersonDialogVisible = ref(false)
  850. const responsiblePersonList = ref([]) // 所有责任人列表
  851. const selectedResponsiblePersonIds = ref([]) // 选中的责任人ID
  852. const currentEditingRowForResponsible = ref(null) // 当前正在编辑责任人的行
  853. const submitterDialogVisible = ref(false)
  854. const submitterList = ref([]) // 所有填报人列表
  855. const selectedSubmitterIds = ref([]) // 选中的日报填报人ID
  856. // 动态属性相关变量
  857. const dynamicAttrs = ref<any[]>([]) // 存储动态属性列表
  858. // 跟踪是否已从任务数据中获取动态属性
  859. const hasDynamicAttrsFromTask = ref(false)
  860. // 添加 workAreaOptions 引用和加载状态
  861. const workAreaOptions = ref<any[]>([])
  862. const loadingWorkAreaOptions = ref(false)
  863. const workAreaAutocomplete = ref() // 添加对el-autocomplete的引用
  864. // currentDictLabel 响应式变量
  865. const currentDictLabel = ref('') // 存储当前项目对应的施工区域字典类型
  866. // 当前正在操作的平台井索引
  867. const currentPlatformWellIndex = ref(-1)
  868. // 施工工艺相关变量
  869. const technologyOptions = ref<any[]>([])
  870. const loadingTechnologyOptions = ref(false)
  871. const currentTechnologyDictLabel = ref('') // 存储当前项目对应的施工工艺字典类型
  872. // 添加一个变量来保存平台井详情数据
  873. const platformWellDetailsBackup = ref([])
  874. // 存储井号到工作量列表的映射(key: wellName, value: Array<{workloadUnit, workloadDesign}>)
  875. const workloadMap = ref(new Map())
  876. // 工作量数据备份
  877. const workloadBackup = ref<Map<string, any[]>>(new Map())
  878. // 工作量维护相关变量
  879. const workloadDialogVisible = ref(false)
  880. const workloadList = ref<any[]>([])
  881. const hasInitialWorkload = ref(false)
  882. // 跟踪设备列表是否为空
  883. const hasDevicesAvailable = ref(false) // 默认假设有设备,等接口返回后更新
  884. // 设计工作量错误信息
  885. const workloadDesignError = ref('')
  886. /** 项目信息 表单 */
  887. defineOptions({ name: 'IotProjectTaskInfo' })
  888. const formData = ref({
  889. id: undefined,
  890. contractId: undefined,
  891. contractName: undefined,
  892. contractCode: undefined,
  893. workloadTotal: undefined,
  894. workloadFinish: undefined,
  895. workloadUnit: undefined,
  896. startTime: undefined,
  897. endTime: undefined,
  898. location: undefined,
  899. technique: undefined,
  900. payment: undefined,
  901. remark: undefined,
  902. manufactureName: undefined,
  903. manufacturerId: undefined,
  904. userName: undefined,
  905. userId: undefined,
  906. deptId: undefined // 新增项目部门ID字段
  907. })
  908. const close = () => {
  909. delView(unref(currentRoute))
  910. push({ name: 'IotProjectTask', params: {} })
  911. }
  912. // 添加计算属性来判断是否为特定部门
  913. const isSpecialDept = computed(() => {
  914. return formData.value.deptId === 163
  915. })
  916. // 定义新的树选择器配置,添加禁用逻辑
  917. const treeSelectProps = {
  918. children: 'children',
  919. label: 'name',
  920. disabled: (data: any) => {
  921. // 只有叶子节点(type = 3)可以选择,非叶子节点禁用
  922. return data.type !== '3'
  923. }
  924. }
  925. const getProjectInfo = async (contractId: number) => {
  926. const project = projectList.value.find((item) => item.id === contractId)
  927. if (project) {
  928. formData.value.contractName = project.contractName
  929. formData.value.contractCode = project.contractCode
  930. formData.value.payment = project.payment
  931. formData.value.workloadTotal = project.workloadTotal
  932. formData.value.startTime = project.startTime
  933. formData.value.endTime = project.endTime
  934. formData.value.remark = project.remark
  935. formData.value.manufactureName = project.manufactureName
  936. formData.value.manufacturerId = project.manufacturerId
  937. formData.value.id = project.id
  938. formData.value.deptId = project.deptId // 保存项目部门ID
  939. // 获取施工区域数据字典集合
  940. await loadWorkAreaOptions(formData.value.deptId)
  941. // 获取施工工艺数据字典集合
  942. await loadTechnologyOptions(formData.value.deptId)
  943. // 获取动态属性
  944. await fetchDynamicAttrs()
  945. }
  946. }
  947. const queryParams = reactive({
  948. projectId: undefined,
  949. id: undefined
  950. })
  951. const formRules = reactive({
  952. contractId: [{ required: true, message: '合同名称不能为空', trigger: 'blur' }],
  953. manufacturerId: [{ required: true, message: '客户不能为空', trigger: 'blur' }],
  954. payment: [{ required: true, message: '结算方式不能为空', trigger: 'blur' }],
  955. // workloadTotal: [{ required: true, message: '工作量总数不能为空', trigger: 'blur' }],
  956. startTime: [{ required: true, message: '开始时间不能为空', trigger: 'blur' }],
  957. endTime: [{ required: true, message: '结束时间不能为空', trigger: 'blur' }]
  958. })
  959. const formRef = ref() // 表单 Ref
  960. const zzClear = () => {
  961. formData.value.manufacturerId = undefined
  962. formData.value.manufactureName = undefined
  963. }
  964. // 根据部门ID获取部门名称
  965. const getDeptNames = (deptIds) => {
  966. if (!deptIds || deptIds.length === 0) return ''
  967. const names = []
  968. const findDept = (list, id) => {
  969. for (const item of list) {
  970. if (item.id === id) {
  971. names.push(item.name)
  972. return true
  973. }
  974. if (item.children && findDept(item.children, id)) {
  975. return true
  976. }
  977. }
  978. return false
  979. }
  980. deptIds.forEach((id) => findDept(deptList.value, id))
  981. if (names.length > 1) {
  982. return `${names[0]}...`
  983. }
  984. return names.join(', ')
  985. }
  986. const getAllDeptNames = (deptIds) => {
  987. if (!deptIds || deptIds.length === 0) return '无施工队伍'
  988. const names = []
  989. const findDept = (list, id) => {
  990. for (const item of list) {
  991. if (item.id === id) {
  992. names.push(item.name)
  993. return true
  994. }
  995. if (item.children && findDept(item.children, id)) {
  996. return true
  997. }
  998. }
  999. return false
  1000. }
  1001. deptIds.forEach((id) => findDept(deptList.value, id))
  1002. return names.join(', ') || '无有效施工队伍'
  1003. }
  1004. const getDeviceNames = (deviceIds: number[]) => {
  1005. if (!deviceIds || deviceIds.length === 0) return ''
  1006. // 获取所有有效设备名称
  1007. const deviceNames = deviceIds
  1008. .map((id) => deviceMap.value[id]?.deviceCode)
  1009. .filter((name) => name !== undefined && name !== '')
  1010. if (deviceNames.length === 0) return ''
  1011. // 如果设备数量超过2个,显示前两个加省略号
  1012. if (deviceNames.length > 2) {
  1013. return `${deviceNames[0]}, ${deviceNames[1]}...`
  1014. }
  1015. // 设备数量不超过2个,正常显示所有
  1016. return deviceNames.join(', ')
  1017. }
  1018. const initDynamicAttrsToCurrentTask = () => {
  1019. dynamicAttrs.value.forEach((attr) => {
  1020. if (!currentTask.value.hasOwnProperty(attr.identifier)) {
  1021. // 如果是从任务数据中获取的属性,并且有实际值,使用实际值
  1022. if (
  1023. hasDynamicAttrsFromTask.value &&
  1024. attr.actualValue !== undefined &&
  1025. attr.actualValue !== null &&
  1026. attr.actualValue !== ''
  1027. ) {
  1028. currentTask.value[attr.identifier] = attr.actualValue
  1029. } else {
  1030. // 否则使用默认值
  1031. currentTask.value[attr.identifier] = attr.defaultValue || ''
  1032. }
  1033. }
  1034. })
  1035. }
  1036. // 当前编辑的任务
  1037. const currentTask = ref({
  1038. id: undefined,
  1039. wellName: '',
  1040. wellType: '',
  1041. wellCategory: '',
  1042. location: '',
  1043. dictType: '',
  1044. technique: '',
  1045. workloadDesign: '',
  1046. workloadUnit: '',
  1047. deptIds: [],
  1048. deviceIds: [],
  1049. responsiblePerson: [],
  1050. submitter: [],
  1051. remark: '',
  1052. projectId: '',
  1053. platformWell: '0', // 新增平台井字段,默认非平台井
  1054. platformWellDetails: [] // 新增平台井详情列表
  1055. })
  1056. const isNewTask = ref(false) // 是否是新任务
  1057. const taskFormRef = ref() // 任务表单ref
  1058. const currentEditingIndex = ref(-1) // 当前编辑的行索引
  1059. // 任务表单验证规则
  1060. const taskFormRules = computed(() => {
  1061. const rules = {
  1062. wellName: [
  1063. { required: currentTask.value.platformWell !== '1', message: '井号不能为空', trigger: 'blur' }
  1064. ],
  1065. wellType: [{ required: true, message: '井型不能为空', trigger: 'change' }],
  1066. location: [{ required: true, message: '施工地点不能为空', trigger: 'blur' }],
  1067. technique: [{ required: true, message: '施工工艺不能为空', trigger: 'change' }],
  1068. workloadDesign: [
  1069. {
  1070. required: currentTask.value.platformWell !== '1',
  1071. message: '设计工作量不能为空',
  1072. trigger: 'blur'
  1073. },
  1074. {
  1075. validator: (rule, value, callback) => {
  1076. if (currentTask.value.platformWell === '1') {
  1077. callback()
  1078. return
  1079. }
  1080. if (value === '' || value === null || value === undefined) {
  1081. callback(new Error('设计工作量不能为空'))
  1082. return
  1083. }
  1084. const numValue = Number(value)
  1085. if (isNaN(numValue) || numValue < 0) {
  1086. callback(new Error('请填写大于0的数字'))
  1087. } else {
  1088. callback()
  1089. }
  1090. },
  1091. trigger: 'blur'
  1092. }
  1093. ],
  1094. workloadUnit: [
  1095. {
  1096. required: currentTask.value.platformWell !== '1',
  1097. message: '工作量单位不能为空',
  1098. trigger: 'change'
  1099. }
  1100. ],
  1101. deptIds: [{ required: true, message: '施工队伍不能为空', trigger: 'change' }],
  1102. deviceIds: [
  1103. { required: hasDevicesAvailable.value, message: '施工设备不能为空', trigger: 'change' }
  1104. ],
  1105. responsiblePerson: [
  1106. {
  1107. required: true,
  1108. message: isSpecialDept.value ? '带班干部不能为空' : '责任人不能为空',
  1109. trigger: 'change',
  1110. validator: (rule, value, callback) => {
  1111. if (!value || value.length === 0) {
  1112. callback(new Error(isSpecialDept.value ? '带班干部不能为空' : '责任人不能为空'))
  1113. } else {
  1114. callback()
  1115. }
  1116. }
  1117. }
  1118. ],
  1119. submitter: [
  1120. {
  1121. required: isSpecialDept.value,
  1122. message: '填报人不能为空',
  1123. trigger: 'change',
  1124. validator: (rule, value, callback) => {
  1125. if (isSpecialDept.value && (!value || value.length === 0)) {
  1126. callback(new Error('填报人不能为空'))
  1127. } else {
  1128. callback()
  1129. }
  1130. }
  1131. }
  1132. ]
  1133. }
  1134. return rules
  1135. })
  1136. // 动态属性验证规则
  1137. const getDynamicAttrRules = (attr) => {
  1138. const rules = []
  1139. if (attr.required === 1) {
  1140. rules.push({ required: true, message: `${attr.name}不能为空`, trigger: 'blur' })
  1141. }
  1142. // 数字类型验证
  1143. if (attr.dataType === 'double') {
  1144. rules.push({
  1145. validator: (rule, value, callback) => {
  1146. if (value === '' || value === null || value === undefined) {
  1147. callback()
  1148. return
  1149. }
  1150. const numValue = Number(value)
  1151. if (isNaN(numValue)) {
  1152. callback(new Error(`${attr.name}必须是数字`))
  1153. } else if (attr.minValue !== null && numValue < Number(attr.minValue)) {
  1154. // callback(new Error(`${attr.name}不能小于${attr.minValue}`));
  1155. } else if (attr.maxValue !== null && numValue > Number(attr.maxValue)) {
  1156. // callback(new Error(`${attr.name}不能大于${attr.maxValue}`));
  1157. } else {
  1158. callback()
  1159. }
  1160. },
  1161. trigger: 'blur'
  1162. })
  1163. }
  1164. return rules
  1165. }
  1166. const tableData = ref([])
  1167. // 打开责任人选择对话框(用于表单)
  1168. const openResponsiblePersonDialogForForm = async () => {
  1169. if (!currentTask.value.deptIds || currentTask.value.deptIds.length === 0) {
  1170. ElMessage.warning('请先选择施工队伍')
  1171. return
  1172. }
  1173. selectedResponsiblePersonIds.value = [...(currentTask.value.responsiblePerson || [])]
  1174. try {
  1175. const params = {
  1176. deptIds: currentTask.value.deptIds // 使用当前项目所属部门的deptId
  1177. }
  1178. const response = await UserApi.selectedDeptsEmployee(params)
  1179. responsiblePersonList.value = response
  1180. responsiblePersonDialogVisible.value = true
  1181. } catch (error) {
  1182. ElMessage.error('获取责任人列表失败')
  1183. console.error('获取责任人列表失败:', error)
  1184. }
  1185. }
  1186. // 打开工单人选择对话框(用于表单)
  1187. const openSubmitterDialogForForm = async () => {
  1188. if (!currentTask.value.deptIds || currentTask.value.deptIds.length === 0) {
  1189. ElMessage.warning('请先选择施工队伍')
  1190. return
  1191. }
  1192. selectedSubmitterIds.value = [...(currentTask.value.submitter || [])]
  1193. try {
  1194. const params = {
  1195. deptIds: currentTask.value.deptIds // 使用当前项目所属部门的deptId
  1196. }
  1197. const response = await UserApi.selectedDeptsEmployee(params)
  1198. submitterList.value = response
  1199. submitterDialogVisible.value = true
  1200. } catch (error) {
  1201. ElMessage.error('获取填报人列表失败')
  1202. console.error('获取填报人列表失败:', error)
  1203. }
  1204. }
  1205. // 获取动态属性
  1206. const fetchDynamicAttrs = async () => {
  1207. // 如果已经通过任务数据获取了动态属性,则不再调用接口
  1208. if (hasDynamicAttrsFromTask.value) {
  1209. return
  1210. }
  1211. if (!formData.value.deptId) {
  1212. console.warn('部门ID为空,无法获取动态属性')
  1213. return
  1214. }
  1215. try {
  1216. const queryParams = {
  1217. deptId: formData.value.deptId
  1218. }
  1219. const response = await IotProjectTaskAttrsApi.getIotProjectTaskAttrsList(queryParams)
  1220. dynamicAttrs.value = response || []
  1221. // 初始化动态属性到当前任务
  1222. initDynamicAttrsToCurrentTask()
  1223. } catch (error) {
  1224. console.error('获取动态属性失败:', error)
  1225. ElMessage.error('获取动态属性失败')
  1226. }
  1227. }
  1228. // 打开设备选择对话框(用于表单)
  1229. const openDeviceDialogForForm = async () => {
  1230. if (!currentTask.value.deptIds || currentTask.value.deptIds.length === 0) {
  1231. ElMessage.warning('请先选择施工队伍')
  1232. return
  1233. }
  1234. selectedDeviceIds.value = [...(currentTask.value.deviceIds || [])]
  1235. try {
  1236. const params = {
  1237. deptIds: currentTask.value.deptIds
  1238. }
  1239. const data = await IotDeviceApi.getDevicesByDepts(params)
  1240. // 更新 hasDevicesAvailable 状态
  1241. hasDevicesAvailable.value = data && data.length > 0
  1242. // 更新设备映射表
  1243. const newDeviceMap = { ...deviceMap.value }
  1244. data.forEach((device) => {
  1245. newDeviceMap[device.id] = device
  1246. })
  1247. deviceMap.value = newDeviceMap
  1248. filteredDeviceList.value = data
  1249. deviceDialogVisible.value = true
  1250. // 如果没有设备可用,显示提示信息
  1251. if (!hasDevicesAvailable.value) {
  1252. ElMessage.info('当前施工队伍下没有可用设备,设备字段为非必填项')
  1253. }
  1254. } catch (error) {
  1255. ElMessage.error('获取设备列表失败')
  1256. console.error('获取设备列表失败:', error)
  1257. // 如果获取失败,也设为非必填,避免用户无法提交
  1258. hasDevicesAvailable.value = false
  1259. }
  1260. }
  1261. // 打开工作量维护对话框
  1262. const openWorkloadDialog = () => {
  1263. currentPlatformWellIndex.value = -1 // 设置为-1表示普通井模式
  1264. // 前置校验:设计工作量不合法则直接返回
  1265. if (!validateWorkloadDesign()) {
  1266. ElMessage.error(workloadDesignError.value)
  1267. return
  1268. }
  1269. // 重置列表
  1270. workloadList.value = []
  1271. hasInitialWorkload.value = false
  1272. // 获取当前操作的井号(兼容普通井/平台井)
  1273. let currentWellName = ''
  1274. if (currentTask.value.platformWell === '1') {
  1275. // 平台井:取主井号(优先当前任务wellName,其次取平台井详情第一个)
  1276. currentWellName =
  1277. currentTask.value.wellName ||
  1278. (currentTask.value.platformWellDetails.length > 0
  1279. ? currentTask.value.platformWellDetails[0].wellName
  1280. : '')
  1281. } else {
  1282. // 普通井:直接取当前任务井号
  1283. currentWellName = currentTask.value.wellName
  1284. }
  1285. if (!currentWellName) {
  1286. ElMessage.warning('请先填写井号')
  1287. return
  1288. }
  1289. // 从Map中回显当前井号的工作量数据
  1290. if (workloadMap.value.has(currentWellName)) {
  1291. // 深拷贝避免原数据被修改
  1292. workloadList.value = JSON.parse(JSON.stringify(workloadMap.value.get(currentWellName)))
  1293. hasInitialWorkload.value = workloadList.value.length > 0
  1294. } else {
  1295. // 无历史数据时,沿用原有逻辑(取表单已有值初始化首行)
  1296. if (currentTask.value.workloadUnit && currentTask.value.workloadDesign) {
  1297. workloadList.value.push({
  1298. workloadUnit: currentTask.value.workloadUnit,
  1299. workloadDesign: currentTask.value.workloadDesign
  1300. })
  1301. hasInitialWorkload.value = true
  1302. }
  1303. }
  1304. workloadDialogVisible.value = true
  1305. }
  1306. // 添加工作量项
  1307. const addWorkloadItem = () => {
  1308. workloadList.value.push({
  1309. workloadUnit: '',
  1310. workloadDesign: ''
  1311. })
  1312. }
  1313. // 删除工作量项
  1314. const removeWorkloadItem = (index: number) => {
  1315. workloadList.value.splice(index, 1)
  1316. }
  1317. // 确认工作量选择
  1318. const confirmWorkloadSelection = () => {
  1319. // 验证工作量对话框中的所有数据
  1320. let allValid = true
  1321. workloadList.value.forEach((item, index) => {
  1322. if (!validateWorkloadDialogDesign(index)) {
  1323. allValid = false
  1324. }
  1325. })
  1326. if (!allValid) {
  1327. ElMessage.error('请完善所有工作量信息')
  1328. return
  1329. }
  1330. // 验证工作量单位唯一性
  1331. const unitList = workloadList.value.map((item) => item.workloadUnit).filter(Boolean)
  1332. const uniqueUnits = new Set(unitList)
  1333. if (unitList.length !== uniqueUnits.size) {
  1334. ElMessage.error('工作量单位不能重复,请选择不同的单位')
  1335. return
  1336. }
  1337. // 获取当前井号并存储到Map
  1338. let currentWellName = ''
  1339. if (currentPlatformWellIndex.value >= 0) {
  1340. // 平台井模式
  1341. const wellDetail = currentTask.value.platformWellDetails[currentPlatformWellIndex.value]
  1342. currentWellName = wellDetail.wellName
  1343. // 同步更新平台井表格中的工作量单位
  1344. if (workloadList.value.length > 0) {
  1345. const firstItem = workloadList.value[0]
  1346. if (wellDetail.workloadUnit !== firstItem.workloadUnit) {
  1347. wellDetail.workloadUnit = firstItem.workloadUnit
  1348. }
  1349. wellDetail.workloadDesign = firstItem.workloadDesign
  1350. }
  1351. } else {
  1352. // 普通井模式
  1353. currentWellName = currentTask.value.wellName
  1354. // 同步更新表单中的工作量单位
  1355. if (workloadList.value.length > 0) {
  1356. const firstItem = workloadList.value[0]
  1357. if (currentTask.value.workloadUnit !== firstItem.workloadUnit) {
  1358. currentTask.value.workloadUnit = firstItem.workloadUnit
  1359. }
  1360. currentTask.value.workloadDesign = firstItem.workloadDesign
  1361. }
  1362. }
  1363. // 存储到Map
  1364. if (currentWellName) {
  1365. workloadMap.value.set(currentWellName, JSON.parse(JSON.stringify(workloadList.value)))
  1366. }
  1367. workloadDialogVisible.value = false
  1368. currentPlatformWellIndex.value = -1 // 重置索引
  1369. ElMessage.success('工作量信息已更新')
  1370. }
  1371. // 处理穿梭框变化
  1372. const handleTransferChange = (value, direction, movedKeys) => {
  1373. // 可以添加额外的处理逻辑
  1374. }
  1375. // 确认设备选择(用于表单)
  1376. const confirmDeviceSelection = () => {
  1377. currentTask.value.deviceIds = [...selectedDeviceIds.value]
  1378. // 强制更新视图
  1379. currentTask.value = { ...currentTask.value }
  1380. deviceDialogVisible.value = false
  1381. }
  1382. // 确认责任人选择(用于表单)
  1383. const confirmResponsiblePersonSelection = () => {
  1384. currentTask.value.responsiblePerson = [...selectedResponsiblePersonIds.value]
  1385. responsiblePersonDialogVisible.value = false
  1386. // 立即触发责任人字段验证
  1387. nextTick(() => {
  1388. taskFormRef.value.validateField('responsiblePerson')
  1389. })
  1390. }
  1391. // 确认填报人选择(用于表单)
  1392. const confirmSubmitterSelection = () => {
  1393. currentTask.value.submitter = [...selectedSubmitterIds.value]
  1394. submitterDialogVisible.value = false
  1395. // 立即触发填报人字段验证
  1396. nextTick(() => {
  1397. taskFormRef.value.validateField('submitter')
  1398. })
  1399. }
  1400. // 关闭设备选择对话框
  1401. const handleDeviceDialogClose = () => {
  1402. deviceDialogVisible.value = false
  1403. }
  1404. // 关闭责任人选择对话框
  1405. const handleResponsiblePersonDialogClose = () => {
  1406. responsiblePersonDialogVisible.value = false
  1407. }
  1408. // 关闭填报人选择对话框
  1409. const handleSubmitterDialogClose = () => {
  1410. submitterDialogVisible.value = false
  1411. }
  1412. // 获取井型标签的方法
  1413. const getWellTypeLabel = (value) => {
  1414. const options = getStrDictOptions(DICT_TYPE.PMS_PROJECT_WELL_TYPE)
  1415. const option = options.find((opt) => opt.value === value)
  1416. return option ? option.label : value
  1417. }
  1418. // 获取井别标签的方法
  1419. const getWellCategoryLabel = (value) => {
  1420. const options = getStrDictOptions(DICT_TYPE.PMS_PROJECT_WELL_CATEGORY)
  1421. const option = options.find((opt) => opt.value === value)
  1422. return option ? option.label : value
  1423. }
  1424. // 获取施工工艺标签的方法
  1425. const getTechniqueLabel = (value) => {
  1426. const options = getStrDictOptions(DICT_TYPE.PMS_PROJECT_TECHNOLOGY)
  1427. const option = options.find((opt) => opt.value === value)
  1428. return option ? option.label : value
  1429. }
  1430. // 获取 工作量单位 标签的方法
  1431. const getWorkloadUnitLabel = (value) => {
  1432. const options = getStrDictOptions(DICT_TYPE.PMS_PROJECT_WORKLOAD_UNIT)
  1433. const option = options.find((opt) => opt.value === value)
  1434. return option ? option.label : value
  1435. }
  1436. // 打开平台井工作量对话框
  1437. const openPlatformWellWorkloadDialog = (index) => {
  1438. currentPlatformWellIndex.value = index
  1439. const wellDetail = currentTask.value.platformWellDetails[index]
  1440. // 前置校验
  1441. if (!validatePlatformWellWorkloadDesign(index)) {
  1442. ElMessage.error(wellDetail.workloadDesignError)
  1443. return
  1444. }
  1445. // 重置列表
  1446. workloadList.value = []
  1447. hasInitialWorkload.value = false
  1448. if (!wellDetail.wellName) {
  1449. ElMessage.warning('请先填写井号')
  1450. return
  1451. }
  1452. // 从Map中回显工作量数据
  1453. if (workloadMap.value.has(wellDetail.wellName)) {
  1454. workloadList.value = JSON.parse(JSON.stringify(workloadMap.value.get(wellDetail.wellName)))
  1455. hasInitialWorkload.value = workloadList.value.length > 0
  1456. } else {
  1457. // 无历史数据时,使用当前行的值初始化
  1458. if (wellDetail.workloadUnit && wellDetail.workloadDesign) {
  1459. workloadList.value.push({
  1460. workloadUnit: wellDetail.workloadUnit,
  1461. workloadDesign: wellDetail.workloadDesign
  1462. })
  1463. hasInitialWorkload.value = true
  1464. }
  1465. }
  1466. workloadDialogVisible.value = true
  1467. }
  1468. // 校验平台井设计工作量
  1469. const validatePlatformWellWorkloadDesign = (index) => {
  1470. const wellDetail = currentTask.value.platformWellDetails[index]
  1471. wellDetail.workloadDesignError = ''
  1472. const value = wellDetail.workloadDesign
  1473. if (value === '' || value === null || value === undefined) {
  1474. wellDetail.workloadDesignError = '设计工作量不能为空'
  1475. return false
  1476. }
  1477. const numValue = Number(value)
  1478. if (isNaN(numValue) || numValue < 0) {
  1479. wellDetail.workloadDesignError = '请填写大于0的数字'
  1480. return false
  1481. }
  1482. return true
  1483. }
  1484. /** 同步当前任务表单数据到表格数据 */
  1485. const syncCurrentTaskToTable = () => {
  1486. // 平台井模式特殊处理
  1487. if (currentTask.value.platformWell === '1') {
  1488. if (currentTask.value.platformWellDetails.length === 0) {
  1489. ElMessage.warning('请先添加平台井详情')
  1490. return false
  1491. }
  1492. // 验证平台井详情数据
  1493. const invalidDetails = currentTask.value.platformWellDetails.some(
  1494. (detail) => !detail.wellName || !detail.wellName.trim() || !detail.workloadDesign
  1495. )
  1496. if (invalidDetails) {
  1497. ElMessage.error('请完善平台井的井号和设计工作量信息')
  1498. return false
  1499. }
  1500. // 平台井模式:为每个平台井详情生成任务对象
  1501. const platformTasks = []
  1502. // 查找当前编辑的主任务对应的平台井详情
  1503. let mainTaskDetailIndex = -1
  1504. // 如果有当前任务ID,查找对应的平台井详情
  1505. if (currentTask.value.id) {
  1506. mainTaskDetailIndex = currentTask.value.platformWellDetails.findIndex(
  1507. (detail) => detail.taskId === currentTask.value.id
  1508. )
  1509. }
  1510. // 如果没有找到对应的详情,使用第一个详情作为主任务
  1511. if (mainTaskDetailIndex === -1 && currentTask.value.platformWellDetails.length > 0) {
  1512. mainTaskDetailIndex = 0
  1513. }
  1514. // 处理每个平台井详情
  1515. currentTask.value.platformWellDetails.forEach((detail, index) => {
  1516. // 获取当前井号的工作量数据
  1517. const workloadData = workloadMap.value.get(detail.wellName) || []
  1518. if (index === mainTaskDetailIndex) {
  1519. // 主任务:使用当前任务对象
  1520. currentTask.value.wellName = detail.wellName
  1521. currentTask.value.workloadDesign = detail.workloadDesign
  1522. currentTask.value.workloadUnit = detail.workloadUnit
  1523. // platformWell 保持为 '1' - 主平台井任务
  1524. currentTask.value.platformWell = '1'
  1525. platformTasks.push({ ...currentTask.value })
  1526. } else {
  1527. // 子任务:创建新的任务对象
  1528. const newTask = {
  1529. ...currentTask.value, // 拷贝所有属性
  1530. id: detail.taskId || undefined, // 已有任务使用taskId,新增任务为undefined
  1531. wellName: detail.wellName,
  1532. workloadDesign: detail.workloadDesign,
  1533. workloadUnit: detail.workloadUnit,
  1534. platformWell: detail.taskId ? '2' : '2' // 子任务platformWell设为2
  1535. }
  1536. // 移除不需要的属性
  1537. delete newTask.platformWellDetails
  1538. platformTasks.push(newTask)
  1539. }
  1540. })
  1541. // 设置项目ID
  1542. platformTasks.forEach((task) => {
  1543. task.projectId = formData.value.id
  1544. })
  1545. if (isNewTask.value) {
  1546. // 新增任务 - 为所有任务生成ID
  1547. let maxId =
  1548. tableData.value.length > 0 ? Math.max(...tableData.value.map((item) => item.id)) : 0
  1549. platformTasks.forEach((task) => {
  1550. maxId += 1
  1551. task.id = maxId
  1552. tableData.value.unshift({ ...task })
  1553. })
  1554. isNewTask.value = false
  1555. } else {
  1556. // 更新现有任务 - 比较复杂,需要先删除原有任务再添加新任务
  1557. // 这里简化处理:删除当前任务相关的所有平台井任务,然后重新添加
  1558. const currentTaskId = currentTask.value.id
  1559. tableData.value = tableData.value.filter((item) => item.id !== currentTaskId)
  1560. platformTasks.forEach((task) => {
  1561. tableData.value.unshift({ ...task })
  1562. })
  1563. }
  1564. return true
  1565. } else {
  1566. // 非平台井模式,验证原有字段
  1567. if (!currentTask.value.wellName) {
  1568. ElMessage.warning('请先填写任务详情')
  1569. return false
  1570. }
  1571. // 设置项目ID
  1572. currentTask.value.projectId = formData.value.id
  1573. if (isNewTask.value) {
  1574. // 新增任务 - 生成唯一ID并添加到表格
  1575. const newId =
  1576. tableData.value.length > 0 ? Math.max(...tableData.value.map((item) => item.id)) + 1 : 1
  1577. currentTask.value.id = newId
  1578. tableData.value.unshift({ ...currentTask.value })
  1579. isNewTask.value = false
  1580. } else {
  1581. // 更新现有任务
  1582. const index = tableData.value.findIndex((item) => item.id === currentTask.value.id)
  1583. if (index !== -1) {
  1584. tableData.value.splice(index, 1, { ...currentTask.value })
  1585. } else {
  1586. // 如果没有找到,添加到表格(可能是意外情况)
  1587. tableData.value.unshift({ ...currentTask.value })
  1588. }
  1589. }
  1590. return true
  1591. }
  1592. }
  1593. // 重置任务表单
  1594. const resetTaskForm = () => {
  1595. // 记录旧井号,用于清理Map
  1596. const oldWellName = currentTask.value.wellName
  1597. currentTask.value = {
  1598. id: undefined,
  1599. wellName: '',
  1600. wellType: '',
  1601. wellCategory: '',
  1602. location: '',
  1603. technique: '',
  1604. workloadDesign: '',
  1605. workloadUnit: '',
  1606. deptIds: [],
  1607. deviceIds: [],
  1608. responsiblePerson: [],
  1609. remark: '',
  1610. projectId: formData.value.id,
  1611. platformWell: '0', // 重置平台井状态
  1612. platformWellDetails: [], // 清空平台井详情
  1613. // 如果是特殊部门,初始化填报人字段
  1614. ...(isSpecialDept.value ? { submitter: [] } : {})
  1615. }
  1616. // 清理当前井号对应的Map数据
  1617. if (oldWellName) {
  1618. if (workloadMap.value.has(oldWellName)) {
  1619. workloadMap.value.delete(oldWellName)
  1620. }
  1621. if (workloadBackup.value.has(oldWellName)) {
  1622. workloadBackup.value.delete(oldWellName)
  1623. }
  1624. }
  1625. // 重新初始化动态属性
  1626. initDynamicAttrsToCurrentTask()
  1627. isNewTask.value = false
  1628. taskFormRef.value?.resetFields()
  1629. // 清除表单验证状态
  1630. nextTick(() => {
  1631. taskFormRef.value?.clearValidate()
  1632. })
  1633. }
  1634. // 获取已选的工作量单位(排除当前行) ==========
  1635. const getSelectedWorkloadUnits = (currentIndex) => {
  1636. if (!workloadList.value || workloadList.value.length === 0) {
  1637. return []
  1638. }
  1639. // 过滤当前行 + 空值,收集已选的单位
  1640. return workloadList.value
  1641. .filter((_, index) => index !== currentIndex)
  1642. .map((item) => item.workloadUnit)
  1643. .filter((unit) => unit && unit.trim() !== '')
  1644. }
  1645. // 处理行点击事件
  1646. const handleRowClick = (row, index) => {
  1647. if (row) {
  1648. currentTask.value = { ...row }
  1649. currentEditingIndex.value = index // 保存当前编辑的行索引
  1650. isNewTask.value = false
  1651. }
  1652. }
  1653. // 设备过滤方法
  1654. const filterDeviceMethod = (query: string, item: IotDeviceVO) => {
  1655. if (!query) return true
  1656. const searchText = query.toLowerCase()
  1657. const deviceCode = (item.deviceCode || '').toLowerCase()
  1658. const deviceName = (item.deviceName || '').toLowerCase()
  1659. // 同时匹配设备编码和设备名称
  1660. return deviceCode.includes(searchText) || deviceName.includes(searchText)
  1661. }
  1662. // 根据责任人ID获取责任人名称
  1663. const getResponsiblePersonNames = (responsiblePersonIds: number[]) => {
  1664. if (!responsiblePersonIds || responsiblePersonIds.length === 0) return ''
  1665. // 获取所有有效责任人名称
  1666. const personNames = responsiblePersonIds
  1667. .map((id) => {
  1668. const person = responsiblePersonList.value.find((p) => p.id === id)
  1669. return person ? person.nickname : ''
  1670. })
  1671. .filter((name) => name !== undefined && name !== '')
  1672. if (personNames.length === 0) return ''
  1673. // 如果责任人数量超过2个,显示前两个加省略号
  1674. if (personNames.length > 2) {
  1675. return `${personNames[0]}, ${personNames[1]}...`
  1676. }
  1677. // 责任人数量不超过2个,正常显示所有
  1678. return personNames.join(', ')
  1679. }
  1680. // 获取所有责任人名称(用于tooltip提示)
  1681. const getAllResponsiblePersonNames = (responsiblePersonIds: number[]) => {
  1682. if (!responsiblePersonIds || responsiblePersonIds.length === 0) return '无责任人'
  1683. const personNames = responsiblePersonIds
  1684. .map((id) => {
  1685. const person = responsiblePersonList.value.find((p) => p.id === id)
  1686. return person ? person.nickname : '未知人员'
  1687. })
  1688. .filter((name) => name !== '未知人员')
  1689. return personNames.join(', ') || '无有效责任人'
  1690. }
  1691. // 获取所有设备名称(用于tooltip提示)
  1692. const getAllDeviceNames = (deviceIds: number[]) => {
  1693. if (!deviceIds || deviceIds.length === 0) return '无设备'
  1694. const deviceNames = deviceIds
  1695. .map((id) => deviceMap.value[id]?.deviceCode || '未知设备')
  1696. .filter((name) => name !== '未知设备')
  1697. return deviceNames.join(', ') || '无有效设备'
  1698. }
  1699. const companyName = ref('')
  1700. /** 打开弹窗 */
  1701. const open = async () => {
  1702. resetForm()
  1703. resetTaskForm()
  1704. hasDynamicAttrsFromTask.value = false // 重置标志
  1705. // 修改时,设置数据
  1706. if (id) {
  1707. formType.value = 'update'
  1708. formLoading.value = true
  1709. try {
  1710. queryParams.id = id
  1711. const data = await IotProjectTaskApi.getIotProjectTaskPage(queryParams)
  1712. tableData.value = data.list
  1713. const company = await IotOpeationFillApi.getOrgName(tableData.value[0].deptId)
  1714. companyName.value = company
  1715. // 收集所有设备ID
  1716. const allDeviceIds = new Set<number>()
  1717. // 收集所有责任人ID
  1718. const allResponsiblePersonIds = new Set<number>()
  1719. // 收集所有填报人ID
  1720. const allSubmitterIds = new Set<number>()
  1721. data.list.forEach((item) => {
  1722. if (item.deviceIds?.length) {
  1723. item.deviceIds.forEach((id) => allDeviceIds.add(id))
  1724. }
  1725. if (item.responsiblePerson?.length) {
  1726. item.responsiblePerson.forEach((id) => allResponsiblePersonIds.add(id))
  1727. }
  1728. if (item.submitter?.length) {
  1729. item.submitter.forEach((id) => allSubmitterIds.add(id))
  1730. }
  1731. })
  1732. // 批量获取设备信息
  1733. if (allDeviceIds.size > 0) {
  1734. const deviceIdsArray = Array.from(allDeviceIds)
  1735. const devices = await IotDeviceApi.getDevicesByDepts({
  1736. deviceIds: deviceIdsArray
  1737. })
  1738. // 更新设备列表和映射表
  1739. deviceList.value = devices
  1740. deviceMap.value = {}
  1741. devices.forEach((device) => {
  1742. deviceMap.value[device.id] = device
  1743. })
  1744. }
  1745. // 批量获取责任人信息
  1746. if (allResponsiblePersonIds.size > 0) {
  1747. const personIdsArray = Array.from(allResponsiblePersonIds)
  1748. const params = {
  1749. userIds: personIdsArray
  1750. }
  1751. const persons = await UserApi.companyDeptsEmployee(params)
  1752. // 更新责任人列表
  1753. responsiblePersonList.value = persons
  1754. }
  1755. // 批量获取填报人信息
  1756. if (allSubmitterIds.size > 0) {
  1757. const personIdsArray = Array.from(allSubmitterIds)
  1758. const params = {
  1759. userIds: personIdsArray
  1760. }
  1761. const persons = await UserApi.companyDeptsEmployee(params)
  1762. // 更新责任人列表
  1763. submitterList.value = persons
  1764. }
  1765. if (tableData.value && tableData.value.length > 0) {
  1766. // 使用深拷贝,避免修改表单时直接影响表格数据
  1767. currentTask.value = JSON.parse(JSON.stringify(tableData.value[0]))
  1768. isNewTask.value = false
  1769. // 如果当前任务有施工队伍,立即查询设备并更新 hasDevicesAvailable
  1770. if (currentTask.value.deptIds && currentTask.value.deptIds.length > 0) {
  1771. try {
  1772. const params = {
  1773. deptIds: currentTask.value.deptIds
  1774. }
  1775. const deviceData = await IotDeviceApi.getDevicesByDepts(params)
  1776. // 更新 hasDevicesAvailable 状态
  1777. hasDevicesAvailable.value = deviceData && deviceData.length > 0
  1778. // 更新设备列表和映射表(如果有设备)
  1779. if (hasDevicesAvailable.value) {
  1780. deviceList.value = deviceData
  1781. deviceMap.value = {}
  1782. deviceData.forEach((device) => {
  1783. deviceMap.value[device.id] = device
  1784. })
  1785. }
  1786. } catch (error) {
  1787. console.error('初始化查询设备失败:', error)
  1788. hasDevicesAvailable.value = false
  1789. }
  1790. } else {
  1791. // 如果没有施工队伍,默认没有设备可用
  1792. hasDevicesAvailable.value = false
  1793. }
  1794. // 处理平台井数据
  1795. // 将数字类型的 platformWell 转换为字符串类型
  1796. currentTask.value.platformWell = currentTask.value.platformWell?.toString() || '0'
  1797. // 如果 platformWell 为 1,处理 platformWells 数据
  1798. if (currentTask.value.platformWell === '1' && currentTask.value.platformWells) {
  1799. // 将 platformWells 映射到 platformWellDetails
  1800. currentTask.value.platformWellDetails = currentTask.value.platformWells.map(
  1801. (item: any) => ({
  1802. taskId: item.id,
  1803. wellName: item.wellName,
  1804. workloadUnit: item.workloadUnit || '', // 确保有workloadUnit字段
  1805. workloadDesign: item.workloadDesign || '',
  1806. workloadDesignError: '' // 新增错误信息字段
  1807. })
  1808. )
  1809. // 使用专门的排序方法
  1810. sortPlatformWellDetails()
  1811. // 初始化备份数据
  1812. platformWellDetailsBackup.value = [...currentTask.value.platformWellDetails]
  1813. // 处理每个平台井的工作量数据
  1814. processPlatformWellWorkloadData(currentTask.value.platformWells)
  1815. } else {
  1816. // 非平台井模式,确保 platformWellDetails 是数组
  1817. currentTask.value.platformWellDetails = currentTask.value.platformWellDetails || []
  1818. platformWellDetailsBackup.value = []
  1819. // 处理非平台井的工作量数据
  1820. if (currentTask.value.extProperty?.[0]?.dropdownList) {
  1821. processWorkloadDataForWell(
  1822. currentTask.value.wellName,
  1823. currentTask.value.extProperty[0].dropdownList
  1824. )
  1825. }
  1826. }
  1827. // 检查任务数据中是否有extProperty
  1828. if (tableData.value[0].extProperty && tableData.value[0].extProperty.length > 0) {
  1829. // 使用任务数据中的extProperty作为动态属性
  1830. dynamicAttrs.value = tableData.value[0].extProperty
  1831. hasDynamicAttrsFromTask.value = true
  1832. // 将extProperty中的值设置到当前任务
  1833. tableData.value[0].extProperty.forEach((attr) => {
  1834. if (attr.identifier) {
  1835. // 优先使用actualValue,如果没有则使用defaultValue
  1836. currentTask.value[attr.identifier] =
  1837. attr.actualValue !== undefined &&
  1838. attr.actualValue !== null &&
  1839. attr.actualValue !== ''
  1840. ? attr.actualValue
  1841. : attr.defaultValue || ''
  1842. }
  1843. })
  1844. }
  1845. const attachments = tableData.value[0].attachments || []
  1846. constructionFiles.value = attachments
  1847. .filter((item) => item.type === 'CONSTRUCTION_DESIGN')
  1848. .map((item) => ({
  1849. name: item.filename,
  1850. percentage: 100,
  1851. response: { data: item },
  1852. status: 'success',
  1853. uid: item.createTime
  1854. }))
  1855. geologicalFiles.value = attachments
  1856. .filter((item) => item.type === 'GEOLOGICAL_DESIGN')
  1857. .map((item) => ({
  1858. name: item.filename,
  1859. percentage: 100,
  1860. response: { data: item },
  1861. status: 'success',
  1862. uid: item.createTime
  1863. }))
  1864. completionFiles.value = attachments
  1865. .filter((item) => item.type === 'COMPLETION_DESIGN')
  1866. .map((item) => ({
  1867. name: item.filename,
  1868. percentage: 100,
  1869. response: { data: item },
  1870. status: 'success',
  1871. uid: item.createTime
  1872. }))
  1873. }
  1874. } finally {
  1875. formLoading.value = false
  1876. }
  1877. } else {
  1878. formType.value = 'create'
  1879. // 初始化备份数据
  1880. platformWellDetailsBackup.value = []
  1881. }
  1882. // 如果有projectId参数,自动选中对应的合同
  1883. if (projectId.value) {
  1884. autoSelectContract(projectId.value)
  1885. }
  1886. }
  1887. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  1888. // 获取平台井已选的工作量单位(排除当前行)
  1889. const getPlatformWellWorkloadUnits = (currentIndex) => {
  1890. if (
  1891. !currentTask.value.platformWellDetails ||
  1892. currentTask.value.platformWellDetails.length === 0
  1893. ) {
  1894. return []
  1895. }
  1896. // 获取当前井号的井名
  1897. const currentWellName = currentTask.value.platformWellDetails[currentIndex]?.wellName
  1898. if (!currentWellName) {
  1899. return []
  1900. }
  1901. // 从workloadMap中获取当前井号的工作量列表
  1902. const currentWellWorkloadList = workloadMap.value.get(currentWellName) || []
  1903. return currentWellWorkloadList
  1904. .filter((_, index) => index !== 0)
  1905. .map((item) => item.workloadUnit)
  1906. .filter((unit) => unit && unit.trim() !== '')
  1907. }
  1908. /** 自动选择合同 */
  1909. const autoSelectContract = async (projectId: string) => {
  1910. console.log('项目id:' + projectId)
  1911. // 查找匹配的合同
  1912. const project = projectList.value.find((item) => item.id === Number(projectId))
  1913. if (project) {
  1914. // 设置选中值
  1915. formData.value.contractId = project.id
  1916. // 触发合同信息加载
  1917. getProjectInfo(project.id)
  1918. } else {
  1919. ElMessage.warning('未找到指定的合同信息')
  1920. }
  1921. }
  1922. /** 校验所有行数据 */
  1923. const validateAllRows = (): boolean => {
  1924. // 判断任务列表是否为空
  1925. if (!tableData.value || tableData.value.length === 0) {
  1926. ElMessage.error('没有任务数据,无法保存')
  1927. return false
  1928. }
  1929. let allValid = true
  1930. tableData.value.forEach((row) => {
  1931. if (!row.wellName || row.wellName.trim() === '') {
  1932. allValid = false
  1933. }
  1934. // 对于平台井模式下的后续任务,platformWell为0,但wellName和workloadDesign仍需验证
  1935. if (!row.workloadDesign) {
  1936. allValid = false
  1937. }
  1938. if (!row.location || row.location.trim() === '') {
  1939. allValid = false
  1940. }
  1941. if (!row.technique || row.technique.trim() === '') {
  1942. allValid = false
  1943. }
  1944. if (!row.deptIds || row.deptIds.length === 0) {
  1945. allValid = false
  1946. }
  1947. // 修改:只有当有设备可用时才验证设备字段
  1948. if (hasDevicesAvailable.value && (!row.deviceIds || row.deviceIds.length === 0)) {
  1949. allValid = false
  1950. }
  1951. if (!row.responsiblePerson || row.responsiblePerson.length === 0) {
  1952. allValid = false
  1953. }
  1954. // 如果是特殊部门,验证填报人
  1955. if (isSpecialDept.value && (!row.submitter || row.submitter.length === 0)) {
  1956. allValid = false
  1957. }
  1958. })
  1959. if (!allValid) {
  1960. ElMessage.error('请检查表格中的数据,部分必填项未填写或格式不正确')
  1961. }
  1962. return allValid
  1963. }
  1964. // 添加表单专用的格式化方法
  1965. // 格式化设备显示(用于表单)
  1966. const formatDevicesForForm = (deviceIds: number[]) => {
  1967. if (!deviceIds || deviceIds.length === 0) return ''
  1968. const deviceInfos = deviceIds
  1969. .map((id) => {
  1970. const device = deviceMap.value[id]
  1971. return device ? `${device.deviceCode}-${device.deviceName}` : ''
  1972. })
  1973. .filter((info) => info !== '')
  1974. if (deviceInfos.length === 0) return ''
  1975. if (deviceInfos.length > 2) {
  1976. return `${deviceInfos[0]}, ${deviceInfos[1]}...`
  1977. }
  1978. return deviceInfos.join(', ')
  1979. }
  1980. // 获取所有设备名称(用于表单的tooltip)
  1981. const getAllDeviceNamesForForm = (deviceIds: number[]) => {
  1982. if (!deviceIds || deviceIds.length === 0) return '无设备'
  1983. const deviceInfos = deviceIds
  1984. .map((id) => {
  1985. const device = deviceMap.value[id]
  1986. return device ? `${device.deviceCode}-${device.deviceName}` : '未知设备'
  1987. })
  1988. .filter((info) => info !== '未知设备')
  1989. return deviceInfos.join(', ') || '无有效设备'
  1990. }
  1991. // 格式化责任人显示(用于表单)
  1992. const formatResponsiblePersonsForForm = (responsiblePersonIds: number[]) => {
  1993. if (!responsiblePersonIds || responsiblePersonIds.length === 0) return ''
  1994. const personNames = responsiblePersonIds
  1995. .map((id) => {
  1996. const person = responsiblePersonList.value.find((p) => p.id === id)
  1997. return person ? person.nickname : ''
  1998. })
  1999. .filter((name) => name !== undefined && name !== '')
  2000. if (personNames.length === 0) return ''
  2001. if (personNames.length > 2) {
  2002. return `${personNames[0]}, ${personNames[1]}...`
  2003. }
  2004. return personNames.join(', ')
  2005. }
  2006. // 获取任务的工作量dropdownList数据
  2007. const getWorkloadDropdownListForTask = (task: any) => {
  2008. const dropdownList = []
  2009. // 从workloadMap中获取当前任务井号的工作量数据
  2010. const workloadItems = workloadMap.value.get(task.wellName) || []
  2011. if (workloadItems.length > 0) {
  2012. // 如果workloadMap中有数据,使用workloadMap的数据
  2013. workloadItems.forEach((item) => {
  2014. if (item.workloadUnit && item.workloadDesign) {
  2015. // 获取工作量单位的标签
  2016. const unitOptions = getStrDictOptions(DICT_TYPE.PMS_PROJECT_WORKLOAD_UNIT)
  2017. const unitLabel =
  2018. unitOptions.find((opt) => opt.value === item.workloadUnit)?.label || item.workloadUnit
  2019. dropdownList.push({
  2020. name: unitLabel, // 工作量单位名称
  2021. value: item.workloadDesign // 工作量值
  2022. })
  2023. }
  2024. })
  2025. } else {
  2026. // 【新增】如果workloadMap中没有数据,使用任务本身的工作量数据(直接从表格行中填写的数据)
  2027. if (task.workloadUnit && task.workloadDesign) {
  2028. const unitOptions = getStrDictOptions(DICT_TYPE.PMS_PROJECT_WORKLOAD_UNIT)
  2029. const unitLabel =
  2030. unitOptions.find((opt) => opt.value === task.workloadUnit)?.label || task.workloadUnit
  2031. dropdownList.push({
  2032. name: unitLabel,
  2033. value: task.workloadDesign
  2034. })
  2035. }
  2036. }
  2037. return dropdownList
  2038. }
  2039. // 平台井工作量加号按钮禁用状态
  2040. const getPlatformWellWorkloadAddBtnDisabled = (index) => {
  2041. const wellDetail = currentTask.value.platformWellDetails[index]
  2042. return !wellDetail.workloadUnit || !!wellDetail.workloadDesignError
  2043. }
  2044. // 格式化填报人显示(用于表单)
  2045. const formatSubmittersForForm = (submitterIds: number[]) => {
  2046. if (!submitterIds || submitterIds.length === 0) return ''
  2047. const personNames = submitterIds
  2048. .map((id) => {
  2049. const person = submitterList.value.find((p) => p.id === id)
  2050. return person ? person.nickname : ''
  2051. })
  2052. .filter((name) => name !== undefined && name !== '')
  2053. if (personNames.length === 0) return ''
  2054. if (personNames.length > 2) {
  2055. return `${personNames[0]}, ${personNames[1]}...`
  2056. }
  2057. return personNames.join(', ')
  2058. }
  2059. // 获取所有责任人名称(用于表单的tooltip)
  2060. const getAllResponsiblePersonNamesForForm = (responsiblePersonIds: number[]) => {
  2061. if (!responsiblePersonIds || responsiblePersonIds.length === 0) return '无责任人'
  2062. const personNames = responsiblePersonIds
  2063. .map((id) => {
  2064. const person = responsiblePersonList.value.find((p) => p.id === id)
  2065. return person ? person.nickname : '未知人员'
  2066. })
  2067. .filter((name) => name !== '未知人员')
  2068. return personNames.join(', ') || '无有效责任人'
  2069. }
  2070. // 获取所有填报人名称(用于表单的tooltip)
  2071. const getAllSubmitterNamesForForm = (submitterIds: number[]) => {
  2072. if (!submitterIds || submitterIds.length === 0) return '无填报人'
  2073. const personNames = submitterIds
  2074. .map((id) => {
  2075. const person = submitterList.value.find((p) => p.id === id)
  2076. return person ? person.nickname : '未知人员'
  2077. })
  2078. .filter((name) => name !== '未知人员')
  2079. return personNames.join(', ') || '无有效填报人'
  2080. }
  2081. /** 提交表单 */
  2082. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  2083. // 处理平台井工作量数据
  2084. const processPlatformWellWorkloadData = (platformWells: any[]) => {
  2085. if (!platformWells || !platformWells.length) return
  2086. platformWells.forEach((well: any) => {
  2087. if (well.wellName && well.extProperty?.[0]?.dropdownList) {
  2088. processWorkloadDataForWell(well.wellName, well.extProperty[0].dropdownList)
  2089. }
  2090. })
  2091. }
  2092. // 处理单个井的工作量数据
  2093. const processWorkloadDataForWell = (wellName: string, dropdownList: any[]) => {
  2094. if (!wellName || !dropdownList || !dropdownList.length) return
  2095. // 转换dropdownList格式为workloadMap需要的格式
  2096. const workloadData = dropdownList.map((item) => ({
  2097. workloadUnit: getWorkloadUnitValueByName(item.name), // 通过name获取对应的value
  2098. workloadDesign: item.value
  2099. }))
  2100. // 存储到workloadMap
  2101. workloadMap.value.set(wellName, workloadData)
  2102. // 如果这个井在platformWellDetails中,更新其工作量单位和工作量设计
  2103. if (currentTask.value.platformWellDetails) {
  2104. const detailIndex = currentTask.value.platformWellDetails.findIndex(
  2105. (detail: any) => detail.wellName === wellName
  2106. )
  2107. if (detailIndex !== -1 && workloadData.length > 0) {
  2108. // 使用第一个工作量项作为平台井表格中显示的值
  2109. currentTask.value.platformWellDetails[detailIndex].workloadUnit = workloadData[0].workloadUnit
  2110. currentTask.value.platformWellDetails[detailIndex].workloadDesign =
  2111. workloadData[0].workloadDesign
  2112. }
  2113. }
  2114. // 如果是主任务井,也更新当前任务的工作量数据
  2115. if (wellName === currentTask.value.wellName && workloadData.length > 0) {
  2116. currentTask.value.workloadUnit = workloadData[0].workloadUnit
  2117. currentTask.value.workloadDesign = workloadData[0].workloadDesign
  2118. }
  2119. }
  2120. // 通过工作量单位名称获取对应的值
  2121. const getWorkloadUnitValueByName = (name: string): string => {
  2122. const options = getStrDictOptions(DICT_TYPE.PMS_PROJECT_WORKLOAD_UNIT)
  2123. const option = options.find((opt) => opt.label === name)
  2124. return option ? option.value : ''
  2125. }
  2126. const submitForm = async () => {
  2127. // 施工区域的数据字典类型
  2128. currentTask.value.dictType = currentDictLabel.value
  2129. // 先校验设计工作量
  2130. if (currentTask.value.platformWell !== '1' && !validateWorkloadDesign()) {
  2131. ElMessage.error('请完善设计工作量信息')
  2132. return
  2133. }
  2134. // 在同步任务前,确保平台井关联井的工作量数据正确设置
  2135. if (currentTask.value.platformWell === '1') {
  2136. currentTask.value.platformWellDetails.forEach((detail) => {
  2137. // 如果该关联井在workloadMap中没有数据,但表格行中有工作量数据,则设置到workloadMap中
  2138. if (
  2139. detail.wellName &&
  2140. !workloadMap.value.has(detail.wellName) &&
  2141. detail.workloadUnit &&
  2142. detail.workloadDesign
  2143. ) {
  2144. workloadMap.value.set(detail.wellName, [
  2145. {
  2146. workloadUnit: detail.workloadUnit,
  2147. workloadDesign: detail.workloadDesign
  2148. }
  2149. ])
  2150. }
  2151. })
  2152. }
  2153. // 先同步当前任务表单数据到表格
  2154. if (!syncCurrentTaskToTable()) {
  2155. return
  2156. }
  2157. // 校验表单
  2158. await formRef.value.validate()
  2159. // 校验所有行数据
  2160. if (!validateAllRows()) {
  2161. return
  2162. }
  2163. const getFileType = (filename: string) => {
  2164. const ext = filename.split('.').pop()?.toLowerCase()
  2165. if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(ext || '')) {
  2166. return 'image'
  2167. } else if (['pdf'].includes(ext || '')) {
  2168. return 'pdf'
  2169. } else if (['doc', 'docx'].includes(ext || '')) {
  2170. return 'word'
  2171. } else if (['xls', 'xlsx'].includes(ext || '')) {
  2172. return 'excel'
  2173. } else {
  2174. return 'other'
  2175. }
  2176. }
  2177. const formatFileSize = (bytes: number) => {
  2178. if (bytes === 0) return '0 Bytes'
  2179. const k = 1024
  2180. const sizes = ['Bytes', 'KB', 'MB', 'GB']
  2181. const i = Math.floor(Math.log(bytes) / Math.log(k))
  2182. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
  2183. }
  2184. function formatterAttachments(attachments: any[], type: string, taskId: number) {
  2185. return attachments.flatMap((item) => {
  2186. if (item.response.data.files) {
  2187. return item.response.data.files.map((file) => ({
  2188. category: 'DAILY_REPORT',
  2189. bizId: taskId,
  2190. filename: file.name || '未知文件',
  2191. fileType: getFileType(file.name),
  2192. filePath: file.filePath,
  2193. fileSize: formatFileSize(file.size || 0),
  2194. remark: '',
  2195. type
  2196. }))
  2197. } else return item.response.data
  2198. })
  2199. }
  2200. // 处理动态属性数据
  2201. const processedTableData = tableData.value.map((task) => {
  2202. // 获取当前任务的工作量数据并转换为dropdownList格式
  2203. const workloadDropdownList = getWorkloadDropdownListForTask(task)
  2204. // 为每个任务构建extProperty数组
  2205. const extProperties = dynamicAttrs.value.map((attr) => {
  2206. return {
  2207. name: attr.name,
  2208. sort: attr.sort,
  2209. unit: attr.unit,
  2210. actualValue: task[attr.identifier] || '', // 从任务中获取用户填写的值
  2211. dataType: attr.dataType,
  2212. maxValue: attr.maxValue,
  2213. minValue: attr.minValue,
  2214. required: attr.required,
  2215. accessMode: attr.accessMode,
  2216. identifier: attr.identifier,
  2217. defaultValue: attr.defaultValue,
  2218. // 添加dropdownList到任务对象中
  2219. dropdownList: workloadDropdownList
  2220. }
  2221. })
  2222. // 返回处理后的任务数据,包含extProperty字段
  2223. return {
  2224. ...task,
  2225. dictType: task.dictType || currentDictLabel.value, // 确保每个任务都有dictType
  2226. extProperty: extProperties,
  2227. attachments: formatterAttachments(constructionFiles.value, 'CONSTRUCTION_DESIGN', task.id)
  2228. .concat(formatterAttachments(geologicalFiles.value, 'GEOLOGICAL_DESIGN', task.id))
  2229. .concat(formatterAttachments(completionFiles.value, 'COMPLETION_REPORT', task.id))
  2230. }
  2231. })
  2232. // 提交请求
  2233. formLoading.value = true
  2234. try {
  2235. tableData.value.forEach((item) => {
  2236. item.projectId = formData.value.id
  2237. })
  2238. const data = {
  2239. taskList: processedTableData
  2240. }
  2241. if (formType.value === 'create') {
  2242. await IotProjectTaskApi.createIotProjectTask(data)
  2243. message.success(t('common.createSuccess'))
  2244. } else {
  2245. await IotProjectTaskApi.updateIotProjectTask(data)
  2246. message.success(t('common.updateSuccess'))
  2247. }
  2248. // 发送操作成功的事件
  2249. emit('success')
  2250. close()
  2251. } finally {
  2252. formLoading.value = false
  2253. }
  2254. }
  2255. // 判断是否为主要的平台井详情(不能删除)
  2256. const isMainPlatformWellDetail = (index: number) => {
  2257. if (
  2258. !currentTask.value.platformWellDetails ||
  2259. currentTask.value.platformWellDetails.length === 0
  2260. ) {
  2261. return false
  2262. }
  2263. const detail = currentTask.value.platformWellDetails[index]
  2264. // 主记录的条件:是第一条记录且有关联的任务ID,或者是自动从非平台井转换过来的主记录
  2265. return (
  2266. index === 0 &&
  2267. (detail.taskId === currentTask.value.id ||
  2268. (detail.wellName === currentTask.value.wellName &&
  2269. detail.workloadDesign === currentTask.value.workloadDesign))
  2270. )
  2271. }
  2272. // 处理平台井开关变化
  2273. const handlePlatformWellChange = (value) => {
  2274. if (value === '1') {
  2275. // 切换到平台井模式前,备份当前井号的工作量数据
  2276. if (currentTask.value.wellName) {
  2277. const currentWorkload = workloadMap.value.get(currentTask.value.wellName)
  2278. if (currentWorkload) {
  2279. workloadBackup.value.set(currentTask.value.wellName, [...currentWorkload])
  2280. }
  2281. }
  2282. // 检查是否是从非平台井切换过来,且当前任务有井号信息
  2283. const hasWellName = currentTask.value.wellName && currentTask.value.wellName.trim() !== ''
  2284. const hasWorkloadDesign = currentTask.value.workloadDesign
  2285. if (hasWellName && hasWorkloadDesign) {
  2286. // 从非平台井切换到平台井,自动添加一条记录
  2287. const mainDetail = {
  2288. taskId: currentTask.value.id, // 关联当前任务ID
  2289. wellName: currentTask.value.wellName,
  2290. workloadUnit: currentTask.value.workloadUnit, // 同步工作量单位
  2291. workloadDesign: currentTask.value.workloadDesign,
  2292. workloadDesignError: ''
  2293. }
  2294. // 如果workloadMap中有主井数据,同步到平台井表格
  2295. if (workloadMap.value.has(currentTask.value.wellName)) {
  2296. const workloadData = workloadMap.value.get(currentTask.value.wellName)
  2297. if (workloadData && workloadData.length > 0) {
  2298. mainDetail.workloadUnit = workloadData[0].workloadUnit
  2299. mainDetail.workloadDesign = workloadData[0].workloadDesign
  2300. }
  2301. }
  2302. // 清空现有详情,添加主记录
  2303. currentTask.value.platformWellDetails = [mainDetail]
  2304. } else {
  2305. // 恢复之前保存的数据或初始化
  2306. if (platformWellDetailsBackup.value.length > 0) {
  2307. currentTask.value.platformWellDetails = [...platformWellDetailsBackup.value]
  2308. sortPlatformWellDetails()
  2309. } else {
  2310. addPlatformWellDetail()
  2311. }
  2312. }
  2313. // 更新备份数据
  2314. platformWellDetailsBackup.value = [...currentTask.value.platformWellDetails]
  2315. } else {
  2316. // 如果有平台井详情,将第一个详情的数据设置回主任务
  2317. if (currentTask.value.platformWellDetails.length > 0) {
  2318. const mainDetail = currentTask.value.platformWellDetails[0]
  2319. currentTask.value.wellName = mainDetail.wellName || ''
  2320. currentTask.value.workloadDesign = mainDetail.workloadDesign || ''
  2321. // 恢复工作量数据
  2322. if (mainDetail.wellName && workloadBackup.value.has(mainDetail.wellName)) {
  2323. const backupWorkload = workloadBackup.value.get(mainDetail.wellName)
  2324. if (backupWorkload && backupWorkload.length > 0) {
  2325. workloadMap.value.set(mainDetail.wellName, [...backupWorkload])
  2326. // 恢复表单中的工作量单位(取第一项)
  2327. currentTask.value.workloadUnit = backupWorkload[0].workloadUnit
  2328. currentTask.value.workloadDesign = backupWorkload[0].workloadDesign
  2329. }
  2330. }
  2331. }
  2332. // 切换到非平台井模式,保存当前数据到备份
  2333. platformWellDetailsBackup.value = [...currentTask.value.platformWellDetails]
  2334. // 切换到非平台井模式,清空详情列表
  2335. currentTask.value.platformWellDetails = []
  2336. }
  2337. }
  2338. // 校验工作量对话框中的设计工作量
  2339. const validateWorkloadDialogDesign = (index) => {
  2340. const workloadItem = workloadList.value[index]
  2341. workloadItem.workloadDesignError = ''
  2342. const value = workloadItem.workloadDesign
  2343. if (value === '' || value === null || value === undefined) {
  2344. workloadItem.workloadDesignError = '设计工作量不能为空'
  2345. return false
  2346. }
  2347. const numValue = Number(value)
  2348. if (isNaN(numValue) || numValue < 0) {
  2349. workloadItem.workloadDesignError = '请填写大于0的数字'
  2350. return false
  2351. }
  2352. return true
  2353. }
  2354. // 获取表单中已选的工作量单位(来自workloadMap)
  2355. const getFormSelectedWorkloadUnits = () => {
  2356. // 兼容普通井/平台井的井号获取逻辑(与工作量弹窗逻辑一致)
  2357. let currentWellName = ''
  2358. if (currentTask.value.platformWell === '1') {
  2359. // 平台井:取主井号(优先当前任务wellName,其次取平台井详情第一个)
  2360. currentWellName =
  2361. currentTask.value.wellName ||
  2362. (currentTask.value.platformWellDetails.length > 0
  2363. ? currentTask.value.platformWellDetails[0].wellName
  2364. : '')
  2365. } else {
  2366. // 普通井:直接取当前任务井号
  2367. currentWellName = currentTask.value.wellName
  2368. }
  2369. // 从Map中获取当前井号的工作量列表,提取已选单位
  2370. const workloadList = workloadMap.value.get(currentWellName) || []
  2371. return workloadList.map((item) => item.workloadUnit).filter((unit) => unit && unit.trim() !== '') // 过滤空值
  2372. }
  2373. // 添加平台井详情行
  2374. const addPlatformWellDetail = () => {
  2375. const newDetail = {
  2376. taskId: '',
  2377. wellName: '',
  2378. workloadUnit: '', // 新增工作量单位字段
  2379. workloadDesign: '',
  2380. workloadDesignError: '' // 新增错误信息字段
  2381. }
  2382. // 将新记录添加到数组末尾,而不是开头
  2383. currentTask.value.platformWellDetails.push(newDetail)
  2384. }
  2385. // 删除平台井详情行
  2386. const removePlatformWellDetail = (index: number) => {
  2387. // 获取被删除的井号,清理Map
  2388. const removedDetail = currentTask.value.platformWellDetails[index]
  2389. if (removedDetail.wellName && workloadMap.value.has(removedDetail.wellName)) {
  2390. workloadMap.value.delete(removedDetail.wellName)
  2391. }
  2392. currentTask.value.platformWellDetails.splice(index, 1)
  2393. // 删除后重新排序
  2394. sortPlatformWellDetails()
  2395. }
  2396. // 平台井详情排序方法
  2397. const sortPlatformWellDetails = () => {
  2398. if (
  2399. !currentTask.value.platformWellDetails ||
  2400. currentTask.value.platformWellDetails.length === 0
  2401. ) {
  2402. return
  2403. }
  2404. currentTask.value.platformWellDetails.sort((a, b) => {
  2405. // 主记录(关联当前任务ID或从非平台井转换过来的记录)排在最前面
  2406. const aIsMain = a.taskId === currentTask.value.id
  2407. const bIsMain = b.taskId === currentTask.value.id
  2408. if (aIsMain && !bIsMain) return -1
  2409. if (!aIsMain && bIsMain) return 1
  2410. // 其他记录保持原有顺序
  2411. return 0
  2412. })
  2413. }
  2414. /** 重置表单 */
  2415. const resetForm = () => {
  2416. formData.value = {
  2417. id: undefined,
  2418. contractId: undefined,
  2419. contractName: undefined,
  2420. contractCode: undefined,
  2421. workloadTotal: undefined,
  2422. workloadFinish: undefined,
  2423. workloadUnit: undefined,
  2424. startTime: undefined,
  2425. endTime: undefined,
  2426. location: undefined,
  2427. technique: undefined,
  2428. payment: undefined,
  2429. remark: undefined,
  2430. manufactureName: undefined,
  2431. manufacturerId: undefined,
  2432. userName: undefined,
  2433. userId: undefined
  2434. }
  2435. formRef.value?.resetFields()
  2436. }
  2437. // 加载工作区域选项的方法
  2438. const loadWorkAreaOptions = async (deptId: number) => {
  2439. // 如果正在加载,直接返回
  2440. if (loadingWorkAreaOptions.value) return
  2441. loadingWorkAreaOptions.value = true
  2442. try {
  2443. // 先尝试通过 getDictLabel 获取字典标签
  2444. const dictLabel = await getDictLabel(DICT_TYPE.PMS_PROJECT_WORK_AREA, deptId)
  2445. console.log('当前专业公司的施工区域数据字典类型:' + dictLabel)
  2446. // 将 dictLabel 存储到 currentDictLabel
  2447. currentDictLabel.value = dictLabel || '' // 如果没有获取到,设为空字符串
  2448. if (dictLabel) {
  2449. // 如果获取到标签,再获取完整的字典选项
  2450. const dictOptions = getStrDictOptions(dictLabel)
  2451. console.log('当前专业公司的施工区域数据字典集合长度:' + dictOptions.length)
  2452. workAreaOptions.value = dictOptions.map((option) => ({
  2453. value: option.label, // 使用标签作为显示值
  2454. id: option.value // 保留原始值
  2455. }))
  2456. } else {
  2457. // 如果获取不到标签,清空选项
  2458. workAreaOptions.value = []
  2459. }
  2460. } catch (error) {
  2461. console.error('获取工作区域选项失败:', error)
  2462. workAreaOptions.value = []
  2463. } finally {
  2464. loadingWorkAreaOptions.value = false
  2465. }
  2466. }
  2467. // 当没有查询字符串时返回所有选项
  2468. const querySearch = (queryString: string, cb: any) => {
  2469. // 如果没有查询字符串,返回所有选项
  2470. if (!queryString) {
  2471. cb(workAreaOptions.value)
  2472. return
  2473. }
  2474. // 有查询字符串时进行筛选
  2475. const results = workAreaOptions.value.filter((option) =>
  2476. option.value.toLowerCase().includes(queryString.toLowerCase())
  2477. )
  2478. // 调用 callback 返回建议列表的数据
  2479. cb(results)
  2480. }
  2481. // 添加处理施工区域获取焦点的方法
  2482. const handleWorkAreaFocus = async () => {
  2483. // 如果已经有选项数据,直接显示下拉框
  2484. if (workAreaOptions.value.length > 0) {
  2485. // 使用Element Plus提供的方法触发下拉框
  2486. try {
  2487. // 直接调用el-autocomplete的focus方法
  2488. if (workAreaAutocomplete.value && typeof workAreaAutocomplete.value.focus === 'function') {
  2489. workAreaAutocomplete.value.focus()
  2490. }
  2491. } catch (error) {
  2492. console.error('触发下拉框显示失败:', error)
  2493. }
  2494. return
  2495. }
  2496. // 如果没有选项数据,尝试加载
  2497. if (formData.value.deptId && !loadingWorkAreaOptions.value) {
  2498. await loadWorkAreaOptions(formData.value.deptId)
  2499. // 加载完成后尝试显示下拉框
  2500. if (workAreaOptions.value.length > 0) {
  2501. try {
  2502. if (workAreaAutocomplete.value && typeof workAreaAutocomplete.value.focus === 'function') {
  2503. workAreaAutocomplete.value.focus()
  2504. }
  2505. } catch (error) {
  2506. console.error('触发下拉框显示失败:', error)
  2507. }
  2508. }
  2509. }
  2510. }
  2511. // 添加选择处理方法
  2512. const handleSelect = (item: any) => {
  2513. // 这里可以根据需要处理选择后的逻辑
  2514. console.log('选择了:', item.value)
  2515. }
  2516. // 加载施工工艺选项的方法
  2517. const loadTechnologyOptions = async (deptId: number) => {
  2518. if (loadingTechnologyOptions.value) return
  2519. loadingTechnologyOptions.value = true
  2520. try {
  2521. // 先尝试通过 getDictLabel 获取字典标签
  2522. const dictLabel = await getDictLabel(DICT_TYPE.PMS_PROJECT_TECHNOLOGY, deptId)
  2523. console.log('当前专业公司的施工工艺数据字典类型:' + dictLabel)
  2524. // 将 dictLabel 存储到 currentTechnologyDictLabel
  2525. currentTechnologyDictLabel.value = dictLabel || '' // 如果没有获取到,设为空字符串
  2526. if (dictLabel) {
  2527. // 如果获取到标签,再获取完整的字典选项
  2528. const dictOptions = getStrDictOptions(dictLabel)
  2529. console.log('当前专业公司的施工工艺数据字典集合长度:' + dictOptions.length)
  2530. technologyOptions.value = dictOptions.map((option) => ({
  2531. value: option.value,
  2532. label: option.label
  2533. }))
  2534. } else {
  2535. // 如果获取不到标签,清空选项
  2536. technologyOptions.value = []
  2537. }
  2538. } catch (error) {
  2539. console.error('获取施工工艺选项失败:', error)
  2540. technologyOptions.value = []
  2541. } finally {
  2542. loadingTechnologyOptions.value = false
  2543. }
  2544. }
  2545. // 工作量加号按钮禁用状态(计算属性)
  2546. const getWorkloadAddBtnDisabled = computed(() => {
  2547. // 禁用条件:无工作量单位 || 平台井模式 || 设计工作量校验失败
  2548. return (
  2549. !currentTask.value.workloadUnit ||
  2550. currentTask.value.platformWell === '1' ||
  2551. !!workloadDesignError.value
  2552. )
  2553. })
  2554. // 监听平台井状态变化,清空错误信息
  2555. watch(
  2556. () => currentTask.value.platformWell,
  2557. () => {
  2558. workloadDesignError.value = ''
  2559. }
  2560. )
  2561. // 监听工作量单位变化,同步更新到 workloadMap
  2562. watch(
  2563. () => currentTask.value.workloadUnit,
  2564. (newWorkloadUnit, oldWorkloadUnit) => {
  2565. if (!newWorkloadUnit || newWorkloadUnit === oldWorkloadUnit) return
  2566. // 获取当前井号(兼容普通井/平台井)
  2567. let currentWellName = ''
  2568. if (currentTask.value.platformWell === '1') {
  2569. currentWellName =
  2570. currentTask.value.wellName ||
  2571. (currentTask.value.platformWellDetails.length > 0
  2572. ? currentTask.value.platformWellDetails[0].wellName
  2573. : '')
  2574. } else {
  2575. currentWellName = currentTask.value.wellName
  2576. }
  2577. if (!currentWellName) return
  2578. // 如果workloadMap中存在当前井号的工作量数据,更新第一项的workloadUnit
  2579. if (workloadMap.value.has(currentWellName)) {
  2580. const workloadList = workloadMap.value.get(currentWellName)
  2581. if (workloadList && workloadList.length > 0) {
  2582. // 更新第一项的workloadUnit
  2583. workloadList[0].workloadUnit = newWorkloadUnit
  2584. // 重新设置到Map中(虽然引用相同,但为了确保响应性)
  2585. workloadMap.value.set(currentWellName, [...workloadList])
  2586. } else {
  2587. // 如果列表为空但有设计工作量,创建新项
  2588. if (currentTask.value.workloadDesign) {
  2589. workloadMap.value.set(currentWellName, [
  2590. {
  2591. workloadUnit: newWorkloadUnit,
  2592. workloadDesign: currentTask.value.workloadDesign
  2593. }
  2594. ])
  2595. }
  2596. }
  2597. } else if (currentTask.value.workloadDesign) {
  2598. // 如果Map中不存在但有设计工作量,创建新条目
  2599. workloadMap.value.set(currentWellName, [
  2600. {
  2601. workloadUnit: newWorkloadUnit,
  2602. workloadDesign: currentTask.value.workloadDesign
  2603. }
  2604. ])
  2605. }
  2606. },
  2607. { deep: true }
  2608. )
  2609. // 校验设计工作量
  2610. const validateWorkloadDesign = () => {
  2611. workloadDesignError.value = ''
  2612. if (currentTask.value.platformWell === '1') {
  2613. return true
  2614. }
  2615. const value = currentTask.value.workloadDesign
  2616. if (value === '' || value === null || value === undefined) {
  2617. workloadDesignError.value = '设计工作量不能为空'
  2618. return false
  2619. }
  2620. const numValue = Number(value)
  2621. if (isNaN(numValue) || numValue < 0) {
  2622. workloadDesignError.value = '请填写大于0的数字'
  2623. return false
  2624. }
  2625. return true
  2626. }
  2627. // 监听设计工作量变化
  2628. watch(
  2629. () => currentTask.value.workloadDesign,
  2630. () => {
  2631. if (workloadDesignError.value) {
  2632. validateWorkloadDesign()
  2633. }
  2634. }
  2635. )
  2636. // 监听当前任务的变化,设置默认展开的keys
  2637. watch(
  2638. () => currentTask.value.deptIds,
  2639. (newVal, oldVal) => {
  2640. if (newVal && newVal.length > 0) {
  2641. defaultExpandedKeys.value = [...newVal]
  2642. }
  2643. // 【新增】施工队伍变化时,重新查询设备并更新状态
  2644. const params = {
  2645. deptIds: newVal
  2646. }
  2647. /* IotDeviceApi.getDevicesByDepts(params).then(data => {
  2648. // 更新 hasDevicesAvailable 状态
  2649. hasDevicesAvailable.value = data && data.length > 0;
  2650. // 更新设备列表和映射表
  2651. if (hasDevicesAvailable.value) {
  2652. const newDeviceMap = {...deviceMap.value};
  2653. data.forEach(device => {
  2654. newDeviceMap[device.id] = device;
  2655. });
  2656. deviceMap.value = newDeviceMap;
  2657. }
  2658. }).catch(error => {
  2659. console.error('施工队伍变化时查询设备失败:', error);
  2660. hasDevicesAvailable.value = false;
  2661. }); */
  2662. if (!newVal || newVal.length === 0) {
  2663. // 清空施工队伍时,同时清空相关人员和设备
  2664. currentTask.value.responsiblePerson = []
  2665. currentTask.value.submitter = []
  2666. currentTask.value.deviceIds = []
  2667. // 重置设备可用状态
  2668. hasDevicesAvailable.value = true
  2669. // 清除相关字段的验证状态
  2670. nextTick(() => {
  2671. taskFormRef.value?.validateField('responsiblePerson')
  2672. taskFormRef.value?.validateField('submitter')
  2673. taskFormRef.value?.validateField('deviceIds')
  2674. })
  2675. } else if (newVal !== oldVal) {
  2676. // 施工队伍发生变化时,重置设备可用状态(因为不同队伍可能有不同的设备)
  2677. // hasDevicesAvailable.value = true;
  2678. }
  2679. },
  2680. { immediate: true, deep: true }
  2681. )
  2682. // 监听部门列表加载完成
  2683. watch(
  2684. () => deptList.value,
  2685. (newVal) => {
  2686. if (
  2687. newVal &&
  2688. newVal.length > 0 &&
  2689. currentTask.value.deptIds &&
  2690. currentTask.value.deptIds.length > 0
  2691. ) {
  2692. // defaultExpandedKeys.value = [...currentTask.value.deptIds];
  2693. // 过滤掉非叶子节点的ID,只保留叶子节点
  2694. const leafNodeIds = currentTask.value.deptIds.filter((id) => {
  2695. const node = findDeptNodeById(newVal, id)
  2696. return node && node.type === '3'
  2697. })
  2698. if (leafNodeIds.length > 0) {
  2699. defaultExpandedKeys.value = [...leafNodeIds]
  2700. }
  2701. }
  2702. },
  2703. { immediate: true, deep: true }
  2704. )
  2705. // 根据ID在部门树中查找节点
  2706. const findDeptNodeById = (tree: any[], id: number): any => {
  2707. for (const node of tree) {
  2708. if (node.id === id) {
  2709. return node
  2710. }
  2711. if (node.children && node.children.length > 0) {
  2712. const found = findDeptNodeById(node.children, id)
  2713. if (found) return found
  2714. }
  2715. }
  2716. return null
  2717. }
  2718. // 监听项目列表变化,确保列表加载完成后才执行自动选择
  2719. watch(projectList, (newVal) => {
  2720. if (newVal && newVal.length > 0) {
  2721. // 如果是编辑模式,使用任务数据中的合同ID
  2722. if (id && tableData.value.length > 0 && tableData.value[0].projectId) {
  2723. autoSelectContract(tableData.value[0].projectId.toString())
  2724. }
  2725. // 如果是新增模式且有传递的projectId,使用传递的projectId
  2726. else if (!id && projectId.value) {
  2727. console.log('watch-新增模式且有传递的projectId' + projectId.value + ' projectId not found')
  2728. autoSelectContract(projectId.value)
  2729. }
  2730. }
  2731. })
  2732. // 处理树形下拉框可见性变化
  2733. const handleTreeVisibleChange = (visible: boolean) => {
  2734. if (visible && currentTask.value.deptIds && currentTask.value.deptIds.length > 0) {
  2735. // 当下拉框显示且当前任务有已选部门时,设置默认展开的keys
  2736. defaultExpandedKeys.value = [...currentTask.value.deptIds]
  2737. // 使用nextTick确保DOM更新后再执行展开操作
  2738. nextTick(() => {
  2739. if (treeSelectRef.value) {
  2740. // 尝试访问内部树实例并展开节点
  2741. const treeInstance = treeSelectRef.value.treeRef
  2742. if (treeInstance && treeInstance.setExpandedKeys) {
  2743. treeInstance.setExpandedKeys(defaultExpandedKeys.value)
  2744. }
  2745. }
  2746. })
  2747. }
  2748. }
  2749. onMounted(async () => {
  2750. // 查询当前登录人所属公司下的所有部门
  2751. deptList.value = handleTree(await DeptApi.companyLevelChildrenDepts())
  2752. let deptId = useUserStore().getUser.deptId
  2753. projectList.value = await IotProjectInfoApi.getIotProjectInfoUser(deptId)
  2754. // 初始化时过滤当前任务中的部门ID,移除非叶子节点
  2755. if (currentTask.value.deptIds && currentTask.value.deptIds.length > 0) {
  2756. const validDeptIds = currentTask.value.deptIds.filter((id) => {
  2757. const node = findDeptNodeById(deptList.value, id)
  2758. return node && node.type === '3'
  2759. })
  2760. if (validDeptIds.length !== currentTask.value.deptIds.length) {
  2761. currentTask.value.deptIds = validDeptIds
  2762. }
  2763. }
  2764. // 查询当前任务已经选中的设备信息
  2765. open()
  2766. })
  2767. </script>
  2768. <style scoped>
  2769. .edit-input {
  2770. margin-right: 10px;
  2771. }
  2772. .error-message {
  2773. margin-top: 5px;
  2774. font-size: 12px;
  2775. color: #f56c6c;
  2776. }
  2777. .action-cell {
  2778. display: flex;
  2779. gap: 8px;
  2780. }
  2781. /* 1. 穿梭框父容器:居中 + 内边距 */
  2782. .transfer-container {
  2783. padding: 0; /* 上下内边距,避免紧贴对话框边缘 */
  2784. text-align: center;
  2785. }
  2786. /* 2. 穿梭框组件:控制宽度,避免过窄或过宽 */
  2787. .transfer-component {
  2788. width: 100%; /* 占对话框90%宽度,兼顾美观和内容显示 */
  2789. min-width: 600px;
  2790. }
  2791. /* 3. 直接调整 el-transfer 左右窗口的宽度 */
  2792. :deep(.el-transfer-panel) {
  2793. width: 40% !important; /* 强制设置左右面板宽度,确保两侧面板对等 */
  2794. }
  2795. /* 3. 深度选择器:修改el-transfer选项样式(解决内容省略问题) */
  2796. :deep(.el-transfer-panel__item) {
  2797. /* white-space: nowrap; 文本不换行,保证一行显示 */
  2798. /* overflow: hidden; 超出部分隐藏 */
  2799. /* text-overflow: ellipsis; 超出显示省略号 */
  2800. /* max-width: 100%; 确保文本不超出选项容器宽度 */
  2801. /* padding: 6px 6px; 适当增加内边距,优化点击体验 */
  2802. }
  2803. :deep(.el-transfer-panel__item) {
  2804. display: flex !important;
  2805. height: 32px !important;
  2806. padding: 0 8px !important;
  2807. margin: 0 !important;
  2808. overflow: hidden;
  2809. line-height: 32px !important;
  2810. text-overflow: ellipsis;
  2811. white-space: nowrap;
  2812. align-items: center !important;
  2813. }
  2814. /* 4. 选项文本:确保继承父容器宽度,省略号正常生效 */
  2815. .transfer-option-text {
  2816. display: inline-block;
  2817. max-width: 100%;
  2818. }
  2819. /* 设备名称显示区域样式 */
  2820. .device-names {
  2821. max-width: 200px; /* 根据实际列宽调整 */
  2822. overflow: hidden;
  2823. text-overflow: ellipsis;
  2824. white-space: nowrap;
  2825. }
  2826. :deep(.el-transfer-panel__list) {
  2827. width: 100% !important; /* 使面板内部内容宽度占满 */
  2828. }
  2829. /* 责任人名称显示区域样式 */
  2830. .responsible-names {
  2831. max-width: 200px; /* 根据实际列宽调整 */
  2832. overflow: hidden;
  2833. text-overflow: ellipsis;
  2834. white-space: nowrap;
  2835. }
  2836. /* 添加部门名称的样式 */
  2837. .dept-names {
  2838. display: inline-block;
  2839. max-width: 200px; /* 根据实际列宽调整 */
  2840. overflow: hidden;
  2841. text-overflow: ellipsis;
  2842. white-space: nowrap;
  2843. vertical-align: bottom;
  2844. }
  2845. /* 部门选择器样式优化 */
  2846. :deep(.department-tree-select .el-select__tags) {
  2847. overflow: hidden;
  2848. text-overflow: ellipsis;
  2849. white-space: nowrap;
  2850. flex-wrap: nowrap;
  2851. }
  2852. :deep(.department-tree-select .el-select__tags .el-tag) {
  2853. display: inline-block;
  2854. max-width: 120px;
  2855. overflow: hidden;
  2856. text-overflow: ellipsis;
  2857. }
  2858. :deep(.department-tree-select .el-select__tags .el-tag + .el-tag) {
  2859. margin-left: 6px;
  2860. }
  2861. :deep(.department-tree-select .el-select__tags-text) {
  2862. display: inline-block;
  2863. max-width: 100px;
  2864. overflow: hidden;
  2865. text-overflow: ellipsis;
  2866. }
  2867. /* 当有多个标签被折叠时显示的 "+N" 标签样式 */
  2868. :deep(.department-tree-select .el-select__collapse-tags) {
  2869. display: inline-block;
  2870. white-space: nowrap;
  2871. }
  2872. .task-edit-form {
  2873. padding: 20px;
  2874. margin-bottom: 20px;
  2875. background-color: #fafafa;
  2876. border: 1px solid #ebeef5;
  2877. border-radius: 4px;
  2878. }
  2879. /* 按钮文字样式 - 红色字体 */
  2880. :deep(.workload-add-btn .btn-text) {
  2881. font-size: 18px; /* 更大的字号 */
  2882. font-weight: 900; /* 更粗的字体 */
  2883. line-height: 1;
  2884. color: #f00 !important;
  2885. }
  2886. /* 设计工作量加号按钮 - 启用状态(深蓝色) */
  2887. :deep(.workload-add-btn .el-icon) {
  2888. color: #f00 !important; /* Element Plus 主色调深蓝色,可替换为 #003366 等自定义深蓝色 */
  2889. }
  2890. /* 按钮禁用状态 */
  2891. :deep(.workload-add-btn:disabled .btn-text) {
  2892. color: #c0c4cc !important;
  2893. }
  2894. /* 调整按钮整体样式,确保icon居中 */
  2895. :deep(.workload-add-btn) {
  2896. display: flex;
  2897. width: 100%;
  2898. height: 100%;
  2899. min-width: auto;
  2900. padding: 0 8px;
  2901. align-items: center;
  2902. justify-content: center;
  2903. }
  2904. /* 调整输入框append部分的宽度 */
  2905. :deep(.workload-input-with-button .el-input-group__append) {
  2906. width: 45px; /* 稍微增加宽度以容纳文字 */
  2907. padding: 0;
  2908. }
  2909. /* 确保按钮在禁用状态下有正确的样式 */
  2910. :deep(.workload-add-btn:disabled) {
  2911. cursor: not-allowed;
  2912. background-color: #f5f7fa;
  2913. border-color: #e4e7ed;
  2914. }
  2915. /* 设计工作量错误输入框样式 */
  2916. :deep(.error-input .el-input__inner) {
  2917. background-color: #fef0f0 !important;
  2918. border-color: #f56c6c !important;
  2919. box-shadow: 0 0 0 1px rgb(245 108 108 / 40%) !important;
  2920. }
  2921. :deep(.error-input .el-input__inner:hover) {
  2922. background-color: #fef0f0 !important;
  2923. border-color: #f56c6c !important;
  2924. }
  2925. :deep(.error-input .el-input__inner:focus) {
  2926. background-color: #fef0f0 !important;
  2927. border-color: #f56c6c !important;
  2928. box-shadow: 0 0 0 1px rgb(245 108 108 / 20%) !important;
  2929. }
  2930. /* 设计工作量tooltip样式 */
  2931. :deep(.workload-design-tooltip) {
  2932. max-width: 300px;
  2933. padding: 8px 12px;
  2934. font-size: 12px;
  2935. color: #f56c6c !important;
  2936. background: #fef0f0 !important;
  2937. border: 1px solid #fbc4c4 !important;
  2938. }
  2939. /* 隐藏 Tooltip 箭头 */
  2940. :deep(.workload-design-tooltip .el-tooltip__arrow),
  2941. :deep(.workload-design-tooltip .el-tooltip__arrow::before) {
  2942. display: none !important;
  2943. width: 0 !important;
  2944. height: 0 !important;
  2945. }
  2946. </style>