<template>
  <div>
    <van-nav-bar
      title="确权颁证调查统计表"
      left-text="退出"
      right-text="新增"
      left-arrow
      @click-left="$router.back(-1)"
      @click-right="onClickRight"
    />
    <van-dropdown-menu>
      <van-dropdown-item v-model="value1" :options="option1" @change="changeDept(1)"/>
      <van-dropdown-item v-model="value11" :options="option11" :disabled="value1==0" @change="changeDept(2)"/>
    </van-dropdown-menu>
    <van-dropdown-menu>
      <van-dropdown-item v-model="value2" :options="option2" :disabled="value11==0" @change="changeDept(3)"/>
      <van-dropdown-item v-model="value22" :options="option22" :disabled="value2==0" @change="changeDept(4)"/>
    </van-dropdown-menu>
    <van-pull-refresh v-model="refreshing" @refresh="">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onL"
      >
        <van-row style="text-align: center;font-weight: bold;border:1px solid #ddd;font-size:.4rem;background: #1989fa;color: #fff;line-height: 1rem;border-radius: 10px;">
          <van-col span="8" style="border: 1px solid #FFF">
            <span >农户名</span>
          </van-col>
          <van-col span="8" style="border: 1px solid #FFF">
            <span >调查状态</span>
          </van-col>
          <van-col span="8" style="border: 1px solid #FFF">
            <span >操作</span>
          </van-col>
        </van-row>

        <van-swipe-cell v-for="(item,index) in samplingList" stop-propagation :key="index">
          <template #left>
            <van-button square type="danger" style="height: 30px" text="删除" @click="removeRow(item.id,index)"/>
          </template>
          <van-row style="text-align: center;line-height: 30px;border: 1px solid #FFF">
            <van-col span="8" >
              <span>{{item.farmerName}}</span>
            </van-col>
            <van-col span="8" >
              <span >{{item.status}}</span>
            </van-col>
            <van-col span="8" >
              <van-button type="primary" size="mini" v-show="item.status=='未调查'" style="vertical-align: middle" @click="selectType(1,item,index)">替补</van-button>
              <van-button type="info" size="mini" v-show="item.status=='电话调查'||item.status=='未调查'" style="vertical-align: middle" @click="selectType(2,item,index)">电话</van-button>
              <van-button type="warning" size="mini" v-show="item.status=='现场调查'||item.status=='未调查'" style="vertical-align: middle" @click="selectType(3,item,index)">现场</van-button>
            </van-col>
          </van-row>
        </van-swipe-cell>
      </van-list>
    </van-pull-refresh>
    <van-action-sheet v-model="showXCDC" title="现场调查">
      <van-form @submit="onSubmitXCDC">
        <van-field
          v-model="xcdcform.countName"
          name="countName"
          label="县（区）"
          label-width="120px"
          placeholder="县（区）"
          :rules="[{ required: true, message: '请填写县（区）' }]"
        />
        <van-field
          v-model="xcdcform.townName"
          name="townName"
          label="乡（镇、街）"
          label-width="120px"
          placeholder="乡（镇、街）"
          :rules="[{ required: true, message: '请填写乡（镇、街）' }]"
        />
        <van-field
          v-model="xcdcform.villageName"
          name="villageName"
          label="经联社"
          label-width="120px"
          placeholder="经联社"
          :rules="[{ required: true, message: '请填写经联社' }]"
        />
        <van-field
          v-model="xcdcform.cooperativeName"
          name="cooperativeName"
          label="经济社（小组）"
          label-width="120px"
          placeholder="经济社（小组））"
          :rules="[{ required: true, message: '请填写经济社（小组））' }]"
        />
        <van-field
          v-model="xcdcform.farmerName"
          name="farmerName"
          label="抽查户主名称"
          label-width="120px"
          placeholder="抽查户主名称"
          :rules="[{ required: true, message: '请填写抽查户主名称' }]"
        />
        <van-field
          v-model="xcdcform.originalNameCheckedBy"
          name="originalNameCheckedBy"
          label="原抽查户主姓名"
          label-width="120px"
          placeholder="原抽查户主姓名"
        />
        <van-field
          v-model="xcdcform.nameCheckedBy"
          name="nameCheckedBy"
          label="被核查人姓名"
          label-width="120px"
          placeholder="被核查人姓名"
          :rules="[{ required: true, message: '请填写被核查人姓名' }]"
        >
          <template #button>
           <van-uploader :after-read="afterRead" v-model="fileList" :max-size="1024 * 1024 * 16" @oversize="onOversize" :preview-image="false" :max-count="1" :accept="'image/*'" capture="camera">
              <van-button icon="photograph" type="primary" size="mini">扫描身份证</van-button>
            </van-uploader>
          </template>
        </van-field>
        <van-field
          v-model="xcdcform.idcardCheckedBy"
          name="idcardCheckedBy"
          label="被核查人身份证号"
          label-width="120px"
          placeholder="被核查人身份证号"
          :rules="[{ required: true, message: '请填写被核查人身份证号' }]"
        />
        <van-row type="flex" justify="space-around">
          <van-col span="9"><van-uploader v-model="fileList1" :after-read="afterRead1" @delete="remove(1)" :max-count="1" :accept="'image/*'" capture="camera"></van-uploader></van-col>
          <van-col span="9"><van-uploader v-model="fileList2" :after-read="afterRead2" @delete="remove(2)"  :max-count="1" :accept="'image/*'" capture="camera"></van-uploader></van-col>
        </van-row>
        <h2 class="van-doc-demo-block__title">农村土地承包经营权证</h2>
        <van-field name="item1" label="是否有证书" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item1" direction="horizontal" @change="haveCertificate(1)">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item2" label="印鉴是否合规" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item2" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item3" label="发包方是否准确" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item3" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item4" label="户主姓名是否正确" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item4" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item5" label="户主身份证号是否正确" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item5" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
          v-model="xcdcform.item6"
          name="item6"
          label="地块数(块)"
          placeholder="地块数"
          label-width="120px"
          :rules="[{ required: true, message: '请填写地块数' }]"
        />
        <van-field
          v-model="xcdcform.item7"
          name="item7"
          label="面积(亩)"
          placeholder="面积"
          label-width="120px"
          :rules="[{ required: true, message: '请填写面积' }]"
        />
        <van-field name="item8" label="期限是否合法" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item8" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item9" label="承包合同编号是否正确" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item9" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <h2 class="van-doc-demo-block__title">农村土地承包经营权证</h2>
        <van-field name="item10" label="是否保存合同" label-width="200px" >
          <template #input>
            <van-radio-group v-model="xcdcform.item10" direction="horizontal" @change="haveCertificate(2)">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field><van-field name="item11" label="印鉴是否合规" label-width="200px">
        <template #input>
          <van-radio-group v-model="xcdcform.item11" direction="horizontal">
            <van-radio name="Y">是</van-radio>
            <van-radio name="N">否</van-radio>
          </van-radio-group>
        </template>
      </van-field><van-field name="item12" label="发包方是否与证书一致" label-width="200px">
        <template #input>
          <van-radio-group v-model="xcdcform.item12" direction="horizontal">
            <van-radio name="Y">是</van-radio>
            <van-radio name="N">否</van-radio>
          </van-radio-group>
        </template>
      </van-field>
        <van-field name="item13" label="户主姓名是否与证书一致" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item13" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item14" label="户主身份证号码是否正确" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item14" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item15" label="地块数是否与证书一致" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item15" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item16" label="面积是否与证书一致" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item16" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item17" label="期限是否与证书一致" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item17" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field name="item18" label="承包合同编号是否正确" label-width="200px">
          <template #input>
            <van-radio-group v-model="xcdcform.item18" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
          v-model="xcdcform.checkedBy"
          name="checkedBy"
          label="检查人"
          label-width="120px"
          placeholder="检查人"
          :rules="[{ required: true, message: '请填写检查人' }]"
        />
        <van-field
          v-model="xcdcform.fileName"
          name="fileName"
          label="影像文件名称"
          label-width="120px"
          placeholder="影像文件名称"
          :rules="[{ required: true, message: '请填写影像文件名称' }]"
        />
        <van-field
          v-model="xcdcform.fileTime"
          name="fileTime"
          label="影像起始时间"
          label-width="120px"
          placeholder="影像起始时间"
          @click="showPop"
          :rules="[{ required: true, message: '请填写影像起始时间' }]"
        >
        </van-field>
        <van-popup v-model="showDate" position="bottom" :style="{ height: '40%' }">
          <van-datetime-picker v-model="currentValue" type="datetime" @change="changeFn()" @confirm="confirmFn()" @cancel="cancelFn()"/>
        </van-popup>
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
      </van-form>
    </van-action-sheet>
    <van-action-sheet v-model="showDHDC" title="电话调查">
      <van-form @submit="onSubmitDHDC">
        <van-field
          v-model="dhdcform.countName"
          name="countName"
          label="县（区）"
          label-width="120px"
          placeholder="县（区）"
          :rules="[{ required: true, message: '请填写县（区）' }]"
        />
        <van-field
          v-model="dhdcform.townName"
          name="townName"
          label="乡（镇、街）"
          label-width="120px"
          placeholder="乡（镇、街）"
          :rules="[{ required: true, message: '请填写乡（镇、街）' }]"
        />
        <van-field
          v-model="dhdcform.villageName"
          name="villageName"
          label="经联社"
          label-width="120px"
          placeholder="经联社"
          :rules="[{ required: true, message: '请填写经联社' }]"
        />
        <van-field
          v-model="dhdcform.cooperativeName"
          name="cooperativeName"
          label="经济社（小组）"
          label-width="120px"
          placeholder="经济社（小组））"
          :rules="[{ required: true, message: '请填写经济社（小组））' }]"
        />
        <van-field
          v-model="dhdcform.farmerName"
          name="farmerName"
          label="抽查户主名称"
          label-width="120px"
          placeholder="抽查户主名称"
          :rules="[{ required: true, message: '请填写抽查户主名称' }]"
        />
        <van-field
          v-model="dhdcform.idcardCheckedBy"
          name="idcardCheckedBy"
          label="抽查户主身份证号"
          label-width="120px"
          placeholder="抽查户主身份证号"
          :rules="[{ required: true, message: '请填写抽查户主身份证号' }]"
        />
        <van-field
          v-model="dhdcform.originalNameCheckedBy"
          name="originalNameCheckedBy"
          label="原抽查户主姓名"
          label-width="120px"
          placeholder="原抽查户主姓名"
        />
        <van-field
          v-model="dhdcform.callPhone"
          name="callPhone"
          label="主叫号码"
          label-width="120px"
          placeholder="主叫号码"
          :rules="[{ required: true, message: '请填写主叫号码' }]"
        />
        <van-field
          v-model="dhdcform.calledPhone"
          name="calledPhone"
          label="被叫号码"
          label-width="120px"
          placeholder="被叫号码"
          :rules="[{ required: true, message: '请填写被叫号码' }]"
        />
        <h2 class="van-doc-demo-block__title">农村土地承包经营权证</h2>
        <van-field name="item1" label="是否有证书">
          <template #input>
            <van-radio-group v-model="dhdcform.item1" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <h2 class="van-doc-demo-block__title">农村土地承合同</h2>
        <van-field name="item10" label="是否保存合同">
          <template #input>
            <van-radio-group v-model="dhdcform.item10" direction="horizontal">
              <van-radio name="Y">是</van-radio>
              <van-radio name="N">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
          v-model="dhdcform.checkedBy"
          name="checkedBy"
          label="检查人"
          label-width="120px"
          placeholder="检查人"
          :rules="[{ required: true, message: '请填写检查人' }]"
        />
        <van-field
          v-model="dhdcform.fileName"
          name="fileName"
          label="影像文件名称"
          label-width="120px"
          placeholder="影像文件名称"
          :rules="[{ required: true, message: '请填写影像文件名称' }]"
        />
        <van-field
          v-model="dhdcform.fileTime"
          name="fileTime"
          label="影像起始时间"
          label-width="120px"
          @click="showPop1"
          placeholder="影像起始时间"
          :rules="[{ required: true, message: '请填写影像起始时间' }]"
        >
        </van-field>
        <van-popup v-model="showDate1" position="bottom" :style="{ height: '40%' }">
          <van-datetime-picker v-model="currentValue" type="datetime" @change="changeFn()" @confirm="confirmFn()" @cancel="cancelFn()"/>
        </van-popup>
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
      </van-form>
    </van-action-sheet>
    <van-action-sheet v-model="show" title="基础数据">
      <van-form @submit="onSubmit">
        <van-field
          v-model="queryform.countName"
          name="countName"
          label="县（区）"
          label-width="120px"
          placeholder="县（区）"
          :rules="[{ required: true, message: '请填写县（区）' }]"
        />
        <van-field
          v-model="queryform.townName"
          name="townName"
          label="乡（镇、街）"
          label-width="120px"
          placeholder="乡（镇、街）"
          :rules="[{ required: true, message: '请填写乡（镇、街）' }]"
        />
        <van-field
          v-model="queryform.villageName"
          name="villageName"
          label="经联社"
          label-width="120px"
          placeholder="经联社"
          :rules="[{ required: true, message: '请填写经联社' }]"
        />
        <van-field
          v-model="queryform.cooperativeName"
          name="cooperativeName"
          label="经济社（小组）"
          label-width="120px"
          placeholder="经济社（小组））"
          :rules="[{ required: true, message: '请填写经济社（小组））' }]"
        />
        <van-field
          v-model="queryform.farmerName"
          name="farmerName"
          label="抽查户主名称"
          label-width="120px"
          placeholder="抽查户主名称"
          :rules="[{ required: true, message: '请填写抽查户主名称' }]"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
      </van-form>
    </van-action-sheet>
  </div>
