Przeglądaj źródła

Merge branch 'feature_20260427_经销商用户多身份切换' into uat(dev)

zhujindu 1 dzień temu
rodzic
commit
d9527ac4f7
1 zmienionych plików z 27 dodań i 8 usunięć
  1. 27 8
      src/views/week/changeChain.vue

+ 27 - 8
src/views/week/changeChain.vue

@@ -6,11 +6,11 @@
         <div
           class="box"
           v-if="userInfo && userInfo.userMultipleChains && userInfo.userMultipleChains.length > 0">
-          <van-radio-group v-model="userInfo.chainCode" @change="chainChange">
+          <van-radio-group v-model="selectedChainIndex" @change="chainChange">
             <van-radio
-              v-for="value in userInfo.userMultipleChains"
-              :key="value.chainCode"
-              :name="value.chainCode">
+              v-for="(value, index) in userInfo.userMultipleChains"
+              :key="`${value.chainCode}-${index}`"
+              :name="index">
               {{ value.chainName }}
             </van-radio>
           </van-radio-group>
@@ -31,13 +31,32 @@ export default {
     }),
   },
   data() {
-    return {};
+    return {
+      selectedChainIndex: null,
+    };
+  },
+  watch: {
+    'userInfo.userMultipleChains'(val) {
+      this.initSelectedChain(val);
+    },
+  },
+  created() {
+    this.initSelectedChain(this.userInfo && this.userInfo.userMultipleChains);
   },
-  created() {},
   methods: {
-    chainChange(value) {
+    initSelectedChain(val) {
+      if (val && val.length > 0) {
+        const currentIndex = val.findIndex((item) => item.check);
+        this.selectedChainIndex = currentIndex >= 0 ? currentIndex : 0;
+      }
+    },
+    chainChange(index) {
+      const chain = this.userInfo.userMultipleChains[index];
+      if (!chain) {
+        return;
+      }
       this.toastLoading(0, '切换中,请稍候...', true);
-      switchChainIdentity({ chainCode: value }).then((res) => {
+      switchChainIdentity({ userMultipleChainId: chain.multipleChainId }).then((res) => {
         this.toastLoading().clear();
         if (res.code === 200) {
           store.dispatch('getUserInfo').then(() => {