石广澎
2024-01-05 b2429057ae17e9f5b357435b0bff5f6cc0040b69
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
<template>
  <win-md :title="setting.title" @close="close" :width="'800px'" :loading="loading">
    <div class="section-container">
      <div class="section-left">
        <div class="header-row"><span class="title">选择人员:</span></div>
        <div class="section-body">
          <el-tree ref="tree" :data="treeData" node-key="id" :props="defaultProps" default-expand-all>
            <template slot-scope="{ node, data }">
              <div v-if="data.type != 'user'">{{ data.name }}</div>
              <div v-else class="leaf-node" :class="data.checked ? 'checked' : ''" @click="handleCheckItem(data)">
                <div>{{ data.name }}</div>
                <i style="font-size: 18px;font-weight: bold;color: #0d997c;margin-right: 10px"
                   class="el-icon-check"></i>
              </div>
            </template>
          </el-tree>
        </div>
      </div>
      <div class="section-right">
        <div class="header-row">
          <span class="title">已选:</span>
          <span class="btn" @click="handleClear">清空</span>
        </div>
        <div class="section-body">
          <div class="section-item" v-for="(item, index) in selectdSections" :key="index">
            <span class="label">{{ item.name }}</span>
            <span class="btn del-btn" @click="handleDel(item)">删除</span>
          </div>
        </div>
      </div>
    </div>
    <div slot="footer" align="center" class="dialog-footer">
      <my-button name="取消" site="form" @click="close"/>
      <my-button name="保存" site="form" @click="save"/>
    </div>
  </win-md>
</template>
 
<script>
import {userSelectDepartment, warehouseManagerList, warehouseManagerAdd} from '@/api/foudation/store';
import winMd from '@/components/win/win-md';
import myButton from '@/components/myButton/myButton';
 
export default {
  name: 'person',
  components: {winMd, myButton},
  props: {
    setting: {
      type: Object,
      default: () => {
      },
    },
  },
  data() {
    return {
      loading: true,
      loadingText: '加载中',
      selectdSections: [],
      treeData: [],
      formData: {},
      defaultProps: {
        children: 'children',
        label: 'name',
      },
      key: Math.random(),
    };
  },
  computed: {
    checkedKeys() {
      return this.selectdSections.map((v) => v.id);
    },
  },
  created() {
    if (this.setting.info) {
      this.formData = Object.assign({}, JSON.parse(this.setting.info));
    }
    this.init();
  },
  methods: {
    async init() {
      let managerRes = await warehouseManagerList({warehouseId: this.formData.id});
      this.selectdSections = managerRes.map((item) => {
        item.name = item.managerName;
        item.id = item.managerId;
        item.checked = true
        return item;
      });
      const res = await userSelectDepartment({agencyId: this.formData.agencyId});
      this.treeData = this.deepList([res]);
      this.key = Math.random();
      this.loading = false
    },
    deepList(list) {
      return list.map((item) => {
        if (item.children && item.children.length) {
          this.deepList(item.children);
        } else {
          item.checked = this.selectdSections.some(s=>item.id===s.id)
        }
        return item;
      });
    },
    handleCheckItem(data) {
      if (!data.checked) {
        this.selectdSections.push(data);
      } else {
        let idx = this.selectdSections.findIndex(item => item.id === data.id)
        if (idx !== -1) {
          this.selectdSections.splice(idx, 1)
        }
      }
      this.treeData[0].children.forEach((item, index) => {
        if (item.children) {
          item.children.forEach((child, childIndex) => {
            if (child.id == data.id) {
              this.$set(this.treeData[0].children[index].children[childIndex], 'checked', !child.checked);
            }
          });
        }
      });
    },
    handleDel(item) {
      this.handleCheckItem(item);
    },
    handleClear() {
      this.selectdSections.forEach((item) => {
        this.handleCheckItem(item);
      });
      this.selectdSections = [];
    },
    close() {
      this.$emit('close');
    },
    save() {
      if(this.selectdSections.length===0){
        this.$message.error('请选择库管员!');
        return
      }
      let params = {
        warehouseId: this.setting.id,
        warehouseManagerInfoList: [],
      };
      this.selectdSections.forEach((item) => {
        params.warehouseManagerInfoList.push({
          managerId: item.id,
          managerName: item.name,
        });
      });
      warehouseManagerAdd(params).then((res) => {
        this.$message.success('保存成功!');
        this.close();
        this.$emit('search');
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.section-container {
  height: 400px;
  display: flex;
  justify-content: space-between;
 
  ::v-deep {
    .el-tree-node__expand-icon.is-leaf {
      display: none;
    }
  }
}
 
.section-left,
.section-right {
  width: calc((100% - 20px) / 2);
  height: 100%;
  border: 1px solid #dcdfe6;
  padding: 10px;
  box-sizing: border-box;
  border-radius: 4px;
  overflow-y: auto;
}
 
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
 
  .title {
    color: #3d3d3d;
    font-size: 14px;
    font-style: normal;
    font-weight: 400;
  }
}
 
.section-body {
  margin-top: 20px;
}
 
.section-right {
  .btn {
    display: inline-block;
    width: 44px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    flex-shrink: 0;
    border-radius: 4px;
    color: #0d997c;
    border: 1px solid #0d997c;
    background: rgba($color: #0d997c, $alpha: 0.1);
    cursor: pointer;
  }
 
  .del-btn {
    color: #f9675b;
    border: 1px solid #f9675b;
    background: rgba($color: #f9675b, $alpha: 0.1);
  }
 
  .section-item {
    width: 44%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
  }
}
 
.leaf-node {
  width: 100%;
  height: 26px;
  line-height: 26px;
  padding-left: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
 
  i {
    display: none;
  }
}
 
.checked {
  i {
    display: inline-flex;
  }
}
</style>