qq_41295110
9 天以前 c466006a64f1cbbcbf04e0ae4a2d73de302aa92a
1
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<template>
  <div style="padding: 10px;">
    <el-row>
      <el-button type="primary" @click="handleSaver">保存</el-button>
      <el-button type="primary" @click="close">退出</el-button>
    </el-row>
    <el-row>
      <el-col :span="8" style="padding-right:5px ;">
        <el-tree :data="treeOptions" :props="defaultProps" :expand-on-click-node="false"
          :filter-node-method="filterNode" ref="tree" node-key="id" :default-expand-all="false" highlight-current
          @node-click="handleNodeClick" />
      </el-col>
      <el-col :span="8" style="box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)">
        <el-row style="margin-top: 10px;">
          <el-radio-group v-model="HSouceBillType" @input="typeInput">
            <el-radio-button label="yh">用户</el-radio-button>
            <el-radio-button label="js">角色</el-radio-button>
          </el-radio-group>
        </el-row>
        <div class="btnQueryBox">
          <div style="flex: 1;">
            <el-button type="success" size="mini" icon="refresh" @click="getList">刷新</el-button>
            <el-button type="success" size="mini" icon="search" @click="handleNodeClick">查看</el-button>
          </div>
          <div>
            <el-button icon="el-icon-download" size="mini" title="导出" @click="handleExport"></el-button>
          </div>
        </div>
        <div class="tableBox" v-loading="loading">
          <el-table :data="tableData" ref="tableData" max-height="750" @selection-change="handleSelectionChange" border
            v-if="tableShow">
            <template v-for="(item, index) in btList">
              <el-table-column type="selection" width="55" align="center" :fixed="item.fixed"
                v-if="item.type == 'checkbox'" :key="index" />
              <el-table-column :align="item.align" :prop="item.field" :label="item.title" :width="item.width"
                :key="item.sorderid" v-else-if="!item.hide && item.type != 'checkbox'" :sortable="item.sort"
                show-overflow-tooltip :fixed="item.fixed">
                <template slot-scope="{row,  column }">
                  <el-checkbox v-model="checked" v-if="item.type == 'checkbox'"></el-checkbox>
                  <div :style="item.style">{{ row[column.label] }}</div>
                </template>
              </el-table-column>
            </template>
          </el-table>
          <pagination v-show="total > 0" :total="total" :page.sync="page" :limit.sync="pageSize" :pageSizes="pageSizes"
            @pagination="currentPage" />
        </div>
      </el-col>
      <el-col :span="8" style="padding-left: 10px;">
        <el-table :data="queryData" ref="queryMultipleTable" max-height="800" @selection-change="handleQueryChange"
          border v-if="tableQueryShow">
          <el-table-column type="selection" width="55" prop="AuthorityID" align="center" />
          <el-table-column align="center" prop="AuthorityID" label="是否权限" show-overflow-tooltip>
            <template slot-scope="scope">
              <span style="color: green;" v-if="scope.row.AuthorityID == 1">是</span>
              <span v-else-if="scope.row.AuthorityID == 0">否</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="gnms" label="功能说明" show-overflow-tooltip />
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>
 
