index.vue 16 KB

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