addStore.vue 7.98 KB
Newer Older
xd's avatar
xd committed
1 2 3
<template>
  <div class="ct">
    <el-dialog
xd's avatar
xd committed
4
      :visible.sync="addStoreDialog"
xd's avatar
xd committed
5 6
      width="65%"
      :show-close="false"
xd's avatar
xd committed
7
     :before-close="handleClose"
xd's avatar
xd committed
8 9 10 11 12 13 14 15 16 17 18 19 20
    >
      <div class="choose">
        <div class="title">
          <div class="cg">添加门店</div>
          <div class="circle" @click="handleClose">
            <d2-icon-svg name="close" class="icon" />
          </div>
        </div>
        <div class="br">
          <el-form
            class="searchzone"
            :model="formData"
            label-width="auto"
xd's avatar
xd committed
21
            ref="addStore"
xd's avatar
xd committed
22 23
            :rules="rules"
          >
xd's avatar
xd committed
24
            <el-form-item label="门店名称:" prop="name">
xd's avatar
xd committed
25 26 27 28 29 30 31
              <el-input
                size="small"
                v-model="formData.name"
                style="width:240px"
                placeholder="请输入门店名称"
              />
            </el-form-item>
xd's avatar
xd committed
32
            <el-form-item label="门店类型:" prop="type">
xd's avatar
xd committed
33 34 35 36 37 38 39
              <el-select
                size="small"
                v-model="formData.type"
                placeholder="请选择门店类型"
                style="width:240px"
              >
                <el-option
xd's avatar
xd committed
40
                  v-for="item in storeType"
xd's avatar
xd committed
41 42 43 44 45 46
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
xd's avatar
xd committed
47
            <el-form-item label="门店负责人:" prop="people">
xd's avatar
xd committed
48 49
              <el-select
                size="small"
xd's avatar
xd committed
50 51
                v-model="formData.people"
                placeholder="请选择门店负责人"
xd's avatar
xd committed
52 53 54
                style="width:240px"
              >
                <el-option
xd's avatar
xd committed
55
                  v-for="item in personList"
xd's avatar
xd committed
56 57 58 59 60 61
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
xd's avatar
xd committed
62
            <el-form-item label="所属柜组:" prop="counter">
xd's avatar
xd committed
63 64
              <el-select
                size="small"
xd's avatar
xd committed
65 66
                v-model="formData.counter"
                placeholder="请选择所属柜组"
xd's avatar
xd committed
67 68 69
                style="width:240px"
              >
                <el-option
xd's avatar
xd committed
70
                  v-for="item in counter"
xd's avatar
xd committed
71 72 73 74 75
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
xd's avatar
xd committed
76 77
            </el-form-item>         
            <el-form-item label="门牌号:" prop="number">
xd's avatar
xd committed
78 79 80 81 82 83 84
              <el-input
                size="small"
                v-model="formData.number"
                style="width:240px"
                placeholder="请输入门牌号"
              />
            </el-form-item>
xd's avatar
xd committed
85
            <el-form-item label="位置:" prop="area">
xd's avatar
xd committed
86 87 88 89 90 91 92 93 94 95
              <el-input
                size="small"
                v-model="formData.area"
                style="width:240px"
                placeholder="请输入位置"
              />
            </el-form-item>
            <div class="cs">
              <el-form-item label="绑定店员:">
              </el-form-item>
xd's avatar
xd committed
96
              <div style="display:inline-block;">
xd's avatar
xd committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
                <el-transfer
                  style="text-align: left; display: inline-block"
                  v-model="value4"
                  :left-default-checked="[]"
                  :right-default-checked="[]"
                  :titles="['选择', '已选']"
                  :button-texts="['删除', '添加']"
                  @change="handleChange"
                  :data="data"
                >
                  <span slot-scope="{ option }"
                    >{{ option.key }} - {{ option.label }}</span
                  >
                </el-transfer>
              </div>
            </div>
          </el-form>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
xd's avatar
xd committed
117 118
        <el-button @click="handleCancel('addStore')" size="small">取 消</el-button>
        <el-button type="primary" @click="handleFinish('addStore')" size="small">确 定</el-button>
xd's avatar
xd committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    const generateData = _ => {
      const data = [];
      for (let i = 1; i <= 15; i++) {
        data.push({
          key: i,
          label: `备选项 ${i}`,
          disabled: i % 4 === 0
        });
      }
      return data;
    };
