<template>
    <div class="app-container">
      <van-nav-bar
        title="公示信息"
        left-arrow
        fixed
        placeholder
        @click-left="$router.back(-1)"
      />
      <van-steps :active="active" active-color="#38f">
        <van-step>申请</van-step>
        <van-step>开工</van-step>
        <van-step>验收</van-step>
      </van-steps>
      <p class="topTit">农村宅基地和建房（规划许可）申请表</p>
      <div class="main">
        <van-form>
          <div v-if="applicationDetail.tHouseApplyProposer">
            <p class="main_title">申请用户信息</p>
            <div class="main_box">
            <van-field :readonly="auditStatus" :rules="[{ required: true }]" required v-model="applicationDetail.tHouseApplyProposer.memberName" label="姓名" placeholder="姓名" input-align="right"/>
              <van-field
                readonly
                clickable
                v-model="sexValue"
                label="性别"
                placeholder="选择性别"
                @click=" auditStatus==true ? '' : showSex = true"
                input-align="right"
                :rules="[{ required: true }]" required
              />
              <van-popup v-model="showSex" position="bottom">
                <van-picker
                  show-toolbar
                  :columns="userSex"
                  @confirm="onConfirmSex"
                  @cancel="showSex = false"
                  :readonly="auditStatus"
                />
              </van-popup>
            <van-field :readonly="auditStatus" :rules="[{ required: true }]" required v-model="applicationDetail.tHouseApplyProposer.age" label="年龄" placeholder="年龄" input-align="right"/>
            <van-field :readonly="auditStatus" :rules="[{ required: true }]" required v-model="applicationDetail.tHouseApplyProposer.phone" label="联系电话" placeholder="联系电话" input-align="right"/>
            <van-field :readonly="auditStatus" :rules="[{ required: true }]" required v-model="applicationDetail.tHouseApplyProposer.idcard" label="身份证号" placeholder="身份证号" input-align="right"/>
            <van-field :readonly="auditStatus" :rules="[{ required: true }]" required v-model="applicationDetail.tHouseApplyProposer.householdRegister" label="户口所在地" placeholder="户口所在地" input-align="right"/>
            <van-field :readonly="auditStatus" :rules="[{ required: true }]" required v-model="applicationDetail.tHouseApplyProposer.familyAddress" label="家庭住址" placeholder="家庭住址" input-align="right"/>
            <van-field :readonly="auditStatus" :rules="[{ required: true }]" required v-model="applicationDetail.tHouseApplyProposer.members" label="家庭人口数" placeholder="家庭人口数" input-align="right"/>
            <van-cell title="是否已有宅基地">
              <template #right-icon>
                {{applicationDetail.tHouseApplyProposer.existHomestead=='Y'?'是':'否'}}
              </template>
            </van-cell>
          </div>
          </div>

          <div v-if="applicationDetail.tHouseApplyFamilyMembers && applicationDetail.tHouseApplyFamilyMembers!=''">
            <p class="main_title">家庭成员信息<van-button icon="plus" size="mini" type="info" native-type="button" class="addFamily" @click="addFamily" v-if="!auditStatus" /></p>
            <van-collapse  v-model="activeNames" v-if="auditStatus">
              <van-collapse-item  class="collapse" v-for="(item , index) in applicationDetail.tHouseApplyFamilyMembers" :key="index" :name="index+1">
                <template #title>
                  <van-row>
                    <van-col span="8">{{item.memberName}}</van-col>
                    <van-col span="8">{{item.age}}</van-col>
                    <van-col span="8">{{item.familyStatusName}}</van-col>
                  </van-row>
                </template>
                <van-field :readonly="auditStatus" v-model="item.memberName" label="姓名" placeholder="姓名" input-align="right"/>
                <van-field :readonly="auditStatus" v-model="item.age" label="年龄" placeholder="年龄" input-align="right"/>
                <van-field :readonly="auditStatus" v-model="item.familyStatusName" label="与户主关系" placeholder="与户主关系" input-align="right"/>
                <van-field :readonly="auditStatus" v-model="item.idcard" label="身份证号" placeholder="身份证号" input-align="right"/>
                <van-field :readonly="auditStatus" v-model="item.householdRegister" label="户口所在地" placeholder="户口所在地" input-align="right"/>
              </van-collapse-item>
            </van-collapse>
            <div class="familyList" v-if="!auditStatus" v-for="(item , index) in applicationDetail.tHouseApplyFamilyMembers" :key="index">
              <div class="main_box" style="margin-bottom: 20px">
                <van-button icon="minus" size="mini" type="danger" class="deleteFamily" native-type="button" v-if="index!=0" @click="deleteFamily(index)" />
                <van-field v-model="item.memberName" label="姓名" placeholder="姓名" input-align="right"/>
                <van-field v-model="item.age" label="年龄" placeholder="年龄" input-align="right"/>
                <van-field v-model="item.familyStatusName" label="与户主关系" placeholder="与户主关系" input-align="right"/>
                <van-field v-model="item.idcard" label="身份证号" placeholder="身份证号" input-align="right"/>
                <van-field v-model="item.householdRegister" label="户口所在地" placeholder="户口所在地" input-align="right"/>
              </div>
            </div>
