Browse Source

feat: 企微主体选择下拉组件封装(系统消息模块已使用)

zhengxy 1 year ago
parent
commit
bc9ca2ac8b

+ 154 - 0
project/src/components/assembly/screen/selectCorp.vue

@@ -0,0 +1,154 @@
1
+<template>
2
+  <div class="common-screen-item">
3
+    <label class="common-screen-label">{{ labelName }}</label>
4
+    <!-- 系统管理员 -->
5
+    <el-cascader v-if="isSuperManage" v-model="system_enterprise_res" size="small" :options="enterpriseList" :props="{value:'self_id',label:'self_name',children:'manage_corp_list'}" @change="onChangeCorpidSystem" clearable filterable :placeholder="placeholder" class="select-cls cascader" />
6
+    <!-- 非系统管理员 -->
7
+    <el-select v-else v-model="enterprise_res" size="small" filterable :placeholder="placeholder" @change="onChangeCorpid" clearable class="select-cls">
8
+      <el-option v-for="(item, index) in enterpriseList" :key="index+'enterpriseList'" :label="item.corp_name?item.corp_name:item.corp_full_name?item.corp_full_name:item.corpid" :value="item.corpid" />
9
+    </el-select>
10
+  </div>
11
+</template>
12
+
13
+<script>
14
+export default {
15
+  props: {
16
+    value: {
17
+      type: String,
18
+      default: () => '',
19
+    },
20
+    labelName: {
21
+      type: String,
22
+      default: () => '企微主体'
23
+    },
24
+    placeholder: {
25
+      type: String,
26
+      default: () => '请选择'
27
+    },
28
+  },
29
+  data() {
30
+    return {
31
+      enterpriseList: [], // 企微主体数据
32
+      enterprise: {}, // 当前选择的企微信息
33
+      system_enterprise_res: [], // 企微主体数据
34
+      enterprise_res: '',
35
+    }
36
+  },
37
+  computed: {
38
+    isSuperManage() {
39
+      return this.$cookie.getCookie('isSuperManage') == 1
40
+    },
41
+  },
42
+  watch: {
43
+    value(newVal) {
44
+      if (!newVal) { // 初始化当前企微数据
45
+        this.enterprise = {}
46
+        this.system_enterprise_res = []
47
+        this.enterprise_res = ''
48
+        return
49
+      }
50
+      if (this.isSuperManage) { // 获取超管下的当前企微信息
51
+        this.handleGetCurrentEnterpriseSys(newVal)
52
+        const res = this.enterpriseList.find(e => {
53
+          return e.manage_corp_list && e.manage_corp_list.length && e.manage_corp_list.some(corp => corp.corpid == newVal)
54
+        })
55
+        this.system_enterprise_res = res ? [String(res.group_id), newVal] : []
56
+      } else { // 获取当前企微信息
57
+        this.handleGetCurrentEnterprise(newVal)
58
+        this.enterprise_res = this.enterprise.corpid || ''
59
+      }
60
+    }
61
+  },
62
+  mounted() {
63
+    this.handleInitCorpOptions()
64
+  },
65
+  methods: {
66
+    // 企业筛选初始化
67
+    handleInitCorpOptions() {
68
+      if (this.isSuperManage) {//系统管理员
69
+        const enterpriseList = this.$store.state.authorize_corpList;
70
+        enterpriseList.forEach(item => {//为了el-cascader更改props
71
+          item.self_id = item.group_id.toString();
72
+          item.self_name = item.group_name;
73
+          item.manage_corp_list.forEach(item1 => {
74
+            item1.self_id = item1.corpid;
75
+            item1.self_name = item1.corp_name;
76
+          })
77
+        });
78
+        this.enterpriseList = enterpriseList
79
+      } else {
80
+        this.enterpriseList = this.$store.state.authorize_corpList;
81
+      }
82
+    },
83
+    handleGetCurrentEnterprise(currentCorpid) {
84
+      if (!currentCorpid) {
85
+        this.enterprise = {}
86
+      } else {
87
+        const res = this.enterpriseList.filter(v => v.corpid == currentCorpid)[0];
88
+        this.enterprise = res || {}
89
+      }
90
+    },
91
+    handleGetCurrentEnterpriseSys(currentCorpid) {
92
+      if (!currentCorpid) {
93
+        this.enterprise = {}
94
+      } else {
95
+        this.enterprise = {}
96
+        this.enterpriseList.forEach((item) => {
97
+          item.manage_corp_list.forEach((item1) => {
98
+            if (item1.corpid == currentCorpid) {
99
+              this.enterprise = item1
100
+            }
101
+          })
102
+        })
103
+      }
104
+    },
105
+    onChangeCorpidSystem(val) {
106
+      if (val && val.length) {
107
+        this.handleGetCurrentEnterpriseSys(val[1])
108
+      } else {
109
+        this.handleGetCurrentEnterpriseSys('')
110
+      }
111
+      this.handleEmit()
112
+    },
113
+    onChangeCorpid(val) {
114
+      this.handleGetCurrentEnterprise(val)
115
+      this.handleEmit()
116
+    },
117
+    handleEmit() {
118
+      this.$emit('input', this.enterprise.corpid || '')
119
+      this.$emit('change', this.enterprise.corpid ? this.enterprise : null)
120
+    },
121
+  }
122
+}
123
+</script>
124
+
125
+<style lang="scss" scoped>
126
+.select-cls {
127
+  /deep/ .el-input__inner {
128
+    width: 210px;
129
+  }
130
+  /deep/ &.el-select .el-input.is-focus .el-input__inner,
131
+  /deep/ &.el-select .el-input__inner:focus,
132
+  /deep/ &.el-cascader .el-input.is-focus .el-input__inner,
133
+  /deep/ &.el-cascader .el-input__inner:focus {
134
+    border-color: #DCDFE6;
135
+  }
136
+  /deep/ .el-input__suffix {
137
+    border-top-right-radius: 4px;
138
+    border-bottom-right-radius: 4px;
139
+    border: 1px solid #DCDFE6;
140
+    right: 0;
141
+    width: 30px;
142
+    background-color: #F1F1F1;
143
+    .el-input__icon {
144
+      color: #909399;
145
+    }
146
+  }
147
+  &.cascader {
148
+    /deep/ .el-input__suffix {
149
+      height: 32px;
150
+      top: 2px;
151
+    }
152
+  }
153
+}
154
+</style>

