index.vue 16 KB

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