addGroup.vue 10.6 KB
Newer Older
wengjianling's avatar
wengjianling committed
1 2 3 4 5
<template>
  <div class="ct">
    <el-dialog
      title="创建子部门"
      :visible.sync="addDialog"
xd's avatar
xd committed
6
      width="58%"
wengjianling's avatar
wengjianling committed
7 8 9
      :show-close="false"
      :close-on-click-modal="false"
    >
xd's avatar
xd committed
10
      <el-form :model="addForm" label-width="auto" ref="addStore" :rules="rules" v-loading="formLoading" :element-loading-text="loadText">
xd's avatar
xd committed
11
        <el-form-item label="部门名称:" prop="label">
xd's avatar
xd committed
12 13
          <el-input
            size="small"
xd's avatar
xd committed
14
            v-model="addForm.label"
xd's avatar
xd committed
15 16 17 18
            placeholder="请输入部门名称"
            style="width: 50%;"
          />
        </el-form-item>
xd's avatar
xd committed
19
        <el-form-item label="上级部门:" prop="parentId">
xd's avatar
xd committed
20
          <el-cascader v-model="addForm.parentId" :options="orgTree" :props="deptOption" :show-all-levels="false"  clearable style="width: 50%;" @change="handleDpetChange"></el-cascader>
xd's avatar
xd committed
21
        </el-form-item>
xd's avatar
xd committed
22
        <el-form-item label="门店名称:" prop="oyStallName">
xd's avatar
xd committed
23 24
           <el-input
            size="small"
xd's avatar
xd committed
25
            v-model="addForm.oyStallName"
xd's avatar
xd committed
26 27 28 29
            placeholder="请输入门店名称"
            style="width: 50%;"
          />
        </el-form-item>
xd's avatar
xd committed
30
        <el-form-item label="门店Id:" prop="oyStallCode">
xd's avatar
xd committed
31 32
           <el-input
            size="small"
xd's avatar
xd committed
33
            v-model="addForm.oyStallCode"
xd's avatar
xd committed
34 35 36 37
            placeholder="请输入门店Id"
            style="width: 50%;"
          />
        </el-form-item>
xd's avatar
xd committed
38
        <el-form-item label="门店会员id:" prop="oyStallMemberId" >
xd's avatar
xd committed
39 40
          <el-input
            size="small"
xd's avatar
xd committed
41
            v-model="addForm.oyStallMemberId"
42
            placeholder="门店会员id"
xd's avatar
xd committed
43 44 45
            style="width: 50%;"
          />
        </el-form-item>
xd's avatar
xd committed
46
        <el-form-item label="设置主管:" prop="clerkIds"  >
47
          <el-cascader :props="props" ref="direcRef" v-model="deptId" :disabled="ifDisabled" :options="parentDeptList" :show-all-levels="false"  filterable style="width: 30%;margin-right:15px;" @change="handleParentChange" ></el-cascader>
xd's avatar
xd committed
48
          <el-select v-model="addForm.clerkIds" filterable multiple placeholder="请选择" style="width: 30%;" clearble  @change="handleMemberChange" :loading="optionLoading" loading-text="数据加载中">
xd's avatar
xd committed
49 50 51 52
            <el-option
              v-for="item in peopleList"
              :key="item.id"
              :label="item.userName"
53 54
              :value="item.id"
             >
xd's avatar
xd committed
55 56
            </el-option>
          </el-select>
xd's avatar
xd committed
57 58
        </el-form-item>
      </el-form>
wengjianling's avatar
wengjianling committed
59 60
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleAddCancel" size="small">取 消</el-button>
xd's avatar
xd committed
61
        <el-button type="primary" @click="handleAddFinish('addStore')" size="small">确 定</el-button>
xd's avatar
xd committed
62
      </span> 
wengjianling's avatar
wengjianling committed
63 64 65 66 67 68
    </el-dialog>
    <div></div>
  </div>
</template>

<script>
xd's avatar
xd committed
69
import { addGroup, getWxAllDeptList, getAllMemberList,getGroupById,getAllPeopleList,getOrgTree } from "@/api/in/mail";
wengjianling's avatar
wengjianling committed
70 71 72 73 74 75 76 77 78 79
import { log } from "util";

