<template>
  <el-dialog
    @close="closeDialog"
    :title="!dataForm.seriesId ? this.$i18n.t('crud.addTitle') : this.$i18n.t('temp.modify')"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="系列名称" prop="seriesName">
        <el-input v-model="dataForm.seriesName"></el-input>
      </el-form-item>
      <el-form-item label="模板用途" prop="seriesUsage">
        <el-select v-model="usageList" clearable filterable multiple>
          <el-option key="smallcard" label="小卡" value="smallcard,YXK,ZJXK,DBYXK,DBZJXK,YYYXK,YYZJXK"></el-option>
          <el-option key="squarecard" label="大方卡" value="squarecard,FK"></el-option>
          <el-option key="XFK" label="小方卡" value="XFK"></el-option>
          <el-option key="badge" label="徽章" value="badge,HZ"></el-option>
          <el-option key="postcard" label="明信片" value="postcard,MXP,YSZMXP"></el-option>
          <el-option key="bookmark" label="书签" value="bookmark,SQ"></el-option>
          <el-option key="tipscard" label="手幅" value="tipscard,SF"></el-option>
          <el-option key="covercard" label="直拍封面" value="covercard,ZP"></el-option>
          <el-option key="stub" label="票根" value="stub,PG"></el-option>
          <el-option key="FP" label="3寸花式拍立得" value="FP,polaroid"></el-option>
          <el-option key="4CFP" label="4寸花式拍立得" value="4CFP"></el-option>
          <el-option key="5CFP" label="5寸花式拍立得" value="5CFP"></el-option>
          <el-option key="SBSGG" label="竖版四宫格" value="SBSGG"></el-option>
          <el-option key="TZSGG" label="田字四宫格" value="TZSGG"></el-option>
          <el-option key="3CFZFP" label="3寸仿真拍立得" value="3CFZFP"></el-option>
          <el-option key="4CFZFP" label="4寸仿真拍立得" value="4CFZFP"></el-option>
          <el-option key="5CFZFP" label="5寸仿真拍立得" value="5CFZFP"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="排序" prop="seq">
        <el-input v-model="dataForm.seq" type="number"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button class="default-btn" @click="visible = false">{{$t("crud.filter.cancelBtn")}}</el-button>
      <el-button class="default-btn primary-btn" type="primary" @click="dataFormSubmit()">{{$t("crud.filter.submitBtn")}}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        seriesId: null,
        seriesName: null,
        shopId: 1
      },
      usageList:[],
      dataRule: {
      }
    }
  },
  methods: {
    init (series) {
      this.visible = true
      this.$nextTick(() => {
        if (series) {
          this.$http({
            url: this.$http.adornUrl('/prod/prodTemplateSeries/info/' + series.seriesName),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            this.dataForm = data
            // this.usageList = data.templateUsage.split(",")
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.dataForm.seriesUsage = this.usageList.join(",");
          this.$http({
            url: this.$http.adornUrl('/prod/prodTemplateSeries'),
            method: this.dataForm.seriesId ? 'put' : 'post',
            data: this.$http.adornData(this.dataForm)
          }).then(({data}) => {
            this.$message({
              message: this.$i18n.t('publics.operation'),
              type: 'success',
              duration: 500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          })
        }
      })
    },
    closeDialog(){
      this.dataForm = {}
    }
  }
}
</script>
