<template>
  <div>
    <el-dialog title="实施反馈" :visible.sync="dialogInfo.show" :close-on-click-modal="true" width="80%">
      <div>
        <el-form ref="form" :model="form" label-width="160px" :rules="rules">
          <el-row>
            <el-col :span="12">
              <el-form-item label="执行措施编码">
                <el-input v-model="form.sid" placeholder="请输入执行措施编码" />
                <div>多个措施以分号分隔</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="奖惩名单名称" prop="mdmc">
                <el-input v-model="form.mdmc" placeholder="请输入奖惩名单名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="主体名称" prop="ztmc">
                <el-input v-model="form.ztmc" placeholder="请输入主体名称" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主体类别" prop="ztlb">
                <el-select v-model="form.ztlb" placeholder="请选择主体类别">
                  <el-option
                    v-for="item in ztlbOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="奖惩类型" prop="jclb">
                <el-select v-model="form.jclb" placeholder="请选择奖惩类型">
                  <el-option
                    v-for="item in jclbOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="form.ztlb === '0'" :span="12">
              <el-form-item label="主体统一社会信用代码">
                <el-input v-model="form.tyshxydm" placeholder="请输入主体统一社会信用代码" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="form.ztlb === '0'">
            <el-col :span="12">
              <el-form-item label="主体工商注册号">
                <el-input v-model="form.qyzch" placeholder="请输入主体工商注册号" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主体组织机构代码">
                <el-input v-model="form.zzjgdm" placeholder="请输入主体组织机构代码" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="form.ztlb === '1'">
            <el-col :span="12">
              <el-form-item label="主体证件类型" :prop="form.ztlb === '1'? 'zjlx' : ''">
                <el-select v-model="form.zjlx" placeholder="请选择主体证件类型">
                  <el-option
                    v-for="item in zjlxOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主体证件号码" :prop="form.ztlb === '1'? 'zjhm' : ''">
                <el-input v-model="form.zjhm" placeholder="请输入主体证件号码" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="涉及金额" prop="sjje">
                <el-input-number v-model="form.sjje" :precision="4" :controls="false" placeholder="请输入涉及金额" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="奖惩说明" prop="jcsm">
                <el-input v-model="form.jcsm" placeholder="请输入奖惩说明" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="事项编码" prop="qlbm">
                <el-input v-model="form.qlbm" placeholder="请输入事项编码" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="事项名称">
                <el-input v-model="form.qlmc" placeholder="请输入事项名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="名单查询流水号">
                <el-input v-model="form.cxcode" placeholder="请输入名单查询流水号" />
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row>
            <el-col :span="24">
              <el-form-item label="执行措施内容" prop="csnr">
                <el-input v-model="form.csnr" type="textarea" :rows="4" placeholder="请输入执行措施内容" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer">
        <el-button @click="cancelDiaolog">取 消</el-button>
        <el-button type="primary" @click="comfirmData('form')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { entLockMeasureFeedBack } from '@/api/search.js'
export default {
  data() {
    return {
      dialogInfo: {
        show: false
      },
      form: {
        sid: '',
        mdmc: '',
        ztmc: '',
        ztlb: '',
        jclb: '',
        tyshxydm: '',
        qyzch: '',
        zzjgdm: '',
        zjlx: '',
        zjhm: '',
        csnr: '',
        sjje: '',
        jcsm: '',
        qlbm: '',
        qlmc: '',
        cxcode: ''
      },
      ztlbOptions: [
        {
          value: '0',
          label: '法人'
        },
        {
          value: '1',
          label: '自然人'
        }
      ],
      jclbOptions: [
        {
          value: '1',
          label: '奖惩'
        },
        {
          value: '2',
          label: '激励'
        }
      ],
      zjlxOptions: [
        {
          value: '10',
          label: '身份证'
        },
        {
          value: '20',
          label: '军人身份有效证件'
        },
        {
          value: '30',
          label: '港澳居民往来大陆通行证'
        },
        {
          value: '40',
          label: '台湾居民往来大陆通行证'
        },
        {
          value: '50',
          label: '护照'
        },
        {
          value: '90',
          label: '其他法定认可的证件'
        }
      ],
      rules: {
        mdmc: [
          { required: true, message: '请选择奖惩名单', trigger: ['blur', 'select'] }
        ],
        ztmc: [
          { required: true, message: '请输入主体名称', trigger: ['blur', 'select'] }
        ],
        ztlb: [
          { required: true, message: '请选择主体类别', trigger: ['blur', 'select'] }
        ],
        jclb: [
          { required: true, message: '请选择奖惩类型', trigger: ['blur', 'select'] }
        ],
        zjlx: [
          { required: true, message: '请选择主体证件类型', trigger: ['blur', 'select'] }
        ],
        zjhm: [
          { required: true, message: '请输入主体证件号码', trigger: 'blur' }
        ],
        csnr: [
          { required: true, message: '请输入执行措施内容', trigger: ['blur', 'select'] }
        ],
        sjje: [
          { required: true, message: '请输入涉及金额', trigger: ['blur', 'select'] }
        ],
        qlbm: [
          { required: true, message: '请输入事项编码', trigger: ['blur', 'select'] }
        ],
        jcsm: [
          { required: true, message: '请输入奖惩说明', trigger: ['blur', 'select'] }
        ]
      }
    }
  },
  watch: {
    'form.ztlb': function(val) {
      if (val === '0') {
        this.form.zjlx = ''
        this.form.zjhm = ''
      } else {
        this.form.tyshxydm = ''
        this.form.qyzch = ''
        this.form.zzjgdm = ''
      }
    }
  },
  created() {

  },
  mounted() {

  },
  methods: {
    comfirmData(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.form.ztlb === '0') {
            if (this.form.tyshxydm === '' && this.form.qyzch === '' && this.form.zzjgdm === '') {
              this.$message.warning('主体类别为法人时，主体统一社会信用代码、主体工商注册号、主体组织机构代码三项必填一项')
              return
            }
          } else {
            if (this.form.zjhm === '') {
              this.$message.warning('请填写主体证件号码')
              return
            }
            if (this.form.zjlx === '') {
              this.$message.warning('请选择主体证件类型')
              return
            }
          }
          entLockMeasureFeedBack(this.form).then(res => {
            if (res.code === 0) {
              this.$message.succss('反馈成功')
              this.cancelDiaolog()
            }
          })
        } else {
          return false
        }
      })
    },
    cancelDiaolog() {
      this.form = {
        sid: '',
        mdmc: '',
        ztmc: '',
        ztlb: '',
        jclb: '',
        tyshxydm: '',
        qyzch: '',
        zzjgdm: '',
        zjlx: '',
        zjhm: '',
        csnr: '',
        sjje: '',
        jcsm: '',
        qlbm: '',
        qlmc: '',
        cxcode: ''
      }
      this.dialogInfo.show = false
    },
    openDiaolog(item) {
      this.dialogInfo.show = true
      item = item || {}
      this.form = { ...item }
    }
  }
}
</script>

<style scoped lang="scss">
.el-select,.el-input-number .el-input {
  width: 100%;
}
</style>