export default {
  props: {
    addDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
80 81 82 83 84 85 86 87 88 89
     // 检查名称
    const checkLabel = (rule, value, callback) => {
		  let labelReg = /^[\u4e00-\u9fa5A-Za-z0-9\-\_]*$/;
		  if (value == "") {
		    callback(new Error("请输入部门名称"));
		  } else if (!labelReg.test(value)) {//引入methods中封装的检查手机格式的方法
		    callback(new Error("只可以输入中文、字母、数字和减号!"));
		  } else {
		    callback();
		  }
xd's avatar
xd committed
90 91 92 93 94 95 96 97 98 99
    }
    // 限制id 
      const idNumber = (rule, value, callback) => {
		  let idReg = /^\+?(0|[1-9][0-9]*)$/
		  if (!idReg.test(value)) {
		    callback(new Error("只可以输入正整数"))
		  } else {
		    callback();
		  }
    }
100 101 102 103 104 105 106 107
    const memberNumber = (rule, value, callback) => {
		  let idReg = /^\+?(0|[1-9][0-9]*)$/
		  if (!idReg.test(value) && value != '') {
		    callback(new Error("只可以输入正整数"))
		  } else {
		    callback();
		  }
    }
wengjianling's avatar
wengjianling committed
108
    return {
xd's avatar
xd committed
109 110
      clerkIds: [],
      loadText: '加载中',
wengjianling's avatar
wengjianling committed
111
      treeData: [],
xd's avatar
xd committed
112 113
      group_name: "",
      shop_code: "",
wengjianling's avatar
wengjianling committed
114
      showTree: false,
xd's avatar
xd committed
115
      formLoading: false,
wengjianling's avatar
wengjianling committed
116
      params: {
xd's avatar
xd committed
117 118 119 120 121 122 123
        d_name: "",
        d_parentId: "",
        code: ""
      },
      checked: false,
      ////
      addForm: {
xd's avatar
xd committed
124 125 126 127 128
        label: '',
        parentId: '',
        oyStallName: '',
        oyStallMemberId: '',
        oyStallCode: '',
xd's avatar
xd committed
129
        clerkIds: [],
130
        oydeptId: ''
xd's avatar
xd committed
131
      },
xd's avatar
xd committed
132
      detail: 2,
133
      ifDisabled: false,
xd's avatar
xd committed
134
      deptId: '',
xd's avatar
xd committed
135 136 137
      // 上级部门
      parentDeptList: [],
      peopleList: [],
xd's avatar
xd committed
138
      orgTree: [],
139
      optionLoading: false,
xd's avatar
xd committed
140
      rules: {
xd's avatar
xd committed
141
        label: [
xd's avatar
xd committed
142
          { required: true, message: "请输入部门名称", trigger: "blur" },
xd's avatar
xd committed
143 144
          { max: 50, message: "长度在50个字符以内", trigger: "blur" }
        ],
xd's avatar
xd committed
145
        parentId: [{ required: true, message: "请选择上级部门", trigger: "change" }],
146
        oyStallCode: [{  required: true, validator: idNumber, trigger: "blur" }],
147
        oyStallMemberId: [{  required: false, validator: memberNumber, trigger: "blur" }],
xd's avatar
xd committed
148
        clerkIds: [{  required: true, message: "主管不能为空", trigger: "change" }]
wengjianling's avatar
wengjianling committed
149
      },
xd's avatar
xd committed
150 151 152
      deptOption: {
          value: 'id',
          children: 'children',
xd's avatar
xd committed
153 154 155 156 157 158
          lazy: true,
          emitPath: false,
          checkStrictly: true,
          lazyLoad (node, resolve) {
            const { level } = node;
            setTimeout(() => {
xd's avatar
xd committed
159
              const nodes = Array.from(level)
xd's avatar
xd committed
160 161 162 163
                .map(item => ({
                  value: level.id,
                  label: level.label,
                  leaf: level >= 2
xd's avatar
xd committed
164
                }))
xd's avatar
xd committed
165 166 167 168
              // 通过调用resolve将子节点数据返回,通知组件数据加载完成
              resolve(nodes);
            }, 1000);
          }
xd's avatar
xd committed
169
      },
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
      props: {
        value: 'id',
        children: 'children',
        lazy: true,
        emitPath: false,
        checkStrictly: true,
        lazyLoad (node, resolve) {
          const { level } = node;
          setTimeout(() => {
            const nodes = Array.from(level)
              .map(item => ({
                value: level.id,
                label: level.label,
                leaf: level >= 2
              }))
            // 通过调用resolve将子节点数据返回,通知组件数据加载完成
            resolve(nodes);
          }, 1000);
        }     
      }
xd's avatar
xd committed
190
    }
wengjianling's avatar
wengjianling committed
191 192
  },
  created() {
xd's avatar
xd committed
193
    this.formLoading = true
xd's avatar
xd committed
194
    this.getOrgTree()
xd's avatar
xd committed
195
    this.getDeptList()
wengjianling's avatar
wengjianling committed
196 197
  },
  methods: {
xd's avatar
xd committed
198 199 200 201 202 203
    handleDpetChange(val) {
      console.log(val,'val')   
    },
    getOrgTree() {
      getOrgTree().then(res => {
        this.orgTree = [res.data.organizations]
xd's avatar
xd committed
204
        this.formLoading = false
xd's avatar
xd committed
205 206
      });
    },
207 208 209
    handleParentChange(val) { 
      this.addForm.oydeptId = val
      this.optionLoading = true     
xd's avatar
xd committed
210 211
      this.clerkIds = []
      this.addForm.clerkIds = []
212
      this.getGroupMember(val)         
xd's avatar
xd committed
213 214
    },
    getDeptList() {
xd's avatar
xd committed
215
      getWxAllDeptList()
xd's avatar
xd committed
216
        .then(res => {
xd's avatar
xd committed
217 218
          console.log(res,'全部部门')
          this.parentDeptList = res.data
xd's avatar
xd committed
219 220
        })
        .catch(err => {
xd's avatar
xd committed
221
          console.log(err)
xd's avatar
xd committed
222 223
        });
    },
wengjianling's avatar
wengjianling committed
224
    handleAddCancel() {
xd's avatar
xd committed
225
      this.$emit("handleAddCancel")
wengjianling's avatar
wengjianling committed
226
    },
xd's avatar
xd committed
227
    handleAddFinish(formName) {   
xd's avatar
xd committed
228 229
      this.$refs[formName].validate((valid) => {
        if (valid) {
xd's avatar
xd committed
230 231
          this.formLoading = true
          this.loadText = "处理中"
xd's avatar
xd committed
232 233 234 235
          this.addForm.clerkIds = this.addForm.clerkIds + ""
          // let data = Object.assign(this.addForm,{ clerkIdss })
          // delete data.clerkIds
          addGroup(this.addForm).then(res => {
236
            if(res.result == "success") {
xd's avatar
xd committed
237 238
              if(res.data.isSuccessful == 0) {    
                this.addForm.clerkIds = this.clerkIds 
239
                this.$message.error("门店id不能重复")
xd's avatar
xd committed
240
                this.formLoading = false
241 242
              }else{
                this.$emit("handleAddFinish")
xd's avatar
xd committed
243
                this.formLoading = false
244 245
              }
            }else {
xd's avatar
xd committed
246
              this.addForm.clerkIds = this.clerkIds 
xd's avatar
xd committed
247
              this.$message.error(res.errorMsg)
xd's avatar
xd committed
248
              this.formLoading = false
xd's avatar
xd committed
249
            }
250
            
xd's avatar
xd committed
251 252 253
          })
        } else {
          return false;
xd's avatar
xd committed
254
        }
255
        })    
wengjianling's avatar
wengjianling committed
256
    },
xd's avatar
xd committed
257
    // 获取所有人员
xd's avatar
xd committed
258
    getGroupMember(id) {
259 260
      this.ifDisabled = true
      getAllPeopleList({ id }).then(res => {   
261 262
        this.peopleList = res.data       
        this.optionLoading = false
263
        this.ifDisabled = false
xd's avatar
xd committed
264
      })
265
    },
xd's avatar
xd committed
266 267 268 269 270 271 272
    handleMemberChange(val) {    
      this.clerkIds = val 
      // if(val.length == 0) {
      //   this.addForm.clerkIds = ''
      // }else {
      //   this.addForm.clerkIds = '验证用'
      // }
273
    }
274 275 276 277 278 279 280
  },
  watch: {
    deptId() {
      if (this.$refs.direcRef) {
        this.$refs.direcRef.dropDownVisible = false; //监听值发生变化就关闭它
      }
    }
wengjianling's avatar
wengjianling committed
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 343 344 345 346
  }
};
</script>

