<template>
  <section class="Add">
    <ai-detail class="add" v-if="!id || isEdit==true">
      <template #title>
        <ai-title :title="params.id ? '编辑土地流转经营登记' : '新增土地流转经营登记'" :isShowBack="true" :isShowBottomBorder="true" @onBackClick="cancel(false)" />
      </template>
      <template #content>
        <ai-card title="合同信息">
          <template #right v-if="params.id">
            <span style="color:#2266FF;margin-left: 16px;cursor: pointer;font-size: 12px;" v-if="isEdit==true" @click="isEdit=false">取消</span>
            <span style="color:#2266FF;margin-left: 16px;cursor: pointer;font-size: 12px;" v-if="isEdit==true" @click="confirm()">保存</span>
          </template>
          <template #content>
            <el-form ref="form" :model="form" :rules="rules" size="small"  label-width="150px">
              <el-form-item label="土地流出方" prop="unifiedCode">
                <el-radio-group v-model="radioFrom">
                  <el-radio :label="1">企业组织</el-radio>
                  <el-radio :label="2">个人农户</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-row type="flex" v-if="radioFrom == 1">
                <el-col :span="20">
                  <el-form-item label="单位名称" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入土地流出方单位名称"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="信用代码" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入土地流出方统一社会信用代码"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex" v-if="radioFrom == 2">
                <el-col :span="20">
                  <el-form-item label="人员姓名" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入土地流出方人员姓名"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="身份证号" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入土地流出方身份证号"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-form-item label="土地承接方" prop="unifiedCode">
                <el-radio-group v-model="radioTo">
                  <el-radio :label="1">企业组织</el-radio>
                  <el-radio :label="2">个人农户</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-row type="flex" v-if="radioTo == 1">
                <el-col :span="20">
                  <el-form-item label="单位名称" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入土地承接方单位名称"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="信用代码" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入土地承接方统一社会信用代码"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex" v-if="radioTo == 2">
                <el-col :span="20">
                  <el-form-item label="人员姓名" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入土地承接方人员姓名"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="身份证号" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入土地承接方人员身份证号"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="20">
                  <el-form-item label="合同编号" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入合同编号"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="流转形式" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入流转形式"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="20">
                  <el-form-item label="土地面积/㎡" prop="unifiedCode">
                     <ai-select v-model="form.unifiedCode" placeholder="请选择" :selectList="$dict.getDict('')"></ai-select>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="每亩年租金" prop="unifiedCode">
                    <el-input v-model="form.unifiedCode" placeholder="请输入"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
              <el-col :span="20">
                <el-form-item label="开始日期" prop="unifiedCode">
                  <el-date-picker v-model="form.unifiedCode" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width:375px">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="20">
                <el-form-item label="截止日期" prop="unifiedCode">
                  <el-date-picker v-model="form.unifiedCode" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width:375px">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="土地信息" prop="unifiedCode">
              <el-input type="textarea" v-model="form.unifiedCode" placeholder="请说明土地流转的地块名称地界四至" maxlength="500" show-word-limit :rows="5" />
            </el-form-item>
            <el-form-item label="土地用途" prop="unifiedCode">
              <el-input type="textarea" v-model="form.unifiedCode" placeholder="请说明流转土地的用途" maxlength="500" show-word-limit :rows="5" />
            </el-form-item>
            </el-form>
          </template>
        </ai-card>
      </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>
    <ai-detail class="add" v-if="id && !isEdit">
      <template slot="title">
        <ai-title title="详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)"></ai-title>
      </template>
      <template slot="content">
        <ai-card title="基本信息">
          <template #right>
              <span style="color:#2266FF;cursor: pointer;font-size: 12px;" class="iconfont iconEdit" v-if="isEdit==false" @click="isEdit=true,forms=data">修改</span>
            </template>
          <template #content>
            <ai-wrapper>
              <ai-info-item label="土地流出方" :value="data.taxpayer"></ai-info-item>
              <ai-info-item label="信用代码" :value="data.taxpayerNumber"></ai-info-item>
              <ai-info-item label="身份证" :value="data.taxpayerNumber"></ai-info-item>
              <ai-info-item label="土地承接方" :value="data.taxYear"></ai-info-item>
              <ai-info-item label="信用代码" :value="data.taxpayerNumber"></ai-info-item>
              <ai-info-item label="身份证号">{{ dict.getLabel('taxInfoLevel', data.taxLevel) }}</ai-info-item>
              <ai-info-item label="流转形式" :value="data.enterpriseName"></ai-info-item>
              <ai-info-item label="土地面积" :value="data.unifiedCode"></ai-info-item>
              <ai-info-item label="每亩年租金" :value="data.unifiedCode"></ai-info-item>
              <ai-info-item label="土地面积" :value="data.unifiedCode"></ai-info-item>
              <ai-info-item label="开始日期" :value="data.unifiedCode"></ai-info-item>
              <ai-info-item label="截止日期" :value="data.unifiedCode"></ai-info-item>
              <ai-info-item label="土地信息" :value="data.unifiedCode"></ai-info-item>
              <ai-info-item label="土地用途" :value="data.unifiedCode"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
      </template>
    </ai-detail>
  </section>
</template>

<script>
export default {
  name: "Add",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function,
    params: Object,
  },
  data() {
    return {
      radioTo: '',
      radioFrom: '',
      form: {
        unifiedCode: '',
      },
      data: {},
      isEdit: false,
      id: '',
    }
  },
  computed: {
    rules() {
      return {
        unifiedCode: [{required: true, message: "请输入名称", trigger: "blur"}],
      }
    },

  },
  created() {
    if(this.params && this.params.id) {
      this.id = this.params.id
      this.getDetail(this.params.id)
    }
  },
  methods: {
    cancel(isRefresh) {
      this.$emit('change', {
        type: 'List',
        isRefresh: !!isRefresh,
      })
    },
    getDetail(id) {
      // this.instance.post(`/appcreditadminstrativelicense/queryDetailById?id=${id}`).then(res => {
      //   if (res.code === 0) {
      //     this.data = res.data
      //   }
      // })
    },
    confirm() {
      // this.$refs.forms.validate((valid) => {
      //   if (valid) {
      //     this.instance.post(`/appcreditadminstrativelicense/addOrUpdate`, {
      //       ...this.forms,
      //       id: this.params.id || '',
      //     }).then(res => {
      //       if (res.code == 0) {
      //         this.$message.success('提交成功')
      //         setTimeout(() => {
      //           this.cancel(true)
      //         }, 600)
      //       }
      //     })
      //   }
      // })
    },
  },
}
</script>

<style lang="scss" scoped>
.Add {
  height: 100%;
  // background: #f3f4f5;

  .footer {

    background: #FFF;
  }
}
</style>