<template>
  <el-dialog
    title="编辑门店名称"
    :visible.sync="dialogVisible"
    width="750px"
    :append-to-body="true"
    :before-close="close"
    :destroy-on-close="true"
    :close-on-click-modal="false"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="120px"
      style="max-height: 375px;overflow: auto;"
    >
      <el-form-item label="门店名称" prop="name" style="width: 60%;margin: 40px 0">
          <el-input v-model="form.name" placeholder="例如xxxx店, 对用户可见" />
        </el-form-item>
      </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" :disabled="loading" @click="saveClick">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { updateSaleSite, getSaleSiteDetail } from "@/api/admin/salesite";
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    editId: [Number, String] //  编辑用
  },
  data() {
    return {
      loading: false,
      // 表单参数
      form: {
        name:"",
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "请输入门店名称", trigger: "blur" }
        ],
      },
      //招商推广宣传图
      picture: []
    };
  },
  created() {
    // 是编辑
    if (this.editId) {
      this.getDetail();
    }
  },
  methods: {
    getDetail() {
      this.loading = true;
      getSaleSiteDetail(this.editId).then(res => {
        this.form.name = res.data.name
        this.loading = false
      }).catch(() => {
          this.loading = false;
        });
    },
    //确定修改
    saveClick(){
      this.loading = true
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitForm(this.form);
        } else {
          this.loading = false;
          this.$message.error('门店名称不能为空')
          return false;
        }
      });
    },
    //保存
    submitForm(params) {
      if (this.editId) {
        params.channelId = this.editId;
      }
      updateSaleSite(params).then(response => {
        this.loading = false
        this.$message.success('编辑成功')
        this.$emit('saveSuccess')
        this.close()
      }).catch(() => {
        this.loading = false
      });
    },
    //关闭
    close() {
      this.$emit("close");
    }
  }
};
</script>

<style scoped lang="scss">
.tag {
  margin-right: 15px;
  width: 90px;
  text-align: center;
  cursor: pointer;
}

.tag-select {
  background-color: #409eff !important;
  border-color: #409eff !important;
  color: #fff !important;
}

.cover-content-item {
  width: 220px;
  float: left;
  position: relative;
  .cover-img {
    width: 200px;
    height: 100px;
  }
  .cover-mark {
    position: absolute;
    top: 0px;
    right: 28px;
    z-index: 1;
    color: red;
    cursor: pointer;
    visibility: hidden;
  }
  .select {
    visibility: visible !important;
  }
}

.dialog-footer {
  text-align: center;
}
</style>

<style lang="scss">
.ygp-form-items {
  .el-form-item {
    padding: 0 5px;
  }
  .el-form-item__label {
    line-height: 1.2;
    padding-bottom: 8px;
    word-break: break-all;
    word-wrap: break-word;
    color: #333;
  }

  .el-form-item__error {
    position: relative;
    top: auto;
    left: auto;
  }

  .el-form-item.is-desc_text {
    .el-form-item__label {
      display: none;
    }
  }
}
</style>