+ 8 - 63
project/src/components/manage/systemMsg.vue

@@ -5,15 +5,7 @@
5 5
       <!-- 日期 -->
6 6
       <datePicker :reset="reset" title="自定义" :quickFlag="true" :afferent_time="default_time" :clearFlag="false" @changeTime="onChangeTime" />
7 7
       <!-- 企微主体 -->
8
-      <div style="margin-right: 30px;" class="common-screen-item">
9
-        <label class="common-screen-label">企微主体</label>
10
-        <!-- 系统管理员 -->
11
-        <el-cascader v-if="$cookie.getCookie('isSuperManage') == 1" v-model="system_enterprise" size="small" :options="enterpriseList" :props="{value:'self_id',label:'self_name',children:'manage_corp_list'}" @change="onChangeCorpidSystem" clearable filterable placeholder="请选择" class="select-cls cascader" />
12
-        <!-- 非系统管理员 -->
13
-        <el-select v-else v-model="filter.corpid" size="small" filterable placeholder="请选择" @change="onChangeCorpid" clearable class="select-cls">
14
-          <el-option v-for="(item, index) in enterpriseList" :key="index+'enterpriseList'" :label="item.corp_name?item.corp_name:item.corp_full_name?item.corp_full_name:item.corpid" :value="item.corpid" />
15
-        </el-select>
16
-      </div>
8
+      <selfSelectCorp style="margin-right: 30px;" v-model="filter.corpid" @change="onChangeCorpid" />
17 9
       <!-- 成员 -->
18 10
       <selfInputV2 style="margin-left: -20px;"  :labelWidth="true" v-model="filter.user_name" label_name="成员" placeholder="请输入" @change="onChangeUserName" />
19 11
 
@@ -48,12 +40,14 @@
48 40
 <script>
49 41
 import selfChannel from '@/components/assembly/screen/channel.vue'
50 42
 import selfInputV2 from '@/components/assembly/screen/inputV2.vue'
