<template>
  <cy-dialog ref="addStoreRef" :title="addSuccess ? '添加店铺' : '店铺准入'">
    <template v-if="!addSuccess">
      <el-form class="rule-form-orange" :model="ruleForm">
        <el-form-item label="店铺名称" style="width: 100%;">
          <el-select v-model="ruleForm.storeName" @change="storeNameChange">
            <el-option
              v-for="item in storeList"
              :label="item.name"
              :key="item.name"
              :value="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="店铺ID" style="width: 100%;">
          <el-input v-model="ruleForm.storeId" disabled></el-input>
        </el-form-item>
      </el-form>
    </template>
    <template v-else>
      <div class="success-tip">店铺添加成功。前往补充企业信息。</div>
    </template>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button v-if="!addSuccess" @click="handleCertain" type="primary">确 定</el-button>
      <el-button v-if="addSuccess" @click="toGoEnterprisePage" type="primary">确 定</el-button>
    </div>
  </cy-dialog>
</template>

<script>
export default {
  data() {
    return {
      addSuccess: false,
      ruleForm: {
        storeName: '',
        storeId: ''
      },
      storeList: []
    }
  },
  methods: {
    initForm() {
      this.ruleForm.storeName = ''
      this.ruleForm.storeId = ''
    },
    showAddStore() {
      this.$refs.addStoreRef.show = true
    },
    storeNameChange(val) {
      const find = this.storeList.find(el => el.name === val)

      if (find) {
        this.ruleForm.storeId = find.id
      }
    },
    closeDialog() {
      this.$refs.addStoreRef.show = false
    },
    async handleCertain() {},
    toGoEnterprisePage() {
      this.$emit('goEnterprise', true)
      this.closeDialog()
    }
  }
}
</script>

<style lang="scss" scoped>
.success-tip {
  width: 100%;
  height: 300px;
  line-height: 300px;
  font-size: #ebeb;
  padding-left: 100px;
}
</style>
