index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <route lang="json">
  2. {
  3. "style": {
  4. "navigationBarTitleText": "设计师认证",
  5. "navigationStyle": "custom"
  6. }
  7. }
  8. </route>
  9. <script lang="ts" setup>
  10. import Card from '@/components/card.vue'
  11. import DataForm from '@/components/data-form.vue'
  12. import NavBarEvo from '@/components/navbar-evo.vue'
  13. import SectionHeading from '@/components/section-heading.vue'
  14. import {
  15. createUserAuthInfo,
  16. getByDictType,
  17. getUserAuthInfo,
  18. updateUserAuthInfo,
  19. validateReferrerCode,
  20. } from '../../../core/libs/requests'
  21. import { DictType } from '../../../core/libs/models'
  22. import { useUserStore } from '../../../store'
  23. import pageHeaderFilter from '@designer-hub/assets/src/assets/svgs/pageHeaderFilter'
  24. import { storeToRefs } from 'pinia'
  25. import { useMessage, useToast } from 'wot-design-uni'
  26. import { useRouter } from '../../../core/utils/router'
  27. import { requestToast } from '../../../core/utils/common'
  28. import { omit, pick } from 'radash'
  29. import UploadEvo from '@/components/upload-evo.vue'
  30. import { DataFormSchema } from '../../../components/data-form'
  31. import { messages } from '../../../core/libs/messages'
  32. const { alert } = useMessage()
  33. const router = useRouter()
  34. const userStore = useUserStore()
  35. const { userInfo, isDesigner } = storeToRefs(userStore)
  36. const { error } = useToast()
  37. const formData = ref<any>({ mobile: userInfo.value?.mobile })
  38. const attachment = ref()
  39. const formInited = ref(false)
  40. const uploadDisabled = ref(false)
  41. const { data: userAuthInfo, run: setUserAuthInfo } = useRequest(() => getUserAuthInfo())
  42. const schema = ref<DataFormSchema>({
  43. channelSource: {
  44. type: 'Select',
  45. label: '来源',
  46. labelWidth: 63,
  47. props: {
  48. placeholder: '请选择通过哪个渠道入驻的筑巢荟',
  49. columns: [],
  50. disabled: userAuthInfo.value != null,
  51. 'onUpdate:modelValue': (value) => setReferrerExisting(value),
  52. },
  53. },
  54. referrer: {
  55. type: 'TextField',
  56. label: '推荐人',
  57. existing: true,
  58. labelWidth: 63,
  59. props: {
  60. placeholder: '请填写推荐人编号',
  61. disabled: false,
  62. },
  63. },
  64. designerName: {
  65. type: 'TextField',
  66. label: '姓名',
  67. labelWidth: 63,
  68. props: {
  69. placeholder: '请输入真实姓名',
  70. },
  71. },
  72. mobile: {
  73. type: 'TextField',
  74. label: '电话',
  75. labelWidth: 63,
  76. props: {
  77. placeholder: '请输入电话号码',
  78. disabled: true,
  79. },
  80. },
  81. employer: {
  82. type: 'TextField',
  83. label: '公司',
  84. labelWidth: 63,
  85. props: {
  86. placeholder: '请输入所在公司或自己公司名称',
  87. },
  88. },
  89. spatialExpertiseType: {
  90. type: 'Checkbox',
  91. label: '擅长空间类型',
  92. labelWidth: 84,
  93. props: {
  94. placeholder: ' ',
  95. columns: [],
  96. },
  97. },
  98. })
  99. const setReferrerExisting = (value: string) => {
  100. if (value === '4') {
  101. schema.value.referrer.existing = false
  102. } else {
  103. schema.value.referrer.existing = true
  104. schema.value.referrer.props.placeholder = {
  105. '1': '请填写渠道邀请码',
  106. '2': '请填写设计师会员号',
  107. '3': '请填写材料商名称',
  108. }[value]
  109. }
  110. formData.value.referrer = ''
  111. }
  112. const handleSubmit = async () => {
  113. console.log(formData.value)
  114. if (formData.value.channelSource && formData.value.channelSource !== '4' && !userAuthInfo.value) {
  115. if ((formData.value.referrer ?? '') === '') {
  116. uni.showToast({ title: messages.mine.authentication.referrerErrorText, icon: 'none' })
  117. return
  118. }
  119. const { data, code: status } = await requestToast(() =>
  120. validateReferrerCode({
  121. code: formData.value.referrer,
  122. channelSource: formData.value.channelSource,
  123. }),
  124. )
  125. if (data === false || status !== 0) {
  126. uni.showToast({ title: '推荐人编号不正确', icon: 'none' })
  127. return
  128. }
  129. }
  130. const body = {
  131. ...formData.value,
  132. spatialExpertiseType: formData.value.spatialExpertiseType?.join(','),
  133. attachment: attachment.value,
  134. }
  135. const rules = {
  136. channelSource: { required: true, message: messages.mine.authentication.channelSourceErrorText },
  137. // referrer: { required: true, message: messages.mine.authentication.referrerErrorText },
  138. designerName: { required: true, message: messages.mine.authentication.designerNameErrorText },
  139. employer: { required: true, message: messages.mine.authentication.employerErrorText },
  140. spatialExpertiseType: {
  141. required: true,
  142. message: messages.mine.authentication.spatialExpertiseTypeErrorText,
  143. },
  144. attachment: { required: true, message: messages.mine.authentication.attachmentErrorText },
  145. }
  146. // 校验上述字段
  147. const errors = Object.entries(rules)
  148. .filter(([key, value]) => (body[key] ?? '') === '')
  149. .map(([key, value]) => value.message)
  150. console.log(errors)
  151. if (errors.length > 0) {
  152. uni.showToast({ title: errors[0], icon: 'none' })
  153. return
  154. }
  155. if (!userAuthInfo.value) {
  156. console.log(3333)
  157. const { code, msg } = await createUserAuthInfo({
  158. gender: userInfo.value.sex,
  159. attachment: attachment.value,
  160. userId: userInfo.value.userId,
  161. ...formData.value,
  162. spatialExpertiseType: formData.value.spatialExpertiseType?.join(','),
  163. })
  164. if (code === 0) {
  165. router.replace(`/pages/mine/authentication/submit/success/index`)
  166. } else {
  167. error(msg)
  168. }
  169. } else {
  170. const toBeUpdate = {
  171. ...omit(formData.value, ['spatialExpertiseType']),
  172. spatialExpertiseType: formData.value.spatialExpertiseType?.join(','),
  173. attachment: attachment.value,
  174. id: userAuthInfo.value.id,
  175. gender: userInfo.value.sex,
  176. }
  177. const { code } = await requestToast(() => updateUserAuthInfo({ ...toBeUpdate, auditStatus: 1 }))
  178. if (code === 0) {
  179. router.replace(`/pages/mine/authentication/submit/success/index`)
  180. }
  181. }
  182. }
  183. onMounted(async () => {
  184. await setUserAuthInfo()
  185. if (userAuthInfo.value) {
  186. formData.value = {
  187. ...pick(userAuthInfo.value, [
  188. 'channelSource',
  189. 'referrer',
  190. 'designerName',
  191. 'designerName',
  192. 'mobile',
  193. 'employer',
  194. ]),
  195. channelSource: userAuthInfo.value.channelSource.toString(),
  196. spatialExpertiseType: userAuthInfo.value.spatialExpertiseType?.split(','),
  197. }
  198. setReferrerExisting(userAuthInfo.value.channelSource.toString())
  199. attachment.value = userAuthInfo.value.attachment
  200. // schema.value.channelSource.props.disabled = true
  201. // schema.value.referrer.props.disabled = true
  202. }
  203. const { data } = await getByDictType('member_channel_source')
  204. const { data: res } = await getByDictType(DictType.memberSpatialExpertiseType)
  205. console.log(res)
  206. schema.value.channelSource.props.columns = data
  207. schema.value.spatialExpertiseType.props.columns = res
  208. formInited.value = true
  209. if (userInfo.value.userAuthStatus === 1) {
  210. Object.entries(schema.value).forEach(([key]) => {
  211. schema.value[key].props.disabled = true
  212. })
  213. uploadDisabled.value = true
  214. alert({
  215. msg: '您的认证申请已提交,请耐心等待审核,审核通过后您将获得通知',
  216. title: '提示',
  217. confirmButtonText: '我知道了',
  218. })
  219. }
  220. if (userInfo.value.userAuthStatus === 2) {
  221. alert({
  222. title: '审核不通过',
  223. msg: userAuthInfo.value?.remark || '由于系统原因,您提交的认证暂时无法通过,请修改后重新提交',
  224. })
  225. }
  226. })
  227. defineExpose({})
  228. </script>
  229. <template>
  230. <div class="flex-grow">
  231. <div class="relative aspect-[3.6/1]">
  232. <div class="absolute top-0 left--1 right--1 bottom--18.5">
  233. <wd-img
  234. width="100%"
  235. height="100%"
  236. :src="'https://image.zhuchaohui.com/zhucaohui/21d6584cb711834f037a763855d05572433f776b308596d94aca97dd37e6cfa.png'"
  237. ></wd-img>
  238. </div>
  239. <div class="absolute top-0 left-0 right-0 bottom--18.5">
  240. <wd-img width="100%" height="100%" :src="pageHeaderFilter"></wd-img>
  241. </div>
  242. </div>
  243. <NavBarEvo transparent dark title="设计师认证"></NavBarEvo>
  244. <div class="flex-grow flex flex-col p-3.5 gap-3.5 relative">
  245. <Card>
  246. <SectionHeading size="base" title="基本信息" custom-class="mb-4"></SectionHeading>
  247. <template v-if="formInited">
  248. <DataForm v-model="formData" :schema="schema" direction="horizontal"></DataForm>
  249. </template>
  250. </Card>
  251. <Card>
  252. <SectionHeading
  253. size="base"
  254. title="上传附件"
  255. subtitle="请上传名片或者获奖信息凭证"
  256. custom-class="mb-4"
  257. ></SectionHeading>
  258. <div class="h-0.25 bg-[#e1e1e1] mb-5"></div>
  259. <!-- <wd-upload></wd-upload> -->
  260. <UploadEvo v-if="formInited" v-model="attachment" :disabled="uploadDisabled"></UploadEvo>
  261. </Card>
  262. <div class="flex-1"></div>
  263. <div>
  264. <wd-button
  265. v-if="!(isDesigner || String(userInfo.userAuthStatus) === '1')"
  266. block
  267. :round="false"
  268. :disabled="isDesigner || userInfo.userAuthStatus === 1"
  269. @click="handleSubmit"
  270. >
  271. 提交
  272. </wd-button>
  273. <!-- <wd-button @click="handleSubmit">test</wd-button> -->
  274. </div>
  275. </div>
  276. </div>
  277. </template>