<template>
  <section class="Add">
    <ai-detail class="add">
      <template #title>
        <ai-title :title="params.id ? '编辑' : '新增失信被执行人'" :isShowBack="true" :isShowBottomBorder="true" @onBackClick="cancel(false)" />
      </template>
      <template #content>
        <div class="add-form">
          <ai-bar title="失信被执行人信息"></ai-bar>
          <el-form ref="forms" :model="forms" :rules="formRules" size="small"  label-width="150px">
            <el-row type="flex">
              <el-col :span="20">
                <el-form-item label="执行案号" prop="executionCode">
                  <el-input v-model="forms.executionCode" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="20">
                <el-form-item label="执行法院" prop="executionCourt">
                  <el-input v-model="forms.executionCourt" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row type="flex">
              <el-col :span="20">
                <el-form-item label="执行时间" prop="executionTime">
                  <el-date-picker v-model="forms.executionTime" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width:375px">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="20">
                <el-form-item label="履行情况" prop="executionSituation">
                  <ai-select v-model="forms.executionSituation" placeholder="请选择文档类型" :selectList="$dict.getDict('dishonestPersonSituation')"></ai-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row type="flex">
              <el-col :span="20">
                <el-form-item label="失信被执行主体" prop="enterpriseName">
                  <el-input v-model="forms.enterpriseName" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="20">
                <el-form-item label="统一信用代码" prop="unifiedCode">
                  <el-input v-model="forms.unifiedCode" placeholder="请输入"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="失信事实" prop="dishonestFact">
              <el-input v-model="forms.dishonestFact" placeholder="请输入失信事实" type="textarea" show-word-limit maxlength="500" :rows="5"></el-input>
            </el-form-item>
          </el-form>
        </div>
      </template>
      <template slot="footer" class="footer">
        <el-button class="delete-btn footer-btn" @click="cancel(false)">取消</el-button>
        <el-button class="footer-btn" type="primary" @click="confirm()">保存</el-button>
      </template>
    </ai-detail>
  </section>
</template>

<script>
export default {
  name: "Add",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function,
    params: Object,
  },
  computed: {
    formRules() {
      return {
        executionCode: [{required: true,message:"请输入执行编号",trigger: "blur"}],
        executionCourt: [{required: true,message:"请输入执行法院",trigger: "blur"}],
        executionTime: [{required: true,message:"请输入执行时间",trigger: "blur"}],
        executionSituation: [{required: true,message:"请选择履行情况",trigger: "blur"}],
        enterpriseName: [{required: true,message:"请输入失信被执行主体",trigger: "blur"}],
        unifiedCode: [{required: true,message:"请输入统一信用代码",trigger: "blur"}],
        dishonestFact: [{required: true,message:"请输入失信事实",trigger: "blur"}],
      }
    }
  },
  created() {
    this.$dict.load('dishonestPersonSituation')
  },
  data() {
    return {
      forms: {
        executionCode: '',
        executionCourt: '',
        executionTime: '',
        executionSituation: '',
        enterpriseName: '',
        unifiedCode: '',
        dishonestFact: '',
      }
    }
  },
  methods: {
    cancel(isRefresh) {
      this.$emit('change', {
        type: 'List',
        isRefresh: !!isRefresh,
      })
    },
    confirm( ) {
      this.$refs.forms.validate((valid) => {
        if (valid) {
          this.instance.post(`/appcreditdishonestperson/addOrUpdate`, {
            ...this.forms,
            id: this.params.id || '',
            // picture: this.form.picture.length ? this.form.picture[0].url : ''
          }).then(res => {
            if (res.code == 0) {
              this.$message.success('提交成功')
              setTimeout(() => {
                this.cancel(true)
              }, 600)
            }
          })
        }
      })
    },
  },

}
</script>

<style lang="scss" scoped>
.Add {
  height: 100%;
  overflow: hidden;
  background: #f2f4f6 !important;

  .add-form__item {
    display: flex;
    align-items: center;
  }

  ::v-deep .el-form-item__label {
    padding-right: 40px;
  }

  ::v-deep .ai-detail__footer {
    background: #fff !important;
  }

  ::v-deep .ai-detail__content--active {
    padding: 20px;

    .ai-detail__content--wrapper {
      width: 100%;
    }

    .aibar {
      padding: 0 16px;
    }

    .el-form {
      padding: 0 96px 20px 50px;
    }

    .add-form {
      background: #fff;
    }
  }

  ::v-deep .ai-wrapper {
    align-items: inherit !important;
  }

  .user-wrapper {
    display: flex;
    justify-content: space-between;
  }

  .avatar {
    width: 100px;
    height: 100px;
    object-fit: contain;
    border-radius: 10px;
  }

  .footer-btn {
    width: 130px;
  }

  .el-form {
    padding-bottom: 80px;
  }
}
</style>