changeChain.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div class="changeChain">
  3. <van-nav-bar class="navBar" title="切换经销商" left-arrow @click-left="onClickLeft" />
  4. <div class="content">
  5. <div class="module">
  6. <div
  7. class="box"
  8. v-if="userInfo && userInfo.userMultipleChains && userInfo.userMultipleChains.length > 0">
  9. <van-radio-group v-model="userInfo.chainCode" @change="chainChange">
  10. <van-radio
  11. v-for="value in userInfo.userMultipleChains"
  12. :key="value.chainCode"
  13. :name="value.chainCode">
  14. {{ value.chainName }}
  15. </van-radio>
  16. </van-radio-group>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import { mapState } from 'vuex';
  24. import { switchChainIdentity } from '@/api/week';
  25. import store from '@/store';
  26. export default {
  27. name: 'changeChain',
  28. computed: {
  29. ...mapState({
  30. userInfo: (state) => state.user.userInfo,
  31. }),
  32. },
  33. data() {
  34. return {};
  35. },
  36. created() {},
  37. methods: {
  38. chainChange(value) {
  39. this.toastLoading(0, '切换中,请稍候...', true);
  40. switchChainIdentity({ chainCode: value }).then((res) => {
  41. this.toastLoading().clear();
  42. if (res.code === 200) {
  43. store.dispatch('getUserInfo').then(() => {
  44. this.$toast('切换成功');
  45. });
  46. } else {
  47. this.$toast(res.message || '切换失败');
  48. }
  49. });
  50. },
  51. onClickLeft() {
  52. this.$router.go(-1);
  53. },
  54. },
  55. };
  56. </script>
  57. <style lang="scss" scoped>
  58. .changeChain {
  59. width: 100%;
  60. height: 100%;
  61. .content {
  62. margin: 10px 16px;
  63. .module {
  64. margin-bottom: 10px;
  65. .title {
  66. font-size: 16px;
  67. padding: 10px 0;
  68. }
  69. .box {
  70. background: #fff;
  71. display: flex;
  72. align-items: center;
  73. justify-content: space-between;
  74. padding: 10px;
  75. font-size: 16px;
  76. .van-radio {
  77. padding: 8px 0;
  78. }
  79. }
  80. }
  81. }
  82. }
  83. </style>