liuying
2024-05-09 f4078b75fe80f03e58af3217bf642d0de118d1c9
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
<template>
  <a-modal
    title="PDA菜单授权"
    width="600px"
    :visible="visible"
    dialogClass="zero-modal"
    @cancel="handleCancel"
  >
    <div class="system-role-pda-menu-modal">
       <a-collapse v-model="activeKey">
         <a-collapse-panel v-for="(itema,indexa) in menus" :key="String(indexa)" :header="itema.workShopName">
           <div class="menu-lists">
             <div class="menu-item" v-for="(itemb,indexb) in (itema.wmsPdaPowerOutput || [])" :key="`${indexa}-${indexb}`">
               <a-checkbox :checked="itemb.isCheck" @change="onChangeChecked(itemb)">{{itemb.name}}</a-checkbox>
             </div>
           </div>
         </a-collapse-panel>
       </a-collapse>
    </div>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button type="primary" key="ok" @click="onConfirm">确认</a-button>
    </template>
  </a-modal> 
</template>
 
<script>
import { getPdaMenuList } from '@/api/modular/system/menuManage'
import { sysRoleGrantPdaMenu } from '@/api/modular/system/roleManage'
 
export default {
  name:'systemRolePdaMenuModal',
  emits:['update:visible'],
  props:{
    visible:{
      type:Boolean,
      default:false
    },
    roleid:{
      type:[Number,String,null],
      default:null
    }
  },
  data(){
    return {
      menus:[],
      activeKey:[]
    }
  },
  watch:{
    visible(newV,oldV){
      if (newV!==oldV){
        this.initShow()
      }
    }
  },
  methods:{
    handleCancel(){
      this.$emit('update:visible',false)
    },
    initShow(){
      if (this.visible) {
        this.getMenus()
      }
    },
    getMenus(){
      this.$loading.show()
      getPdaMenuList(this.roleid).then((d)=>{
        this.menus = d.data || []
        if (this.menus.length>0) {
          this.activeKey = ['0']
        }
        this.$loading.hide()
      }).catch(()=>{
        this.$loading.hide()
      })
    },
    onChangeChecked(row){
      row.isCheck = !row.isCheck
    },
    onConfirm(){
      this.$loading.show()
      this.handleUpdateAjax((f)=>{
        this.$loading.hide()
        if (f) {
          this.$message.success('操作成功!');
          this.handleCancel()
        }
      })
    },
    handleUpdateAjax(callback){
      let _params = {
        id:this.roleid,
        grantMenuIdList:[]
      }
      this.menus.forEach((itema)=>{
        if (itema.wmsPdaPowerOutput instanceof Array) {
          itema.wmsPdaPowerOutput .forEach((itemb)=>{
            if (itemb.isCheck){
              _params.grantMenuIdList.push(itemb.id)
            }
          })
        }
      })
      if (_params.grantMenuIdList.length<=0) {
        callback(false)
      } else {
        sysRoleGrantPdaMenu(_params).then(()=>{
          callback(true)
        }).catch(()=>{
          callback(false)
        })
      }
    }
  }
}
</script>
 
<style lang="less" scoped>
.system-role-pda-menu-modal{
  padding: 16px;
}
</style>