-
zhangwei
2024-09-12 f7aa204aa8d20b090d7943969ddeb9871a1fad76
src/pages/enterprise/enterprise.vue
@@ -6,9 +6,8 @@
               <fui-upload immediate :url="`${apiBaseUrl}/api/UpFile/UpBizLicense`" ref="uploadB" max='1'
                  background='#fff' @success="success" @error="error" @complete="complete" width="300"
                  :sizeType='sizeType' height="150">
                  <image
                     :src="enterpriseInfo.businessLicense?enterpriseInfo.businessLicense:'/static/enterprise.png'"
                     mode="widthFix" style="width: 300rpx;height: 150rpx;"></image>
                  <image src="/static/enterprise.png" mode="widthFix" style="width: 300rpx;height: 150rpx;">
                  </image>
               </fui-upload>
               <!-- <template #right>
                  <up-icon name="arrow-right"></up-icon>
@@ -59,6 +58,10 @@
      onShow,
      onReady
   } from "@dcloudio/uni-app";
   import {
      useStore
   } from 'vuex'
   const store = useStore()
   let sizeType = ['compressed']
   let rules = {
      businessLicense: {
@@ -96,11 +99,21 @@
         message: '公司简介不能为空',
         trigger: ['blur', 'change']
      }, //公司简介
      phone: {
      phone:  [{
         required: true,
         message: '电话号码不能为空',
         message: '联系电话不能为空',
         trigger: ['blur', 'change']
      }
      },{
         // 自定义验证函数,见上说明
         validator: (rule, value, callback) => {
            // 上面有说,返回true表示校验通过,返回false表示不通过
            // uni.$u.test.mobile()就是返回true或者false的
            return uni.$u.test.mobile(value);
         },
         message: '联系电话不正确',
         // 触发器可以同时用blur和change
         trigger: ['change','blur'],
      }]
   }
   import {
      ref,
@@ -114,6 +127,7 @@
      $util,
      $db
   } = getCurrentInstance().appContext.config.globalProperties
   let uploadB = ref()
   onLoad(() => {
      const userToken = $db.get("userToken");
      if (!userToken) {
@@ -132,7 +146,7 @@
            }
         });
      }
      let data = $db.get('userInfo') ? JSON.parse($db.get('userInfo')).userCompany : null
      let data = $db.get('userInfo') ? $db.get('userInfo').userCompany : null
      if (data) {
         enterpriseInfo.businessLicense = data.businessLicense
         enterpriseInfo.suppliername = data.suppliername //企业名称
@@ -150,6 +164,10 @@
   const formRef = ref(null);
   onReady(() => {
      formRef.value.setRules(rules);
      if (enterpriseInfo.businessLicense) {
         uploadB.value.urls = [enterpriseInfo.businessLicense]
         uploadB.value.status = ['success']
      }
   })
   onMounted(() => {
      formRef.value.setRules(rules);
@@ -192,22 +210,24 @@
      console.log(e, '删除')
   }
   const getUserInfo = async () => {
      await store.dispatch('getUserInfo')
      uni.navigateBack()
      $util.showToast({
         title: "保存成功!",
         icon: "success"
      })
   }
   const saveUserCompany = () => {
      formRef.value.validate().then(res => {
         isLoading.value = true
         $api.saveUserCompany(enterpriseInfo).then(res => {
            if (res.code == 1) {
               $api.getUser().then(res => {
                  $db.set('userInfo', JSON.stringify(res.data))
               })
               $util.showToast({
                  title: "保存成功!",
                  icon: "success"
               })
               uni.navigateBack()
               getUserInfo()
            } else {
               $util.showToast({
                  title: res.msg
                  title: res.msg ? res.msg : res.error
               })
            }
            isLoading.value = false