edit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <template>
  2. <view class="edit-auth-container">
  3. <!-- 自定义头部 -->
  4. <view class="custom-header">
  5. <view class="header-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);"></image>
  7. </view>
  8. <text class="header-title">修改认证信息</text>
  9. <view class="header-right"></view>
  10. </view>
  11. <view class="header-placeholder"></view>
  12. <!-- 顶部警告提示 -->
  13. <view class="warning-tip">
  14. <text class="warning-icon">⚠</text>
  15. <text class="warning-text">若修改认证信息,将在审核通过后生效</text>
  16. </view>
  17. <!-- 身份认证 -->
  18. <view class="section-card">
  19. <view class="section-title">身份认证</view>
  20. <text class="section-subtitle">点击图片修改</text>
  21. <view class="id-card-row">
  22. <!-- 身份证正面 -->
  23. <view class="id-card-upload" @click="chooseImage('front')">
  24. <image v-if="idCardFront" :src="idCardFront" class="id-card-img" mode="aspectFill"></image>
  25. <view v-else class="id-card-placeholder">
  26. <text class="placeholder-text">ID Front</text>
  27. </view>
  28. <view class="delete-btn" v-if="idCardFront" @click.stop="deleteImage('front')">×</view>
  29. <view class="corner-tag">人像面</view>
  30. </view>
  31. <!-- 身份证反面 -->
  32. <view class="id-card-upload" @click="chooseImage('back')">
  33. <image v-if="idCardBack" :src="idCardBack" class="id-card-img" mode="aspectFill"></image>
  34. <view v-else class="id-card-placeholder">
  35. <text class="placeholder-text">ID Back</text>
  36. </view>
  37. <view class="delete-btn" v-if="idCardBack" @click.stop="deleteImage('back')">×</view>
  38. <view class="corner-tag">国徽面</view>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 服务类型 -->
  43. <view class="section-card">
  44. <view class="section-title">服务类型</view>
  45. <text class="section-subtitle">可多选</text>
  46. <view class="service-list">
  47. <view
  48. class="service-item"
  49. v-for="(service, index) in serviceOptions"
  50. :key="service.id"
  51. @click="toggleService(service)"
  52. >
  53. <text class="service-name">{{ service.name }}</text>
  54. <view class="check-icon" :class="{ active: selectedServices.map(String).includes(String(service.id)) }">
  55. <text v-if="selectedServices.map(String).includes(String(service.id))">✓</text>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 资质证书 -->
  61. <view class="section-card">
  62. <view class="section-title">资质证书</view>
  63. <text class="section-subtitle">请上传对应服务的资质</text>
  64. <!-- 动态渲染每个服务类型的资质上传 -->
  65. <view v-for="(serviceId, index) in selectedServices" :key="serviceId" class="qual-section">
  66. <text class="qual-title">{{ getServiceName(serviceId) }}资质</text>
  67. <view class="qual-upload-row">
  68. <!-- 已上传的资质图片 -->
  69. <view
  70. class="qual-item"
  71. v-for="(img, imgIndex) in qualifications[getServiceName(serviceId)]"
  72. :key="imgIndex"
  73. @click="previewImage(getServiceName(serviceId), imgIndex)"
  74. >
  75. <image :src="img" class="qual-img" mode="aspectFill"></image>
  76. <view class="delete-btn" @click.stop="deleteQualImage(getServiceName(serviceId), imgIndex)">×</view>
  77. </view>
  78. <!-- 上传按钮 -->
  79. <view class="qual-upload-btn" @click="chooseQualImage(getServiceName(serviceId))">
  80. <text class="plus-icon">+</text>
  81. </view>
  82. </view>
  83. </view>
  84. <text v-if="selectedServices.length === 0" class="empty-hint">请先选择服务类型</text>
  85. </view>
  86. <!-- 底部提交按钮 -->
  87. <view class="bottom-btn-area">
  88. <button class="submit-btn" @click="submitAuth">提交审核</button>
  89. </view>
  90. </view>
  91. </template>
  92. <script>
  93. import { getAuthInfo, uploadFile, updateAuthInfo, getServiceTypes } from '@/api/fulfiller'
  94. export default {
  95. data() {
  96. return {
  97. idCardFront: '',
  98. idCardBack: '',
  99. idCardFrontOssId: '',
  100. idCardBackOssId: '',
  101. serviceOptions: [],
  102. selectedServices: [],
  103. qualifications: {},
  104. qualOssIds: {}
  105. }
  106. },
  107. async onLoad() {
  108. await this.loadServiceOptions()
  109. this.loadAuthInfo()
  110. },
  111. methods: {
  112. async loadServiceOptions() {
  113. try {
  114. const res = await getServiceTypes()
  115. this.serviceOptions = (res.data || []).map(item => ({
  116. id: String(item.id),
  117. name: item.name
  118. }))
  119. } catch (e) {
  120. console.error('加载服务类型失败', e)
  121. }
  122. },
  123. async loadAuthInfo() {
  124. try {
  125. uni.showLoading({ title: '加载中...' })
  126. const res = await getAuthInfo()
  127. if (res.code === 200 && res.data) {
  128. this.idCardFront = res.data.idCardFrontUrl || ''
  129. this.idCardBack = res.data.idCardBackUrl || ''
  130. this.idCardFrontOssId = res.data.idCardFront || ''
  131. this.idCardBackOssId = res.data.idCardBack || ''
  132. // 解析服务类型ID列表(逗号分隔,去重)
  133. let serviceIds = []
  134. if (res.data.serviceTypes) {
  135. serviceIds = [...new Set(
  136. String(res.data.serviceTypes).replace(/[\[\]"']/g, '').split(',')
  137. .map(s => s.trim())
  138. .filter(id => id && id !== '0' && id !== 'null' && id !== 'undefined')
  139. )]
  140. }
  141. this.selectedServices = serviceIds
  142. // 解析资质图片URL和OSS ID
  143. const qualUrlList = res.data.qualImageUrls ? res.data.qualImageUrls.split(',').filter(Boolean) : []
  144. const qualOssIdList = res.data.qualImages ? res.data.qualImages.replace(/[\[\]"]/g, '').split(',').map(s => s.trim()).filter(Boolean) : []
  145. // 收集有效的服务名称列表
  146. const validNames = serviceIds.map(sid => this.getServiceName(sid)).filter(Boolean)
  147. // 为每个已选服务类型初始化资质数据,并均匀分配已有图片
  148. validNames.forEach((name, idx) => {
  149. // 将已有资质图片按服务类型数量均匀分配
  150. const start = Math.floor(idx * qualUrlList.length / validNames.length)
  151. const end = Math.floor((idx + 1) * qualUrlList.length / validNames.length)
  152. this.$set(this.qualifications, name, qualUrlList.slice(start, end))
  153. this.$set(this.qualOssIds, name, qualOssIdList.slice(start, end))
  154. })
  155. }
  156. uni.hideLoading()
  157. } catch (e) {
  158. uni.hideLoading()
  159. console.error('加载认证信息失败', e)
  160. uni.showToast({ title: '加载失败', icon: 'none' })
  161. }
  162. },
  163. navBack() {
  164. uni.navigateBack({ delta: 1 })
  165. },
  166. chooseImage(side) {
  167. uni.chooseImage({
  168. count: 1,
  169. sizeType: ['compressed'],
  170. sourceType: ['album', 'camera'],
  171. success: async (res) => {
  172. const tempPath = res.tempFilePaths[0]
  173. if (side === 'front') {
  174. this.idCardFront = tempPath
  175. } else {
  176. this.idCardBack = tempPath
  177. }
  178. try {
  179. uni.showLoading({ title: '上传中...' })
  180. const uploadRes = await uploadFile(tempPath)
  181. if (side === 'front') {
  182. this.idCardFrontOssId = uploadRes.data.ossId
  183. } else {
  184. this.idCardBackOssId = uploadRes.data.ossId
  185. }
  186. uni.hideLoading()
  187. uni.showToast({ title: '上传成功', icon: 'success' })
  188. } catch (err) {
  189. uni.hideLoading()
  190. console.error('上传身份证图片失败:', err)
  191. uni.showToast({ title: '上传失败', icon: 'none' })
  192. }
  193. }
  194. })
  195. },
  196. deleteImage(side) {
  197. if (side === 'front') {
  198. this.idCardFront = ''
  199. this.idCardFrontOssId = ''
  200. } else {
  201. this.idCardBack = ''
  202. this.idCardBackOssId = ''
  203. }
  204. },
  205. getServiceName(serviceId) {
  206. const found = this.serviceOptions.find(s => String(s.id) === String(serviceId))
  207. return found ? found.name : ''
  208. },
  209. toggleService(service) {
  210. const index = this.selectedServices.indexOf(service.id)
  211. if (index > -1) {
  212. this.selectedServices.splice(index, 1)
  213. this.$delete(this.qualifications, service.name)
  214. this.$delete(this.qualOssIds, service.name)
  215. } else {
  216. this.selectedServices.push(service.id)
  217. this.$set(this.qualifications, service.name, [])
  218. this.$set(this.qualOssIds, service.name, [])
  219. }
  220. this.$forceUpdate()
  221. },
  222. chooseQualImage(service) {
  223. uni.chooseImage({
  224. count: 9,
  225. sizeType: ['compressed'],
  226. sourceType: ['album', 'camera'],
  227. success: async (res) => {
  228. if (!this.qualifications[service]) {
  229. this.qualifications[service] = []
  230. this.qualOssIds[service] = []
  231. }
  232. for (const tempPath of res.tempFilePaths) {
  233. this.qualifications[service].push(tempPath)
  234. this.$forceUpdate()
  235. try {
  236. uni.showLoading({ title: '上传中...' })
  237. const uploadRes = await uploadFile(tempPath)
  238. this.qualOssIds[service].push(uploadRes.data.ossId)
  239. uni.hideLoading()
  240. } catch (err) {
  241. uni.hideLoading()
  242. console.error('上传资质图片失败:', err)
  243. }
  244. }
  245. }
  246. })
  247. },
  248. deleteQualImage(service, index) {
  249. this.qualifications[service].splice(index, 1)
  250. if (this.qualOssIds[service]) {
  251. this.qualOssIds[service].splice(index, 1)
  252. }
  253. this.$forceUpdate()
  254. },
  255. previewImage(service, index) {
  256. uni.previewImage({
  257. urls: this.qualifications[service],
  258. current: index
  259. })
  260. },
  261. async submitAuth() {
  262. if (!this.idCardFront || !this.idCardBack) {
  263. uni.showToast({ title: '请上传身份证正反面', icon: 'none' })
  264. return
  265. }
  266. if (this.selectedServices.length === 0) {
  267. uni.showToast({ title: '请选择服务类型', icon: 'none' })
  268. return
  269. }
  270. for (const serviceId of this.selectedServices) {
  271. const name = this.getServiceName(serviceId)
  272. if (!this.qualifications[name] || this.qualifications[name].length === 0) {
  273. uni.showToast({ title: `请上传${name}资质`, icon: 'none' })
  274. return
  275. }
  276. }
  277. uni.showModal({
  278. title: '提示',
  279. content: '修改认证信息需要重新审核,审核期间无法接单,确定要继续吗?',
  280. success: (res) => {
  281. if (res.confirm) {
  282. this.doSubmit()
  283. }
  284. }
  285. })
  286. },
  287. async doSubmit() {
  288. const allQualOssIds = []
  289. Object.values(this.qualOssIds).forEach(ids => {
  290. allQualOssIds.push(...ids)
  291. })
  292. const submitData = {
  293. idCardFront: this.idCardFrontOssId,
  294. idCardBack: this.idCardBackOssId,
  295. serviceTypes: this.selectedServices.join(','), // 逗号分隔的服务类型ID
  296. qualifications: allQualOssIds.join(',') // 逗号分隔的资质图片OSS ID
  297. }
  298. try {
  299. uni.showLoading({ title: '提交中...' })
  300. await updateAuthInfo(submitData)
  301. uni.hideLoading()
  302. uni.showToast({ title: '提交成功,等待审核', icon: 'success', duration: 1500 })
  303. setTimeout(() => {
  304. uni.navigateBack({ delta: 1 })
  305. }, 1500)
  306. } catch (err) {
  307. uni.hideLoading()
  308. console.error('提交失败:', err)
  309. uni.showToast({ title: '提交失败', icon: 'none' })
  310. }
  311. }
  312. }
  313. }
  314. </script>
  315. <style scoped>
  316. page {
  317. background-color: #F8F8F8;
  318. }
  319. .custom-header {
  320. position: fixed;
  321. top: 0;
  322. left: 0;
  323. width: 100%;
  324. height: 88rpx;
  325. padding-top: var(--status-bar-height);
  326. background-color: #fff;
  327. display: flex;
  328. align-items: center;
  329. justify-content: space-between;
  330. padding-left: 30rpx;
  331. padding-right: 30rpx;
  332. box-sizing: content-box;
  333. z-index: 100;
  334. }
  335. .header-placeholder {
  336. height: calc(88rpx + var(--status-bar-height));
  337. }
  338. .back-icon {
  339. width: 40rpx;
  340. height: 40rpx;
  341. }
  342. .header-title {
  343. font-size: 28rpx;
  344. font-weight: bold;
  345. color: #333;
  346. }
  347. .header-right {
  348. width: 40rpx;
  349. }
  350. .edit-auth-container {
  351. padding: 20rpx 30rpx;
  352. padding-bottom: 180rpx;
  353. }
  354. .warning-tip {
  355. background: linear-gradient(90deg, #FFF3E0 0%, #FFE0B2 100%);
  356. border-radius: 16rpx;
  357. padding: 24rpx 30rpx;
  358. display: flex;
  359. align-items: center;
  360. margin-bottom: 30rpx;
  361. }
  362. .warning-icon {
  363. font-size: 32rpx;
  364. margin-right: 16rpx;
  365. }
  366. .warning-text {
  367. font-size: 26rpx;
  368. color: #E65100;
  369. flex: 1;
  370. }
  371. .section-card {
  372. background-color: #fff;
  373. border-radius: 20rpx;
  374. padding: 30rpx;
  375. margin-bottom: 30rpx;
  376. }
  377. .section-title {
  378. font-size: 32rpx;
  379. font-weight: bold;
  380. color: #333;
  381. margin-bottom: 10rpx;
  382. }
  383. .section-subtitle {
  384. font-size: 24rpx;
  385. color: #999;
  386. display: block;
  387. margin-bottom: 30rpx;
  388. }
  389. .id-card-row {
  390. display: flex;
  391. justify-content: space-between;
  392. }
  393. .id-card-upload {
  394. width: 48%;
  395. height: 200rpx;
  396. border-radius: 16rpx;
  397. position: relative;
  398. overflow: hidden;
  399. background-color: #E8F5E9;
  400. }
  401. .id-card-img {
  402. width: 100%;
  403. height: 100%;
  404. }
  405. .id-card-placeholder {
  406. width: 100%;
  407. height: 100%;
  408. display: flex;
  409. align-items: center;
  410. justify-content: center;
  411. }
  412. .placeholder-text {
  413. font-size: 36rpx;
  414. color: #4CAF50;
  415. font-weight: bold;
  416. }
  417. .delete-btn {
  418. position: absolute;
  419. top: 10rpx;
  420. right: 10rpx;
  421. width: 40rpx;
  422. height: 40rpx;
  423. background-color: rgba(255, 87, 34, 0.9);
  424. border-radius: 50%;
  425. display: flex;
  426. align-items: center;
  427. justify-content: center;
  428. color: #fff;
  429. font-size: 32rpx;
  430. font-weight: bold;
  431. }
  432. .corner-tag {
  433. position: absolute;
  434. right: 0;
  435. bottom: 0;
  436. background-color: rgba(0, 0, 0, 0.5);
  437. color: #fff;
  438. font-size: 20rpx;
  439. padding: 4rpx 10rpx;
  440. border-top-left-radius: 8rpx;
  441. }
  442. .service-list {
  443. display: flex;
  444. flex-direction: column;
  445. }
  446. .service-item {
  447. background-color: #FFF8E1;
  448. border-radius: 16rpx;
  449. padding: 24rpx 30rpx;
  450. margin-bottom: 20rpx;
  451. display: flex;
  452. justify-content: space-between;
  453. align-items: center;
  454. }
  455. .service-item:last-child {
  456. margin-bottom: 0;
  457. }
  458. .service-name {
  459. font-size: 28rpx;
  460. color: #333;
  461. }
  462. .check-icon {
  463. width: 40rpx;
  464. height: 40rpx;
  465. border: 2rpx solid #FF9800;
  466. border-radius: 50%;
  467. display: flex;
  468. align-items: center;
  469. justify-content: center;
  470. color: #fff;
  471. font-size: 24rpx;
  472. }
  473. .check-icon.active {
  474. background-color: #FF9800;
  475. }
  476. .qual-section {
  477. margin-top: 30rpx;
  478. }
  479. .qual-section:first-child {
  480. margin-top: 0;
  481. }
  482. .qual-title {
  483. font-size: 26rpx;
  484. color: #666;
  485. display: block;
  486. margin-bottom: 20rpx;
  487. }
  488. .qual-upload-row {
  489. display: flex;
  490. flex-wrap: wrap;
  491. }
  492. .qual-item {
  493. width: 150rpx;
  494. height: 150rpx;
  495. border-radius: 12rpx;
  496. margin-right: 20rpx;
  497. margin-bottom: 20rpx;
  498. position: relative;
  499. overflow: hidden;
  500. }
  501. .qual-img {
  502. width: 100%;
  503. height: 100%;
  504. }
  505. .qual-upload-btn {
  506. width: 150rpx;
  507. height: 150rpx;
  508. border-radius: 12rpx;
  509. border: 2rpx dashed #ccc;
  510. display: flex;
  511. flex-direction: column;
  512. align-items: center;
  513. justify-content: center;
  514. background-color: #F5F5F5;
  515. }
  516. .plus-icon {
  517. font-size: 60rpx;
  518. color: #999;
  519. }
  520. .empty-hint {
  521. font-size: 26rpx;
  522. color: #999;
  523. text-align: center;
  524. display: block;
  525. padding: 40rpx 0;
  526. }
  527. .bottom-btn-area {
  528. position: fixed;
  529. bottom: 0;
  530. left: 0;
  531. right: 0;
  532. padding: 20rpx 40rpx;
  533. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  534. background-color: #fff;
  535. box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
  536. box-sizing: border-box;
  537. z-index: 99;
  538. }
  539. .submit-btn {
  540. width: 100%;
  541. height: 88rpx;
  542. background-color: #FF5722;
  543. color: #fff;
  544. font-size: 32rpx;
  545. border-radius: 44rpx;
  546. border: none;
  547. line-height: 88rpx;
  548. text-align: center;
  549. margin: 0 auto;
  550. padding: 0;
  551. }
  552. </style>