activity-detail.vue 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757
  1. <template>
  2. <view class="page-container">
  3. <!-- 页面滚动区域 -->
  4. <scroll-view class="page-scroll" scroll-y>
  5. <!-- 地块信息卡片 -->
  6. <view class="info-card">
  7. <view class="card-title">
  8. <text>地块信息</text>
  9. </view>
  10. <view class="info-item">
  11. <text class="info-label">地块名称</text>
  12. <text class="info-value">{{ formData.fieldName || '未知' }}</text>
  13. </view>
  14. <view class="info-item">
  15. <text class="info-label">作物名称</text>
  16. <text class="info-value">{{ formData.growCrops || '未知' }}</text>
  17. </view>
  18. <view class="info-item">
  19. <text class="info-label">负责人</text>
  20. <text class="info-value">{{ formData.manager || '未知' }}</text>
  21. </view>
  22. </view>
  23. <!-- 任务填写表单 -->
  24. <view class="form-card">
  25. <view class="card-title">
  26. <text>任务信息</text>
  27. </view>
  28. <!-- 任务名称 -->
  29. <view class="form-item">
  30. <view class="form-label required">任务名称</view>
  31. <input
  32. v-model="formData.taskName"
  33. placeholder="请输入任务名称,例如:水稻田施肥"
  34. :disabled="pageMode === 'view'"
  35. class="form-input"
  36. />
  37. </view>
  38. <!-- 任务类型 -->
  39. <view class="form-item" @click="pageMode !== 'view' && showTaskTypeSelector()">
  40. <view class="form-label required">任务类型</view>
  41. <view class="select-wrapper">
  42. <!-- <input
  43. :value="formData.typeName"
  44. :placeholder="dictLoading ? '加载中...' : '请选择任务类型'"
  45. readonly
  46. class="form-input select-input"
  47. /> -->
  48. <view class="form-input select-input">
  49. {{ formData.typeName || (dictLoading ? '加载中...' : '请选择任务类型') }}
  50. </view>
  51. <view v-if="pageMode !== 'view'" class="select-arrow">
  52. <text>▼</text>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 执行时间 -->
  57. <view class="form-item" @click="pageMode !== 'view' && selectExecuteTime()">
  58. <view class="form-label required">执行时间</view>
  59. <view class="select-wrapper">
  60. <!-- <input
  61. :value="formattedExecuteTime"
  62. placeholder="请选择任务计划时间"
  63. readonly
  64. class="form-input select-input"
  65. readonly
  66. /> -->
  67. <view class="form-input select-input">
  68. {{ formattedExecuteTime || '请选择任务计划时间' }}
  69. </view>
  70. <view v-if="pageMode !== 'view'" class="select-arrow">
  71. <text>选择</text>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 负责人选择 -->
  76. <view class="form-item" @click="pageMode !== 'view' && showUserSelector()">
  77. <view class="form-label required">负责人</view>
  78. <view class="select-wrapper">
  79. <!-- <input
  80. :value="formData.assigneeName"
  81. placeholder="请选择负责人"
  82. readonly
  83. class="form-input select-input"
  84. /> -->
  85. <view class="form-input select-input">
  86. {{ formData.assigneeName || '请选择负责人' }}
  87. </view>
  88. <view v-if="pageMode !== 'view'" class="select-arrow">
  89. <text>选择</text>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 任务说明 -->
  94. <view class="form-item">
  95. <view class="form-label">任务说明</view>
  96. <textarea
  97. v-model="formData.remark"
  98. placeholder="请输入任务要点,例如:每亩用肥20kg"
  99. :disabled="pageMode === 'view'"
  100. class="form-textarea"
  101. maxlength="200"
  102. ></textarea>
  103. <view class="char-count">{{ (formData.remark || '').length }}/200</view>
  104. </view>
  105. <!-- 任务完成情况 -->
  106. <view class="section-divider"></view>
  107. <view class="section-title">
  108. <text>任务完成情况</text>
  109. </view>
  110. <!-- 完成状态选择 - 新建和编辑模式 -->
  111. <view class="form-item" v-if="pageMode === 'create' || pageMode === 'edit'">
  112. <view class="form-label">完成状态</view>
  113. <view class="radio-group">
  114. <view
  115. class="radio-item"
  116. v-for="(item, index) in completionStatusOptions"
  117. :key="index"
  118. @click="selectCompletionStatus(item.value)"
  119. >
  120. <view class="radio-circle" :class="{'radio-checked': formData.completionStatus === item.value}">
  121. <view v-if="formData.completionStatus === item.value" class="radio-dot"></view>
  122. </view>
  123. <text class="radio-label">{{ item.label }}</text>
  124. </view>
  125. </view>
  126. </view>
  127. <!-- 查看模式显示完成状态 -->
  128. <view class="form-item" v-if="pageMode === 'view'">
  129. <view class="form-label">完成状态</view>
  130. <view class="status-completed">
  131. <text class="status-icon">✓</text>
  132. <text>已完成</text>
  133. </view>
  134. </view>
  135. <!-- 完成时间 -->
  136. <view class="form-item" v-if="formData.completionStatus === '1'">
  137. <view class="form-label" :class="{'required': (pageMode === 'create' || pageMode === 'edit') && formData.completionStatus === '1'}">完成时间</view>
  138. <view class="select-wrapper" @click="(pageMode === 'create' || pageMode === 'edit') && formData.completionStatus === '1' && selectCompletionTime()">
  139. <!-- <input
  140. :value="formattedCompletionTime"
  141. placeholder="请选择实际完成时间"
  142. readonly
  143. class="form-input select-input"
  144. /> -->
  145. <view class="form-input select-input">
  146. {{ formattedCompletionTime || '请选择实际完成时间' }}
  147. </view>
  148. <view v-if="(pageMode === 'create' || pageMode === 'edit') && formData.completionStatus === '1'" class="select-arrow">
  149. <text>选择</text>
  150. </view>
  151. </view>
  152. </view>
  153. <!-- 完成说明 -->
  154. <view class="form-item" v-if="formData.completionStatus === '1'">
  155. <view class="form-label" :class="{'required': (pageMode === 'create' || pageMode === 'edit') && formData.completionStatus === '1'}">完成说明</view>
  156. <textarea
  157. v-model="formData.completionDesc"
  158. placeholder="请输入完成说明,例如:已完成并拍照记录"
  159. :disabled="pageMode === 'view'"
  160. class="form-textarea"
  161. maxlength="300"
  162. ></textarea>
  163. <view class="char-count">{{ (formData.completionDesc || '').length }}/300</view>
  164. <view class="form-error" v-if="formErrors.completionDesc">
  165. {{ formErrors.completionDesc }}
  166. </view>
  167. </view>
  168. <!-- 现场图片 -->
  169. <view class="form-item" v-if="formData.completionStatus === '1'">
  170. <view class="form-label">现场图片</view>
  171. <!-- 新建和编辑模式 -->
  172. <view v-if="pageMode === 'create' || pageMode === 'edit'" class="image-upload">
  173. <view class="image-list">
  174. <view
  175. class="image-preview"
  176. v-for="(item, index) in formData.images"
  177. :key="index"
  178. @click="previewImage(item, index)"
  179. >
  180. <!-- <image :src="getImageUrl(item)" mode="aspectFill"/> -->
  181. <image :src="item.url" mode="aspectFill"/>
  182. <view class="delete-btn" @click.stop="deletePic(index)">
  183. <text>×</text>
  184. </view>
  185. </view>
  186. <view
  187. v-if="formData.images.length < 6"
  188. class="upload-btn"
  189. @click="chooseImage"
  190. >
  191. <text class="upload-icon">+</text>
  192. <text class="upload-text">添加图片</text>
  193. </view>
  194. </view>
  195. <view class="upload-tip">最多可上传6张图片</view>
  196. </view>
  197. <!-- 查看模式 -->
  198. <view v-else-if="pageMode === 'view' && formData.images && formData.images.length > 0" class="image-view">
  199. <view class="image-list">
  200. <view
  201. class="image-preview"
  202. v-for="(item, index) in formData.images"
  203. :key="index"
  204. @click="previewImage(item, index)"
  205. >
  206. <!-- <image :src="getImageUrl(item)" mode="aspectFill"/> -->
  207. <image :src="item.url" mode="aspectFill"/>
  208. </view>
  209. </view>
  210. </view>
  211. <!-- 无图片提示 -->
  212. <view v-else class="no-images">
  213. <text>暂无图片</text>
  214. </view>
  215. </view>
  216. </view>
  217. <!-- 底部占位 -->
  218. <view class="bottom-safe"></view>
  219. </scroll-view>
  220. <!-- 底部提交按钮 -->
  221. <view class="footer-safe" v-if="pageMode !== 'view'">
  222. <view class="footer-content">
  223. <button
  224. class="submit-button"
  225. :class="{'loading': isSubmitting}"
  226. @click="submitForm"
  227. :disabled="isSubmitting"
  228. >
  229. {{ isSubmitting ? '提交中...' : submitButtonText }}
  230. </button>
  231. </view>
  232. </view>
  233. <!-- 遮罩层 -->
  234. <view v-if="showTaskTypePicker || showDateTimeSelector || showUserPicker" class="picker-mask" @click="closePickers"></view>
  235. <!-- 任务类型选择弹窗 -->
  236. <view v-if="showTaskTypePicker" class="picker-popup">
  237. <view class="picker-header">
  238. <text class="picker-cancel" @click="showTaskTypePicker = false">取消</text>
  239. <text class="picker-title">选择任务类型</text>
  240. <text class="picker-confirm" @click="confirmTaskType">确定</text>
  241. </view>
  242. <view class="picker-content">
  243. <view v-if="dictLoading" class="picker-loading">
  244. <text>加载中...</text>
  245. </view>
  246. <view
  247. v-else
  248. class="picker-item"
  249. v-for="(item, index) in taskTypeOptions"
  250. :key="index"
  251. :class="{'selected': tempTaskTypeIndex === index}"
  252. @click="tempTaskTypeIndex = index"
  253. >
  254. <text>{{ item.dictLabel }}</text>
  255. <text v-if="tempTaskTypeIndex === index" class="check-mark">✓</text>
  256. </view>
  257. </view>
  258. </view>
  259. <!-- 用户选择弹窗 -->
  260. <view v-if="showUserPicker" class="picker-popup">
  261. <view class="picker-header">
  262. <text class="picker-cancel" @click="showUserPicker = false">取消</text>
  263. <text class="picker-title">选择负责人</text>
  264. <text class="picker-confirm" @click="confirmUser">确定</text>
  265. </view>
  266. <view class="picker-content">
  267. <view v-if="usersLoading" class="picker-loading">
  268. <text>加载中...</text>
  269. </view>
  270. <view v-else-if="userList.length === 0" class="picker-empty">
  271. <text>暂无可选负责人</text>
  272. </view>
  273. <view
  274. v-else
  275. class="picker-item"
  276. v-for="(user, index) in userList"
  277. :key="user.userId"
  278. :class="{'selected': tempUserIndex === index}"
  279. @click="tempUserIndex = index"
  280. >
  281. <text>{{ user.userName }}</text>
  282. <text v-if="tempUserIndex === index" class="check-mark">✓</text>
  283. </view>
  284. </view>
  285. </view>
  286. <!-- 日期时间选择弹窗 -->
  287. <view v-if="showDateTimeSelector" class="picker-popup datetime-picker">
  288. <view class="picker-header">
  289. <text class="picker-cancel" @click="cancelDateTime">取消</text>
  290. <text class="picker-title">选择时间</text>
  291. <text class="picker-confirm" @click="confirmDateTime">确定</text>
  292. </view>
  293. <view class="datetime-picker-content">
  294. <picker-view
  295. class="datetime-picker-view"
  296. :value="dateTimePickerValue"
  297. @change="onDateTimePickerChange"
  298. :indicator-style="'height: 80rpx;'"
  299. :mask-style="'background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.6)), linear-gradient(0deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.6));'"
  300. >
  301. <picker-view-column>
  302. <view class="picker-view-item" v-for="(item, index) in dateTimePickerRange[0]" :key="'year-'+index">
  303. <text class="picker-item-text">{{ item }}</text>
  304. </view>
  305. </picker-view-column>
  306. <picker-view-column>
  307. <view class="picker-view-item" v-for="(item, index) in dateTimePickerRange[1]" :key="'month-'+index">
  308. <text class="picker-item-text">{{ item }}</text>
  309. </view>
  310. </picker-view-column>
  311. <picker-view-column>
  312. <view class="picker-view-item" v-for="(item, index) in dateTimePickerRange[2]" :key="'day-'+index">
  313. <text class="picker-item-text">{{ item }}</text>
  314. </view>
  315. </picker-view-column>
  316. <picker-view-column>
  317. <view class="picker-view-item" v-for="(item, index) in dateTimePickerRange[3]" :key="'hour-'+index">
  318. <text class="picker-item-text">{{ item }}</text>
  319. </view>
  320. </picker-view-column>
  321. <picker-view-column>
  322. <view class="picker-view-item" v-for="(item, index) in dateTimePickerRange[4]" :key="'min-'+index">
  323. <text class="picker-item-text">{{ item }}</text>
  324. </view>
  325. </picker-view-column>
  326. </picker-view>
  327. </view>
  328. </view>
  329. </view>
  330. </template>
  331. <script setup>
  332. import { ref, reactive, computed, onMounted } from 'vue'
  333. import api from "@/config/api.js";
  334. import { onShow, onLoad } from '@dcloudio/uni-app'
  335. import { getAgriculturalTasksById, addAgriculturalTask, updateAgriculturalTask } from '@/api/services/activity.js';
  336. import { getUsersByPlotId, getUserInfo } from '@/api/services/user.js';
  337. import { useDict } from '@/utils/composables/useDict';
  338. import storage from "@/utils/storage.js";
  339. // 使用字典组合式函数
  340. const { dictData, dictLoading, loadDict } = useDict(['task_type', 'task_status'])
  341. // 页面模式:create-新建, edit-编辑, view-查看
  342. const pageMode = ref('create')
  343. // 选择器显示状态
  344. const showTaskTypePicker = ref(false)
  345. const showDateTimeSelector = ref(false)
  346. const showUserPicker = ref(false)
  347. // 临时选择的任务类型索引
  348. const tempTaskTypeIndex = ref(0)
  349. const tempUserIndex = ref(0)
  350. // 时间选择器相关
  351. const currentTimeType = ref('')
  352. const dateTimePickerValue = ref([0, 0, 0, 0, 0])
  353. const dateTimePickerRange = ref([])
  354. // 表单数据
  355. const formData = reactive({
  356. // 任务ID,新建任务时为空
  357. id: '',
  358. // 地块基础信息
  359. plotId: '',
  360. fieldName: '',
  361. growCrops: '',
  362. manager: '',
  363. // 任务信息
  364. taskName: '',
  365. typeName: '',
  366. typeNameId: '',
  367. executeTime: new Date(),
  368. remark: '',
  369. // 完成情况
  370. taskStatus: '0',
  371. completionStatus: '0',
  372. completionTime: new Date(),
  373. completionDesc: '',
  374. images: [],
  375. taskImages: '',
  376. // 负责人信息
  377. assigneeId: '',
  378. assigneeName: '',
  379. // 创建人信息
  380. create_by: ''
  381. })
  382. // 完成状态选项
  383. const completionStatusOptions = [
  384. { label: '待完成', value: '0' },
  385. { label: '已完成', value: '1' }
  386. ]
  387. // 是否正在提交
  388. const isSubmitting = ref(false)
  389. // 表单验证错误
  390. const formErrors = reactive({
  391. completionDesc: ''
  392. })
  393. // 用户列表
  394. const userList = ref([])
  395. const usersLoading = ref(false)
  396. // 任务类型列表
  397. const taskStatusList = ref([])
  398. // 计算属性
  399. const pageTitle = computed(() => {
  400. switch (pageMode.value) {
  401. case 'create':
  402. return '新建农事任务'
  403. case 'edit':
  404. return '编辑农事任务'
  405. default:
  406. return '农事任务详情'
  407. }
  408. })
  409. const submitButtonText = computed(() => {
  410. switch (pageMode.value) {
  411. case 'create':
  412. return '创建任务'
  413. case 'edit':
  414. return '保存修改'
  415. default:
  416. return ''
  417. }
  418. })
  419. const formattedExecuteTime = computed(() => {
  420. return formatDateTime(formData.executeTime)
  421. })
  422. const formattedCompletionTime = computed(() => {
  423. return formatDateTime(formData.completionTime)
  424. })
  425. const taskTypeOptions = computed(() => {
  426. return dictData.task_type
  427. })
  428. const taskTypeIndex = computed(() => {
  429. console.log("taskTypeOptions", taskTypeOptions.value)
  430. const index = taskTypeOptions.value.findIndex(item => item.dictValue === formData.typeNameId)
  431. console.log("查找:", index)
  432. return index >= 0 ? index : 0
  433. })
  434. // 初始化字典数据
  435. loadDict().then(() => {
  436. console.log("dictData:",dictData.task_type);
  437. // 字典加载完成后,如果没有设置任务类型,则默认选择第一个
  438. if (!formData.typeName && dictData.task_type && dictData.task_type.length > 0) {
  439. const firstType = dictData.task_type[0]
  440. taskStatusList.value = dictData.task_type
  441. console.log("dictData", dictData.task_status[0].dictLabel)
  442. formData.typeName = firstType.dictLabel
  443. formData.typeNameId = firstType.dictValue
  444. }
  445. })
  446. // uni-app 生命周期
  447. onLoad((options) => {
  448. console.log('页面加载,接收参数:', options)
  449. // 设置页面模式
  450. if (options.mode) {
  451. pageMode.value = options.mode
  452. }
  453. // 设置地块基础信息
  454. formData.fieldName = decodeURIComponent(options.fieldName === 'undefined' ? '未选择地块' : options.fieldName)
  455. formData.growCrops = decodeURIComponent(options.growCrops === 'undefined' ? '未选择地块' : options.growCrops)
  456. formData.manager = decodeURIComponent(options.manager === 'undefined' ? '未选择地块' : options.manager)
  457. formData.plotId = parseInt(options.plotId || '1')
  458. formData.farmId = parseInt(options.farmId || '1')
  459. // 加载用户列表
  460. loadUserList(formData.farmId)
  461. // 如果是编辑或查看模式,获取任务详情
  462. if (options.id && options.id !== 'new') {
  463. formData.id = options.id
  464. loadTaskDetail(options.id)
  465. } else if (options.id === 'new') {
  466. // 加载当前登录用户
  467. loadAssigneeInfo()
  468. }
  469. // 设置导航栏标题
  470. uni.setNavigationBarTitle({
  471. title: pageTitle.value
  472. })
  473. // 初始化时间选择器数据
  474. initDateTimeRange()
  475. })
  476. // 方法定义
  477. // 跨端安全解析日期
  478. const normalizeToDate = (input) => {
  479. if (!input) return new Date()
  480. let dateObj = input
  481. if (typeof input === 'string') {
  482. // 兼容 iOS:将 2025-08-12 12:30:00 转为 2025/08/12 12:30:00
  483. dateObj = input.replace(/-/g, '/')
  484. }
  485. if (typeof input === 'number') {
  486. // 秒级时间戳转毫秒
  487. if (input.toString().length === 10) {
  488. dateObj = input * 1000
  489. }
  490. }
  491. const d = new Date(dateObj)
  492. return isNaN(d.getTime()) ? new Date() : d
  493. }
  494. // 加载任务详情
  495. const loadTaskDetail = (taskId) => {
  496. uni.showLoading({
  497. title: '加载中...',
  498. mask: true
  499. })
  500. getAgriculturalTasksById(taskId).then(res => {
  501. if (res.data.code === 200) {
  502. const taskDetail = res.data.data
  503. // 设置表单数据
  504. Object.assign(formData, {
  505. ...taskDetail,
  506. manager: formData.manager,
  507. completionStatus: taskDetail.taskStatus
  508. })
  509. // 转换任务类型值
  510. if (taskStatusList.value && taskStatusList.value.length > 0) {
  511. const typeDict = taskStatusList.value.find(item => item.dictValue === taskDetail.typeName.toString())
  512. if (typeDict) {
  513. formData.typeName = typeDict.dictLabel
  514. formData.typeNameId = typeDict.dictValue
  515. }
  516. }
  517. // 处理图片数据
  518. if (formData.taskImages) {
  519. try {
  520. const imageUrls = formData.taskImages.split(',')
  521. formData.images = imageUrls.filter(url => url && url.trim()).map(url => ({
  522. url: url.trim(),
  523. status: 'success'
  524. }))
  525. console.log('解析后的图片数据:', formData.images)
  526. } catch (e) {
  527. console.error('解析图片数据失败:', e)
  528. formData.images = []
  529. }
  530. } else {
  531. formData.images = []
  532. }
  533. console.log("formData.assigneeId", formData.assigneeId)
  534. console.log("!formData.assigneeName", formData.assigneeName)
  535. // 如果有负责人ID但没有负责人名称,获取负责人信息
  536. if (formData.assigneeId && !formData.assigneeName) {
  537. loadAssigneeInfo(formData.assigneeId)
  538. }
  539. uni.hideLoading();
  540. } else {
  541. uni.hideLoading();
  542. uni.showToast({
  543. title: res.data.msg || '获取任务详情失败',
  544. icon: 'none'
  545. });
  546. // 失败后返回上一页
  547. setTimeout(() => {
  548. uni.navigateBack();
  549. }, 1500);
  550. }
  551. }).catch(err => {
  552. console.error('获取任务详情失败:', err);
  553. uni.hideLoading();
  554. uni.showToast({
  555. title: '获取任务详情失败',
  556. icon: 'none'
  557. });
  558. // 失败后返回上一页
  559. setTimeout(() => {
  560. uni.navigateBack();
  561. }, 1500);
  562. });
  563. }
  564. // 加载负责人信息
  565. const loadAssigneeInfo = (userId) => {
  566. getUserInfo(userId).then(res => {
  567. console.log("你是谁:",res);
  568. if (res.data.code === 200) {
  569. const userData = res.data.data;
  570. formData.assigneeName = userData.userName || '未知用户';
  571. formData.assigneeId = userData.userId;
  572. }
  573. }).catch(err => {
  574. console.error('获取负责人信息失败:', err);
  575. formData.assigneeName = '未知用户';
  576. });
  577. }
  578. // 加载用户列表
  579. const loadUserList = (farmId) => {
  580. usersLoading.value = true;
  581. const params = {
  582. pageNum: 1,
  583. pageSize: 10,
  584. deptId: farmId
  585. }
  586. getUsersByPlotId(params).then(res => {
  587. console.log("加载用户:",res);
  588. if (res.data.code === 200) {
  589. userList.value = res.data.rows || [];
  590. // 设置默认选中第一个用户
  591. if (userList.value.length > 0 && !formData.assigneeId) {
  592. formData.assigneeId = userList.value[0].userId;
  593. formData.assigneeName = userList.value[0].userName;
  594. }
  595. } else {
  596. console.error('获取用户列表失败:', res.data.msg);
  597. uni.showToast({
  598. title: '获取用户列表失败',
  599. icon: 'none'
  600. });
  601. }
  602. }).catch(err => {
  603. console.error('获取用户列表失败:', err);
  604. uni.showToast({
  605. title: '获取用户列表失败',
  606. icon: 'none'
  607. });
  608. }).finally(() => {
  609. usersLoading.value = false;
  610. });
  611. }
  612. // 初始化时间选择器范围数据
  613. const initDateTimeRange = () => {
  614. // 年份:从2020年开始显示10年
  615. const startYear = 2020;
  616. const years = [];
  617. for (let i = 0; i < 10; i++) {
  618. years.push((startYear + i) + '年');
  619. }
  620. // 月份:1-12月
  621. const months = [];
  622. for (let i = 1; i <= 12; i++) {
  623. months.push(i + '月');
  624. }
  625. // 日期:1-31日
  626. const days = [];
  627. for (let i = 1; i <= 31; i++) {
  628. days.push(i + '日');
  629. }
  630. // 小时:0-23时
  631. const hours = [];
  632. for (let i = 0; i <= 23; i++) {
  633. hours.push(i.toString().padStart(2, '0') + '时');
  634. }
  635. // 分钟:0-59分
  636. const minutes = [];
  637. for (let i = 0; i <= 59; i++) {
  638. minutes.push(i.toString().padStart(2, '0') + '分');
  639. }
  640. dateTimePickerRange.value = [years, months, days, hours, minutes];
  641. console.log('日期选择器范围:', {
  642. years: years.length,
  643. months: months.length,
  644. days: days.length,
  645. hours: hours.length,
  646. minutes: minutes.length
  647. });
  648. }
  649. // 初始化日期时间选择器
  650. const initDateTimePicker = (timestamp) => {
  651. const date = normalizeToDate(timestamp);
  652. const currentYear = date.getFullYear();
  653. const currentMonth = date.getMonth() + 1; // 1-12
  654. const currentDate = date.getDate(); // 1-31
  655. const currentHour = date.getHours();
  656. const currentMinute = date.getMinutes();
  657. // 基准年份,用于计算索引
  658. const startYear = 2020;
  659. // 如果当前年份小于起始年份或大于结束年份,调整为合法范围内
  660. let yearIndex = currentYear - startYear;
  661. if (yearIndex < 0) yearIndex = 0;
  662. if (yearIndex >= 10) yearIndex = 9;
  663. console.log('初始化日期选择器:', {
  664. timestamp,
  665. year: currentYear,
  666. month: currentMonth,
  667. date: currentDate,
  668. hour: currentHour,
  669. minute: currentMinute,
  670. yearIndex
  671. });
  672. // 设置选择器的初始值
  673. dateTimePickerValue.value = [
  674. yearIndex, // 年份索引
  675. currentMonth - 1, // 月份索引(0-11)
  676. currentDate - 1, // 日期索引(0-30)
  677. currentHour, // 小时索引
  678. currentMinute // 分钟索引
  679. ];
  680. console.log('选择器初始值:', dateTimePickerValue.value);
  681. // 更新日期范围
  682. updateDaysRange();
  683. }
  684. // 更新日期范围(根据选择的年月)
  685. const updateDaysRange = () => {
  686. const yearIndex = dateTimePickerValue.value[0];
  687. const monthIndex = dateTimePickerValue.value[1];
  688. // 计算实际年月
  689. const year = 2020 + yearIndex;
  690. const month = monthIndex + 1; // 索引为0-11,实际月份为1-12
  691. // 获取该月的天数
  692. const daysInMonth = new Date(year, month, 0).getDate();
  693. // 更新天数范围
  694. const days = [];
  695. for (let i = 1; i <= daysInMonth; i++) {
  696. days.push(i + '日');
  697. }
  698. // 更新日期列
  699. dateTimePickerRange.value[2] = days;
  700. // 如果当前选择的日期超过了该月的天数,调整为该月最后一天
  701. if (dateTimePickerValue.value[2] >= daysInMonth) {
  702. dateTimePickerValue.value[2] = daysInMonth - 1;
  703. }
  704. console.log('更新日期范围:', {
  705. year,
  706. month,
  707. daysInMonth,
  708. daysLength: days.length
  709. });
  710. }
  711. // 显示任务类型选择器
  712. const showTaskTypeSelector = () => {
  713. tempTaskTypeIndex.value = taskTypeIndex.value;
  714. showTaskTypePicker.value = true;
  715. }
  716. // 确认任务类型选择
  717. const confirmTaskType = () => {
  718. const selectedType = taskTypeOptions.value[tempTaskTypeIndex.value];
  719. console.log("选中:",selectedType);
  720. formData.typeName = selectedType.dictLabel;
  721. formData.typeNameId = selectedType.dictValue; // 设置typeNameId为dictValue值
  722. showTaskTypePicker.value = false;
  723. }
  724. // 选择执行时间
  725. const selectExecuteTime = () => {
  726. currentTimeType.value = 'executeTime';
  727. initDateTimePicker(formData.executeTime);
  728. showDateTimeSelector.value = true;
  729. }
  730. // 选择完成时间
  731. const selectCompletionTime = () => {
  732. currentTimeType.value = 'completionTime';
  733. initDateTimePicker(formData.completionTime);
  734. showDateTimeSelector.value = true;
  735. }
  736. // 日期时间选择器变更
  737. const onDateTimePickerChange = (e) => {
  738. dateTimePickerValue.value = e.detail.value;
  739. // 当年月变更时,更新日期范围
  740. updateDaysRange();
  741. }
  742. // 确认时间选择
  743. const confirmDateTime = () => {
  744. const values = dateTimePickerValue.value;
  745. // 计算实际日期时间
  746. const year = 2020 + values[0];
  747. const month = values[1] + 1; // 索引为0-11,实际月份为1-12
  748. const date = values[2] + 1; // 索引为0-30,实际日期为1-31
  749. const hour = values[3];
  750. const minute = values[4];
  751. console.log('确认日期时间:', {
  752. selectedValues: values,
  753. convertedDate: `${year}-${month}-${date} ${hour}:${minute}`
  754. });
  755. // 创建日期对象
  756. const selectedTime = new Date(year, month - 1, date, hour, minute).getTime();
  757. // 更新相应的表单字段
  758. if (currentTimeType.value === 'executeTime') {
  759. formData.executeTime = selectedTime;
  760. } else if (currentTimeType.value === 'completionTime') {
  761. formData.completionTime = selectedTime;
  762. }
  763. // 关闭选择器
  764. showDateTimeSelector.value = false;
  765. uni.showToast({
  766. title: '时间已设置',
  767. icon: 'success',
  768. duration: 1500
  769. });
  770. }
  771. // 取消时间选择
  772. const cancelDateTime = () => {
  773. showDateTimeSelector.value = false;
  774. }
  775. // 显示用户选择器
  776. const showUserSelector = () => {
  777. tempUserIndex.value = userList.value.findIndex(user => user.userId === formData.assigneeId);
  778. showUserPicker.value = true;
  779. }
  780. // 确认用户选择
  781. const confirmUser = () => {
  782. const selectedUser = userList.value[tempUserIndex.value];
  783. formData.assigneeId = selectedUser.userId;
  784. formData.assigneeName = selectedUser.userName;
  785. showUserPicker.value = false;
  786. }
  787. // 关闭所有选择器
  788. const closePickers = () => {
  789. showTaskTypePicker.value = false;
  790. showDateTimeSelector.value = false;
  791. showUserPicker.value = false;
  792. }
  793. // 选择完成状态
  794. const selectCompletionStatus = (value) => {
  795. formData.completionStatus = value;
  796. formData.taskStatus = value; // 同时设置taskStatus字段
  797. if (value === '1') {
  798. formData.completionTime = new Date();
  799. }
  800. }
  801. // 格式化日期时间
  802. /**
  803. * 日期格式化工具(兼容 iOS 和安卓)
  804. * @param {string|number|Date} date - 日期对象 / 时间戳 / 日期字符串
  805. * @param {string} format - 格式模板,默认 'yyyy-MM-dd HH:mm:ss'
  806. * @returns {string} 格式化后的日期
  807. */
  808. const formatDateTime = (date, format = 'yyyy-MM-dd HH:mm') => {
  809. if (!date) return '';
  810. // 如果是字符串,做 iOS 兼容(将 2025-08-12 替换为 2025/08/12)
  811. if (typeof date === 'string') {
  812. date = date.replace(/-/g, '/');
  813. }
  814. // 如果是数字(时间戳),判断是否是秒级
  815. if (typeof date === 'number') {
  816. if (date.toString().length === 10) {
  817. date *= 1000; // 秒转毫秒
  818. }
  819. }
  820. // 转换为 Date 对象
  821. date = new Date(date);
  822. if (isNaN(date.getTime())) return '';
  823. const map = {
  824. 'yyyy': date.getFullYear(),
  825. 'MM': String(date.getMonth() + 1).padStart(2, '0'),
  826. 'dd': String(date.getDate()).padStart(2, '0'),
  827. 'HH': String(date.getHours()).padStart(2, '0'),
  828. 'mm': String(date.getMinutes()).padStart(2, '0'),
  829. // 'ss': String(date.getSeconds()).padStart(2, '0')
  830. };
  831. return format.replace(/yyyy|MM|dd|HH|mm/g, match => map[match]);
  832. }
  833. // 选择图片
  834. const chooseImage = () => {
  835. uni.chooseImage({
  836. count: 6 - formData.images.length,
  837. sizeType: ['original', 'compressed'],
  838. sourceType: ['album', 'camera'],
  839. success: (res) => {
  840. console.log('选择图片成功:', res);
  841. // 验证文件类型和大小
  842. const validFiles = [];
  843. const invalidFiles = [];
  844. const maxSize = 5 * 1024 * 1024; // 5MB 最大限制
  845. // 检查每个文件
  846. res.tempFiles.forEach((file, index) => {
  847. // 检查文件类型
  848. const isImage = /\.(jpg|jpeg|png|gif)$/i.test(file.name);
  849. // 检查文件大小
  850. const isValidSize = file.size <= maxSize;
  851. if (isImage && isValidSize) {
  852. validFiles.push(res.tempFilePaths[index]);
  853. } else {
  854. invalidFiles.push({
  855. path: file.path,
  856. size: file.size,
  857. reason: !isImage ? '文件格式不支持' : '文件大于5MB'
  858. });
  859. }
  860. });
  861. // 显示无效文件提示
  862. if (invalidFiles.length > 0) {
  863. uni.showToast({
  864. title: `${invalidFiles.length}个文件无效,请检查格式和大小`,
  865. icon: 'none',
  866. duration: 2000
  867. });
  868. }
  869. // 如果有有效文件,则上传
  870. if (validFiles.length > 0) {
  871. uploadImages(validFiles);
  872. }
  873. },
  874. fail: (err) => {
  875. console.error('选择图片失败:', err);
  876. uni.showToast({
  877. title: '选择图片失败',
  878. icon: 'none'
  879. });
  880. }
  881. });
  882. }
  883. // 上传图片到服务器
  884. const uploadImages = (tempFilePaths) => {
  885. uni.showLoading({
  886. title: '上传中...',
  887. mask: true
  888. });
  889. // 上传成功的图片计数
  890. let successCount = 0;
  891. let failCount = 0;
  892. const totalFiles = tempFilePaths.length;
  893. const newImages = [];
  894. // 遍历处理每张图片
  895. tempFilePaths.forEach((path, index) => {
  896. // 调用上传API
  897. uni.uploadFile({
  898. // url: api.serve + '/base/tasks/uploadTaskImage',
  899. url: api.serve + '/file/upload',
  900. filePath: path,
  901. name: 'file', // 文件参数名称,需要与后端接口匹配
  902. formData: {
  903. type: 'task', // 标识文件类型,用于后端区分不同业务的文件
  904. // directory: '/opt/app/nongxiaoyu/uploadImage' // 指定保存目录
  905. },
  906. header: {'Authorization': `Bearer ${storage.getAccessToken()}`},
  907. success: (res) => {
  908. try {
  909. const response = JSON.parse(res.data);
  910. uni.showToast({
  911. title: `返回: ${response.data}`,
  912. icon: 'none',
  913. });
  914. if (response.code === 200) {
  915. // 获取返回的URL
  916. const imageUrl = response.data.url;
  917. console.log('上传成功,返回的图片URL:', imageUrl);
  918. // 上传成功,将图片信息添加到数组
  919. newImages.push({
  920. url: imageUrl, // 保存原始URL,在显示时会通过getImageUrl方法处理
  921. path: path, // 保存本地路径用于预览
  922. status: 'success',
  923. fileName: response.data.fileName || '' // 保存文件名,如果后端返回的话
  924. });
  925. successCount++;
  926. } else {
  927. failCount++;
  928. console.error('上传失败:', response.msg);
  929. }
  930. } catch (e) {
  931. failCount++;
  932. uni.showToast({
  933. title: `解析响应失败: ${e}`,
  934. icon: 'none',
  935. });
  936. console.error('解析响应失败:', e);
  937. }
  938. },
  939. fail: (err) => {
  940. failCount++;
  941. console.error('上传请求失败:', err);
  942. uni.showToast({
  943. title: `上传请求失败: ${err}`,
  944. icon: 'none',
  945. });
  946. },
  947. complete: () => {
  948. // 当所有文件都已处理完成
  949. if (successCount + failCount === totalFiles) {
  950. if (newImages.length > 0) {
  951. // 将新上传的图片添加到已有图片列表
  952. formData.images = [...formData.images, ...newImages];
  953. console.log("formData.images",formData.images);
  954. // 更新taskImages字段,将图片URL用逗号连接
  955. formData.taskImages = formData.images.map(img => img.url).join(',');
  956. // 显示成功提示
  957. uni.hideLoading();
  958. uni.showToast({
  959. title: `成功上传${successCount}张图片`,
  960. icon: 'success'
  961. });
  962. } else {
  963. // 全部失败
  964. uni.showToast({
  965. title: `图片上传: ${newImages}`,
  966. icon: 'none',
  967. });
  968. uni.hideLoading();
  969. // uni.showToast({
  970. // title: '图片上传失败',
  971. // icon: 'none',
  972. // });
  973. }
  974. }
  975. }
  976. });
  977. });
  978. }
  979. // 删除图片
  980. const deletePic = (index) => {
  981. uni.showModal({
  982. title: '确认删除',
  983. content: '确定要删除这张图片吗?',
  984. success: (res) => {
  985. if (res.confirm) {
  986. formData.images.splice(index, 1);
  987. // 更新taskImages字段
  988. formData.taskImages = formData.images.map(img => img.url).join(',');
  989. uni.showToast({
  990. title: '已删除',
  991. icon: 'none'
  992. });
  993. }
  994. }
  995. });
  996. }
  997. // 获取图片URL
  998. const getImageUrl = (item) => {
  999. // 默认返回url或path
  1000. return api.upload + item.url;
  1001. }
  1002. // 预览图片
  1003. const previewImage = (item, index) => {
  1004. // 获取所有图片的完整URL
  1005. // const urls = formData.images.map(file => this.getImageUrl(file));
  1006. const urls = formData.images.map(item => item.url);
  1007. uni.previewImage({
  1008. urls: urls,
  1009. current: index
  1010. });
  1011. }
  1012. // 表单验证
  1013. const validateForm = () => {
  1014. // 重置错误信息
  1015. formErrors.completionDesc = '';
  1016. // 基本字段验证
  1017. if (!formData.taskName.trim()) {
  1018. uni.showToast({
  1019. title: '请输入任务名称',
  1020. icon: 'none'
  1021. });
  1022. return false;
  1023. }
  1024. if (!formData.typeName) {
  1025. uni.showToast({
  1026. title: '请选择任务类型',
  1027. icon: 'none'
  1028. });
  1029. return false;
  1030. }
  1031. // 验证负责人
  1032. if (!formData.assigneeId) {
  1033. uni.showToast({
  1034. title: '请选择负责人',
  1035. icon: 'none'
  1036. });
  1037. return false;
  1038. }
  1039. // 新建和编辑模式且已完成状态下的验证
  1040. if ((pageMode.value === 'create' || pageMode.value === 'edit') && formData.taskStatus === '1') {
  1041. // 验证完成说明
  1042. if (!formData.completionDesc.trim()) {
  1043. formErrors.completionDesc = '请填写完成说明';
  1044. uni.showToast({
  1045. title: '请填写完成说明',
  1046. icon: 'none'
  1047. });
  1048. return false;
  1049. }
  1050. // 验证是否上传了图片
  1051. if (!formData.images || formData.images.length === 0) {
  1052. uni.showToast({
  1053. title: '请上传至少一张现场图片',
  1054. icon: 'none'
  1055. });
  1056. return false;
  1057. }
  1058. }
  1059. return true;
  1060. }
  1061. // 提交表单
  1062. const submitForm = () => {
  1063. if (!validateForm()) {
  1064. return;
  1065. }
  1066. isSubmitting.value = true;
  1067. // 构建提交数据
  1068. const submitData = {
  1069. // 如果是编辑模式,需要提供ID
  1070. ...(formData.id ? { id: formData.id } : {}),
  1071. farmId: formData.farmId,
  1072. plotId: formData.plotId,
  1073. fieldName: formData.fieldName,
  1074. growCrops: formData.growCrops,
  1075. taskName: formData.taskName,
  1076. taskImages: formData.taskImages,
  1077. typeName: formData.typeNameId,
  1078. taskStatus: formData.taskStatus,
  1079. executeTime: formatDateTime(formData.executeTime),
  1080. assigneeId: formData.assigneeId,
  1081. assigneeName:formData.assigneeName,
  1082. remark: formData.remark,
  1083. completionTime: formData.taskStatus === '1' ? formatDateTime(formData.completionTime) : null,
  1084. completionDesc: formData.taskStatus === '1' ? formData.completionDesc : null,
  1085. create_by: formData.create_by || null
  1086. };
  1087. console.log('提交数据:', submitData);
  1088. uni.showLoading({
  1089. title: '提交中...',
  1090. mask: true
  1091. });
  1092. // 根据模式决定是创建还是更新
  1093. const requestPromise = pageMode.value === 'create'
  1094. ? addAgriculturalTask(submitData)
  1095. : updateAgriculturalTask(submitData);
  1096. requestPromise.then(res => {
  1097. isSubmitting.value = false;
  1098. uni.hideLoading();
  1099. if (res.data.code === 200) {
  1100. const successMessage = pageMode.value === 'create' ? '任务创建成功' : '保存修改成功';
  1101. uni.showToast({
  1102. title: successMessage,
  1103. icon: 'success',
  1104. duration: 1500
  1105. });
  1106. setTimeout(() => {
  1107. uni.navigateBack();
  1108. }, 1500);
  1109. } else {
  1110. uni.showToast({
  1111. title: res.data.msg || '操作失败',
  1112. icon: 'none'
  1113. });
  1114. }
  1115. }).catch(err => {
  1116. console.error('提交表单失败:', err);
  1117. isSubmitting.value = false;
  1118. uni.hideLoading();
  1119. uni.showToast({
  1120. title: '操作失败,请稍后重试',
  1121. icon: 'none'
  1122. });
  1123. });
  1124. }
  1125. </script>
  1126. <style scoped>
  1127. .page-container {
  1128. height: 100vh;
  1129. background-color: #F5F5F5;
  1130. display: flex;
  1131. flex-direction: column;
  1132. }
  1133. .page-scroll {
  1134. flex: 1;
  1135. overflow: hidden;
  1136. }
  1137. /* 地块基础信息卡片 */
  1138. .info-card {
  1139. background: #F9F9F9;
  1140. margin: 24rpx;
  1141. padding: 24rpx;
  1142. border-radius: 8rpx;
  1143. border: 1rpx solid #E5E5E5;
  1144. }
  1145. .card-title {
  1146. font-size: 30rpx;
  1147. font-weight: 600;
  1148. color: #333333;
  1149. margin-bottom: 16rpx;
  1150. padding-bottom: 12rpx;
  1151. border-bottom: 1rpx solid #E5E5E5;
  1152. }
  1153. .info-item {
  1154. display: flex;
  1155. justify-content: space-between;
  1156. align-items: center;
  1157. margin-bottom: 12rpx;
  1158. padding: 8rpx 0;
  1159. }
  1160. .info-item:last-child {
  1161. margin-bottom: 0;
  1162. }
  1163. .info-label {
  1164. font-size: 28rpx;
  1165. color: #666666;
  1166. flex-shrink: 0;
  1167. }
  1168. .info-value {
  1169. font-size: 28rpx;
  1170. color: #333333;
  1171. font-weight: 500;
  1172. }
  1173. /* 任务填写表单 */
  1174. .form-card {
  1175. background: #FFFFFF;
  1176. margin: 0 24rpx 24rpx;
  1177. padding: 24rpx;
  1178. border-radius: 8rpx;
  1179. border: 1rpx solid #E5E5E5;
  1180. }
  1181. .section-divider {
  1182. height: 1rpx;
  1183. background: #F0F0F0;
  1184. margin: 32rpx 0 24rpx;
  1185. }
  1186. .section-title {
  1187. font-size: 30rpx;
  1188. font-weight: 600;
  1189. color: #333333;
  1190. margin-bottom: 16rpx;
  1191. padding-bottom: 12rpx;
  1192. border-bottom: 1rpx solid #F0F0F0;
  1193. }
  1194. .form-item {
  1195. margin-bottom: 24rpx;
  1196. }
  1197. .form-item:last-child {
  1198. margin-bottom: 0;
  1199. }
  1200. .form-label {
  1201. font-size: 28rpx;
  1202. color: #333333;
  1203. margin-bottom: 12rpx;
  1204. font-weight: 500;
  1205. }
  1206. .form-label.required::before {
  1207. content: '*';
  1208. color: #FF6B6B;
  1209. margin-right: 4rpx;
  1210. }
  1211. .form-input {
  1212. width: 100%;
  1213. line-height: 80rpx;
  1214. height: 80rpx;
  1215. background: #F8F8F8;
  1216. border: 1rpx solid #E5E5E5;
  1217. border-radius: 8rpx;
  1218. padding: 0 16rpx;
  1219. font-size: 28rpx;
  1220. color: #333333;
  1221. box-sizing: border-box;
  1222. }
  1223. .form-input:focus {
  1224. background: #FFFFFF;
  1225. border-color: #3BB44A;
  1226. }
  1227. .form-input::placeholder {
  1228. color: #CCCCCC;
  1229. }
  1230. .form-input:disabled {
  1231. background: #F8F8F8;
  1232. color: #999999;
  1233. }
  1234. .select-wrapper {
  1235. position: relative;
  1236. width: 100%;
  1237. }
  1238. .select-input {
  1239. cursor: pointer;
  1240. }
  1241. .select-arrow {
  1242. position: absolute;
  1243. right: 16rpx;
  1244. top: 50%;
  1245. transform: translateY(-50%);
  1246. color: #999999;
  1247. font-size: 20rpx;
  1248. pointer-events: none;
  1249. }
  1250. .form-textarea {
  1251. width: 100%;
  1252. min-height: 120rpx;
  1253. background: #F8F8F8;
  1254. border: 1rpx solid #E5E5E5;
  1255. border-radius: 8rpx;
  1256. padding: 16rpx;
  1257. font-size: 28rpx;
  1258. color: #333333;
  1259. box-sizing: border-box;
  1260. resize: none;
  1261. line-height: 1.5;
  1262. }
  1263. .form-textarea:focus {
  1264. background: #FFFFFF;
  1265. border-color: #3BB44A;
  1266. }
  1267. .form-textarea::placeholder {
  1268. color: #CCCCCC;
  1269. }
  1270. .form-textarea:disabled {
  1271. background: #F8F8F8;
  1272. color: #999999;
  1273. }
  1274. .char-count {
  1275. font-size: 24rpx;
  1276. color: #CCCCCC;
  1277. text-align: right;
  1278. margin-top: 8rpx;
  1279. }
  1280. .form-error {
  1281. font-size: 24rpx;
  1282. color: #FF6B6B;
  1283. margin-top: 8rpx;
  1284. }
  1285. /* 单选按钮样式 */
  1286. .radio-group {
  1287. display: flex;
  1288. gap: 32rpx;
  1289. }
  1290. .radio-item {
  1291. display: flex;
  1292. align-items: center;
  1293. cursor: pointer;
  1294. }
  1295. .radio-circle {
  1296. width: 32rpx;
  1297. height: 32rpx;
  1298. border: 2rpx solid #CCCCCC;
  1299. border-radius: 50%;
  1300. display: flex;
  1301. align-items: center;
  1302. justify-content: center;
  1303. margin-right: 8rpx;
  1304. }
  1305. .radio-circle.radio-checked {
  1306. border-color: #3BB44A;
  1307. background-color: #3BB44A;
  1308. }
  1309. .radio-dot {
  1310. width: 12rpx;
  1311. height: 12rpx;
  1312. background-color: #FFFFFF;
  1313. border-radius: 50%;
  1314. }
  1315. .radio-label {
  1316. font-size: 28rpx;
  1317. color: #333333;
  1318. }
  1319. /* 完成状态样式 */
  1320. .status-completed {
  1321. display: flex;
  1322. align-items: center;
  1323. color: #3BB44A;
  1324. font-size: 28rpx;
  1325. }
  1326. .status-icon {
  1327. width: 32rpx;
  1328. height: 32rpx;
  1329. background: #3BB44A;
  1330. color: #FFFFFF;
  1331. border-radius: 50%;
  1332. display: flex;
  1333. align-items: center;
  1334. justify-content: center;
  1335. margin-right: 8rpx;
  1336. font-size: 20rpx;
  1337. line-height: 1;
  1338. }
  1339. /* 图片上传样式 */
  1340. .image-upload, .image-view {
  1341. width: 100%;
  1342. }
  1343. .image-list {
  1344. display: flex;
  1345. flex-wrap: wrap;
  1346. gap: 16rpx;
  1347. }
  1348. .image-preview {
  1349. position: relative;
  1350. width: 160rpx;
  1351. height: 160rpx;
  1352. border-radius: 8rpx;
  1353. overflow: hidden;
  1354. background: #F5F5F5;
  1355. }
  1356. .image-preview image {
  1357. width: 100%;
  1358. height: 100%;
  1359. }
  1360. .delete-btn {
  1361. position: absolute;
  1362. top: -6rpx;
  1363. right: -6rpx;
  1364. width: 32rpx;
  1365. height: 32rpx;
  1366. background: rgba(0, 0, 0, 0.6);
  1367. color: #FFFFFF;
  1368. border-radius: 50%;
  1369. display: flex;
  1370. align-items: center;
  1371. justify-content: center;
  1372. font-size: 20rpx;
  1373. line-height: 1;
  1374. }
  1375. .upload-btn {
  1376. width: 160rpx;
  1377. height: 160rpx;
  1378. background: #F8F8F8;
  1379. border: 2rpx dashed #DDDDDD;
  1380. border-radius: 8rpx;
  1381. display: flex;
  1382. flex-direction: column;
  1383. align-items: center;
  1384. justify-content: center;
  1385. }
  1386. .upload-icon {
  1387. font-size: 32rpx;
  1388. margin-bottom: 8rpx;
  1389. color: #999999;
  1390. }
  1391. .upload-text {
  1392. font-size: 24rpx;
  1393. color: #999999;
  1394. }
  1395. .upload-tip {
  1396. font-size: 24rpx;
  1397. color: #999999;
  1398. margin-top: 12rpx;
  1399. }
  1400. .no-images {
  1401. padding: 40rpx 0;
  1402. text-align: center;
  1403. color: #CCCCCC;
  1404. font-size: 28rpx;
  1405. }
  1406. /* 底部安全区域 */
  1407. .bottom-safe {
  1408. height: 120rpx;
  1409. }
  1410. .footer-safe {
  1411. background: #FFFFFF;
  1412. border-top: 1rpx solid #E5E5E5;
  1413. padding-bottom: constant(safe-area-inset-bottom);
  1414. padding-bottom: env(safe-area-inset-bottom);
  1415. }
  1416. .footer-content {
  1417. padding: 24rpx;
  1418. }
  1419. .submit-button {
  1420. width: 100%;
  1421. height: 88rpx;
  1422. background: #3BB44A;
  1423. color: #FFFFFF;
  1424. border: none;
  1425. border-radius: 8rpx;
  1426. font-size: 32rpx;
  1427. font-weight: 600;
  1428. display: flex;
  1429. align-items: center;
  1430. justify-content: center;
  1431. }
  1432. .submit-button:active {
  1433. background: #2D8C3C;
  1434. }
  1435. .submit-button:disabled,
  1436. .submit-button.loading {
  1437. background: #CCCCCC;
  1438. }
  1439. /* 选择器弹窗样式 */
  1440. .picker-mask {
  1441. position: fixed;
  1442. top: 0;
  1443. left: 0;
  1444. width: 100%;
  1445. height: 100%;
  1446. background: rgba(0, 0, 0, 0.5);
  1447. z-index: 999;
  1448. }
  1449. .picker-popup {
  1450. position: fixed;
  1451. bottom: 0;
  1452. left: 0;
  1453. width: 100%;
  1454. background: #FFFFFF;
  1455. border-radius: 16rpx 16rpx 0 0;
  1456. z-index: 1000;
  1457. padding-bottom: constant(safe-area-inset-bottom);
  1458. padding-bottom: env(safe-area-inset-bottom);
  1459. }
  1460. .picker-header {
  1461. display: flex;
  1462. justify-content: space-between;
  1463. align-items: center;
  1464. padding: 24rpx;
  1465. border-bottom: 1rpx solid #E5E5E5;
  1466. }
  1467. .picker-cancel, .picker-confirm {
  1468. font-size: 30rpx;
  1469. color: #3BB44A;
  1470. }
  1471. .picker-title {
  1472. font-size: 32rpx;
  1473. font-weight: 600;
  1474. color: #333333;
  1475. }
  1476. .picker-content {
  1477. max-height: 400rpx;
  1478. overflow-y: auto;
  1479. }
  1480. .picker-item {
  1481. display: flex;
  1482. justify-content: space-between;
  1483. align-items: center;
  1484. padding: 24rpx;
  1485. border-bottom: 1rpx solid #F0F0F0;
  1486. font-size: 30rpx;
  1487. color: #333333;
  1488. }
  1489. .picker-item.selected {
  1490. color: #3BB44A;
  1491. }
  1492. .picker-item:last-child {
  1493. border-bottom: none;
  1494. }
  1495. .check-mark {
  1496. color: #3BB44A;
  1497. font-size: 28rpx;
  1498. }
  1499. /* 日期时间选择器样式 */
  1500. .datetime-picker {
  1501. height: 60vh;
  1502. }
  1503. .datetime-picker-content {
  1504. height: calc(100% - 100rpx);
  1505. padding: 0;
  1506. }
  1507. .datetime-picker-view {
  1508. width: 100%;
  1509. height: 100%;
  1510. }
  1511. .picker-view-item {
  1512. display: flex;
  1513. align-items: center;
  1514. justify-content: center;
  1515. height: 80rpx;
  1516. font-size: 32rpx;
  1517. color: #333333;
  1518. }
  1519. .picker-item-text {
  1520. font-size: 32rpx;
  1521. color: #333333;
  1522. line-height: 80rpx;
  1523. height: 80rpx;
  1524. text-align: center;
  1525. }
  1526. /* 添加加载中样式 */
  1527. .picker-loading {
  1528. display: flex;
  1529. justify-content: center;
  1530. align-items: center;
  1531. padding: 30rpx 0;
  1532. color: #999;
  1533. font-size: 28rpx;
  1534. }
  1535. .picker-empty {
  1536. padding: 30rpx 0;
  1537. text-align: center;
  1538. color: #CCCCCC;
  1539. font-size: 28rpx;
  1540. }
  1541. </style>