<style scoped>
.tree >>> .is-leaf + .el-checkbox .el-checkbox__inner {
  display: inline-block;
}
.tree >>> .el-checkbox .el-checkbox__inner {
  display: none;
}

.choose {
  padding: 16px;
  font-size: 16px;
  font-weight: bold;
  color: rgba(56, 56, 56, 1);
  box-sizing: border-box;
}
.title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* border-bottom: 1px solid #f8f8f8; */
  padding-bottom: 10px;
}
.transfer-footer {
  margin-left: 20px;
  padding: 6px 5px;
}
.ct >>> .el-dialog__header {
  border-bottom: 1px solid #f8f8f8;
}
.ct >>> .el-dialog__body {
  padding: 20px 40px;
}
.ct >>> .el-transfer-panel {
  width: 250px;
}
.circle {
  width: 30px;
  height: 30px;
  line-height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(208, 2, 27, 1);
  position: relative;
}
.circle >>> .icon {
  width: 28px;
  height: 28px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.br {
  border-top: 1px solid #f8f8f8;
  border-bottom: 1px solid #f8f8f8;
  padding: 24px 0;
}
.config_item {
  display: flex;
  flex-direction: row;
  align-items: center;
}
.config_name:before {
xd's avatar
xd committed
347
  content: "* ";
wengjianling's avatar
wengjianling committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
  color: red;
}
.config_name {
  width: 80px;
  text-align: center;
  margin-right: 10px;
}
.config_value {
  width: 230px;
}
.father_group {
  margin: 10px 0;
  width: 228px;
  height: 38px;
  border-radius: 4px;
xd's avatar
xd committed
363
  border: 1px solid #dcdfe6;
wengjianling's avatar
wengjianling committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
  position: relative;
}
.arrow_down {
  width: 0;
  height: 0;
  border-width: 5px;
  border-style: solid;
  border-color: #ccc transparent transparent transparent;
  position: absolute;
  right: 10px;
  top: 20px;
}
.arrow_up {
  width: 0;
  height: 0;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent #ccc transparent;
  position: absolute;
  right: 10px;
  top: 15px;
}
.tree_data {
  margin-left: 90px;
}
.father_name_text {
  line-height: 38px;
  padding-left: 15px;
}
.tips {
  width: 100%;
  text-align: center;
  color: red;
  margin: 5px 0;
}
</style>