addGroup.vue 9.86 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="加载中">
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>
46
        <el-form-item label="设置主管:" prop="clerkId"  >
47
          <el-cascader :props="props" v-model="deptId" :disabled="ifDisabled" :options="parentDeptList" :show-all-levels="false"  filterable style="width: 30%;margin-right:15px;" @change="handleParentChange" ></el-cascader>
48
          <el-select v-model="clerkId" filterable multiple placeholder="请选择" style="width: 30%;" clearble  @change="handleMemberChange">
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 {
109
      clerkId: [],
wengjianling's avatar
wengjianling committed
110
      treeData: [],
xd's avatar
xd committed
111 112
      group_name: "",
      shop_code: "",
wengjianling's avatar
wengjianling committed
113
      showTree: false,
xd's avatar
xd committed
114
      formLoading: false,
wengjianling's avatar
wengjianling committed
115
      params: {
xd's avatar
xd committed
116 117 118 119 120 121 122
        d_name: "",
        d_parentId: "",
        code: ""
      },
      checked: false,
      ////
      addForm: {
xd's avatar
xd committed
123 124 125 126 127
        label: '',
        parentId: '',
        oyStallName: '',
        oyStallMemberId: '',
        oyStallCode: '',
128
        clerkId: ''
xd's avatar
xd committed
129
      },
xd's avatar
xd committed
130
      detail: 2,
131
      ifDisabled: false,
xd's avatar
xd committed
132
      deptId: '',
xd's avatar
xd committed
133 134 135
      // 上级部门
      parentDeptList: [],
      peopleList: [],
xd's avatar
xd committed
136
      orgTree: [],
xd's avatar
xd committed
137
      rules: {
xd's avatar
xd committed
138
        label: [
xd's avatar
xd committed
139
          { required: true, message: "请输入部门名称", trigger: "blur" },
xd's avatar
xd committed
140 141
          { max: 50, message: "长度在50个字符以内", trigger: "blur" }
        ],
xd's avatar
xd committed
142
        parentId: [{ required: true, message: "请选择上级部门", trigger: "change" }],
143
        oyStallCode: [{  required: true, validator: idNumber, trigger: "blur" }],
144 145
        oyStallMemberId: [{  required: false, validator: memberNumber, trigger: "blur" }],
        clerkId: [{  required: true, message: "主管不能为空", trigger: "change" }]
wengjianling's avatar
wengjianling committed
146
      },
xd's avatar
xd committed
147 148 149
      deptOption: {
          value: 'id',
          children: 'children',
xd's avatar
xd committed
150 151 152 153 154 155
          lazy: true,
          emitPath: false,
          checkStrictly: true,
          lazyLoad (node, resolve) {
            const { level } = node;
            setTimeout(() => {
xd's avatar
xd committed
156
              const nodes = Array.from(level)
xd's avatar
xd committed
157 158 159 160
                .map(item => ({
                  value: level.id,
                  label: level.label,
                  leaf: level >= 2
xd's avatar
xd committed
161
                }))
xd's avatar
xd committed
162 163 164 165
              // 通过调用resolve将子节点数据返回,通知组件数据加载完成
              resolve(nodes);
            }, 1000);
          }
xd's avatar
xd committed
166
      },
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
      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
187
    }
wengjianling's avatar
wengjianling committed
188 189
  },
  created() {
xd's avatar
xd committed
190
    this.formLoading = true
xd's avatar
xd committed
191
    this.getOrgTree()
xd's avatar
xd committed
192
    this.getDeptList()
wengjianling's avatar
wengjianling committed
193 194
  },
  methods: {
xd's avatar
xd committed
195 196 197 198 199 200
    handleDpetChange(val) {
      console.log(val,'val')   
    },
    getOrgTree() {
      getOrgTree().then(res => {
        this.orgTree = [res.data.organizations]
xd's avatar
xd committed
201
        this.formLoading = false
xd's avatar
xd committed
202 203 204
      });
    },
    handleParentChange(val) {      
205
      this.clerkId = []
xd's avatar
xd committed
206 207
      this.getGroupMember(val)
           
xd's avatar
xd committed
208 209
    },
    getDeptList() {
xd's avatar
xd committed
210
      getWxAllDeptList()
xd's avatar
xd committed
211
        .then(res => {
xd's avatar
xd committed
212 213
          console.log(res,'全部部门')
          this.parentDeptList = res.data
xd's avatar
xd committed
214 215
        })
        .catch(err => {
xd's avatar
xd committed
216
          console.log(err)
xd's avatar
xd committed
217 218
        });
    },
wengjianling's avatar
wengjianling committed
219
    handleAddCancel() {
xd's avatar
xd committed
220
      this.$emit("handleAddCancel")
wengjianling's avatar
wengjianling committed
221
    },
xd's avatar
xd committed
222 223 224
    handleAddFinish(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
225
          const clerkIds = this.clerkId + ""
xd's avatar
xd committed
226 227 228
          let data = Object.assign(this.addForm,{ clerkIds })
          delete data.clerkId
          addGroup(data).then(res => {
229 230 231 232 233 234 235
            if(res.result == "success") {
              if(res.data.isSuccessful == 0) {       
                this.$message.error("门店id不能重复")
              }else{
                this.$emit("handleAddFinish")
              }
            }else {
xd's avatar
xd committed
236
              this.$message.error(res.errorMsg)
xd's avatar
xd committed
237
            }
238
            
xd's avatar
xd committed
239 240 241
          })
        } else {
          return false;
xd's avatar
xd committed
242
        }
xd's avatar
xd committed
243 244
        });
      
wengjianling's avatar
wengjianling committed
245
      // console.log(addGroup)
xd's avatar
xd committed
246
      
wengjianling's avatar
wengjianling committed
247
    },
xd's avatar
xd committed
248
    // 获取所有人员
xd's avatar
xd committed
249
    getGroupMember(id) {
250 251
      this.ifDisabled = true
      getAllPeopleList({ id }).then(res => {   
xd's avatar
xd committed
252
        this.peopleList = res.data
253
        this.ifDisabled = false
xd's avatar
xd committed
254
      })
255 256 257 258 259 260 261 262 263 264
    },
    handleMemberChange(val) {
      console.log(val,'..');
      
      if(val.length == 0) {
        this.addForm.clerkId = ''
      }else {
        this.addForm.clerkId = '验证用'
      }
    }
wengjianling's avatar
wengjianling committed
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
  }
};
</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
331
  content: "* ";
wengjianling's avatar
wengjianling committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
  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
347
  border: 1px solid #dcdfe6;
wengjianling's avatar
wengjianling committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
  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>