<template>
    <div class="home_wrapper">
    <van-nav-bar title="经营信息维护" left-arrow placeholder safe-area-inset-top @click-left="onClickLeft"/>

      <van-form @submit="onSubmit">
        <div class="main">
          <p class="title"><i></i>经营信息</p>
          <van-field readonly v-model="form.deptName" label="区域位置名称" placeholder="请输入" input-align="right" label-width="auto" />
          <van-field readonly v-model="form.dkbm" label="地块编码" placeholder="请输入" input-align="right" label-width="auto" required :rules="[{ required: true }]"/>
          <van-field readonly v-model="form.dkmc" label="地块名称" placeholder="请输入" input-align="right" label-width="auto" required :rules="[{ required: true }]"/>
          <van-field readonly v-model="form.dkdz" label="地块东至" placeholder="请输入" input-align="right" label-width="auto" />
          <van-field readonly v-model="form.dkxz" label="地块西至" placeholder="请输入" input-align="right" label-width="auto" />
          <van-field readonly v-model="form.dknz" label="地块南至" placeholder="请输入" input-align="right" label-width="auto" />
          <van-field readonly v-model="form.dkbz" label="地块北至" placeholder="请输入" input-align="right" label-width="auto" />

          <van-field v-model="form.jymj" label="经营面积" placeholder="请输入" type="number" input-align="right" label-width="auto" required :rules="[{ required: true }]"/>

          <field-select v-model="form.jyfs" label="经营方式" placeholder="请选择" value-key="dictLabel" data-key="dictValue" remote-url="/system/dict/data/type/jyfs" :on-remote-response="'data'" required/>

          <field-select v-model="form.jydxlx" label="经营对象类型" placeholder="请选择" value-key="dictLabel" data-key="dictValue" remote-url="/system/dict/data/type/jydxlx" :on-remote-response="'data'" required/>

          <van-field v-model="form.jydxmc" label="经营对象名称" placeholder="请输入" input-align="right" label-width="auto" required :rules="[{ required: true }]"/>

          <field-select v-model="form.jydxlx" label="经营对象证件类型" placeholder="请选择" value-key="dictLabel" data-key="dictValue" remote-url="/system/dict/data/type/zjlx" :on-remote-response="'data'"/>

          <van-field v-model="form.jydxzjhm" label="经营对象证件号码" placeholder="请输入" input-align="right" label-width="auto" />

          <field-radio v-model="form.sfqdht" label="是否签订合同" value-key="dictLabel" data-key="dictValue" remote-url="/system/dict/data/type/is_common" :on-remote-response="'data'" required/>

          <field-date-picker v-model="form.jykssj" label="经营开始时间" placeholder="请选择" formatter="yyyy-MM-dd" input-align="right" type="date" :required="true"  size="large"/>

          <field-date-picker v-model="form.jyjssj" label="经营结束时间" placeholder="请选择" formatter="yyyy-MM-dd" input-align="right" type="date" :required="true"  size="large"/>

          <van-field v-model="form.cbje" label="承包金额(元)" placeholder="请输入" type="number" input-align="right" label-width="auto" required :rules="[{ required: true }]"/>
          <van-field v-model="form.dxje" label="兑现金额(元)" placeholder="请输入" type="number" input-align="right" label-width="auto" />
          <van-field v-model="form.sqje" label="尚欠金额(元)" placeholder="请输入" type="number" input-align="right" label-width="auto" />
          <van-field v-model="form.nsy" label="年收益(元)" placeholder="请输入" type="number" input-align="right" label-width="auto" />
          <van-field v-model="form.bzxx" label="备注信息" placeholder="请输入" input-align="right" label-width="auto" />

          <field-radio v-model="form.surveyStatus" label="调查状态" value-key="dictLabel" data-key="dictValue" remote-url="/system/dict/data/type/survey_status" :on-remote-response="'data'" required/>

          <van-field label="实物图" placeholder="" input-align="right" label-width="auto" />
          <CommonUpload v-model="form.dkImg" accept="image/*" multiple :deletable="true" :show-upload="true" fileField="file" />

        </div>

        <van-button round block type="primary" native-type="submit" class="subClass">提交</van-button>
      </van-form>

    </div>