xd's avatar
xd committed
138 139 140 141 142 143 144 145 146
    // 中英文验证规则
    const nameValidate = (rule, value, callback) => {    
      let reg = /^[a-zA-Z\u4e00-\u9fa5]+$/  
      if (!reg.test(value)) {
          callback(new Error('含有非法字符(只能输入字母、汉字)!'))
        } else {
          callback()
        }  
    }
xd's avatar
xd committed
147
    return {
xd's avatar
xd committed
148
      addStoreDialog: false,
xd's avatar
xd committed
149 150 151 152 153 154 155 156 157 158
      data: generateData(),
        value: [1],
        value4: [1],
        renderFunc(h, option) {
          return <span>{ option.key } - { option.label }</span>;
        },
      formData: {
        name: "",
        code: "",
        people: "",
xd's avatar
xd committed
159
        type: "1",
xd's avatar
xd committed
160 161 162
        number: "",
        area: ""
      },
xd's avatar
xd committed
163 164 165 166 167 168 169 170 171 172
      storeType: [
        {
          id: "1",
          name: "普通门店"
        },
        {
          id: "2",
          name: "专柜"
        }
      ],
xd's avatar
xd committed
173 174 175 176 177 178 179 180 181 182
      personList: [
        {
          id: "1",
          name: "张三"
        },
        {
          id: "2",
          name: "李四"
        }
      ],
xd's avatar
xd committed
183 184 185 186 187 188 189 190 191 192
      counter: [
        {
          id: "1",
          name: "张三"
        },
        {
          id: "2",
          name: "李四"
        }
      ],
xd's avatar
xd committed
193
      rules: {
xd's avatar
xd committed
194 195 196
        name: [{ required: true, message: "请输入柜组名称", trigger: "blur" },
               { validator: nameValidate, trigger: "blur" },
               {  max: 50, message: '长度在50个字符以内', trigger: 'blur' }],
xd's avatar
xd committed
197
        people: [
xd's avatar
xd committed
198
          { required: true, message: "请选择门店负责人", trigger: "change" }
xd's avatar
xd committed
199
        ],
xd's avatar
xd committed
200 201 202
         type: [
          { required: true, message: "请选择门店类型", trigger: "change" }
        ],
xd's avatar
xd committed
203 204
        counter: [
          { required: true, message: "请选择所属柜组", trigger: "change" }
xd's avatar
xd committed
205 206 207 208 209 210 211
        ],
        number: [
          {  max: 50, message: '长度在50个字符以内', trigger: 'blur' },
        ],
        area: [
          {  max: 50, message: '长度在100个字符以内', trigger: 'blur' },
        ]
xd's avatar
xd committed
212 213 214 215
      }
    };
  },
  methods: {
xd's avatar
xd committed
216 217 218 219 220 221
    handleClose(done) {
      this.$confirm('确认关闭?')
        .then(_ => {
          this.addStoreDialog = false
        })
        .catch(_ => {});
xd's avatar
xd committed
222
    },
xd's avatar
xd committed
223 224 225 226 227 228 229 230 231 232 233 234 235
    handleCancel(formName) {
      this.$refs[formName].resetFields();
      this.addStoreDialog = false
    },
    handleFinish(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.addStoreDialog = false
        } else {
          console.log('error submit!!');
          return false;
        }
      });
xd's avatar
xd committed
236 237
    },
    handleChange() {},
xd's avatar
xd committed
238 239 240

  },
  watch:{
xd's avatar
xd committed
241 242 243 244
    addStoreDialog(){
      if(this.addStoreDialog){
        if(this.$refs.addStore){
          this.$refs.addStore.resetFields();
xd's avatar
xd committed
245 246
        }
      }
xd's avatar
xd committed
247
    }
xd's avatar
xd committed
248
    }
xd's avatar
xd committed
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
};
</script>

<style scoped>
.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 {
  padding: 0 !important;
}
.ct >>> .el-dialog__body {
  padding: 0;
}
.ct >>> .el-transfer-panel {
xd's avatar
xd committed
278
  width: 180px;
xd's avatar
xd committed
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
}
.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 60px;
}
.cs {
  display: flex;
}
</style>