<!--            <div class=" familyList">-->
<!--              <van-button icon="minus" size="mini" type="danger" class="deleteFamily" />-->
<!--              <div class="main_box">-->
<!--                <van-field label="姓名" placeholder="姓名" input-align="right"/>-->
<!--                <van-field label="年龄" placeholder="年龄" input-align="right"/>-->
<!--                <van-field label="与户主关系" placeholder="与户主关系" input-align="right"/>-->
<!--                <van-field label="身份证号" placeholder="身份证号" input-align="right"/>-->
<!--                <van-field label="户口所在地" placeholder="户口所在地" input-align="right"/>-->
<!--              </div>-->
<!--            </div>-->
          </div>

          <div v-if="CurrentSituation">
            <p class="main_title">现宅基地及农房状况</p>
            <div class="main_box">
              <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyCurrentSituation.landArea" label="宅基地面积" placeholder="宅基地面积" input-align="right"/>
              <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyCurrentSituation.landPerArea" label="人均宅基地面积" placeholder="人均宅基地面积㎡" input-align="right" label-width="auto"/>
              <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyCurrentSituation.landCertificateNo" label="不动产单元号" placeholder="不动产单元号" input-align="right"/>
              <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyCurrentSituation.buildingArea" label="建筑面积" placeholder="建筑面积㎡" input-align="right"/>
              <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyCurrentSituation.buildingPerArea" label="人均建筑面积" placeholder="人均建筑面积㎡" input-align="right"/>
              <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyCurrentSituation.houseCertificateNo" label="农民房屋幢号" placeholder="户口所在地" input-align="right"/>
              <van-field
                readonly
                clickable
                :value="landIsposalValue"
                label="处置情况"
                placeholder="选择宅基地处置情况"
                @click=" auditStatus==true ? '' : showLandIsposal = true"
                input-align="right"
                :readonly="auditStatus"
                :rules="[{ required: true }]" required
              />
              <van-popup v-model="showLandIsposal" position="bottom">
                <van-picker
                  show-toolbar
                  :columns="landIsposal"
                  @confirm="onConfirmLandIsposal"
                  @cancel="showLandIsposal = false"
                  :readonly="auditStatus"
                />
              </van-popup>

  <!--            <van-field-->
  <!--              readonly-->
  <!--              clickable-->
  <!--              name="picker"-->
  <!--              :value="applicationDetail.tHouseApplyCurrentSituation.buildingType"-->
  <!--              label="建房类型"-->
  <!--              placeholder="选择建房类型"-->
  <!--              @click="showBuildingType = true"-->
  <!--              input-align="right"-->
  <!--              right-icon="arrow-down"-->
  <!--            />-->
  <!--            <van-popup v-model="showBuildingType" position="bottom">-->
  <!--              <van-picker-->
  <!--                show-toolbar-->
  <!--                :columns="buildingType"-->
  <!--                @confirm="onConfirmBuildingType"-->
  <!--                @cancel="showBuildingType = false"-->
  <!--              />-->
  <!--            </van-popup>-->
            </div>
          </div>

          <div v-if="applicationDetail.tHouseApplyProposedSituation">
            <p class="main_title">拟申请宅基地及建房情况</p>
            <div class="main_box">
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.location" label="拟建位置" placeholder="拟建位置" input-align="right"/>
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.landArea" label="宅基地面积" placeholder="宅基地面积" input-align="right"/>
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.east" label="东至" placeholder="东至" input-align="right"/>
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.west" label="西至" placeholder="西至" input-align="right"/>
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.south" label="南至" placeholder="南至" input-align="right"/>
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.north" label="北至" placeholder="北至" input-align="right"/>
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.buildingArea" label="建筑面积" placeholder="建筑面积" input-align="right"/>
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.buildingFloors" label="建筑层数" placeholder="建筑层数" input-align="right"/>
            <van-field :rules="[{ required: true }]" required :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposedSituation.buildingHight" label="建筑高度" placeholder="建筑高度" input-align="right"/>
            <van-cell title="是否征求相邻权利人意见">
              <template #right-icon>
                {{applicationDetail.tHouseApplyProposedSituation.isAdvice=='Y'?'是':'否'}}
              </template>
            </van-cell>
            <van-field
              readonly
              clickable
              v-model="housingStructureValue"
              label="房屋构造"
              placeholder="选择房屋构造"
              @click=" auditStatus==true ? '' : showHousingStructure = true"
              input-align="right"
              :rules="[{ required: true }]" required
            />
            <van-popup v-model="showHousingStructure" position="bottom">
              <van-picker
                show-toolbar
                :columns="housingStructure"
                @confirm="onConfirmHousingStructure"
                @cancel="showHousingStructure = false"
                :readonly="auditStatus"
              />
            </van-popup>
            <van-field
              readonly
              clickable
              :value="buildingTypeValue"
              label="建房类型"
              placeholder="选择建房类型"
              @click=" auditStatus==true ? '' : showBuildingType = true"
              input-align="right"
              :rules="[{ required: true }]" required
            />
            <van-popup v-model="showBuildingType" position="bottom">
              <van-picker
                show-toolbar
                :columns="buildingType"
                @confirm="onConfirmBuildingType"
                @cancel="showBuildingType = false"
              />
            </van-popup>
            <van-cell title="设计图纸">
              <template #right-icon>
                {{applicationDetail.tHouseApplyProposedSituation.designPaper == '1' ? '委托设计':'选通用图'}}
              </template>
            </van-cell>
            <van-field
              readonly
              clickable
              :value="houseTypeValue"
              placeholder="选择户型图"
              @click=" auditStatus==true ? '' : showHouseType = true"
              input-align="right"
              right-icon="arrow-down"
              v-if="showHouse"
              :rules="[{ required: true }]" required
            />
            <van-popup v-model="showHouseType" position="bottom">
              <van-picker
                show-toolbar
                :columns="houseType"
                @confirm="onConfirmHouseType"
                @cancel="showHouseType = false"
              />
            </van-popup>
          </div>
          </div>

          <div v-if="applicationDetail.tHouseApplyProposer">
            <p class="main_title">申请理由</p>
            <div class="main_box">
            <van-field
              rows="3"
              autosize
              type="textarea"
              placeholder="申请理由"
              input-align="left"
              v-model="applicationDetail.tHouseApplyProposer.applyReasion"
              :readonly="auditStatus"
              :rules="[{ required: true }]" required
            />
            <van-row>
              <van-col span="12"><van-field :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposer.memberName" label="申请人" placeholder="申请人" input-align="left" label-width="auto"/></van-col>
              <van-col span="12">
                <van-field :rules="[{ required: true }]" required :readonly="auditStatus" clickable v-model="applicationDetail.tHouseApplyProposer.applyTime" label-width="auto" placeholder="选择日期" @click="showApplyTime = true">
                  <template #label>
                    <van-icon name="notes-o" size="20"/>
                  </template>
                </van-field>
                <van-calendar v-model="showApplyTime" :readonly="auditStatus" @confirm="onConfirmApplyTime" />