</template>

<script>
  import { getLandDetail } from "@/api/resource/land"
  import { getOperationDetail, updateOperation, addOperation } from "@/api/resource/operation"
  import { getInfoByImportCode } from "@/api/system/dept";

  import FieldSelect from "@/components/form/FieldSelect.vue";
  import FieldRadio from "@/components/form/FieldRadio.vue";
  import FieldDatePicker from "@/components/form/FieldDatePicker.vue";
  import CommonUpload from "@/components/form/CommonUpload.vue";

  export default {
    dicts: ['zjlx', 'survey_status', 'is_common', 'jydxlx', 'jyfs'],
    name: "appEdit",
    components: {FieldSelect, FieldRadio, FieldDatePicker, CommonUpload},
    data() {
      return {
        importCode: null,
        form: {
          dkbm: null,
          dkmc: null,
          dkdz: null,
          dkxz: null,
          dknz: null,
          dkbz: null,
          jymj: null,
          jyfs: null,
          jydxlx: null,
          jydxmc: null,
          jydxzjlx: null,
          jydxzjhm: null,
          sfqdht: null,
          jykssj: null,
          jyjssj: null,
          cbje: null,
          dxje: null,
          sqje: null,
          nsy: null,
          bzxx: null,
          dkImg: null,
          surveyStatus: null,
          importCode: null,
          deptName: null,
        },
      };
    },
    created() {
      this.getDetail()
    },
    methods: {
      onClickLeft(){
        history.back(-1);
      },
      getDetail(){
        getOperationDetail(this.$route.query.dkbm).then(response => {
          if (response.data){
            this.form = response.data
          }else{
            getLandDetail(this.$route.query.dkbm).then(response => {
              //this.form = response.data
              this.form.deptName = response.data.deptName;
              this.form.importCode = response.data.importCode;
              this.importCode = response.data.importCode;
              this.form.dkbm = response.data.dkbm;
              this.form.dkmc = response.data.dkmc;
              this.form.dkdz = response.data.dkdz;
              this.form.dkxz = response.data.dkxz;
              this.form.dknz = response.data.dknz;
              this.form.dkbz = response.data.dkbz;
              this.form.jymj = response.data.scmjm;

              this.form.jyfs = '110';
              this.form.jydxlx = '1';
              this.form.jydxzjlx = '1';
              this.form.sfqdht = '1';
              this.form.surveyStatus = '2';

              getInfoByImportCode(response.data.importCode).then((res) => {
                this.form.deptId = res.data.deptId
              });
            });
          }
        });
      },
      /** 提交按钮 */
      onSubmit() {
        if (!this.form.id){
          addOperation(this.form).then(response => {
            this.$modal.msgSuccess("新增成功")
            setTimeout(function(){
              history.back(-1);
            },2000)
          })
        }else{
          updateOperation(this.form).then(response => {
            if (response.code == 200){
              this.$modal.msgSuccess("修改成功")
              setTimeout(function(){
                history.back(-1);
              },2000)
            }
          })
        }

      },

    },
  };
</script>

<style scoped lang="scss">
  p{margin: 0;}
  .home_wrapper{
    width: 100vw;
    min-height: 100vh;
    background: #F6F9FB;
    padding-bottom: 5vh;
  }
  .van-nav-bar{
    background: linear-gradient( 173deg, #91E2D3 0%, #CDFCF0 100%);
    ::v-deep.van-icon{
      color: #000000;
    }
  }
  .main{
    width: 94%;
    margin: 3vw auto;
    padding: 3vw;
    background-color: #ffffff;
    border-radius: 10px;
    overflow: hidden;

  }
  .title{
    display: flex;
    align-items: center;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
    i{
      width: 5px;
      height: 20px;
      display: block;
      background-color: #29D2AF;
      margin-right: 10px;
    }
  }
  .subClass{
    background: linear-gradient( 270deg, #53E4A5 0%, #24DBDB 100%);
    border-radius: 50px 50px 50px 50px;
    border: none;
    width: 90%;
    margin: 3vw auto;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 18px;
  }

</style>
