<template>
    <!--  -->
    <el-card class="box-card" v-loading="loading">
        <div class="discharge-date">巡访日期：{{newDate}}</div>
<!--        <el-amap class="amap-box" vid="amapDemo" :zoom="zoom" :center="center" :plugin="plugin"></el-amap>-->
        <!-- <el-amap class="amap-box" vid="amapDemo" :zoom="zoom" :center="center" :plugin="plugin"></el-amap> -->
        <el-form class="visit-top" :rules="rules" :model="formData" ref="formData" label-position="left">
<!--            <el-form-item label="巡访位置">-->
<!--                <div>{{formData.visitLocation}}</div>-->
<!--                <div>经度{{formData.lng}} 纬度{{formData.lat}}</div>-->
<!--            </el-form-item>-->
          <div style="margin: 15px 0;"></div>
            <el-form-item label="老人姓名">
                <el-tag type="success">{{olds?olds.name+(olds.idNumber?"("+olds.idNumber+")":""):''}}</el-tag>
                <el-button type="primary" style="margin-left :10px" size="small" @click="details">老人详情</el-button>
            </el-form-item>

          <div class="discharge-date"><span style="font-size: 17px">家庭状况：</span>
            <el-form-item label="家庭人口" prop="jtrk_bdrs_type">
              <div style="margin: 5px 0;"></div>
              <el-radio-group v-model="formData.jtrk_bdrs_type" @change="changeJtrks">
                <el-radio class="cus-radio" label="0">无变化</el-radio>
                <br>
                <el-radio class="cus-radio" label="1">增加<el-input-number style="width: 65px" size="mini" :min="1" :max="10" v-model="formData.jtrk_bdrs_add" :disabled=formData.jtrk_bdrs_add_disabled></el-input-number>人</el-radio>
                <el-radio class="cus-radio" label="2">减少<el-input-number style="width: 65px" size="mini" :min="1" :max="10" v-model="formData.jtrk_bdrs_decrease" :disabled=formData.jtrk_bdrs_decrease_disabled></el-input-number>人</el-radio>