<!--                <van-field :readonly="auditStatus" v-model="applicationDetail.tHouseApplyProposer.applyTime == '' ? nowTime : applicationDetail.tHouseApplyProposer.applyTime" label-width="auto">-->
<!--                  <template #label>-->
<!--                    <van-icon name="notes-o" size="20"/>-->
<!--                  </template>-->
<!--                </van-field>-->
              </van-col>
            </van-row>
          </div>
          </div>
<!--applicationDetail.tHouseApplyStart-->
          <div v-if="false" >
            <p class="topTit">宅基地开工</p>
            <div class="main_box action-box">
            <van-cell title="计划开工时间">
              <template #right-icon>
                <van-radio-group v-model="radio" direction="horizontal">
                  <van-field readonly clickable style="padding: 0" v-model="applicationDetail.tHouseApplyStart.startDate" label-width="auto" placeholder="选择日期">
                    <template #label>
                      <van-icon name="notes-o" size="20"/>
                    </template>
                  </van-field>
                </van-radio-group>
              </template>
            </van-cell>
            <van-cell title="计划竣工时间">
              <template #right-icon>
                <van-radio-group v-model="radio" direction="horizontal">
                  <van-field readonly clickable style="padding: 0" v-model="applicationDetail.tHouseApplyStart.endDate" label-width="auto" placeholder="选择日期">
                    <template #label>
                      <van-icon name="notes-o" size="20"/>
                    </template>
                  </van-field>
                </van-radio-group>
              </template>
            </van-cell>
          </div>
          </div>

          <div v-if="false">
            <p class="topTit">宅基地验收申请</p>
            <div class="main_box check-box">
            <van-field v-model="applicationDetail.tHouseApplyEnd.memberName" label="申请户主姓名" placeholder="申请户主姓名" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.idcard" label="身份证号" placeholder="身份证号" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.location" label="用地建房位置" placeholder="用地建房位置" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.licenseKey" label="乡村建设规划许可证号" placeholder="乡村建设规划许可证号" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.approvalNumber" label="农村宅基地批准书号" placeholder="农村宅基地批准书号" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.startDate" label="开工日期" readonly clickable input-align="right" label-width="auto" placeholder="选择开工日期" @click="showCalendar = true"></van-field>
            <van-calendar />
            <van-field v-model="applicationDetail.tHouseApplyEnd.endDate" label="竣工日期" readonly clickable input-align="right" label-width="auto" placeholder="选择竣工日期" @click="showCalendar = true"></van-field>
            <van-calendar />
            <van-field v-model="applicationDetail.tHouseApplyEnd.houseCertificateNo" label="权属证书号（不动产）" placeholder="权属证书号（不动产）" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.landCertificateNo" label="权属证书号（宅基地）" placeholder="权属证书号（宅基地）" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.buildingHight" label="批建高度" placeholder="建筑高度" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.buildingFloors" label="批建层数" placeholder="批建层数" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.actualBuildingHight" label="竣工高度" placeholder="竣工高度" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.actualBuildingFloors" label="竣工层数" placeholder="竣工层数" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.buildingArea" label="建筑面积" placeholder="建筑面积" input-align="right" label-width="auto"/>
            <van-field v-model="applicationDetail.tHouseApplyEnd.designPaper" label="建筑风貌" placeholder="建筑风貌" input-align="right" label-width="auto"/>
            <van-cell title="旧宅基地退还情况">
              <template #right-icon>
                <van-radio-group v-model="applicationDetail.tHouseApplyEnd.oldHouseStatus" direction="horizontal">
                  <van-radio name="0">是</van-radio>
                  <van-radio name="1">否</van-radio>
                </van-radio-group>
              </template>
            </van-cell>
            <van-field label="备注" placeholder="" input-align="right"/>
          </div>
          </div>
