<template>
  <div class="app-container">

    <!-- <van-nav-bar left-arrow fixed placeholder @click-left="$router.push({path:'/contracted/village/contractor'})" >
      <template #title>
        <div class="tb_main">
          B村<p><span class="tb">签字完成</span><span class="tb">异常挂起</span></p>
        </div>
      </template>
    </van-nav-bar> -->
    <contractor-header :dept-id="$route.params.deptId" :contractor-code="$route.params.cbfbm" :contractor-name="$route.params.cbfmc" :survey-status="$route.params.surveyStatus" :task-status="taskStatus"></contractor-header>

    <div class="tap_block">
      <p class="active">承包方</p>
      <p @click="skip('contractedVillageContractorFamily')">家庭成员</p>
      <p @click="skip('contractedVillageContractorWord')">承包合同</p>
      <p @click="skip('contractedVillageContractorLand')">承包地</p>
    </div>

    <div class="list_main">
      <van-form ref="formData">
        <van-field v-model="form.cbfbm" label="代码：" placeholder="请输入代码" required :rules="[{ required: true }]" :border="false" input-align="left" disabled maxlength="18" />
        <van-field
          v-model="form.cbflxText"
          label="类型："
          placeholder="请选择类型"
          required
          :rules="[{ required: true }]"
          :border="false"
          input-align="left"
          right-icon="arrow-down"
          readonly
          clickable
          @click="showType = true"
        />
        <van-popup v-model="showType" position="bottom">
          <van-picker
            show-toolbar
            :columns="contractorTypeOptions"
            value-key="dictLabel"
            @confirm="onConfirmTypeOptions"
            @cancel="showType = false"
          />
        </van-popup>
        <van-field v-model="form.cbfmc" label="名称：" placeholder="请输入名称" required :rules="[{ required: true }]" :border="false" input-align="left" maxlength="50" />
        <van-field
          v-model="form.cbfzjlxText"
          label="证件类型："
          placeholder="请选择证件类型"
          required
          :rules="[{ required: true }]"
          :border="false"
          input-align="left"
          right-icon="arrow-down"
          readonly
          clickable
          @click="showZjType = true"
        />
        <van-popup v-model="showZjType" position="bottom">
          <van-picker
            show-toolbar
            :columns="credentialTypeOptions"
            value-key="dictLabel"
            @confirm="onConfirmZjTypeOptions"
            @cancel="showZjType = false"
          />
        </van-popup>

        <van-field v-model="form.cbfzjhm" label="证件号码：" placeholder="请输入证件号码" required :rules="[{ required: true }]" :border="false" input-align="left" maxlength="20" />
        <van-field v-model="form.cbfdz" label="地址：" placeholder="请输入地址" required :rules="[{ required: true }]" :border="false" input-align="left" maxlength="100" />
        <van-field v-model="form.yzbm" label="邮编：" placeholder="请输入邮编" required :rules="[{ required: true }]" :border="false" input-align="left" maxlength="6" />
        <van-field v-model="form.lxdh" label="电话：" placeholder="请输入电话" required :rules="[{ required: true }]" :border="false" input-align="left" maxlength="15" />
        <van-field v-model="form.cbfdcjs" label="调查记事：" type="textarea" rows="3" placeholder="请输入调查记事" required :rules="[{ required: true }]" :border="false" input-align="left" maxlength="250" />
      </van-form>
      <p class="btn" @click="submitForm" v-if="taskStatus === '2' && $route.params.surveyStatus !== '3'">保存</p>
    </div>


  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import contractorHeader from "./contractorHeader";
  import { getCbf, updateCbf } from "@/api/contracted/cbf";

  export default {
    name: "contractedVillageContractor",
    components: {
      contractorHeader
    },
    data() {
      return {
        showType:false,
        showZjType:false,
        // 承包方信息表单
        form: {},
        // 承包方类型字典
        contractorTypeOptions: [],
        // 承包方证件类型字典
        credentialTypeOptions: [],
        // 调查任务的完成状态：1表示已完成，2表示未完成
        taskStatus: null,
      };
    },
    created() {
      this.taskStatus = Cookies.get('taskStatus');
      this.getDicts("cbf_type").then(response => {
        this.contractorTypeOptions = response.data;
      });
      this.getDicts("cert_type").then(response => {
        this.credentialTypeOptions = response.data;
      });
    },
    mounted() {
      setTimeout(() => {
        this.getDetail();
      }, 500);
    },
    methods: {
      getDetail(){
        getCbf(this.$route.params.cbfbm).then(response => {
          this.form = response.data;
          this.$set(this.form, 'cbflxText', this.selectDictLabel(this.contractorTypeOptions, response.data.cbflx));
          this.$set(this.form, 'cbfzjlxText', this.selectDictLabel(this.credentialTypeOptions, response.data.cbfzjlx));
        });
      },
      onConfirmTypeOptions(value){
        this.form.cbflx = value.dictValue;
        this.form.cbflxText = value.dictLabel;
        this.showType = false;
      },
      onConfirmZjTypeOptions(value){
        this.form.cbfzjlx = value.dictValue;
        this.form.cbfzjlxText = value.dictLabel;
        this.showZjType = false;
      },
      submitForm() {
        this.$refs.formData.validate().then(() => {
          updateCbf(this.form).then(response => {
            if (response.code == 200) {
              this.$toast({
                icon: 'success',
                message: '保存成功',
                duration:"1000"
              })
            }
          }).catch(() => {
            this.getDetail();
          });
        }).catch(() => {
          this.$notify({ type: 'danger', message: '请填写完整的表单项' });
        });
      },
      skip(name) {
        this.$router.push({
          name: name,
          params: {
            deptId: this.$route.params.deptId,
            cbfbm: this.$route.params.cbfbm,
            cbfmc: this.$route.params.cbfmc,
            surveyStatus: this.$route.params.surveyStatus
          }
        });
      }
    },
  };
