IotProjectTaskForm.vue 108 KB

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