<!--applicationDetail.tHouseApplyEnd-->
          <div v-if="false" style="margin: 16px;">
            <van-row>
              <van-col span="12" align="center">
                <van-button type="info" native-type="submit" class="submitButton">保存</van-button>
              </van-col>
              <van-col span="12" align="center">
                <van-button type="info" native-type="submit" class="submitButton">保存并提交</van-button>
              </van-col>
            </van-row>
            <div class="clear"></div>
          </div>

        </van-form>
      </div>
    </div>
</template>

<script>
  import { allInformationAnnounce , treeSingleProcessView , attachmentFind , saveHouseBaseInfo , houseList , attach , removeFile , saveHouseBaseInfoThenSubmit} from "@/api/onlineHome/homestead/application";
export default {
  name: "informationDetail",
  data() {
    return {
      active: 0,
      nowTime: '',//当前日期
      fileList: [],
      fileList2: [],
      radio:'1',
      value: '',
      columns: ['杭州', '宁波', '温州', '嘉兴', '湖州'],
      showPicker: false,
      showBuildingType: false,
      showLandIsposal: false,
      showHousingStructure: false,
      showStartDate: false,
      showEndDate: false,
      showApplyTime:false,
      showHouseType:false,
      showHouse:false,
      showSex:false,
      id:'',
      applicationDetail:[],
      //建房类型字典
      buildingType:[],
      //性别字典
      userSex:[],
      //处置情况字典
      landIsposal:[],
      //房屋构造字典
      housingStructure:[],
      //户型
      houseType:[],
      //请求参数
      parameter:{
        businessType: "house",
        houseApplyStatus: '',
        processKey: "baseApply",
        tableName: "t_house_apply_proposer"
      },
      //文件配置
      fileArray:[],
      //获取上传附件
      params:{
        tableId: '',
        tableName: "t_house_apply_proposer",
        fileType: ''
      },
      auditStatus:false,
      activeNames:['1'],
      housingStructureValue:'',//当前显示房屋构造
      buildingTypeValue:'',//当前显示建房类型
      landIsposalValue:'',//当前显示处置情况
      houseTypeValue:'',//当前显示户型
      sexValue:'',//当前显示性别
      CurrentSituation:false,
    };
  },
  created() {
    this.id = this.$route.query.id;
    this.type = this.$route.query.type;
    this.getDetail();
  },
  methods: {
    goFlow(){
      window.location='flowChart?id='+this.id;
    },
    //更新文件回显
    afterRead(file) {
      this.$forceUpdate();
    },
    //删除图片
    deleteFile(elIndex){
      if(elIndex.id != ''){
        removeFile(elIndex.id).then(response => {});
      }
      this.$forceUpdate();
      return (file, name) => {
        let fileIndex = name.index
        this.fileList[elIndex].splice(fileIndex, 1)
        this.upLoadList[elIndex].splice(fileIndex, 1)
      }
    },
    //获取数据集合
    getDetail(){
      allInformationAnnounce(this.id).then(response => {
        //性别字典查询
        this.houseGetDicts("sys_user_sex").then((res) => {
          res.data.map(item => {
            this.userSex.push({ value:item.dictValue, text: item.dictLabel});
          });
          this.sexValue = this.selectDictLabel(res.data, response.data.tHouseApplyProposer.sex);
        });
        //建房类型字典查询
        this.houseGetDicts("building_type").then((res) => {
          res.data.map(item => {
            this.buildingType.push({ value:item.dictValue, text: item.dictLabel});
          });
          this.buildingTypeValue = this.selectDictLabel(res.data, response.data.tHouseApplyProposedSituation.buildingType);
        });
        //房屋构造字典查询
        this.houseGetDicts("housing_structure").then((res) => {
          res.data.map(item => {
            this.housingStructure.push({ value:item.dictValue, text: item.dictLabel});
          });
          this.housingStructureValue = this.selectDictLabel(res.data, response.data.tHouseApplyProposedSituation.housingStructure);
        });
        //处置情况字典查询
        if(response.data.tHouseApplyProposer.existHomestead == 'Y'){
          this.CurrentSituation = true ;
          this.houseGetDicts("land_isposal").then((res) => {
            res.data.map(item => {
              this.landIsposal.push({ value:item.dictValue, text: item.dictLabel});
            });
            this.landIsposalValue= this.selectDictLabel(res.data, response.data.tHouseApplyCurrentSituation.landIsposal);
          });
        }
        //户型图查询
        houseList().then(res => {
          res.rows.map(item => {
            this.houseType.push({ value:item.id, text: item.name});
          });
          if(response.data.tHouseApplyProposedSituation.houseTypeId != null){
            for (let i = 0 ; i < res.rows.length ; i++){
              if (res.rows[i].id = response.data.tHouseApplyProposedSituation.houseTypeId){
                this.houseTypeValue = res.rows[i].name
              }
            }
            this.showHouse = true;
          }
        });
        this.applicationDetail = response.data;
        this.parameter.houseApplyStatus = response.data.tHouseApplyProposer.houseApplyStatus;
        let currentProcessKey = response.data.currentProcessKey;
        this.auditStatus =  response.data.tHouseApplyProposer.auditStatus != 0;
        //判断当前审核进行到哪一步
        if (currentProcessKey == 'baseApply'){
          this.active = 0;
        }
        if (currentProcessKey == 'landscope'){
          this.active = 1;
        }
        if (currentProcessKey == 'accepting'){
          this.active = 2;
        }
        //获取上传文件列表
        treeSingleProcessView(this.parameter).then(res => {
          this.fileArray = res.rows
          this.params.tableId = this.id;
          for (let i = 0 ; i < res.rows.length ; i++){
            this.params.fileType = res.rows[i].fileType;
            this.fileArray[i].findList = [];
            //获取文件集合
            attachmentFind(this.params).then(res2 => {
              for (let j = 0 ; j < res2.data.length ; j++){
                this.fileArray[i].findList[j] = {url: process.env.VUE_APP_BASE_ROUTING_URL+ res2.data[j].fileUrl, isImage: true , id:res2.data[j].id} ;
                this.$forceUpdate();
              }
            });
          }
        });
      });
    },
    onConfirmApplyTime(date) {
      this.applicationDetail.tHouseApplyProposer.applyTime = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
      this.showApplyTime = false;
    },
    //基地开工时间
    onConfirmStartDate(date) {
      this.applicationDetail.tHouseApplyStart.startDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
      this.showStartDate = false;
    },
    //基地竣工时间
    onConfirmEndDate(date) {
      this.applicationDetail.tHouseApplyStart.endDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
      this.showEndDate = false;
    },
    //选择建房类型
    onConfirmBuildingType(data){
      this.buildingTypeValue = data.text;
      this.applicationDetail.tHouseApplyProposedSituation.buildingType = data.value;
      this.showBuildingType = false;
    },
    //选择宅基地处置情况
    onConfirmLandIsposal(data){
      this.landIsposalValue = data.text;
      this.applicationDetail.tHouseApplyCurrentSituation.landIsposal = data.value;
      this.showLandIsposal = false;
    },
    //选择房屋构造
    onConfirmHousingStructure(data){
      this.housingStructureValue = data.text;
      this.applicationDetail.tHouseApplyProposedSituation.housingStructure = data.value;
      this.showHousingStructure = false;
    },
    //选择户型
    onConfirmHouseType(data){
      this.houseTypeValue = data.text;
      this.applicationDetail.tHouseApplyProposedSituation.houseTypeId = data.value;
      this.showHouseType = false;
    },
    //选择性别
    onConfirmSex(data){
      this.sexValue = data.text;
      this.applicationDetail.tHouseApplyProposer.sex = data.value;
      this.showSex = false;
    },
    //添加家庭成员
    addFamily(){
      this.applicationDetail.tHouseApplyFamilyMembers.push({
        applyProposerId:this.applicationDetail.tHouseApplyFamilyMembers[0].applyProposerId,
        memberName:'',
        age:'',
        familyStatusName:'',
        idcard :'',
        householdRegister:'',
      });
    },
    //删除家庭成员
    deleteFamily(index){

      this.applicationDetail.tHouseApplyFamilyMembers.splice(index,1)
    },
    //是否有宅基地选项改变
    existHomesteadChange(name){
      if (name == 'Y'){
        if (this.applicationDetail.tHouseApplyCurrentSituation == null){
          //现宅基地情况
          this.applicationDetail.tHouseApplyCurrentSituation = {
            //宅基地面积
            landArea: '',
            //人均宅基地面积
            landPerArea: '',
            //不动产单元号
            landCertificateNo: '',
            //农民房屋幢号
            houseCertificateNo: '',
            //建筑面积
            buildingArea: '',
            //人均建筑面积
            buildingPerArea: '',
            //现宅基地处置情况 字典 land_isposal
            landIsposal: ""
          };
          this.CurrentSituation = true ;
          //处置情况字典查询
          this.houseGetDicts("land_isposal").then((res) => {
            res.data.map(item => {
              this.landIsposal.push({ value:item.dictValue, text: item.dictLabel});
            });
            this.landIsposalValue= this.selectDictLabel(res.data, this.applicationDetail.tHouseApplyCurrentSituation.landIsposal);
          });
        }
        this.CurrentSituation = true;
      }else{
        this.CurrentSituation = false;
      }
    },
    //图纸选择改变
    designPaperChange(name){
      if(name == 2){
        this.showHouse = true;
      }else{
        this.showHouse = false;
      }
    },
    base64toFile(dataurl, filename = "file") {
      let arr = dataurl.split(",");
      let mime = arr[0].match(/:(.*?);/)[1];
      let suffix = mime.split("/")[1];
      let bstr = atob(arr[1]);
      let n = bstr.length;
      let u8arr = new Uint8Array(n);
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
      }
      return new File([u8arr], `${filename}.${suffix}`, {
        type: mime,
      });
    },
    //申请提交
    onSubmit(type){
      var that = this;
      let form = {};
      form.fileList=[];
      this.fileList.tableId = this.id;
      for (let i = 0 ; i < this.fileArray.length ; i++){
        if (this.fileArray[i].findList == null || this.fileArray[i].findList == undefined || this.fileArray[i].findList == ''){
          continue
        }
        for (let j = 0 ; j < this.fileArray[i].findList.length ; j++){
          const params = new FormData()
          params.append('tableId', this.id)
          params.append('tableName', 't_house_apply_proposer')
          params.append('bizPath', 't_house_apply_proposer')
          params.append('fileType', this.fileArray[i].fileType)
          if (this.fileArray[i].findList[j].url){
            continue;
          }
          params.append('file', this.base64toFile(this.fileArray[i].findList[j].content))
          attach(params).then(res => {
            form.fileList.push(res.id);
          });
        }
      }
      form.tHouseApplyProposer=this.applicationDetail.tHouseApplyProposer;
      form.tHouseApplyFamilyMembers=this.applicationDetail.tHouseApplyFamilyMembers;
      form.tHouseApproveVillageOptions=this.applicationDetail.tHouseApproveVillageOptions;
      form.tHouseApplyCurrentSituation=this.applicationDetail.tHouseApplyCurrentSituation;
      form.tHouseApplyProposedSituation=this.applicationDetail.tHouseApplyProposedSituation;
      setTimeout(function(){
        if (type == 'keep'){
          saveHouseBaseInfo(form).then(res => {
            if(res.code = 200){
              that.$toast.success('保存成功');
            }
          });
        }
        if (type == 'submit'){
          saveHouseBaseInfoThenSubmit(form).then(res => {
            if(res.code = 200){
              that.$toast.success('提交成功');
            }
          });
        }

      },1000)

    },
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    padding-bottom: 5%;
  }
  .van-steps{
    padding: 2% 6% 0;
  }
  .topTit{
    margin-top: 0.4rem;
    font-size: 0.45rem;
    background-color: #1D6FE9;
    color: #FFFFFF;
    line-height: 58px;
    text-align: center;
    padding: 15px 0;
    box-shadow: 0px 3px 6px 0px rgba(15,67,145,0.40);
  }
  .main_title{
    font-size: 0.4rem;
    color: #1D6FE9;
    margin: 0.2rem 6%;
    position: relative;
  }
  .main_box{
    width: 96%;
    margin: 0 auto;
    border-radius: 6px;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
  }
  .collapse{
    width: 96%;
    margin: 0 auto;
    border-radius: 6px;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    margin-bottom: 15px;
  }
  /deep/.van-radio--horizontal{
    margin-left: 20px;
    margin-right: 0;
  }
  .file-box{
    padding: 2% 5% 0;
  }
  .submitButton{
    width: 80%;
    margin: 0 auto;
    background-color: #1D6FE9;
    border-radius: 14px;
  }
  .timeTit{
    text-align: center;
    font-size: 16px;
    line-height: 27px;
  }
  .action-box{
    padding: 15px 0!important;
    margin-top: 0.4rem;
  }
  .check-box{
    margin-top: 0.4rem;
  }
  .addFamily{
    position: absolute;
    top: -2px;
    right: 0;
    border-radius: 50%;
  }
  .deleteFamily{
    position: absolute;
    top: -0.3rem;
    right: 6%;
    z-index: 9;
    border-radius: 50%;
  }
  .familyList{
    margin-top: 0.4rem;
    position: relative;
  }
  .noModify{
    .topTit{
      background-color:#ABABAB ;
      box-shadow: 0px 3px 6px 0px rgba(171,171,171,0.40);
    }
    .van-cell__title{
      color: #B4B0B0;
    }
  }
</style>
