<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-02-05 10:50:57
 * @LastEditors  : 无尘
 * @LastEditTime : 2020-03-02 10:55:50
 -->
<!--
  系统模板设置
  <custom-set v-if="setVisible" :templateObj="templateObj" :storeList="storeList" @closeSet="closeSet"></custom-set>
  import customSet from '@/components/app/cloudDaily/custom-set.vue';
  -->
<template>
  <el-dialog width="600px" title="模板设置" :visible.sync="setVisible" append-to-body :before-close="handleClose">
    <div class="m-t-20">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="模板名称" prop="title">
          <limitInput :inputWidth="340" :limitClass="'limit-color'" :inputValue.sync="ruleForm.title" :holder="''" :disflag="false" :getByType="'word'" :maxLength="10"> </limitInput>
        </el-form-item>
        <el-form-item label="模板描述" prop="description">
          <limitInput :inputWidth="340" :limitClass="'limit-color'" :inputValue.sync="ruleForm.description" :holder="''" :disflag="false" :getByType="'word'" :maxLength="20"> </limitInput>
        </el-form-item>
        <el-form-item label="门店类型" prop="storeType">
          <div class="store-type-cell m-b-20" v-for="(item, index) in storeList" :key="item.name + index">
            <el-radio v-model="ruleForm.storeType" :label="item.id" :disabled="item.disabled">{{ item.name }}</el-radio>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import limitInput from '@/components/limit-input.vue';
/* eslint-disable */
  export default {
    props: {
      templateObj: {
        type: [Array, Object],
        default () {
          return {};
        }
      },
      storeList: {
        type: [Array, Object],
        default () {
          return [];
        }
      },
    },
    data() {
      return {
        setVisible: true,
        rules: {
          title: [
            { required: true, message: '请输入模板名称', trigger: 'blur' },
          ],
          description: [
            { required: true, message: '请输入模板描述', trigger: 'blur' },
          ],
          storeType: [
            { required: true, message: '请选择门店类型', trigger: 'change' }
          ],
        },
        ruleForm: {
          title: '',
          description: '',
          storeType: ''
        }
      };
    },
    computed: {},
    watch: {
      templateObj(val) {
        const that = this;
        if(Object.keys('val').length) {
          that.ruleForm = JSON.parse(JSON.stringify(val));
        }
      }
    },
    methods: {
      
      /**
       * 关闭弹窗
       */
      handleClose(done) {
        const that = this;
        done();
        that.$emit('closeSet','close');
        that.selectId = '';
      },
      cancel() {
        const that = this;
        that.$emit('closeSet','close');
        that.selectId = '';
      },
      /**
       * 确定
       */
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            that.$emit('closeSet', that.ruleForm);
          } else {
            console.log('error submit!!');
            return false;
          }
        });
        
      }
    },
    components: {limitInput},
    mounted() {
      const that = this;
      that.ruleForm = JSON.parse(JSON.stringify(that.templateObj));
    }
  };
</script>
<style scoped>
  .m-t-5 {
    margin-top: 5px;
  }
  .m-l-40 {
    margin-left: 40px;
  }

  .dialog-top {
    margin-bottom: 20px;
  }

  .dialog-top img {
    width: 40px;
    height: 40px;
    border: 1px solid #e4e7ed;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 10px;
  }

  .dialog-top span {
    font-size: 14px;
    font-weight: 600;
    color: #303133;
  }

  .select-info {
    display: inline-block;
    vertical-align: middle;
  }

  .dialog-operate {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .pagination-content {
    text-align: right;
  }

  .dialog-form {
    width: 430px;
    padding-top: 20px;
  }

  .w-215 {
    width: 215px;
  }

  .w-115 {
    width: 115px;
  }

  .select-tree-wrap {
    height: 445px;
    overflow-y: auto;
    border: 1px solid #e4e7ed;
  }
</style>
