Blame view

src/components/store/InitData.vue 2.96 KB
b25b036d   wuxw   v1.9 优化日期
1
  <template>
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    <div></div>
  </template>
  
  <script>
  import { listMyEnteredCommunitys, queryStoreByUser, queryUserPrivilege } from '@/api/store/propertyCompanyManageApi'
  
  export default {
    name: 'InitData',
    props: {
      visible: {
        type: Boolean,
        default: false
      },
      loginUsers: {
        type: Array,
        default: () => []
      },
      pageUrl: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        selectedUser: null
      }
    },
    methods: {
      async initData() {
        if (this.loginUsers.length > 1) {
          this.showUserSelection()
        } else {
          await this.handleUserSelected(this.loginUsers[0])
        }
      },
      showUserSelection() {
        this.$confirm({
          title: this.$t('propertyCompanyManage.selectAccount'),
          message: this.renderUserTable(),
          showCancelButton: true,
          confirmButtonText: this.$t('common.confirm'),
          cancelButtonText: this.$t('common.cancel')
        }).then(() => {
          if (this.selectedUser) {
            this.handleUserSelected(this.selectedUser)
          } else {
            this.$message.warning(this.$t('propertyCompanyManage.selectUserFirst'))
          }
        })
      },
      renderUserTable() {
        return (
          <div style="max-height: 300px; overflow-y: auto;">
            <el-table data={this.loginUsers} on-selection-change={this.handleSelectionChange}>
              <el-table-column type="selection" width="55" />
              <el-table-column property="userName" label={this.$t('propertyCompanyManage.account')} />
              <el-table-column property="storeName" label={this.$t('propertyCompanyManage.belongTo')} />
              <el-table-column property="relCdName" label={this.$t('propertyCompanyManage.role')} />
            </el-table>
          </div>
        )
      },
      handleSelectionChange(val) {
        this.selectedUser = val.length > 0 ? val[0] : null
      },
      async handleUserSelected(user) {
        try {
          // 保存token
          this.$store.dispatch('user/setToken', user.token)
59fd5759   王彪总   feat(map): 替换腾讯地图...
71
  
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
72
73
          // 验证是否有店铺
          await queryStoreByUser({ _uId: 'ccdd00opikookjuhyyttvhnnjuuu' })
59fd5759   王彪总   feat(map): 替换腾讯地图...
74
  
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
75
          // 加载权限
59fd5759   王彪总   feat(map): 替换腾讯地图...
76
          const { datas } = await queryUserPrivilege({ a: '西荣物业' })
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
77
78
          const privileges = datas.map(item => item.pId)
          this.$store.dispatch('user/setPrivileges', privileges)
59fd5759   王彪总   feat(map): 替换腾讯地图...
79
  
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
80
81
82
83
84
85
          // 加载小区信息
          const { communitys } = await listMyEnteredCommunitys({
            _uId: 'ccdd00opikookjuhyyttvhnnjuuu',
            page: 1,
            row: 3
          })
59fd5759   王彪总   feat(map): 替换腾讯地图...
86
  
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
          if (communitys && communitys.length > 0) {
            this.$store.dispatch('community/setCurrentCommunity', communitys[0])
            this.$store.dispatch('community/setCommunitys', communitys)
            this.$router.push(this.pageUrl)
          } else {
            this.$message.error(this.$t('propertyCompanyManage.noCommunityAssigned'))
          }
        } catch (error) {
          this.$message.error(error.message)
        }
      }
    },
    mounted() {
      this.initData()
    }
  }
59fd5759   王彪总   feat(map): 替换腾讯地图...
103
  </script>