Ver código fonte

fix: 组件同时初始化,无法缓存接口复用

zhangyuhan 3 dias atrás
pai
commit
925e73ce47

+ 14 - 6
apps/mobile/src/views/create-order/components/analysis-report/FooterProductionCard.vue

@@ -101,16 +101,16 @@ export default {
     // 直接调用 mutation
     const updateProductSpecId = (payload) => store.commit('createOrder/updateProductSpecId', payload)
 
-    const { zhimaReportAccountInfo } = useAccountInfoModel((model) => {
-      // 非首购、非会员时选中年卡
-      if (!model.value?.isFirstBuy && !model.value?.inPack) {
+    const { zhimaReportAccountInfo, getAccountInfoModel } = useAccountInfoModel((model) => {
+      if (!model.isFirstBuy && !model.inPack) {
         updateProductSpecId(1514)
       } else {
         updateProductSpecId(1511)
       }
     })
     return {
-      zhimaReportAccountInfo
+      zhimaReportAccountInfo,
+      getAccountInfoModel
     }
   },
   data() {
@@ -216,7 +216,7 @@ export default {
       return result
     }
   },
-  created() {
+  async created() {
     const { buyer } = this.$route.query
     if (buyer) {
       this.info.buyer = buyer
@@ -224,8 +224,16 @@ export default {
     this.updateLayout({
       footerNotice: true
     })
+    // 必须等待接口回调
+    await this.getAccountInfoModel().then(() => {
+      if (!this.useNowState.isFirstBuy && !this.useNowState.inPack) {
+        this.updateProductSpecId(1514)
+      } else {
+        this.updateProductSpecId(1511)
+      }
+    })
   },
-   mounted() {
+  mounted() {
      this.updatePayAmount()
      this.getUserInfoFun()
   },

+ 1 - 1
apps/mobile/src/views/create-order/components/analysis-report/HeaderAdsense.vue

@@ -65,7 +65,7 @@ export default {
 <style lang="scss" scoped>
 .header-show-group {
   background: linear-gradient(180deg, #FBFFFF 0%, #DAFFFF 100%);
-  padding: 12px 0 24px;
+  padding: 12px 0 12px;
 
   .label-desc {
     display: inline-block;

+ 0 - 1
apps/mobile/src/views/create-order/components/analysis-report/ProductionCard.vue

@@ -44,7 +44,6 @@ export default {
 .analysis-report-production-card {
   border-top-left-radius: 12px;
   border-top-right-radius: 12px;
-  margin-top: -12px;
   padding-bottom: 12px;
 
   .report-tip {

+ 4 - 7
apps/mobile/src/views/create-order/components/analysis-report/model/account.js

@@ -31,19 +31,16 @@ const zhimaReportAccountInfo = computed(() => {
   }
 })
 
-function getAccountInfoModel (cb) {
-  pdfaccount().then(res => {
+async function getAccountInfoModel () {
+  return pdfaccount().then(res => {
     accountInfoModel.value = res.data.zhima || {}
-    typeof cb === 'function' && cb(zhimaReportAccountInfo)
   })
 }
 
-export default function useAccountInfoModel (cb) {
+export default function useAccountInfoModel () {
   if (!window[TEMP_KEY]) {
     window[TEMP_KEY] = Date.now()
-    getAccountInfoModel(cb)
-  } else {
-    typeof cb === 'function' && cb(zhimaReportAccountInfo)
+    getAccountInfoModel()
   }
   return {
     zhimaReportAccountInfo,