<!--                <el-radio class="cus-radio" label="2">减少<el-input-number  style="width: 85px" size="mini" :min="1" :max="10" v-model="formData.jtrk_bdrs_decrease" :disabled=formData.jtrk_bdrs_decrease_disabled></el-input-number>人</el-radio>-->
<!--                <el-radio class="cus-radio" label="1">增加<el-input-number  style="width: 85px" size="mini" :min="1" :max="10" v-model="formData.jtrk_bdrs_add" :disabled=formData.jtrk_bdrs_add_disabled></el-input-number>人</el-radio>-->

              </el-radio-group>
            </el-form-item>
          </div>

          <hr>

            <div class="discharge-date"><span style="font-size: 17px">健康情况：</span>
              <el-form-item label="表达能力" prop="bdnl">
                <div style="margin: 5px 0;"></div>
                <el-radio-group v-model="formData.bdnl">
                  <el-radio label="0">无变化</el-radio>
                  <el-radio label="1">较好</el-radio>
                  <el-radio label="2">较差</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="行动能力" prop="xdnl">
                <div style="margin: 5px 0;"></div>
                <el-radio-group v-model="formData.xdnl">
                  <el-radio label="0">无变化</el-radio>
                  <el-radio label="1">较好</el-radio>
                  <el-radio label="2">较差</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="疾病情况" prop="jbqk">
                <div style="margin: 5px 0;"></div>
                <el-radio-group v-model="formData.jbqk" @change = "changeHealth">
                  <el-radio label="0">无变化</el-radio>
                  <el-radio label="1">转好</el-radio>
                  <el-radio label="2">严重 疾病名称：</el-radio> <el-input type="text" size="mini" show-word-limit style="width:300px" maxlength="20"  v-model="formData.jbqk_bdmc" :disabled=formData.jbqk_bdmc_disabled></el-input>
                </el-radio-group>
              </el-form-item>
            </div>

          <hr>

          <div class="discharge-date"><span style="font-size: 17px">精神状态：</span>
            <el-form-item label="情绪状态" prop="qxzt">
              <div style="margin: 5px 0;"></div>
              <el-radio-group v-model="formData.qxzt">
                <el-radio label="0">无变化</el-radio>
                <el-radio label="1">较好</el-radio>
                <el-radio label="2">较差</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>

          <hr>

          <div class="discharge-date"><span style="font-size: 17px">安全情况：</span>
            <el-form-item label="燃气安全" prop="rqaq">
              <div style="margin: 5px 0;"></div>
              <el-radio-group v-model="formData.rqaq">
                <el-radio label="0">安全</el-radio>
                <el-radio label="1">较安全</el-radio>
                <el-radio label="2">不安全</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="水暖安全" prop="snaq">
              <div style="margin: 5px 0;"></div>
              <el-radio-group v-model="formData.snaq">
                <el-radio label="0">安全</el-radio>
                <el-radio label="1">较安全</el-radio>
                <el-radio label="2">不安全</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="用电安全" prop="ydaq">
              <div style="margin: 5px 0;"></div>
              <el-radio-group v-model="formData.ydaq">
                <el-radio label="0">安全</el-radio>
                <el-radio label="1">较安全</el-radio>
                <el-radio label="2">不安全</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>

          <hr>

          <div class="discharge-date"><span style="font-size: 17px">卫生状况：</span>
            <el-form-item label="个人卫生" prop="grws">
              <div style="margin: 5px 0;"></div>
              <el-radio-group v-model="formData.grws">
                <el-radio label="0">无变化</el-radio>
                <el-radio label="1">较好</el-radio>
                <el-radio label="2">较差</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="家庭卫生" prop="jtws">
              <div style="margin: 5px 0;"></div>
              <el-radio-group v-model="formData.jtws">
                <el-radio label="0">无变化</el-radio>
                <el-radio label="1">较好</el-radio>
                <el-radio label="2">较差</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>

          <hr>

          <div class="discharge-date"><span style="font-size: 17px">居住环境：</span>
            <el-form-item label="室内环境" prop="snhj">
              <div style="margin: 5px 0;"></div>
              <el-radio-group v-model="formData.snhj">
                <el-radio label="0">无变化</el-radio>
                <el-radio label="1">较好</el-radio>
                <el-radio label="2">较差</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>

          <hr>

          <div class="discharge-date"><span style="font-size: 17px">老人需求说明：</span>
            <div style="margin: 5px 0;"></div>
            <el-checkbox-group v-model="formData.demandXQ" @change="changesto">
              <el-checkbox label="fwxq_jtcw">家庭养老床位服务</el-checkbox>
              <el-checkbox label="fwxq_zcfw">上门助餐服务</el-checkbox>
              <el-checkbox label="fwxq_zjfw">上门助洁服务</el-checkbox>
              <el-checkbox label="fwxq_zxfw">上门助行服务</el-checkbox>
              <el-checkbox label="fwxq_xzfw">上门助浴服务</el-checkbox>
              <el-checkbox label="fwxq_kffw">上门康复服务</el-checkbox>
              <el-checkbox label="fwxq_zyfw">上门助医服务</el-checkbox>
              <el-checkbox label="fwxq_rzylyxq">入住养老院需求</el-checkbox>
              <el-checkbox label="fwxq_rzsqyljgxq">入住社区养老院机构需求</el-checkbox>
              <el-checkbox label="fwxq_jkjcxq">健康检查需求</el-checkbox>
              <el-checkbox label="fwxq_qtfwxq">其他服务需求</el-checkbox>
              <el-input v-model="formData.fwxq_qtfwxqms" :disabled=formData.fwxq_qtfwxqms_disabled>其他服务需求</el-input>
            </el-checkbox-group>
          </div>

          <hr>

          <el-form-item label="需求紧急程度" prop="fwxq_jjcd">
            <div style="margin: 5px 0;"></div>
            <el-radio-group v-model="formData.fwxq_jjcd">
              <el-radio label="0">不紧急</el-radio>
              <el-radio label="1">一般</el-radio>
              <el-radio label="2">紧急</el-radio>
            </el-radio-group>
          </el-form-item>

            <el-form-item label="实施服务建议" prop="fwjy">
              <el-input type="textarea" placeholder="请填写实施服务建议" v-model="formData.fwjy"></el-input>
            </el-form-item>
            <el-form-item label="巡访备注说明" prop="bzsm">
                <el-input
                        type="textarea"
                        placeholder="请填写一下巡访备注说明"
                        v-model="formData.bzsm"
                        maxlength="100"
                        show-word-limit
                        rows="5"
                ></el-input>
            </el-form-item>