43
+import selfSelectCorp from '@/components/assembly/screen/selectCorp.vue'
51 44
 import datePicker from '@/components/assembly/screen/datePicker.vue'
52 45
 
53 46
 export default {
54 47
   components: {
55 48
     selfChannel,
56 49
     selfInputV2,
50
+    selfSelectCorp,
57 51
     datePicker,
58 52
   },
59 53
   data() {
@@ -76,11 +70,6 @@ export default {
76 70
         pages: 0,
77 71
         total: 0,
78 72
       },
79
-
80
-      system_enterprise: [], // 企微主体数据
81
-      enterpriseList: [], // 企微主体数据
82
-      enterprise: {}, // 当前选择的企微信息
83
-
84 73
       filter: {
85 74
         sys_group_id: this.$cookie.getCookie('isSuperManage') == 1 ? sessionStorage.getItem('company_session_defaultCorp_level_1').toString() : '',
86 75
         time: DEFAULT_TIME, // 自定义日期
@@ -91,7 +80,6 @@ export default {
91 80
   },
92 81
   created() {
93 82
     this.initTableHeight()
94
-    this.handleInitCorpOptions()
95 83
     this.handleGetData()
96 84
   },
97 85
   methods: {
@@ -144,6 +132,11 @@ export default {
144 132
       this.pagination.page = 1
145 133
       this.handleGetData()
146 134
     },
135
+    // 监听企微主体筛选变化
136
+    onChangeCorpid(corp) {
137
+      this.pagination.page = 1
138
+      this.handleGetData()
139
+    },
147 140
     // 监听客服输入变化
148 141
     onChangeUserName(val) {
149 142
       this.filter.user_name = val
@@ -154,8 +147,6 @@ export default {
154 147
     onClickReset() {
155 148
       this.reset = !this.reset
156 149
       this.filter.time = this.default_time
157
-      this.system_enterprise = []
158
-      this.enterprise = {}
159 150
       this.filter.corpid = ''
160 151
       this.filter.user_name = ''
161 152
       this.pagination.page = 1
@@ -167,52 +158,6 @@ export default {
167 158
     initTableHeight() {
168 159
       this.height = document.documentElement.clientHeight - 240 > 400 ? document.documentElement.clientHeight - 240 : 400
169 160
     },
170
-    // S 企微主体数据
171
-    onChangeCorpidSystem(val) {//二级联选择器
172
-      if (val.length < 1) {
173
-        this.enterprise = {}
174
-      } else {
175
-        this.enterpriseList.forEach((item) => {
176
-          item.manage_corp_list.forEach((item1) => {
177
-            if (item1.corpid == val[1]) {
178
-              this.enterprise = item1
179
-            }
180
-          })
181
-        })
182
-      }
183
-      this.filter.corpid = this.enterprise.corpid || ''
184
-      this.pagination.page = 1
185
-      this.handleGetData()
186
-    },
187
-    onChangeCorpid(val) {
188
-      if (!val) {
189
-        this.enterprise = {}
190
-      } else {
191
-        const res = this.enterpriseList.filter(v => v.corpid == val)[0];
192
-        this.enterprise = res || {}
193
-      }
194
-      this.filter.corpid = this.enterprise.corpid || ''
195
-      this.pagination.page = 1
196
-      this.handleGetData()
197
-    },
198
-    // 企业筛选初始化
199
-    handleInitCorpOptions() {
200
-      if (this.$cookie.getCookie('isSuperManage') == 1) {//系统管理员
201
-        const enterpriseList = this.$store.state.authorize_corpList;
202
-        enterpriseList.forEach(item => {//为了el-cascader更改props
203
-          item.self_id = item.group_id.toString();
204
-          item.self_name = item.group_name;
205
-          item.manage_corp_list.forEach(item1 => {
206
-            item1.self_id = item1.corpid;
207
-            item1.self_name = item1.corp_name;
208
-          })
209
-        });
210
-        this.enterpriseList = enterpriseList
211
-      } else {
212
-        this.enterpriseList = this.$store.state.authorize_corpList;
213
-      }
214
-    },
215
-    // E 企微主体数据
216 161
   },
217 162
 }
218 163
 </script>