<template>
  <div class="ct">
    <el-dialog
      :visible.sync="addStoreDialog"
      width="65%"
      :show-close="false"
     :before-close="handleClose"
    >
      <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"
            ref="addStore"
            :rules="rules"
          >
            <el-form-item label="柜组名称:" prop="name">
              <el-input
                size="small"
                v-model="formData.name"
                style="width:240px"
                placeholder="请输入门店名称"
              />
            </el-form-item>
            <el-form-item label="门店类型:">
              <el-select
                size="small"
                v-model="formData.type"
                placeholder="请选择门店类型"
                style="width:240px"
              >
                <el-option
                  v-for="item in personList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="所属柜组:" prop="counter">
              <el-select
                size="small"
                v-model="formData.counter"
                placeholder="请选择所属柜组"
                style="width:240px"
              >
                <el-option
                  v-for="item in counter"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="柜组负责人:" prop="people">
              <el-select
                size="small"
                v-model="formData.people"
                placeholder="请选择柜组负责人"
                style="width:240px"
              >
                <el-option
                  v-for="item in personList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="门牌号:">
              <el-input
                size="small"
                v-model="formData.number"
                style="width:240px"
                placeholder="请输入门牌号"
              />
            </el-form-item>
            <el-form-item label="位置:">
              <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>
              <div style="display:inline-block;">
                <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">
        <el-button @click="handleCancel('addStore')" size="small">取 消</el-button>
        <el-button type="primary" @click="handleFinish('addStore')" size="small">确 定</el-button>
      </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;
    };
    return {
      addStoreDialog: false,
      data: generateData(),
        value: [1],
        value4: [1],
        renderFunc(h, option) {
          return <span>{ option.key } - { option.label }</span>;
        },
      formData: {
        name: "",
        code: "",
        people: "",
        type: "",
        number: "",
        area: ""
      },
      personList: [
        {
          id: "1",
          name: "张三"
        },
        {
          id: "2",
          name: "李四"
        }
      ],
      rules: {
        name: [{ required: true, message: "请输入柜组名称", trigger: "blur" }],
        people: [
          { required: true, message: "请选择活动负责人", trigger: "change" }
        ],
        counter: [
          { required: true, message: "请选择所属柜组", trigger: "change" }
        ]
      }
    };
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          this.addStoreDialog = false
        })
        .catch(_ => {});
    },
    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;
        }
      });
    },
    handleChange() {},

  },
  watch:{
      addStoreDialog(){
        if(this.addStoreDialog){
          if(this.$refs.addStore){
            this.$refs.addStore.resetFields();
          }
        }
      }
    }
};
</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 {
  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 60px;
}
.cs {
  display: flex;
}
</style>