<!-- 2024-5-6 15:31:56 根据要求，将巡访照片去掉，且不用人脸比对。-->
            <!--            <el-form-item class="oldPhoto" label="现场含面部照片(正面照)" prop="visitPhoto">-->
            <!--                <br/>-->
            <!--                <div>-->
            <!--          <span-->
            <!--                  v-for="(u,index) in urls"-->
            <!--                  :key="index"-->
            <!--                  style="position: relative;display: inline-block; margin-right: 1% "-->
            <!--          >-->
            <!--            <el-image-->
            <!--                    :src="servelUrl+u"-->
            <!--                    @click="look(u)"-->
            <!--                    style="width: 100px;height: 100px;margin-bottom: 5%;"-->
            <!--            >-->
            <!--              <div slot="placeholder" class="image-slot">照片上传中...</div>-->
            <!--            </el-image>-->
            <!--            <span-->
            <!--                    style="position: absolute;top: 3%;right: 5%;color: #ffffff;"-->
            <!--                    @click="deleteImg(index)"-->
            <!--            >-->
            <!--              <i class="el-icon-circle-close"></i>-->
            <!--            </span>-->
            <!--          </span>-->
            <!--                </div>-->
            <!--                <div style="position:relative;">-->
            <!--                    <el-button v-if="isShowUpload" type="primary" size="mini" plain>请上传含面部照片</el-button>-->
            <!--                    <input-->
            <!--                            class="camera"-->
            <!--                            v-if="isShowUpload"-->
            <!--                            type="file"-->
            <!--                            accept="image/*"-->
            <!--                            capture="camera"-->
            <!--                            style="width: 100%;"-->
            <!--                            ref="fileItem"-->
            <!--                            @change="changeFile"-->
            <!--                    />-->
            <!--                </div>-->
            <!--            </el-form-item>-->
            <el-button style="width: 100%;" type="primary" @click="submission">提交</el-button>
            <el-dialog fullscreen :visible.sync="dialogVisible" style="width: 100%">
                <el-image :src="servelUrl+ur"/>
            </el-dialog>
        </el-form>
    </el-card>
</template>

