service-role-apply.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view class="page">
  3. <view class="section">
  4. <view class="section-title">选择申请角色 <text class="required">*</text></view>
  5. <view class="role-grid">
  6. <view
  7. v-for="role in roleList"
  8. :key="role.key"
  9. class="role-card"
  10. :class="{ selected: selectedRoles.indexOf(role.key) > -1 }"
  11. @click="toggleRole(role.key)"
  12. >
  13. <text class="role-icon">{{ role.icon }}</text>
  14. <text class="role-name">{{ role.name }}</text>
  15. <text v-if="selectedRoles.indexOf(role.key) > -1" class="check-mark">✓</text>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="section">
  20. <view class="section-title">身份证信息</view>
  21. <input class="input" v-model="form.idCard" placeholder="请输入身份证号码" maxlength="18" />
  22. <view class="upload-row">
  23. <view class="upload-item" @click="chooseIdCardImage('front')">
  24. <image v-if="form.idCardFront" :src="form.idCardFront" mode="aspectFill" class="upload-preview" />
  25. <view v-else class="upload-placeholder">
  26. <text class="upload-icon">+</text>
  27. <text class="upload-label">身份证正面</text>
  28. </view>
  29. </view>
  30. <view class="upload-item" @click="chooseIdCardImage('back')">
  31. <image v-if="form.idCardBack" :src="form.idCardBack" mode="aspectFill" class="upload-preview" />
  32. <view v-else class="upload-placeholder">
  33. <text class="upload-icon">+</text>
  34. <text class="upload-label">身份证反面</text>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="section">
  40. <view class="section-title">资质证书</view>
  41. <view class="cert-list">
  42. <view v-for="(img, idx) in form.certificateImages" :key="getCertKey(idx)" class="cert-item">
  43. <image :src="img" mode="aspectFill" class="cert-preview" />
  44. <text class="cert-del" @click="removeCert(idx)">×</text>
  45. </view>
  46. <view class="cert-add" @click="chooseCertificate">
  47. <text class="upload-icon">+</text>
  48. <text class="upload-label">添加证书</text>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="section">
  53. <view class="section-title">联系地址 <text class="required">*</text></view>
  54. <AddressPicker ref="addressPicker" @change="onAddressChange" />
  55. <input class="input" v-model="form.addressDetail" placeholder="详细地址(门牌号等)" />
  56. </view>
  57. <button class="submit-btn" :disabled="submitting" @click="handleSubmit">
  58. {{ submitting ? '提交中...' : '提交申请' }}
  59. </button>
  60. </view>
  61. </template>
  62. <script>
  63. import { submitServiceRoleApply, getMyServiceRoleApply, uploadServiceRoleImage } from '../../utils/api'
  64. import AddressPicker from '../../components/address-picker.vue'
  65. export default {
  66. components: { AddressPicker },
  67. data() {
  68. return {
  69. roleList: [
  70. { key: 'planner', name: '规划师', icon: '📋' },
  71. { key: 'nutritionist', name: '营养师', icon: '🥗' },
  72. { key: 'butler', name: '管家', icon: '🔔' },
  73. { key: 'vendor', name: '服务商', icon: '🏪' },
  74. { key: 'article_admin', name: '文章管理员', icon: '📝' },
  75. { key: 'activity_provider', name: '活动提供商', icon: '🎪' }
  76. ],
  77. selectedRoles: [],
  78. form: {
  79. idCard: '',
  80. idCardFront: '',
  81. idCardBack: '',
  82. certificateImages: [],
  83. province: '',
  84. city: '',
  85. district: '',
  86. street: '',
  87. addressDetail: ''
  88. },
  89. submitting: false
  90. }
  91. },
  92. onLoad() {
  93. this.checkExistingApply()
  94. },
  95. methods: {
  96. async checkExistingApply() {
  97. try {
  98. const res = await getMyServiceRoleApply()
  99. if (res.code === 200 && res.data && res.data.status === 0) {
  100. uni.showModal({
  101. title: '提示',
  102. content: '您已提交过申请,请等待审核',
  103. showCancel: false,
  104. success: () => uni.navigateBack()
  105. })
  106. }
  107. } catch (e) {
  108. // 忽略错误
  109. }
  110. },
  111. toggleRole(key) {
  112. const idx = this.selectedRoles.indexOf(key)
  113. if (idx > -1) {
  114. this.selectedRoles.splice(idx, 1)
  115. } else {
  116. this.selectedRoles.push(key)
  117. }
  118. },
  119. chooseIdCardImage(side) {
  120. uni.chooseImage({
  121. count: 1,
  122. sizeType: ['compressed'],
  123. sourceType: ['album', 'camera'],
  124. success: async (res) => {
  125. uni.showLoading({ title: '上传中...' })
  126. try {
  127. const uploadRes = await uploadServiceRoleImage(res.tempFilePaths[0])
  128. uni.hideLoading()
  129. if (uploadRes.code === 200) {
  130. if (side === 'front') {
  131. this.form.idCardFront = uploadRes.data.url
  132. } else {
  133. this.form.idCardBack = uploadRes.data.url
  134. }
  135. uni.showToast({ title: '上传成功', icon: 'success' })
  136. } else {
  137. uni.showToast({ title: uploadRes.message || '上传失败', icon: 'none' })
  138. }
  139. } catch (e) {
  140. uni.hideLoading()
  141. uni.showToast({ title: '上传失败', icon: 'none' })
  142. }
  143. }
  144. })
  145. },
  146. async chooseCertificate() {
  147. uni.chooseImage({
  148. count: 9,
  149. sizeType: ['compressed'],
  150. sourceType: ['album', 'camera'],
  151. success: async (res) => {
  152. uni.showLoading({ title: '上传中...' })
  153. try {
  154. for (const filePath of res.tempFilePaths) {
  155. const uploadRes = await uploadServiceRoleImage(filePath)
  156. if (uploadRes.code === 200) {
  157. this.form.certificateImages.push(uploadRes.data.url)
  158. }
  159. }
  160. uni.hideLoading()
  161. uni.showToast({ title: '上传成功', icon: 'success' })
  162. } catch (e) {
  163. uni.hideLoading()
  164. uni.showToast({ title: '上传失败', icon: 'none' })
  165. }
  166. }
  167. })
  168. },
  169. removeCert(idx) {
  170. this.form.certificateImages.splice(idx, 1)
  171. },
  172. getCertKey(idx) {
  173. return 'cert-' + idx
  174. },
  175. onAddressChange(e) {
  176. this.form.province = e.province || ''
  177. this.form.city = e.city || ''
  178. this.form.district = e.district || ''
  179. this.form.street = e.street || ''
  180. },
  181. async handleSubmit() {
  182. if (this.selectedRoles.length === 0) {
  183. uni.showToast({ title: '请至少选择一个角色', icon: 'none' })
  184. return
  185. }
  186. if (!this.form.idCardFront || !this.form.idCardBack) {
  187. uni.showToast({ title: '请上传身份证正反面照片', icon: 'none' })
  188. return
  189. }
  190. if (!this.form.province) {
  191. uni.showToast({ title: '请选择联系地址', icon: 'none' })
  192. return
  193. }
  194. this.submitting = true
  195. uni.showLoading({ title: '提交中...' })
  196. try {
  197. const res = await submitServiceRoleApply({
  198. roles: this.selectedRoles,
  199. idCard: this.form.idCard,
  200. idCardImages: [this.form.idCardFront, this.form.idCardBack],
  201. certificateImages: this.form.certificateImages,
  202. province: this.form.province,
  203. city: this.form.city,
  204. district: this.form.district,
  205. street: this.form.street,
  206. addressDetail: this.form.addressDetail
  207. })
  208. uni.hideLoading()
  209. if (res.code === 200) {
  210. uni.showModal({
  211. title: '提交成功',
  212. content: '申请已提交,请等待后台审核',
  213. showCancel: false,
  214. success: () => uni.navigateBack()
  215. })
  216. } else {
  217. uni.showToast({ title: res.message || '提交失败', icon: 'none' })
  218. }
  219. } catch (e) {
  220. uni.hideLoading()
  221. uni.showToast({ title: '提交失败,请重试', icon: 'none' })
  222. } finally {
  223. this.submitting = false
  224. }
  225. }
  226. }
  227. }
  228. </script>
  229. <style>
  230. .page {
  231. min-height: 100vh;
  232. background: #f5f5f5;
  233. padding: 20rpx 30rpx 100rpx;
  234. }
  235. .section {
  236. background: #fff;
  237. border-radius: 16rpx;
  238. padding: 30rpx;
  239. margin-bottom: 20rpx;
  240. }
  241. .section-title {
  242. font-size: 28rpx;
  243. font-weight: bold;
  244. margin-bottom: 20rpx;
  245. color: #333;
  246. }
  247. .required {
  248. color: #ff4444;
  249. }
  250. .role-grid {
  251. display: flex;
  252. flex-wrap: wrap;
  253. gap: 20rpx;
  254. }
  255. .role-card {
  256. width: calc(33.33% - 14rpx);
  257. background: #f8f8f8;
  258. border-radius: 12rpx;
  259. padding: 24rpx 0;
  260. display: flex;
  261. flex-direction: column;
  262. align-items: center;
  263. position: relative;
  264. border: 2rpx solid transparent;
  265. }
  266. .role-card.selected {
  267. background: #fff7ed;
  268. border-color: #f97316;
  269. }
  270. .role-icon {
  271. font-size: 40rpx;
  272. margin-bottom: 8rpx;
  273. }
  274. .role-name {
  275. font-size: 24rpx;
  276. color: #333;
  277. }
  278. .check-mark {
  279. position: absolute;
  280. top: 8rpx;
  281. right: 12rpx;
  282. color: #f97316;
  283. font-size: 28rpx;
  284. font-weight: bold;
  285. }
  286. .input {
  287. width: 100%;
  288. height: 72rpx;
  289. border: 2rpx solid #eee;
  290. border-radius: 8rpx;
  291. padding: 0 20rpx;
  292. font-size: 26rpx;
  293. box-sizing: border-box;
  294. margin-bottom: 16rpx;
  295. }
  296. .upload-row {
  297. display: flex;
  298. gap: 20rpx;
  299. }
  300. .upload-item {
  301. flex: 1;
  302. height: 200rpx;
  303. border: 2rpx dashed #ddd;
  304. border-radius: 12rpx;
  305. display: flex;
  306. align-items: center;
  307. justify-content: center;
  308. overflow: hidden;
  309. }
  310. .upload-placeholder {
  311. display: flex;
  312. flex-direction: column;
  313. align-items: center;
  314. }
  315. .upload-icon {
  316. font-size: 48rpx;
  317. color: #ccc;
  318. }
  319. .upload-label {
  320. font-size: 22rpx;
  321. color: #999;
  322. margin-top: 8rpx;
  323. }
  324. .upload-preview {
  325. width: 100%;
  326. height: 100%;
  327. }
  328. .cert-list {
  329. display: flex;
  330. flex-wrap: wrap;
  331. gap: 16rpx;
  332. }
  333. .cert-item {
  334. width: 160rpx;
  335. height: 160rpx;
  336. position: relative;
  337. border-radius: 8rpx;
  338. overflow: hidden;
  339. }
  340. .cert-preview {
  341. width: 100%;
  342. height: 100%;
  343. }
  344. .cert-del {
  345. position: absolute;
  346. top: 4rpx;
  347. right: 4rpx;
  348. width: 32rpx;
  349. height: 32rpx;
  350. background: rgba(0,0,0,0.5);
  351. color: #fff;
  352. border-radius: 50%;
  353. text-align: center;
  354. line-height: 32rpx;
  355. font-size: 24rpx;
  356. }
  357. .cert-add {
  358. width: 160rpx;
  359. height: 160rpx;
  360. border: 2rpx dashed #ddd;
  361. border-radius: 8rpx;
  362. display: flex;
  363. flex-direction: column;
  364. align-items: center;
  365. justify-content: center;
  366. }
  367. .submit-btn {
  368. width: 100%;
  369. height: 88rpx;
  370. background: linear-gradient(135deg, #f97316, #fb923c);
  371. color: #fff;
  372. font-size: 32rpx;
  373. border-radius: 44rpx;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. position: fixed;
  378. bottom: 40rpx;
  379. left: 30rpx;
  380. width: calc(100% - 60rpx);
  381. }
  382. .submit-btn[disabled] {
  383. opacity: 0.6;
  384. }
  385. </style>