index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. }
  111. const handleSubmit = async () => {
  112. console.log(formData.value)
  113. if (formData.value.channelSource && formData.value.channelSource !== '4' && formData.value.channelSource !== '3' && !userAuthInfo.value) {
  114. if ((formData.value.referrer ?? '') === '') {
  115. await uni.showToast({ title: messages.mine.authentication.referrerErrorText, icon: 'none' })
  116. return
  117. }
  118. const { data, code: status } = await requestToast(() =>
  119. validateReferrerCode({
  120. code: formData.value.referrer,
  121. channelSource: formData.value.channelSource,
  122. }),
  123. )
  124. if (data === false || status !== 0) {
  125. await uni.showToast({ title: '推荐人编号不正确', icon: 'none' })
  126. return
  127. }
  128. }
  129. const body = {
  130. ...formData.value,
  131. spatialExpertiseType: formData.value.spatialExpertiseType?.join(','),
  132. attachment: attachment.value,
  133. }
  134. const rules = {
  135. channelSource: { required: true, message: messages.mine.authentication.channelSourceErrorText },
  136. // referrer: { required: true, message: messages.mine.authentication.referrerErrorText },
  137. designerName: { required: true, message: messages.mine.authentication.designerNameErrorText },
  138. employer: { required: true, message: messages.mine.authentication.employerErrorText },
  139. spatialExpertiseType: {
  140. required: true,
  141. message: messages.mine.authentication.spatialExpertiseTypeErrorText,
  142. },
  143. attachment: { required: true, message: messages.mine.authentication.attachmentErrorText },
  144. }
  145. // 校验上述字段
  146. const errors = Object.entries(rules)
  147. .filter(([key, value]) => (body[key] ?? '') === '')
  148. .map(([key, value]) => value.message)
  149. console.log(errors)
  150. if (errors.length > 0) {
  151. await uni.showToast({ title: errors[0], icon: 'none' })
  152. return
  153. }
  154. if (!userAuthInfo.value) {
  155. console.log(3333)
  156. const { code, msg } = await createUserAuthInfo({
  157. gender: userInfo.value.sex,
  158. attachment: attachment.value,
  159. userId: userInfo.value.userId,
  160. ...formData.value,
  161. spatialExpertiseType: formData.value.spatialExpertiseType?.join(','),
  162. })
  163. if (code === 0) {
  164. await router.replace(`/pages-sub/mine/authentication/submit/success/index`)
  165. } else {
  166. error(msg)
  167. }
  168. } else {
  169. const toBeUpdate = {
  170. ...omit(formData.value, ['spatialExpertiseType']),
  171. spatialExpertiseType: formData.value.spatialExpertiseType?.join(','),
  172. attachment: attachment.value,
  173. id: userAuthInfo.value.id,
  174. gender: userInfo.value.sex,
  175. }
  176. const { code } = await requestToast(() => updateUserAuthInfo({ ...toBeUpdate, auditStatus: 1 }))
  177. if (code === 0) {
  178. await router.replace(`/pages-sub/mine/authentication/submit/success/index`)
  179. }
  180. }
  181. }
  182. onLoad(async (query?: Record<string | 'scene', string>) => {
  183. if (query?.scene) {
  184. console.log(query.scene)
  185. try {
  186. const [referrer, channelSource] = decodeURIComponent(query.scene).split('&')
  187. console.log(referrer, channelSource)
  188. formData.value = {
  189. ...formData.value,
  190. referrer,
  191. channelSource,
  192. }
  193. } catch (e) {
  194. await uni.showToast({ title: e.message, icon: 'none' })
  195. }
  196. }
  197. await setUserAuthInfo()
  198. console.log(userAuthInfo.value)
  199. if (userAuthInfo.value) {
  200. formData.value = {
  201. ...pick(userAuthInfo.value, [
  202. 'channelSource',
  203. 'referrer',
  204. 'designerName',
  205. 'designerName',
  206. 'mobile',
  207. 'employer',
  208. ]),
  209. channelSource: userAuthInfo.value.channelSource.toString(),
  210. spatialExpertiseType: userAuthInfo.value.spatialExpertiseType?.split(','),
  211. }
  212. setReferrerExisting(userAuthInfo.value.channelSource.toString())
  213. attachment.value = userAuthInfo.value.attachment
  214. // schema.value.channelSource.props.disabled = true
  215. // schema.value.referrer.props.disabled = true
  216. }
  217. const { data } = await getByDictType('member_channel_source')
  218. const { data: res } = await getByDictType(DictType.memberSpatialExpertiseType)
  219. console.log(res)
  220. schema.value.channelSource.props.columns = data
  221. schema.value.spatialExpertiseType.props.columns = res
  222. formInited.value = true
  223. if (userInfo.value.userAuthStatus === 1) {
  224. console.log(formData.value)
  225. Object.entries(schema.value).forEach(([key]) => {
  226. schema.value[key].props.disabled = true
  227. })
  228. uploadDisabled.value = true
  229. await alert({
  230. msg: '您的认证申请已提交,请耐心等待审核,审核通过后您将获得通知',
  231. title: '提示',
  232. confirmButtonText: '我知道了',
  233. })
  234. }
  235. if (userInfo.value.userAuthStatus === 2) {
  236. await alert({
  237. title: '审核不通过',
  238. msg: userAuthInfo.value?.remark || '由于系统原因,您提交的认证暂时无法通过,请修改后重新提交',
  239. })
  240. }
  241. })
  242. onShow(()=>{
  243. console.log(!userInfo.value.nickname)
  244. if(!userInfo.value.nickname){
  245. router.push('/pages-sub/login/index')
  246. }
  247. })
  248. defineExpose({})
  249. </script>
  250. <template>
  251. <div class="flex-grow">
  252. <div class="relative aspect-[3.6/1]">
  253. <div class="absolute top-0 left--1 right--1 bottom--18.5">
  254. <wd-img
  255. width="100%"
  256. height="100%"
  257. :src="'https://image.zhuchaohui.com/zhucaohui/21d6584cb711834f037a763855d05572433f776b308596d94aca97dd37e6cfa.png'"
  258. ></wd-img>
  259. </div>
  260. <div class="absolute top-0 left-0 right-0 bottom--18.5">
  261. <wd-img width="100%" height="100%" :src="pageHeaderFilter"></wd-img>
  262. </div>
  263. </div>
  264. <NavBarEvo transparent dark title="设计师认证"></NavBarEvo>
  265. <div class="flex-grow flex flex-col p-3.5 gap-3.5 relative">
  266. <Card>
  267. <SectionHeading size="base" title="基本信息" custom-class="mb-4"></SectionHeading>
  268. <template v-if="formInited">
  269. <DataForm v-model="formData" :schema="schema" direction="horizontal"></DataForm>
  270. </template>
  271. </Card>
  272. <Card>
  273. <SectionHeading
  274. size="base"
  275. title="上传附件"
  276. subtitle="请上传名片或者获奖信息凭证"
  277. custom-class="mb-4"
  278. ></SectionHeading>
  279. <div class="h-0.25 bg-[#e1e1e1] mb-5"></div>
  280. <!-- <wd-upload></wd-upload> -->
  281. <UploadEvo v-if="formInited" v-model="attachment" :disabled="uploadDisabled"></UploadEvo>
  282. </Card>
  283. <div class="flex-1"></div>
  284. <div>
  285. <wd-button
  286. v-if="!(isDesigner || String(userInfo.userAuthStatus) === '1')"
  287. block
  288. :round="false"
  289. :disabled="isDesigner || userInfo.userAuthStatus === 1"
  290. @click="handleSubmit"
  291. >
  292. 提交
  293. </wd-button>
  294. <!-- <wd-button @click="handleSubmit">test</wd-button> -->
  295. </div>
  296. </div>
  297. </div>
  298. </template>