<script>
import {
  addVisitData,
  oldsInfo,
  visitFace,
  visitError,
  dictListForPage, pcVisitCommit, userOne
} from "../api";
    import lrz from "lrz";
    import config from '@/util/config'
    import getClient from "../util/oss";
    import {
      decryptChildJsonData_ECB,
      decryptData_ECB,
      decryptOtherJsonData_ECB
    } from "@/api/tool/sm4";
    import uploadType from "@/util/uploadType";
    import axios from 'axios';

    export default {
        name: "Visit",
        data() {
            let self = this;
            return {
                //地图数据
                loading: false,
                m: "",
                zoom: 14,
                //center: [125.290178, 43.8406], //圆心位置
                center: [124.504876, 43.256647], //圆心位置
                // oldCenter: [0, 0], //上一次巡访的位置
                isFirst: true,
                plugin: [
                    {
                        pName: "Geolocation",
                        showMarker: false,
                        events: {
                            init(o) {
                                self.formData.visitLocation = "初始化定位中";
                                //定位成功 自动将marker和circle移到定位点
                                //let that = this; // xiaiu
                                o.getCurrentPosition((status, result) => {
                                    if (result && result.position) {
                                        self.formData.visitLocation = "初始化解析中";
                                        self.center = [result.position.lng, result.position.lat];
                                        let geocoder = new AMap.Geocoder({
                                            radius: 1000,
                                            extensions: "all"
                                        });
                                        self.formData.lng = result.position.lng;
                                        self.formData.lat = result.position.lat;
                                        geocoder.getAddress(
                                            [self.formData.lng, self.formData.lat],
                                            function (status, result2) {
                                                self.loading = false;
                                                if (status === "complete" && result2.info === "OK") {
                                                    if (result2 && result2.regeocode) {
                                                        self.formData.visitLocation =
                                                            result2.regeocode.formattedAddress;
                                                        //that.center = result2.regeocode.formattedAddress; // xiugai
                                                        self.$nextTick();
                                                    } else {
                                                        self.formData.visitLocation = "无地址信息";
                                                    }
                                                } else {
                                                    self.formData.visitLocation = "无地址信息";
                                                }
                                            }
                                        );
                                    } else {
                                        self.$message.error("定位失败,请刷新页面重试");
                                    }
                                });
                            }
                        }
                    }
                ],
                //地图数据END
                isShowUpload: true,
                isUploading: false,
                value: "",
                dialogVisible: false,
                dialogImageUrl: "",
                hideUpload: false,
                urls: [],
                ur: "",
                olds: {},
                formData: {
                    dept5M: "",
                    userid: "",
                    userName: "",
                    infoId: this.$route.params.id,
                    // infoId:'61697c9d4c0b1c003bec550d',
                    // visitMessage: "",
                    visitPhoto: "",
                    // visitLocation: "",
                    // lat: "", //纬度
                    // lng: "", //经度
                    // health: "",
                    // mind: "",
                    // security: "",
                    // hygiene: "",
                    // live: "",
                    // urgency:"",
                    // demand: "",
                    demandXQ: [],


                  jtrk_bdrs: "", // 家庭人口-新增
                  jtrk_bdrs_type: "", // 家庭人口-新增
                  jtrk_bdrs_add: '',
                  jtrk_bdrs_add_disabled: true,
                  jtrk_bdrs_decrease: '',
                  jtrk_bdrs_decrease_disabled: true,
                  bdnl: "", // 家庭人口-新增
                  xdnl: "", // 家庭人口-新增
                  jbqk: "", // 家庭人口-新增
                  jbqk_bdmc: "",
                  jbqk_bdmc_disabled: true, // 疾病情况disabled开关
                  rqaq: "", // 家庭人口-新增
                  snaq: "", // 家庭人口-新增
                  ydaq: "", // 家庭人口-新增
                  grws: "", // 家庭人口-新增
                  jtws: "", // 家庭人口-新增
                  snhj: "", // 家庭人口-新增
                  bzsm: "", // 家庭人口-新增
                  fwxq_jjcd: "", // 家庭人口-新增



                    familyNum: "", // 家庭人口-新增
                    // spzj: "", // 视频主键
                    visitType: 1, // 探访方式

                    // 健康情况-新增
                    // health1: "",
                    // health2: "",
                    // health3: "",
                    // health3Name: "",

                    // 情绪状态-新增
                    qxzt: "",

                    // 安全情况-新增
                    // security1: "",
                    // security2: "",
                    // security3: "",

                    // 卫生情况-新增
                    // hygiene1: "",
                    // hygiene2: "",

                    // 居住情况-新增
                    // live1: "",

                    fwxq_rzylyxq: "", // 需求-新增
                    fwxq_zyfw: "", // 需求-新增
                    fwxq_zjfw: "", // 需求-新增
                    fwxq_zcfw: "", // 需求-新增
                    fwxq_xzfw: "", // 需求-新增
                    fwxq_kffw: "", // 需求-新增
                    fwxq_jtcw: "", // 需求-新增
                    fwxq_rzsqyljgxq: "", // 需求-新增
                    fwxq_jkjcxq: "", // 需求-新增
                    fwxq_qtfwxqms: "", // 需求-新增
                    fwxq_qtfwxq: "", // 需求-新增
                    fwxq_qtfwxqms_disabled: true, // 需求-新增
                    fwxq_zxfw: "", // 需求-新增
                    fwxq: "", // 需求-新增


                  fwjy: "", // 服务建议-新增


                },
                rules: {
                  //数据校验规则
                  // health: [
                  //     {required: true, message: "请选择健康状况", trigger: "blur"}
                  // ],
                  jtrk_bdrs_type: [
                    {required: true, message: "请选择家庭人口变动人数", trigger: "blur"}
                  ],
                  bdnl: [
                    {required: true, message: "请选择表达能力", trigger: "blur"}
                  ],
                  xdnl: [
                    {required: true, message: "请选择行动能力", trigger: "blur"}
                  ],
                  jbqk: [
                    {required: true, message: "请选择残疾状况", trigger: "blur"}
                  ],
                  // mind: [{required: true, message: "请选择精神状态", trigger: "blur"}],
                  qxzt: [{required: true, message: "请选择情绪状态", trigger: "blur"}],
                  // security: [
                  //     {required: true, message: "请选择安全情况", trigger: "blur"}
                  // ],
                  rqaq: [
                    {required: true, message: "请选择燃气安全情况", trigger: "blur"}
                  ],
                  snaq: [
                    {required: true, message: "请选择水暖安全情况", trigger: "blur"}
                  ],
                  ydaq: [
                    {required: true, message: "请选择用电安全情况", trigger: "blur"}
                  ],
                  // hygiene: [
                  //     {required: true, message: "请选择卫生环境", trigger: "blur"}
                  // ],
                  grws: [
                    {required: true, message: "请选择人卫生环境情况", trigger: "blur"}
                  ],
                  jtws: [
                    {required: true, message: "请选择家庭卫生环境情况", trigger: "blur"}
                  ],
                  // live: [{required: true, message: "请选择居住环境", trigger: "blur"}],
                  snhj: [{required: true, message: "请选择室内环境居住环境情况", trigger: "blur"}],
                  // urgency: [{required: true, message: "请选择需求紧急程度", trigger: "blur"}],
                  fwxq_jjcd: [{required: true, message: "请选择需求紧急程度", trigger: "blur"}],
                  // visitMessage: [
                  //     {required: true, message: "请输入备注说明", trigger: "blur"}
                  // ],
                  bzsm: [
                    {required: true, message: "请输入备注说明", trigger: "blur"}
                  ],
                    // visitPhoto: [
                    //     {required: true, message: "请上传现场照片", trigger: "blur"}
                    // ],
                    // demand: [{required: true, message: "请输入老人需求", trigger: "blur"}]
                },
                imageQuality:80,
                distance:2000,
            };
        },
        methods: {
          changesto(data) {
            this.formData.fwxq_qtfwxqms ='';
            this.formData.fwxq_qtfwxqms_disabled = true;
            data.forEach(item=>{
              if(item === 'fwxq_qtfwxq') {
                this.formData.fwxq_qtfwxqms_disabled = false
              }
            })
          },
          changeHealth(data){
            this.formData.jbqk_bdmc ='';
            this.formData.jbqk_bdmc_disabled = true;
            if(data === '2'){
              this.formData.jbqk_bdmc_disabled = false
            }
          },
          changeJtrks(data){
            if(data === '0'){
              this.formData.jtrk_bdrs = 0;
              this.formData.jtrk_bdrs_add_disabled = true;
              this.formData.jtrk_bdrs_decrease_disabled = true;
            } else if(data === '1'){
              this.formData.jtrk_bdrs = this.formData.jtrk_bdrs_add;
              this.formData.jtrk_bdrs_decrease = '';
              this.formData.jtrk_bdrs_add_disabled = false;
              this.formData.jtrk_bdrs_decrease_disabled = true;
            } else if(data === '2'){
              this.formData.jtrk_bdrs = this.formData.jtrk_bdrs_decrease * -1;
              this.formData.jtrk_bdrs_add = '';
              this.formData.jtrk_bdrs_add_disabled = true;
              this.formData.jtrk_bdrs_decrease_disabled = false;
            }
          },
            details() {
                this.$router.push({
                    path: "/info",
                    query: {
                        id: this.olds.fid,
                        name: this.olds.name
                    }
                });
            },
            submission() {
                this.success();
            },
            deleteImg(index) {
                this.urls.splice(index, 1);
                this.formData.visitPhoto = this.urls.join(",");
                this.isShowUpload = this.urls.length < 2;
            },
            look(u) {
                this.ur = u;
                this.dialogVisible = true;
            },
            async success() {
                let bool = false;
                this.$refs.formData.validate(valid => {
                    bool = valid;
                });
              this.formData.demandXQ.forEach((item)=>{
                if (item === 'fwxq_jtcw')  this.formData.fwxq_jtcw = 1;
                if (item === 'fwxq_zcfw')  this.formData.fwxq_zcfw = 1;
                if (item === 'fwxq_zjfw')  this.formData.fwxq_zjfw = 1;
                if (item === 'fwxq_zxfw')  this.formData.fwxq_zxfw = 1; // 助行
                if (item === 'fwxq_xzfw')  this.formData.fwxq_xzfw = 1;
                if (item === 'fwxq_kffw')  this.formData.fwxq_kffw = 1;
                if (item === 'fwxq_zyfw')  this.formData.fwxq_zyfw = 1;
                if (item === 'fwxq_rzylyxq')  this.formData.fwxq_rzylyxq = 1;
                if (item === 'fwxq_rzsqyljgxq')  this.formData.fwxq_rzsqyljgxq = 1;
                if (item === 'fwxq_jkjcxq')  this.formData.fwxq_jkjcxq = 1;
                if (item === 'fwxq_qtfwxq')  this.formData.fwxq_qtfwxq = 1;
              })
              if(this.formData.jtrk_bdrs_type === '0'){
                this.formData.jtrk_bdrs = 0;
              } else if(this.formData.jtrk_bdrs_type === '1' && this.formData.jtrk_bdrs_add){
                this.formData.jtrk_bdrs = this.formData.jtrk_bdrs_add;
              }else if(this.formData.jtrk_bdrs_type === '2' && this.formData.jtrk_bdrs_decrease){
                this.formData.jtrk_bdrs = -1 * this.formData.jtrk_bdrs_decrease;
              }

                if (!bool) {
                    return;
                }

                // if (this.isUploading) {
                //     this.$message.info("图片正在上传中");
                //     return;
                // }
                                  // if (this.isFirst) {
                                  //     this.$message.info("当前老人不存在定位信息，请完善后进行探望");
                                  //     return;
                                  // } else {
                                  //     this.m = AMap.GeometryUtil.distance(this.center, this.oldCenter); //计算两点之间的距离
                                  //     if (this.m > parseInt(this.distance)) {
                                  //         let result = await visitError({
                                  //                 distance: this.m,
                                  //                 lat: this.formData.lat,
                                  //                 lng: this.formData.lng,
                                  //                 infoId: this.formData.infoId,
                                  //                 visitLocation: this.formData.visitLocation
                                  //             });
                                  //         if (result.code === 0) {
                                  //             this.$message.info("当前位置超出老人家范围,请重新扫码定位");
                                  //             //this.$message.info("超出范围");
                                  //             return;
                                  //         }
                                  //     }
                                  // }
                // this.loading = true;
                // 人脸比对
                // let result = await visitFace({
                //     infoId: this.formData.infoId,
                //     visitPhoto: this.formData.visitPhoto
                // });
                // if (result.code === 0) {
                //    if(result.data&&(result.data.score||result.data.score===0)) {
                //        if (result.data.score > parseInt(this.imageQuality)) {
                //    //         // let result1 = await addVisitData(this.formData); 这是之前的
                //            let result1 = await pcVisitCommit(this.formData);
                //            if (result1.code === 0) {
                //                this.$router.replace("/visitInfoRanking");
                //                this.$message.success("提交成功");
                //            }
                //        } else {
                //            this.$message.error("人脸比对相似度过低，请重新拍照！");
                //        }
                //    }
                //                    // else
                //                    // {
                //                    //     this.$message.error("人脸比对失败,请传老人现场照片！");
                //                    // }
                // }
              // this.loading = false;
              let result1 = await pcVisitCommit(this.formData);
              if (result1.code === 0) {
                this.$router.replace("/visitInfoRanking");
                this.$message.success("提交成功");
              }else{
                this.$message.error("提交信息错误，请联系管理员！");
              }
                // this.loading = false;
            },
            async changeFile() {
                this.urls = [];
                this.isUploading = true;
                this.isShowUpload = false;
                this.loading = true;
                let fileItem = this.$refs.fileItem;
                //得到图片的路径
                let file = fileItem.files[0];
                let that = this;
                lrz(file)
                    //成功时执行
                    .then(function (rst) {
                        let fd = rst.formData;
                        that.photo(fd,rst);
                        fileItem.value = "";
                    })
                    .catch(function (error) {
                        that.$message.error(error.message);
                        that.isShowUpload = true;
                        that.isUploading = false;
                        that.loading = false;
                    });
            },
            async photo(fd,rst) {
                let file=getClient.base64toFile(rst.base64,rst.origin.name);

                const forData=new FormData();
                const receiveType = config.fileTypeConfig[uploadType.VISIT];
                const picName = file.name;
                const filetype = picName.substring(picName.lastIndexOf("."));
                const filename =  receiveType + Date.now() + '_' + Math.floor(Math.random() * 10000) + filetype; // 存数据库里的路径需要/
                const objkey = filename.substring(1); // 上传至obs的 需要去掉起始的/
                forData.append("objkey",'sckjpicup$' + objkey);
                forData.append('objdata', file);

                const requestResult = await axios({
                  method: 'post',
                  // url: '/obs-demo/objUpload', // 146.3上测试
                  // url: 'http://abc.ccsckj.com/obs-demo/objUpload', // 测试域名
                  url: 'https://info.windd.cn/obs-demo/objUpload', // 祥云147.2正式
                  data: forData,
                  // headers: forData.getHeaders(),
                });
                if (requestResult.status === 200) {
                  if(filename){
                    this.urls.push(filename);
                    this.formData.visitPhoto = this.urls.join(",");
                  }
                }else{
                  this.$message.error('公众号端上传巡访照片失败!')
                }

                if (this.urls.length < 2) {
                    this.isShowUpload = true;
                }
                this.isUploading = false;
                this.loading = false;
            },
            async loadingOld() {
                let result = await oldsInfo({
                    id: this.$route.params.id
                    // id: '642522a5cea6c6320c1d83de'
                });
              // 这个等外出登记后端接口上了，在恢复
              // 2024-5-6
              // if (result.code === 1){
              //   return this.$router.replace("/main");
              // }
                decryptData_ECB(result,["name","phone","idNumber","partnerName","partnerIdNumber","mainLookName","mainLookPhone"])
                decryptChildJsonData_ECB(result.data);
                decryptOtherJsonData_ECB(result.data);
                if (result.code === 0) {
                    this.olds = result.data;
                    // let split = this.olds.photoAndLocation.split("/");
                    // this.oldCenter = [
                    //     window.parseFloat(split[0]),
                    //     window.parseFloat(split[1])
                    // ];
                    this.isFirst = false;
                    // this.findLocation(this.olds, this.$route.params.id);
                }
            },

            // async findLocation(olds, infoId) {
            //     let result = await visitListByInfoId({infoId: infoId});
            //     console.log(result,"laoren zhao")
            //     if (result.code === 0) {
            //         let list = result.data;
            //         if (list && list.length > 0) {
            //             list.forEach(item => {
            //                 let sumLng = window.parseFloat(item.lng);
            //                 let sumLat = window.parseFloat(item.lat);
            //                 this.oldCenter = [sumLng, sumLat];
            //             });
            //             /*  let sumLng = 0;
            //               let sumLat = 0;
            //               list.forEach(item => {
            //                   sumLng += window.parseFloat(item.lng);
            //                   sumLat += window.parseFloat(item.lat);
            //               });
            //               if (olds.photoAndLocation) {
            //                   let split = olds.photoAndLocation.split("/");
            //                   sumLng = (sumLng + window.parseFloat(split[0])) / (list.length + 1);
            //                   sumLat = (sumLat + window.parseFloat(split[1])) / (list.length + 1);
            //               } else {
            //                   sumLng = sumLng / list.length;
            //                   sumLat = sumLat / list.length;
            //               }*/
            //             // if (sumLng && sumLat) {
            //             //     this.oldCenter = [sumLng, sumLat];
            //             // }
            //             this.isFirst = false;
            //         } else {
            //             if (olds.photoAndLocation) {
            //                 let split = olds.photoAndLocation.split("/");
            //                 this.oldCenter = [split[0], split[1]];
            //                 this.isFirst = false;
            //             }
            //         }
            //     }
            // },

            dateToString(date) {
                var year = date.getFullYear();
                var month = (date.getMonth() + 1).toString();
                var day = date.getDate().toString();
                if (month.length == 1) {
                    month = "0" + month;
                }
                if (day.length == 1) {
                    day = "0" + day;
                }
                var dateTime = year + "-" + month + "-" + day;
                return dateTime;
            },

            async getUserOne(){
              const result = await userOne()
              if(result.code === 0){
                this.formData.dept5M = result.data.dept5._id;
                this.formData.userid = result.data._id;
                this.formData.userName = result.data.loginName;
              }
            },
            async getDict(){
                let result = await dictListForPage({key:'distance'});
                if (result.code === 0) {
                    this.distance=result.data.list[0].name;
                }
                let result1 = await dictListForPage({key:'imageQuality'});
                if(result.code === 0){
                    this.imageQuality=result1.data.list[0].name
                }
            },
        },
        async mounted() {
            // openId.getOpenId(() => {
            //     this.formData.openid = window.localStorage.getItem('openId');
            await this.getDict();
            await this.getUserOne();
            this.loadingOld();
            // });
        },
        computed: {
            newDate() {
                return this.dateToString(new Date());
            }
        }
    };
</script>

<style scoped>

/** 在一行显示修改 */
::v-deep .el-input-number .el-input-number__decrease, ::v-deep .el-input-number .el-input-number__increase{
  width: 20px;
}

::v-deep .el-input-number--mini .el-input__inner{
  padding-left:25px;
  padding-right: 25px;
}
::v-deep .cus-radio{
  margin-right: 20px;
}
    .visit-top >>> .el-form-item__label {
        font-weight: bold;
    }

    .discharge-date {
        font-weight: bold;
        color: #606266;
    }

    .box-card >>> .el-form-item__content {
        line-height: 0px;
    }

    .visit-top >>> .el-form-item__content {
        line-height: 30px !important;
    }

    .visit-top >>> .el-form-item {
        margin-bottom: 15px;
    }

    .camera {
        position: absolute;
        left: 0;
        top: 0;
        opacity: 0;
    }

    #btn {
        margin-right: 5px;
    }

    #text {
        color: red;
    }

    .image-slot {
        width: 100px;
        height: 100px;
        text-align: center;
        line-height: 100px;
        background: #f5f7fa;
    }

    .oldPhoto >>> .el-form-item__content {
        line-height: 0px !important;
    }
</style>
