edit.vue 14 KB

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