</script>
<style scoped lang="scss">

  .app-container{
    background: #fff url("../../../../../static/images/contracted/contracted_index_bg.png") no-repeat center;
    background-size: 100% 100%;
    height: 100vh;
    padding: 0 4vw;
    overflow: hidden;
  }

  /deep/ .van-nav-bar{
    background: transparent;
  }

  /deep/ .van-nav-bar .van-icon{
    color: #000000;
  }

  /deep/ .van-hairline--bottom::after{
    border: none;
  }

  /deep/ .van-search__content{
    background: rgba(255,255,255,.5);
  }
  /deep/ .van-search{
    padding: 0;
    flex: 1;
  }

  /deep/ .van-ellipsis{
    overflow: initial;
  }

  /deep/ .van-field--disabled .van-field__label {
    color: #646566;
  }

  /* .tb_main{
    position: relative;
    p{
      position: absolute;
      display: inline-block;
      margin-left: 10PX;
    }
  }

  .tb{
    font-size: 12px;
    color: #ff8900;
    background: #daf6e7;
    border: 1px solid #d7be6e;
    padding: 2PX 8PX;
    border-radius: 50PX;
    margin-right: 5PX;
  } */

  .tap_block{
    width: 100%;
    display: flex;
    justify-content: space-between;
    background: #ebfaf2;
    padding: 2PX 4PX;
    border-radius: 10PX;
    margin-top: 1vh;
    .active{
      background-image: linear-gradient(to right,#c6fe8b,#48e5a2);
      box-shadow: 0 0 10PX #cccccc;
      color: #333333;
    }
    p{
      width: 25%;
      text-align: center;
      padding: 5PX 0;
      border-radius: 10PX;
      color: #666666;
    }
  }

  .search_main{
    display: flex;
    margin-top: 2vh;
    .search_btn{
      background: rgba(255,255,255,.5);
      width: 25%;
      border-radius: 50PX;
      margin-left: 10PX;
      padding: 2PX;
      .active{
        background-image: linear-gradient(to right,#c6fe8b,#48e5a2);
        color: #333333;
        border-radius: 50PX;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
      }
    }
  }

  .second_tap{
    display: flex;
    align-items: center;
    margin-top: 1vh;
    p{
      background: #dbf1ea;
      border: 1px solid #cdcdcd;
      color: #5f5f5f;
      padding: 5PX 15PX;
      margin-right: 3vw;
      border-radius: 50PX;
    }
    .active{
      background: #99eecb;
      border-color: #48e5a2;
      color: #333333;
    }
  }

  .list_main{
    margin-top: 2vh;
    overflow-y: scroll;
    text-align: center;
    background: #ffffff;
    border-top-left-radius: 10PX;
    border-top-right-radius: 10PX;
    height: 88vh;
    .btn{
      background-image: linear-gradient(to right,#c6fe8b,#48e5a2);
      box-shadow: 0 0 10PX #cccccc;
      padding: 10PX 0PX;
      border-radius: 50PX;
      display: inline-block;
      width: 40%;
      margin-top: 2vh;
    }
  }

</style>
