changeOrganization.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="organization-select">
  3. <view class="common-list">
  4. <view class="common-item" v-for="(item,index) in list" :key="item.id" @tap="select(item)">
  5. <view class="title">{{item.name}}</view>
  6. <view class="date">{{item.contact || '-'}}</view>
  7. <view class="space">{{!!item.address ? JSON.parse(item.address).join('-'):'-'}}</view>
  8. <view class="icon" v-if="organization.id === item.id">
  9. <uv-icon name="checkbox-mark" color="primary" size="60"></uv-icon>
  10. </view>
  11. </view>
  12. </view>
  13. <uv-modal ref="modal" title="WORKARK提示" :content='`是否切换至<${selectOrganization.name}>组织?`' :asyncClose="true"
  14. @confirm="confirm" :showCancelButton="true">
  15. </uv-modal>
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. selectWorkarkOrangaized,
  21. getWorkarkOrangaized
  22. } from '@/request/api/my.js'
  23. import {
  24. getUserInfo
  25. } from '@/request/api/login.js'
  26. export default {
  27. data() {
  28. return {
  29. list: [],
  30. organization: {},
  31. selectOrganization: {}
  32. }
  33. },
  34. onShow() {
  35. this.organization = this.$store.getters.organization;
  36. },
  37. onLoad() {
  38. this.init();
  39. },
  40. methods: {
  41. async init() {
  42. uni.showLoading();
  43. let organizationData = await getWorkarkOrangaized()
  44. if (organizationData.state) this.list = organizationData.data;
  45. uni.hideLoading();
  46. },
  47. async confirm() {
  48. uni.showLoading();
  49. let work = await selectWorkarkOrangaized(this.selectOrganization);
  50. if (!work.state) return this.$refs.modal.close();
  51. let userData = await getUserInfo();
  52. if (!userData.state) return this.$refs.modal.close();
  53. this.$store.dispatch('app/changeOrganization', userData.data.workarkOrganization);
  54. this.$store.dispatch('app/changeUser', userData.data);
  55. uni.setStorageSync('vuex_state', this.$store.state);
  56. uni.hideLoading();
  57. this.$toast('切换成功');
  58. this.$refs.modal.close();
  59. uni.navigateBack();
  60. },
  61. select(item) {
  62. if (this.organization.id === item.id) return;
  63. this.selectOrganization = item;
  64. this.$refs.modal.open();
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss">
  70. .organization-select {
  71. padding: 30rpx 0;
  72. .tag {
  73. display: flex;
  74. .status-tag {
  75. margin-left: 5px;
  76. }
  77. }
  78. }
  79. </style>