<template>
  <el-dialog
    :title="crud.status.title"
    append-to-body
    :before-close="crud.cancelCU"
    :visible.sync="crud.status.cu > 0 || crud.status.view > 0"
  >
    <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="110px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="库区:" prop="sect_code">
            <el-select
              v-model="form.sect_code"
              placeholder=""
              style="width: 200px"
            >
              <el-option
                v-for="item in sectList"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="策略类型:" prop="strategy_type">
            <el-select
              v-model="form.strategy_type"
              placeholder=""
              style="width: 200px"
            >
              <el-option
                v-for="item in strategyTypeList"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="类处理类型:" prop="class_type">
            <el-select
              v-model="form.class_type"
              placeholder=""
              style="width: 200px"
            >
              <el-option
                v-for="item in classTypeList"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="参数:" prop="param">
            <el-input v-model="form.param" style="width: 200px;" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="策略编码:" prop="param">
            <el-input v-model="form.strategy_code" style="width: 200px;" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="描述:" prop="remark">
            <el-input v-model="form.remark" :rows="3" type="textarea" style="width: 560px;" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div v-show="crud.status.cu > 0" slot="footer" class="dialog-footer">
      <el-button type="text" @click="crud.cancelCU">取消</el-button>
      <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
const defaultForm = {
  id: null,
  strategy_code: null,
  strategy_name: null,
  strategy_type: null,
  class_type: null,
  param: null,
  remark: null,
  is_used: null,
  ban: null,
  update_name: null,
  update_time: null,
  is_delete: null
}
import CRUD, { form, crud } from '@crud/crud'

export default {
  name: 'AddDialog',
  mixins: [form(defaultForm), crud()],
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    },
    openParam: {
      type: Object
    }
  },
  watch: {
    dialogShow: {
      handler(newValue, oldValue) {
        this.dialogVisible = newValue
      }
    }
  },
  data() {
    return {
      dialogVisible: false,
      strategyTypeList: [
        { 'label': '入库', 'value': '1' },
        { 'label': '出库', 'value': '2' },
        { 'label': '通用', 'value': '3' }
      ],
      classTypeList: [
        { 'label': '实现类', 'value': '1' },
        { 'label': '表达式', 'value': '2' },
        { 'label': '脚本', 'value': '3' }
      ],
      rules: {
        strategy_name: [
          { required: true, message: '策略名称不能为空', trigger: 'blur' }
        ],
        strategy_type: [
          { required: true, message: '策略类型不能为空', trigger: 'blur' }
        ],
        strategy_code: [
          { required: true, message: '策略编码不能为空', trigger: 'blur' }
        ],
        param: [
          { required: true, message: '参数不能为空', trigger: 'blur' }
        ],
        class_type: [
          { required: true, message: '类处理类型不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {
        })
    },
    close() {
      this.form = []
      this.$emit('update:dialogShow', false)
    }
  }
}
</script>

<style scoped>

</style>