<script>
import axios from 'axios'
export default {
  name: 'XtUserRightQuery',
  components: {},
  props: {
    openPage: { type: String, },
  },
  data() {
    return {
      HModName: 'Xt_UserRightQuery',
      selQueryRows: [],
      nodeData: {},
      linterid: '',
      HSouceBillType: 'yh',
      queryData: [],
      tableQueryShow: false,
      //树结构
      treeOptions: [],
      defaultProps: {
        children: "children",
        label: "title"
      },
      tableShow: true,
      sGnbm: '',
      organizationList: JSON.parse(sessionStorage.getItem('organizationList')),//组织列表
      baseURL: process.env.VUE_APP_BASE_API,
      rowForm: {},
      // 弹出层标题
      title: "",
      // 选中数组
      ids: [],
      // 遮罩层
      loading: true,
      tyResList: [],//列表(接口数据)
      btList: [],//表头列表显示
      btResList: [],
      tableData: [],//列表(分页显示)
      allTableData: [],
      pageSizes: [50, 100, 500, 5000, 50000],
      page: 1,
      pageSize: 0,
      total: 0,
    };
  },
  created() {
    this.getTreeselect()
    this.getList()
  },
  methods: {
    typeInput() {
      this.tableShow = false
      this.loading = true
      this.ids = []
      this.getList()
    },
    getTreeselect() {
      axios.get(this.baseURL + 'Gy_MaintenanceMode/PowerLoadTree').then(response => {
        let data1 = response.data
        if (data1.count == 1) {
          let map = {};
          let treeData = [];
          data1.data.forEach(it => {
            map[it.id.toUpperCase()] = it;    //ID为每个节点的id
          })
          //生成结果集
          data1.data.forEach(it => {
            const parent = map[it.ParentID.toUpperCase()];   //ParentID为父节点的id
            if (parent) {
              if (!Array.isArray(parent.children)) parent.children = [];
              parent.children.push(it);
            } else {
              treeData.push(it)
            }
          })
          this.treeOptions = treeData
        }
      }).catch(error => {
        this.$modal.msgError("接口请求失败!");
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.nodeData = data
      if (!data.id) {
        this.sGnbm = '权限管理-用户'
      } else {
        this.sGnbm = data.id
      }
      this.queryData = []
      this.linterid = ''
      let text = ''
      if (this.HSouceBillType == 'yh') {
        this.linterid = this.rowForm.用户编码
        text = '请选择一位用户!'
      } else if (this.HSouceBillType == 'js') {
        this.linterid = this.rowForm.HGroupID
        text = '请选择一个角色!'
      }
      if (this.linterid) {
        axios.get(this.baseURL + '/PublicPageMethod/PowerList', {
          params: {
            czybm: this.linterid,
            sGnbm: this.sGnbm,
            HSouceBillType: this.HSouceBillType,
          },
        }).then(response => {
          this.queryData = response.data.data
          this.tableQueryShow = true
          this.$nextTick(() => {
            if (this.queryData.length > 0) {
              this.queryData.forEach(row => {
                if (row.AuthorityID) {
                  this.$refs.queryMultipleTable.toggleRowSelection(row);
                }
              });
            } else {
              this.$refs.queryMultipleTable.clearSelection();
            }
          })
        }).catch(error => {
          this.$modal.msgError("接口请求失败!");
        });
      } else {
        this.$modal.msgError(text);
      }
    },
    //列表数据
    getList() {
      this.pageSize = 50
      this.tableShow = false
      this.loading = true
      let url = ''
      if (this.HSouceBillType == 'yh') {
        url = '/Xt_User/list'
        this.btList = [{ type: 'checkbox', fixed: 'left' }
          , { field: 'hmainid', title: '单据ID', hide: true }
          , { field: '用户编码', title: '用户编码' }
          , { field: '用户名称', title: '用户名称' }
          , { field: '用户类型', title: '用户类型' }
          , { field: '对应班组', title: '对应班组' }
          , { field: '对应职员', title: '对应职员' }
          , { field: '对应保管', title: '对应保管' }
          , { field: '对应验收', title: '对应验收' }
          , { field: '对应业务员', title: '对应业务员' }
          , { field: '对应部门', title: '对应部门' }
          , { field: '对应仓库', title: '对应仓库' }
          , { field: '对应调入仓库', title: '对应调入仓库' }
          , { field: '对应供应商', title: '对应供应商' }
          , { field: '对应CLOUD账号', title: '对应CLOUD账号' }
          , { field: '对应CLOUD组织', title: '对应CLOUD组织' }]
      } else if (this.HSouceBillType == 'js') {
        url = '/Xt_UserGroup/list'
        this.btList = [{ type: 'checkbox', fixed: 'left' }
          , { field: 'HGroupID', title: 'HGroupID', sort: true, hide: true }
          , { field: '角色', title: '角色' }
          , { field: '级别', title: '级别' }
          , { field: '说明', title: '说明' }]
      }
      //列表
      axios.get(this.baseURL + url, {
        params: {
          "sWhere": '',
          "user": sessionStorage["HUserName"],
        },
      }).then(response => {
        this.tyResList = response.data.data//总数据
        let data1 = response.data
        this.allTableData = data1.data
        if (data1.code == 1) {
          this.total = data1.data.length;
          for (var i = 1; i < this.btList.length; i++) {
            this.btResList.push({ ColmCols: this.btList[i].field })
          }
          this.tableData = this.getPage(this.page, this.allTableData)//无分页接口分页
          this.tableShow = true
          this.loading = false
        }
      }).catch(error => {
        this.$modal.msgError("接口请求失败!");
      });
    },
    // 单选框选中数据
    handleSelectionChange(selection) {
      if (selection.length > 1) {
        const del_row = selection.shift()
        this.$refs.tableData.toggleRowSelection(del_row, false) //设置这一行取消选中
      }
      this.rowForm = {}
      if (this.HSouceBillType == 'yh') {
        this.ids = selection.map(item => item.用户编码)
      } else if (this.HSouceBillType == 'js') {
        this.ids = selection.map(item => item.HGroupID)
      }
      this.rowForm = selection[0]
    },
    handleQueryChange(selection) {
      this.selQueryRows = selection
      this.queryData.forEach(row => {
        row.AuthorityHID = this.selQueryRows.some(selectedRow => selectedRow.hgnbm === row.hgnbm) ? 1 : 0;
      });
    },
    //退出
    close() {
      const obj = { fullPath: this.$route.path, path: this.$route.path, name: this.$route.name, };
      this.$tab.closePage(obj).then(res => {
        const latestView = res.visitedViews.slice(-1)[0]
        if (latestView) {
          this.$router.push(latestView.fullPath)
        } else {
          if (obj.name === 'Dashboard') {
            this.$router.replace({ path: '/redirect' + obj.fullPath })
          } else {
            this.$router.push('/')
          }
        }
      });
    },
    handleSaver() {
      var sSubStr = JSON.stringify(this.queryData);
      var sMainSub = this.sGnbm + ';' + sSubStr + ';' + this.linterid + ";" + this.HSouceBillType;
      axios({
        method: 'post',
        url: this.baseURL + "/Gy_MaintenanceMode/SaverPower",
        data: {
          'msg': sMainSub
        },
      }).then(response => {
        if (response.data.count == 1) {
          this.subDisabled = true//设置保存按钮不可用
          this.$modal.msgSuccess(response.data.Message);
          this.handleNodeClick(this.nodeData)
        }
      }).catch(error => {
        this.$modal.msgError("接口请求失败!");
      });
    },
    getPage(page, list) {
      let sindex = (parseInt(page) - 1) * this.pageSize
      let eindex = parseInt(page) * this.pageSize
      let newList = list.slice(sindex, eindex)
      return newList
    },
    currentPage(val) {
      this.page = val.page
      setTimeout(() => {
        this.tableData = this.getPage(this.page, this.allTableData)
      }, 100)
    },
    //导出
    handleExport() {
      const ws = this.$XLSX.utils.json_to_sheet(this.tyResList); // 将数据转换为工作表
      const wb = this.$XLSX.utils.book_new(); // 创建一个新的工作簿
      this.$XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); // 将工作表添加到工作簿中,并命名为"Sheet1"
      this.$XLSX.writeFile(wb, this.HSouceBillType+`_${new Date().getTime()}.xlsx`); // 导出文件      
    },
  }
};
</script>
<style>
.xsckdBox .el-date-editor.el-input {
  width: 100%;
}
 
.btnQueryBox {
  margin-top: 10px;
  padding: 5px;
  border-top: 1px solid #ebebeb;
  display: flex;
  justify-content: right;
}
</style>