</template>

<script>

  import {
    addInvestigate,
    addSampling,
    delSampling,
    getInvestigate,
    listSampling, listSamplingDept,
    updateInvestigate,
    updateSampling, uploadFile, uploadFileBase
  } from "../../api/authenticRight";
  import {getDeptList} from "../../api/biddingHall";
  import {Dialog} from "vant";
  import {getInfo} from "@/api/login/index";
  import {getNowFormatDate} from "../../utils/utils";
  import request from '@/utils/request'

  export default {
    name: "authenticRightApply",
    data() {
      return {
        showDate:false,
        showDate1 : false,
        value1:0,
        option1:[{ text: '请选择区县', value: 0 }],
        value11:0,
        option11:[{ text: '请选择乡镇', value: 0 }],
        value2:0,
        option2:[{ text: '请选择村级', value: 0 }],
        value22:0,
        option22:[{ text: '请选择合作社', value: 0 }],
        loading: false,
        finished: false,
        refreshing: false,
        value:"",
        show:false,
        showXCDC:false,
        showDHDC:false,
        radio: '1',
        username: '',
        password: '',
        queryParams:{
          // 分页
          pageNum: 1,
          pageSize: 30,
          // 查询排序
          //orderByColumn: "id",
          //isAsc: "desc",
          countName: null,
          townName: null,
          villageName: null,
          cooperativeName: null,
          farmerName: null,
          status: null,
          id: null,
        },
        samplingList:[

        ],
        queryform:{
          // 分页
          pageNum: 1,
          pageSize: 30,
          // 查询排序
          //orderByColumn: "id",
          //isAsc: "desc",
          countName: null,
          townName: null,
          villageName: null,
          cooperativeName: null,
          farmerName: null,
          status: null,
          id: null,
        },
        xcdcform:{
          countName: null,
          townName: null,
          villageName: null,
          cooperativeName: null,
          farmerName: null,
          status: null,
          callPhone: null,
          calledPhone: null,
          checkedBy: null,
          createBy: null,
          createTime: null,
          fileName: null,
          fileTime: null,
          id: null,
          idcardCheckedBy: null,
          item1: '',
          item2: '',
          item3: '',
          item4: '',
          item5: '',
          item6: '',
          item7: '',
          item8: '',
          item9: '',
          item10: '',
          item11: '',
          item12: '',
          item13: '',
          item14: '',
          item15: '',
          item16: '',
          item17: '',
          item18: '',
          lackCount: null,
          originalNameCheckedBy: null,
          nameCheckedBy: null,
          params: null,
          samplingId: null,
          searchValue: null,
          fileUrl1:[],
          fileUrl2:[],
        },
        dhdcform:{
          callPhone: null,
          calledPhone: null,
          checkedBy: null,
          createBy: null,
          createTime: null,
          fileName: null,
          fileTime: null,
          id: null,
          idcardCheckedBy: null,
          item1: null,
          item10: null,
          lackCount: null,
          originalNameCheckedBy: null,
          nameCheckedBy: null,
          params: null,
          samplingId: null,
          searchValue: null,
          countName: null,
          townName: null,
          villageName: null,
          cooperativeName: null,
          farmerName: null,
          status: null,
        },
        show1: false,
        fieldValue: '',
        cascaderValue: '',
        options: [

        ],
        userId :null,
        nickName:null,
        currentValue:null,
        fileList:[],
        fileList1:[],
        fileList2:[],
      }
    },
    created(){
      listSamplingDept(this.queryParams).then(res => {
        if(res.data){
          this.option1=[{ text: '请选择区县', value: 0 }]
          res.data.map(item => {
            this.option1.push({ "text":item.countName,"value": item.countName})
          })
        }
      })
      getInfo().then(response => {
        this.userId = response.user.userId
        this.nickName = response.user.nickName
      });

    },
    methods:{
      onOversize(file) {
        this.$toast({
          icon: 'error', // 找到自己需要的图标
          message: '上传失败！文件大小不能超过 16m',
          duration:"1000",
        })
      },
      afterRead(file){
        // 创建Canvas对象(画布)
        let canvas =  document.createElement('canvas')
        // 获取对应的CanvasRenderingContext2D对象(画笔)
        let context = canvas.getContext('2d')
        // 创建新的图片对象
        let img = new Image()
        // 指定图片的DataURL(图片的base64编码数据)
        img.src = file.content
        // 监听浏览器加载图片完成，然后进行进行绘制
        const height = 166
        const width = 316
        img.onload = () => {
          const h = img.height
          const w = img.width
          let ch = img.height/4
          let cw = img.width/4
          let canvas = document.createElement('canvas')
          let ctx = canvas.getContext('2d')
          canvas.height = ch
          canvas.width = cw
          ctx.clearRect(0,0,cw,ch)
          ctx.drawImage(img,0,0,cw,ch)
          let base_img = canvas.toDataURL('image/jpeg')
          const blobBin = atob(base_img.split(',')[1])
          let d = []
          for (let i=0;i<blobBin.length;i++){
            d.push(blobBin.charCodeAt(i))
          }
          const data2 = new FormData();
          data2.append("file", new Blob([new Uint8Array(d)],{type:'image/jpeg'}));
          uploadFile(data2).then(res => {
            if(res.code == 200){
              this.xcdcform.idcardCheckedBy = res.idcardCheckedBy
              this.xcdcform.nameCheckedBy = res.nameCheckedBy
              this.xcdcform["fileUrl"] = res.url
            }
          })
          this.fileList = []
        }
        this.fileList = []
      },
      afterRead1(file){
        // 创建Canvas对象(画布)
        let canvas =  document.createElement('canvas')
        // 获取对应的CanvasRenderingContext2D对象(画笔)
        let context = canvas.getContext('2d')
        // 创建新的图片对象
        let img = new Image()
        // 指定图片的DataURL(图片的base64编码数据)
        img.src = file.content
        img.onload = () => {
          const h = img.height
          const w = img.width
          let ch = img.height/4
          let cw = img.width/4
          let canvas = document.createElement('canvas')
          let ctx = canvas.getContext('2d')
          canvas.height = ch
          canvas.width = cw
          ctx.clearRect(0,0,cw,ch)
          ctx.drawImage(img,0,0,cw,ch)
          let base_img = canvas.toDataURL('image/jpeg')
          const blobBin = atob(base_img.split(',')[1])
          let d = []
          for (let i=0;i<blobBin.length;i++){
            d.push(blobBin.charCodeAt(i))
          }
          const data2 = new FormData();
          data2.append("file", new Blob([new Uint8Array(d)],{type:'image/jpeg'}));
          uploadFileBase(data2).then(res => {
            this.xcdcform.fileUrl1=res.fileName
            console.log(res)
           })
        }
      },
      afterRead2(file){
        // 创建Canvas对象(画布)
        let canvas =  document.createElement('canvas')
        // 获取对应的CanvasRenderingContext2D对象(画笔)
        let context = canvas.getContext('2d')
        // 创建新的图片对象
        let img = new Image()
        // 指定图片的DataURL(图片的base64编码数据)
        img.src = file.content
        img.onload = () => {
          const h = img.height
          const w = img.width
          let ch = img.height/4
          let cw = img.width/4
          let canvas = document.createElement('canvas')
          let ctx = canvas.getContext('2d')
          canvas.height = ch
          canvas.width = cw
          ctx.clearRect(0,0,cw,ch)
          ctx.drawImage(img,0,0,cw,ch)
          let base_img = canvas.toDataURL('image/jpeg')
          const blobBin = atob(base_img.split(',')[1])
          let d = []
          for (let i=0;i<blobBin.length;i++){
            d.push(blobBin.charCodeAt(i))
          }
          const data2 = new FormData();
          data2.append("file", new Blob([new Uint8Array(d)],{type:'image/jpeg'}));
          uploadFileBase(data2).then(res => {
            this.xcdcform.fileUrl2=res.fileName
          })
        }
      },
      remove(val){
        if(val==1){
          this.xcdcform.fileUrl1=""
        }else {
          this.xcdcform.fileUrl2=""
        }
      },
      changeFn(val) {
      },
      confirmFn(){
        this.xcdcform.fileTime = getNowFormatDate(this.currentValue)
        this.dhdcform.fileTime = getNowFormatDate(this.currentValue)
        this.showDate = false;
        this.showDate1 = false;
      },
      cancelFn(){
        this.showDate = false;
        this.showDate1 = false;
      }
      ,
      showPop(){
        this.showDate = true;
      },
      showPop1(){
        this.showDate1 = true;
      },
      changeDept(val){
        if(val==1){
          this.queryParams.countName = this.value1
          this.queryParams.townName = null
          this.queryParams.villageName = null
          this.queryParams.cooperativeName = null
          listSamplingDept(this.queryParams).then(res => {
            if(res.data){
              this.option11=[{ text: '请选择乡镇', value: 0 }]
              res.data.map(item => {
                this.option11.push({ "text":item.townName,"value": item.townName})
              })
              this.value11=0
              this.value2=0
              this.value22=0
            }
          })
        }else if(val==2){
          this.queryParams.countName = this.value1
          this.queryParams.townName = this.value11
          this.queryParams.villageName = null
          this.queryParams.cooperativeName = null
          listSamplingDept(this.queryParams).then(res => {
            if(res.data){
              this.option2=[{ text: '请选择村级', value: 0 }]
              res.data.map(item => {
                this.option2.push({ "text":item.villageName,"value": item.villageName})
              })
              this.value2=0
              this.value22=0
            }
          })
        }else if(val==3){
          this.queryParams.countName = this.value1
          this.queryParams.townName = this.value11
          this.queryParams.villageName = this.value2
          this.queryParams.cooperativeName = null
          listSamplingDept(this.queryParams).then(res => {
            if(res.data){
              this.option22=[{ text: '请选择合作社', value: 0 }]
              res.data.map(item => {
                this.option22.push({ "text":item.cooperativeName,"value": item.cooperativeName})
              })
              this.value22=0
            }
          })

        }else if(val==4){
          this.queryParams.countName = this.value1
          this.queryParams.townName = this.value11
          this.queryParams.villageName = this.value2
          this.queryParams.cooperativeName = this.value22
          this.getList()
        }
      },
      reset(){
        this.queryform={
          pageNum: 1,
          pageSize: 30,
          // 查询排序
          //orderByColumn: "id",
          //isAsc: "desc",
          countName: null,
          townName: null,
          villageName: null,
          cooperativeName: null,
          status: null,
          id: null,
        }
        this.xcdcform={
          countName: null,
          townName: null,
          villageName: null,
          cooperativeName: null,
          farmerName: null,
          status: null,
          callPhone: null,
          calledPhone: null,
          checkedBy: null,
          createBy: null,
          createTime: null,
          fileName: null,
          fileTime: null,
          id: null,
          idcardCheckedBy: null,
          item1: '',
          item2: '',
          item3: '',
          item4: '',
          item5: '',
          item6: '',
          item7: '',
          item8: '',
          item9: '',
          item10: '',
          item11: '',
          item12: '',
          item13: '',
          item14: '',
          item15: '',
          item16: '',
          item17: '',
          item18: '',
          lackCount: null,
          originalNameCheckedBy: null,
          nameCheckedBy: null,
          params: null,
          samplingId: null,
          searchValue: null,
          updateBy: null,
          fileUrl1: [],
          fileUrl2: [],
        };
        this.dhdcform={
          countName: null,
          townName: null,
          villageName: null,
          cooperativeName: null,
          farmerName: null,
          status: null,
          callPhone: null,
          calledPhone: null,
          checkedBy: null,
          createBy: null,
          createTime: null,
          fileName: null,
          fileTime: null,
          id: null,
          idcardCheckedBy: null,
          item1: null,
          item10: null,
          lackCount: null,
          originalNameCheckedBy: null,
          nameCheckedBy: null,
          params: null,
          samplingId: null,
          searchValue: null,
          updateBy: null,
        }
        this.fileList = []
        this.fileList1 = []
        this.fileList2 = []
      },
      onClickRight() {
        this.show = true
        this.queryform = this.queryParams
      },
      onSearch() {

      },
      onChange({ value }) {
        this.options.map(i => {
          if (value === i.value) {
            getDeptList(value).then(response => {
              if(response.data.length>0){
                i.children=[]
                response.data.map(item => {
                  i.children.push({ text: item.deptName,value:item.deptId});
                });
              }
            });
          }
        })
      },
      removeRow(id,index){
        let _this = this
        Dialog.confirm({
          title: '删除',
          message: '删除后数据无法恢复，确认要删除么？'
        }).then(() => {
          delSampling(id).then(res => {
            this.$toast({
              icon: 'success', // 找到自己需要的图标
              message: '删除成功',
              duration:"1000",
              onClose:function(){
                _this.getList();
              }
            })
          })
        }).catch(() => {
          // on cancel
        });

      },
      onFinish({ selectedOptions }) {
        this.show1 = false;
        this.fieldValue = selectedOptions.map((option) => option.text).join('/');
      },
      /** 判断是否有证书 */
      haveCertificate(id){
        if(id == "1"){
          if(this.xcdcform.item1=='N'){
            this.xcdcform.item2 = 'N'
            this.xcdcform.item3 = 'N'
            this.xcdcform.item4 = 'N'
            this.xcdcform.item5 = 'N'
            this.xcdcform.item8 = 'N'
            this.xcdcform.item9 = 'N'
          }
        }if(id == "2") {
          if(this.xcdcform.item10=='N'){
            this.xcdcform.item11 = 'N'
            this.xcdcform.item12 = 'N'
            this.xcdcform.item13 = 'N'
            this.xcdcform.item14 = 'N'
            this.xcdcform.item15 = 'N'
            this.xcdcform.item16 = 'N'
            this.xcdcform.item17 = 'N'
            this.xcdcform.item18 = 'N'
          }
        }
      },
      selectType(val,data,index){
        if(val==1){
          let _this = this
          let a ={
            "countName": data.countName,
            "townName": data.townName,
            "villageName": data.villageName,
            "cooperativeName": data.cooperativeName,
            "status": "1",
            "id": data.id
          }
          a.status = "1"
          updateSampling(a).then(res => {
            this.$toast({
              icon: 'success', // 找到自己需要的图标
              message: '修改成功',
              duration:"1000",
              onClose:function(){
                _this.getList();
              }
            })
          })
        }else if(val==3){
          this.reset();
          this.showXCDC=true
          getInvestigate(data.id).then(res => {
            if(res.data){
              this.xcdcform = res.data
              console.log(res.data)
              if(this.xcdcform.fileUrl1){
                this.fileList1.push({
                  "url":this.xcdcform.fileUrl1
                })
              }
              if(this.xcdcform.fileUrl2){
                this.fileList2.push({
                  "url":this.xcdcform.fileUrl2
                })
              }
              this.xcdcform["countName"] = data.countName
              this.xcdcform["townName"] = data.townName
              this.xcdcform["villageName"] = data.villageName
              this.xcdcform["cooperativeName"] = data.cooperativeName
              this.xcdcform["farmerName"] = data.farmerName
            }else{
              this.xcdcform["countName"] = data.countName
              this.xcdcform["townName"] = data.townName
              this.xcdcform["villageName"] = data.villageName
              this.xcdcform["cooperativeName"] = data.cooperativeName
              this.xcdcform["farmerName"] = data.farmerName
              this.xcdcform["samplingId"] = data.id
              this.xcdcform["fileName"] = data.townName+data.villageName
              this.xcdcform["checkedBy"] = this.nickName
              this.xcdcform["fileTime"] = getNowFormatDate()
            }
          })

        }else if(val==2){
          this.reset();
          this.showDHDC=true
          getInvestigate(data.id).then(res => {
            if(res.data){
              this.dhdcform = res.data
              this.dhdcform["countName"] = data.countName
              this.dhdcform["townName"] = data.townName
              this.dhdcform["villageName"] = data.villageName
              this.dhdcform["cooperativeName"] = data.cooperativeName
              this.dhdcform["farmerName"] = data.farmerName
            }else{
              this.dhdcform["countName"] = data.countName
              this.dhdcform["townName"] = data.townName
              this.dhdcform["villageName"] = data.villageName
              this.dhdcform["cooperativeName"] = data.cooperativeName
              this.dhdcform["farmerName"] = data.farmerName
              this.dhdcform["samplingId"] = data.id
              this.dhdcform["fileName"] = data.townName+data.villageName
              this.dhdcform["checkedBy"] = this.nickName
              this.dhdcform["fileTime"] = getNowFormatDate()
            }
          })
        }
      },
      onSubmit(values) {
        this.queryform["createBy"] = this.userId
        this.queryform["createTime"] = getNowFormatDate()
        addSampling(this.queryform).then(res => {
          this.show = false
          this.getList();
        })
      },
      onSubmitXCDC(values) {
        let i = 0
        if(this.xcdcform.item1=='N'){
          i++
        }if(this.xcdcform.item2=='N'){
          i++
        }if(this.xcdcform.item3=='N'){
          i++
        }if(this.xcdcform.item4=='N'){
          i++
        }if(this.xcdcform.item5=='N'){
          i++
        }if(this.xcdcform.item8=='N'){
          i++
        }if(this.xcdcform.item9=='N'){
          i++
        }if(this.xcdcform.item10=='N'){
          i++
        }if(this.xcdcform.item11=='N'){
          i++
        }if(this.xcdcform.item12=='N'){
          i++
        }if(this.xcdcform.item13=='N'){
          i++
        }if(this.xcdcform.item14=='N'){
          i++
        }if(this.xcdcform.item15=='N'){
          i++
        }if(this.xcdcform.item16=='N'){
          i++
        }if(this.xcdcform.item17=='N'){
          i++
        }if(this.xcdcform.item18=='N'){
          i++
        }
        this.xcdcform["lackCount"] = i
        if(this.xcdcform.fileUrl1.length>0){
          this.xcdcform.fileUrl1 = location.protocol+"//"+location.host+request.defaults.baseURL+ this.xcdcform.fileUrl1.replace(location.protocol+"//"+location.host+request.defaults.baseURL,"")
        }else {
          this.xcdcform.fileUrl1=""
        }if(this.xcdcform.fileUrl2.length>0){
          this.xcdcform.fileUrl2 = location.protocol+"//"+location.host+request.defaults.baseURL+ this.xcdcform.fileUrl2.replace(location.protocol+"//"+location.host+request.defaults.baseURL,"")
        }else {
          this.xcdcform.fileUrl2=""
        }
        if(this.xcdcform.id){
          updateInvestigate(this.xcdcform).then(res => {
            this.showXCDC = false
            let _this = this
            this.xcdcform.status = "2"
            this.xcdcform.id = this.xcdcform.samplingId
            updateSampling(this.xcdcform).then(res => {
              _this.reset()
              this.$toast({
                icon: 'success', // 找到自己需要的图标
                message: '修改成功',
                duration:"1000",
                onClose:function(){
                  _this.getList();
                }
              })
            })
          })
        }else {
          addInvestigate(this.xcdcform).then(res => {
            this.showXCDC = false
            let _this = this
            this.xcdcform.status = "2"
            this.xcdcform.id = this.xcdcform.samplingId
            updateSampling(this.xcdcform).then(res => {
              _this.reset()
              this.$toast({
                icon: 'success', // 找到自己需要的图标
                message: '保存成功',
                duration:"1000",
                onClose:function(){
                  _this.getList();
                }
              })
            })
          })
        }},
      onSubmitDHDC(values) {
        if(this.dhdcform.id){
          updateInvestigate(this.dhdcform).then(res => {
            this.showDHDC = false
            let _this = this
            this.dhdcform.status = "3"
            this.dhdcform.id = this.dhdcform.samplingId
            updateSampling(this.dhdcform).then(res => {
              _this.reset()
              this.$toast({
                icon: 'success', // 找到自己需要的图标
                message: '修改成功',
                duration:"1000",
                onClose:function(){
                  _this.getList();
                }
              })
            })
          })
        }else {
          addInvestigate(this.dhdcform).then(res => {
            this.showDHDC = false
            let _this = this
            this.dhdcform.status = "3"
            this.dhdcform.id = this.dhdcform.samplingId
            updateSampling(this.dhdcform).then(res => {
              _this.reset()
              this.$toast({
                icon: 'success', // 找到自己需要的图标
                message: '保存成功',
                duration:"1000",
                onClose:function(){
                  _this.getList();
                }
              })
            })
          })
        }
      },
      getList(){
        this.queryParams["farmerName"] = null
        listSampling(this.queryParams).then(response => {
          if(response.rows.length>0){
            response.rows.map(item => {
              if(item.status==0){
                item.status="未调查"
              }else if(item.status==1){
                item.status="被替补"
              }else if(item.status==2){
                item.status="现场调查"
              }else if(item.status==3){
                item.status="电话调查"
              }
            })
            this.samplingList = response.rows;
            this.loading = false;
          }
        });
      },
      onL() {
        this.refreshing = true;
        this.loading = false;
        this.refreshing = false;
      },
      onRefresh() {
        // 清空列表数据
        this.finished = false;
        // 重新加载数据
        // 将 loading 设置为 true，表示处于加载状态
        this.loading = true;
        this.onL();
      },
    },
  }
</script>

<style scoped>
  .van-doc-demo-block__title {
    margin: 0;
    padding: 32px 16px 16px;
    color: rgba(69, 90, 100, 0.6);
    font-weight: normal;
    font-size: 14px;
    line-height: 16px;
  }
</style>
