<template>
  <div class="page_editPatients">
    <van-sticky>
      <div class="addPatientsTitle">
        <i class="iconfont icon-zuojiantou jiantou" @click="$router.go(-1)"></i>
        <span class="titleName">编辑患者</span>
        <span @click="spread" id="copy">修改</span>
      </div>
    </van-sticky>
    <div class="basicTitle">基本信息</div>
    <div class="basicBox">
      <van-field
        :class="readonly ? 'changeColor' : ''"
        v-model="patientForm.name"
        required
        label="姓名"
        :readonly="readonly"
        placeholder="请输入"
      />
      <van-field
        :class="readonly ? 'changeColor' : ''"
        label="性别"
        v-model="patientForm.sex"
        right-icon="arrow"
        placeholder="请选择"
        required
        :readonly="readonly"
        @click="clickSex"
      />
      <van-popup v-model="show" position="bottom" :style="{ height: '40%' }">
        <van-picker :columns="columns" show-toolbar @change="onChange" />
      </van-popup>
      <van-field
        :class="readonly ? 'changeColor' : ''"
        v-model="patientForm.idCard"
        required
        label="身份证号"
        @blur="checkIdCardNo"
        placeholder="请输入"
        :readonly="readonly"
      />
      <van-field
        :class="readonly ? 'changeColor' : ''"
        v-model="patientForm.birthday"
        required
        label="出生日期"
        :readonly="readonly"
        placeholder="请输入"
      />
      <van-field
        :class="readonly ? 'changeColor' : ''"
        v-model="patientForm.phone"
        type="tel"
        required
        label="手机号"
        placeholder="请输入"
        :readonly="readonly"
      />
      <van-cell>
        <!-- 使用 title 插槽来自定义标题 -->
        <template slot="title">
          <span class="custom-title">患者类型</span>
          <div style="width:60%;margin-left:2rem">
            <van-checkbox-group v-model="result">
              <van-checkbox name="1" shape="square" @click="changeMode"
                >血透患者</van-checkbox
              >
              <van-checkbox name="2" shape="square" @click="changeMode"
                >慢病患者</van-checkbox
              >
              <van-checkbox name="3" shape="square" @click="changeMode"
                >会员患者</van-checkbox
              >
            </van-checkbox-group>
          </div>
        </template>
      </van-cell>
    </div>
    <div v-show="bloodShow">
      <div class="basicTitle">血透信息</div>
      <div class="xtBox">
        <van-field
          :class="readonly ? 'changeColor' : ''"
          v-model="patientForm.dialysis"
          center
          clearable
          required
          label="透析号"
          :readonly="readonly"
        >
          <van-button
            slot="button"
            size="small"
            type="info"
            @click="generatedialysisno"
            >自动生成</van-button
          >
        </van-field>
        <van-field
          :class="readonly ? 'changeColor' : ''"
          label="患者来源"
          v-model="patientForm.patientsoure"
          right-icon="arrow"
          required
          :readonly="readonly"
          placeholder="请选择"
          @click="clickPatientSoure"
        />
        <van-popup v-model="show3" position="bottom" :style="{ height: '40%' }">
          <van-picker :columns="columns2" show-toolbar @change="onChange1" />
        </van-popup>
        <van-field
          :class="readonly ? 'changeColor' : ''"
          label="留治状态"
          v-model="patientForm.lapseto"
          right-icon="arrow"
          required
          :readonly="readonly"
          placeholder="请选择"
          @click="clickLapseto"
        />
        <van-popup v-model="show4" position="bottom" :style="{ height: '40%' }">
          <van-picker :columns="columns4" show-toolbar @change="onChange2" />
        </van-popup>

        <van-cell>
          <!-- 使用 title 插槽来自定义标题 -->
          <template slot="title">
            <span class="custom-title">有无传染病</span>
            <div
              style="width:60%;margin-left:1.3rem;display: flex;align-items: center;"
            >
              <van-radio-group v-model="radio" @change="changRadio">
                <van-radio name="1" shape="square">无</van-radio>
                <van-radio name="2" shape="square">有</van-radio>
              </van-radio-group>
            </div>
          </template>
        </van-cell>

        <van-cell v-show="showOne">
          <!-- 使用 title 插槽来自定义标题 -->
          <template slot="title">
            <span class="custom-title">传染病</span>
            <div style="width:60%;margin-left:3rem">
              <van-checkbox-group v-model="resultTwo">
                <van-checkbox name="2" shape="square">乙肝</van-checkbox>
                <van-checkbox name="3" shape="square">丙肝</van-checkbox>
                <van-checkbox name="4" shape="square">艾滋</van-checkbox>
                <van-checkbox name="5" shape="square">肺结核</van-checkbox>
                <van-checkbox name="6" shape="square">梅毒</van-checkbox>
              </van-checkbox-group>
            </div>
          </template>
        </van-cell>

        <van-field
          :class="readonly ? 'changeColor' : ''"
          v-model="patientForm.admissionNumber"
          :readonly="readonly"
          type="text"
          label="住院(门诊)号"
        />
        <van-field
          :class="readonly ? 'changeColor' : ''"
          label="首次透析日期"
          v-model="patientForm.fistDate"
          right-icon="arrow"
          :readonly="readonly"
          placeholder="请选择"
          @click="clickDate"
        />
        <van-popup v-model="show2" position="bottom" :style="{ height: '40%' }">
          <van-datetime-picker
            v-model="currentDate"
            type="date"
            :min-date="minDate"
            :max-date="maxDate"
            @cancel="onCancel"
            @confirm="onConfirm"
          />
        </van-popup>
        <van-field
          :class="readonly ? 'changeColor' : ''"
          v-model="patientForm.diagnose"
          rows="1"
          autosize
          label="诊断"
          type="textarea"
          maxlength="50"
          :readonly="readonly"
          placeholder="请输入主要诊断信息"
        />
      </div>
    </div>
    <div v-show="slowShow">
      <div class="basicTitle">慢病信息</div>
      <div class="xtBox">
        <van-field
          :class="readonly ? 'changeColor' : ''"
          v-model="patientForm.requipmentId"
          label="设备ID"
          placeholder="请输入"
          :readonly="readonly"
        />

        <van-cell>
          <!-- 使用 title 插槽来自定义标题 -->
          <template slot="title">
            <span class="custom-title2">传染病</span>
            <div style="width:60%;margin-left:3rem">
              <van-checkbox-group v-model="resultThree">
                <van-checkbox name="1" shape="square">乙肝</van-checkbox>
                <van-checkbox name="2" shape="square">丙肝</van-checkbox>
                <van-checkbox name="3" shape="square">艾滋</van-checkbox>
                <van-checkbox name="4" shape="square">肺结核</van-checkbox>
                <van-checkbox name="5" shape="square">梅毒</van-checkbox>
              </van-checkbox-group>
            </div>
          </template>
        </van-cell>

        <van-cell>
          <!-- 使用 title 插槽来自定义标题 -->
          <template slot="title">
            <span class="custom-title2">慢性病</span>
            <div style="width:60%;margin-left:3rem">
              <van-checkbox-group v-model="resultFour">
                <van-checkbox name="1" shape="square">血透</van-checkbox>
                <van-checkbox name="2" shape="square">腹透</van-checkbox>
                <van-checkbox name="3" shape="square">移植</van-checkbox>
                <van-checkbox name="4" shape="square">高血压</van-checkbox>
                <van-checkbox name="5" shape="square">糖尿病</van-checkbox>
                <van-checkbox name="6" shape="square">慢性肾病</van-checkbox>
                <van-checkbox name="7" shape="square">其他</van-checkbox>
              </van-checkbox-group>
            </div>
          </template>
        </van-cell>
      </div>
    </div>
    <div v-show="memberShow">
      <div class="basicTitle">会员资料</div>
      <div class="xtBox">
        <van-field
          :class="readonly ? 'changeColor' : ''"
          label="首次透析日期"
          v-model="patientForm.memberFistDate"
          right-icon="arrow"
          :readonly="readonly"
          placeholder="请选择"
          @click="clickDateTwo"
        />
        <van-popup
          v-model="show12"
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-datetime-picker
            v-model="currentDate"
            type="date"
            :min-date="minDate"
            :max-date="maxDate"
            @cancel="onCancel"
            @confirm="onConfirmOne"
          />
        </van-popup>
        <van-field
          :class="readonly ? 'changeColor' : ''"
          label="病种"
          v-model="patientForm.patient_type"
          right-icon="arrow"
          :readonly="readonly"
          placeholder="请选择"
          @click="clickPatientType"
        />
        <van-popup
          v-model="show14"
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-picker
            :columns="patientType"
            show-toolbar
            @change="onChangeSix"
            @cancel="cancelSeven"
          />
        </van-popup>
        <van-field
          :class="readonly ? 'changeColor' : ''"
          label="治疗方式"
          v-model="patientForm.treatmentMethod"
          right-icon="arrow"
          :readonly="readonly"
          placeholder="请选择"
          @click="clickTreatMethod"
        />
        <van-popup
          v-model="show13"
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-picker
            :columns="treatmentMethod"
            show-toolbar
            @change="onChangeSeven"
            @cancel="cancelEight"
          />
        </van-popup>
      </div>
    </div>
    <div class="moreInfo">如需要完善更多病人信息，请在电脑端完善</div>
  </div>
</template>

<script>
import {
  GenerateDialysisNo,
  GetIllnessList,
  savePatient,
  GetPatientInfo,
  getBloodPatientInfo,
  getSlowPatientInfo,
  getMemberPatientInfo,
  GetPatientDetail,
  updatedPatient
} from "@/api/patient/patient";
import {
  isCardNo,
  checkMobile,
  getFileExtension,
  uParseTime,
  uParseTimeOne
} from "@/utils/tools";
import { getToken } from "@/api/qiniu";
import { setRem, setHeight } from "@/libs/functionRem";
const moment = require("moment");
export default {
  data() {
    var checkMobileRule = (rule, value, callback) => {
      if (!checkMobile(value)) {
        callback(new Error("请填写正确的手机号"));
      } else {
        callback();
      }
    };

    return {
      show: false,
      show1: false,
      show2: false,
      show3: false,
      show4: false,
      name: "",
      columns: ["男", "女"],
      columns1: ["1", "2", "3"],
      columns2: ["门诊", "住院"],
      columns4: ["留治", "转出"],
      sex: "",
      idCard: "",
      birthday: "",
      tel: "",
      result: [],
      dialysisNumber: "",
      source: "",
      source2: "",
      source3: "",
      show10: false,
      show9: false,
      show8: false,
      show7: false,
      show6: false,
      show11: false,
      show12: false,
      show13: false,
      show14: false,
      hospitalNum: "",
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(),
      time: "",
      message: "",
      patient_id: "",
      resultTwo: [],
      resultThree: [],
      resultFour: [],
      patientForm: {
        id: "",
        name: "",
        sex: "",
        idCard: "",
        birthday: "",
        phone: "",
        dialysis: "",
        patient_type: "",
        admissionNumber: "",
        patientsoure: "",
        lapseto: "",
        contagions: [],
        fistDate: "",
        diagnose: "",
        requipmentId: "",
        slowcontagions: [],
        slowDisease: "",
        memberIllnessTime: "",
        memberlapseto: "",
        TreatmentMethod: "",
        bloodPatient: 0,
        slowPatient: 0,
        memberPatient: 0,
        avatar: "",
        memberFistDate: "",
        blood_patients: "",
        slow_patients: "",
        member_patients: ""
      },
      bloodShow: true,
      slowShow: false,
      memberShow: false,
      patientType: [],
      treatmentMethod: [
        "西医治疗",
        "中医治疗",
        "血液透析",
        "腹膜透析",
        "肾移植"
      ],
      illnesslist: [],
      radio: "1",
      showOne: false,
      readonly: true
    };
  },
  methods: {
    onChange(picker, value, index) {
      this.patientForm.sex = value;
      this.show = false;
    },
    onChange1(picker, value, index) {
      this.patientForm.patientsoure = value;
      this.show3 = false;
    },
    onChange2(picker, value, index) {
      this.patientForm.lapseto = value;
      this.show4 = false;
    },
    onChange3(picker, value, index) {
      this.source3 = value;
      this.show3 = false;
    },
    onChange4(picker, value, index) {
      this.source = value;
      this.show1 = false;
    },
    onCancel() {
      this.show2 = false;
    },
    onConfirm(value) {
      let year = value.getFullYear();
      let month = value.getMonth() + 1;
      let day = value.getDate();
      if (month >= 1 && month <= 9) {
        month = `0${month}`;
      }
      if (day >= 1 && day <= 9) {
        day = `0${day}`;
      }

      this.patientForm.fistDate = `${year}-${month}-${day}`;
      this.show2 = false;
    },
    onConfirmOne(value) {
      let year = value.getFullYear();
      let month = value.getMonth() + 1;
      let day = value.getDate();
      if (month >= 1 && month <= 9) {
        month = `0${month}`;
      }
      if (day >= 1 && day <= 9) {
        day = `0${day}`;
      }

      this.patientForm.memberFistDate = `${year}-${month}-${day}`;
      this.show12 = false;
    },
    cancelSeven() {
      this.show14 = false;
    },
    cancelEight() {
      this.show13 = false;
    },
    toReturn() {
      this.$router.push("/patientdetail?patientid=" + this.patient_id);
    },
    changeMode(val) {
      if (val == 1) {
        getBloodPatientInfo(this.patientForm.phone).then(response => {
          if (response.data.state === 1) {
            var msg = response.data.data.msg;
          } else {
            this.$toast("血透患者已存在");
            return false;
          }
        });
      }

      if (val == 2) {
        getSlowPatientInfo(this.patientForm.phone).then(response => {
          if (response.data.state === 1) {
            var msg = response.data.data.msg;
          } else {
            this.$toast("慢病患者已存在");
            return false;
          }
        });
      }

      if (val == 3) {
        getMemberPatientInfo(this.patientForm.phone).then(response => {
          if (response.data.state === 1) {
            var msg = response.data.data.msg;
          } else {
            this.$toast("会员已存在");
            return false;
          }
        });
      }

      if (this.result.indexOf("1") != -1) {
        this.bloodShow = true;
        this.slowShow = false;
        this.memberShow = false;
      }
      if (this.result.indexOf("2") != -1) {
        this.slowShow = true;
        this.bloodShow = false;
        this.memberShow = false;
      }
      if (this.result.indexOf("3") != -1) {
        this.memberShow = true;
        this.bloodShow = false;
        this.slowShow = false;
      }

      if (this.result.indexOf("1") != -1 && this.result.indexOf("2") != -1) {
        this.bloodShow = true;
        this.slowShow = true;
        this.memberShow = false;
      }
      if (
        this.result.indexOf("1") != -1 &&
        this.result.indexOf("2") != -1 &&
        this.result.indexOf("3") != -1
      ) {
        this.bloodShow = true;
        this.slowShow = true;
        this.memberShow = true;
      }

      if (this.result.indexOf("1") != -1 && this.result.indexOf("3") != -1) {
        this.bloodShow = false;
        this.slowShow = true;
        this.memberShow = true;
      }
      if (this.result.indexOf("3") != -1 && this.result.indexOf("1") != -1) {
        this.bloodShow = true;
        this.slowShow = false;
        this.memberShow = true;
      }
      if (this.result.indexOf("2") != -1 && this.result.indexOf("3") != -1) {
        this.bloodShow = false;
        this.slowShow = true;
        this.memberShow = true;
      }

      if (
        this.result.indexOf("2") != -1 &&
        this.result.indexOf("3") != -1 &&
        this.result.indexOf("1") != -1
      ) {
        this.bloodShow = true;
        this.slowShow = true;
        this.memberShow = true;
      }

      if (this.result.length == 0) {
        this.bloodShow = false;
        this.slowShow = false;
        this.memberShow = false;
      }
    },
    generatedialysisno() {
      GenerateDialysisNo().then(response => {
        // eslint-disable-next-line eqeqeq
        if (response.data.state == 1) {
          var no = response.data.data.no + "";
          this.patientForm.dialysis = no;
        }
      });
    },
    onChangeSix(picker, value, index) {
      this.patientForm.patient_type = value;
      this.show14 = false;
    },
    onChangeSeven(picker, value, index) {
      this.patientForm.treatmentMethod = value;
      this.show13 = false;
    },
    GetPatientDetail(patientid) {
      GetPatientDetail(patientid).then(response => {
        if (response.data.state === 1) {
          var patientdetail = response.data.data.patientDetail;
          // console.log("patientdetail", patientdetail);
          var diseases = response.data.data.diseases;
          var slowDisease = response.data.data.slowDiseases;
          for (let i = 0; i < diseases.length; i++) {
            this.resultTwo.push(String(diseases[i]));
          }
          for (let i = 0; i < slowDisease.length; i++) {
            this.resultThree.push(String(slowDisease[i].disease_id));
          }
          var cronicdisease = response.data.data.cronicDiseases;
          for (let i = 0; i < cronicdisease.length; i++) {
            this.resultFour.push(String(cronicdisease[i].disease_id));
          }
          if (patientdetail.gender === 1) {
            patientdetail.gender = "男";
          }
          if (patientdetail.gender === 2) {
            patientdetail.gender = "女";
          }
          if (patientdetail.source === 1) {
            patientdetail.source = "门诊";
          }
          if (patientdetail.source === 2) {
            patientdetail.source = "住院";
          }
          if (patientdetail.lapseto === 1) {
            patientdetail.lapseto = "留治";
          }
          if (patientdetail.lapseto === 2) {
            patientdetail.lapseto = "转出";
          }
          this.patientForm.name = patientdetail.name;
          this.patientForm.sex = patientdetail.gender;
          this.patientForm.idCard = patientdetail.id_card_no;
          this.patientForm.birthday = uParseTime(
            patientdetail.birthday,
            "{y}-{m}-{d}"
          );
          this.patientForm.phone = patientdetail.phone;

          if (patientdetail.blood_patients == 1) {
            this.result.push(String(1));
          }
          if (patientdetail.slow_patients == 1) {
            this.result.push(String(2));
          }
          if (patientdetail.member_patients == 1) {
            this.result.push(String(3));
          }
          this.patientForm.id = patientdetail.id;
          this.patientForm.dialysis = patientdetail.dialysis_no;
          this.patientForm.patientsoure = patientdetail.source;
          this.patientForm.lapseto = patientdetail.lapseto;
          this.patientForm.admissionNumber = patientdetail.admission_number;
          this.patientForm.requipmentId = patientdetail.equitment_id;
          this.patientForm.blood_patients = patientdetail.blood_patients;
          this.patientForm.member_patients = patientdetail.member_patients;
          this.patientForm.slow_patients = patientdetail.slow_patients;
          this.patientForm.memberFistDate = uParseTimeOne(
            patientdetail.member_fistdate,
            "{y}-{m}-{d}"
          );

          console.log("首次透析日期", patientdetail.first_dialysis_date);

          if (patientdetail.first_dialysis_date < 0) {
            this.patientForm.fistDate = "";
          }
          if (patientdetail.first_dialysis_date > 0) {
            this.patientForm.fistDate = uParseTimeOne(
              patientdetail.first_dialysis_date
            );
          }

          this.patientForm.diagnose = patientdetail.diagnose;
          if (patientdetail.member_treatement === 1) {
            this.patientForm.treatmentMethod = "西医治疗";
          }
          if (patientdetail.member_treatement === 2) {
            this.patientForm.treatmentMethod = "中医治疗";
          }
          if (patientdetail.member_treatement === 3) {
            this.patientForm.treatmentMethod = "血液透析";
          }
          if (patientdetail.member_treatement === 4) {
            this.patientForm.treatmentMethod = "腹膜透析";
          }
          if (patientdetail.member_treatement === 5) {
            this.patientForm.treatmentMethod = "肾移植";
          }

          for (let i = 0; i < this.illnesslist.length; i++) {
            if (patientdetail.member_patienttype === this.illnesslist[i].id) {
              this.patientForm.patient_type = this.illnesslist[i].illness_name;
            }
          }

          if (patientdetail.member_patients === 1) {
            this.bloodShow = false;
            this.slowShow = false;
            this.memberShow = true;
          }
          if (patientdetail.slow_patients === 1) {
            this.bloodShow = false;
            this.memberShow = false;
            this.slowShow = true;
          }
          if (
            patientdetail.blood_patients === 1 &&
            patientdetail.slow_patients === 1
          ) {
            this.bloodShow = true;
            this.slowShow = true;
            this.memberShow = false;
          }
          if (
            patientdetail.blood_patients === 1 &&
            patientdetail.member_patients === 1
          ) {
            this.bloodShow = true;
            this.memberShow = true;
            this.slowShow = false;
          }
          if (
            patientdetail.member_patients === 1 &&
            patientdetail.slow_patients === 1
          ) {
            this.memberShow = true;
            this.slowShow = true;
            this.bloodShow = false;
          }
          if (
            patientdetail.blood_patients === 1 &&
            patientdetail.slow_patients === 1 &&
            patientdetail.member_patients === 1
          ) {
            this.bloodShow = 1;
            this.slowShow = 1;
            this.memberShow = 1;
          }
          if (patientdetail.is_infectious === 1) {
            this.showOne = false;
            this.radio = "1";
          }
          if (patientdetail.is_infectious === 2) {
            this.showOne = true;
            this.radio = "2";
          }
        }
      });
    },
    GetIllnessList() {
      GetIllnessList().then(response => {
        if (response.data.state === 1) {
          var illnesslist = response.data.data.illnesslist;
          console.log("illnesslist", illnesslist);
          this.illnesslist = illnesslist;
          var arr = [];
          for (let i = 0; i < illnesslist.length; i++) {
            arr.push(illnesslist[i].illness_name);
          }
          this.patientType = arr;
        }
      });
    },
    checkIdCardNo() {
      if (!isCardNo(this.patientForm.idCard)) {
        this.$toast("身份证号码信息有误!");
        this.patientForm.birthday = "";
        return false;
      }
      var thisLen = this.patientForm.idCard.length;
      var birth = "";
      if (thisLen === 15) {
        birth = "19" + this.patientForm.idCard.substr(6, 6);
      } else {
        birth = this.patientForm.idCard.substr(6, 8);
      }
      this.patientForm.birthday =
        birth.substr(0, 4) +
        "-" +
        birth.substr(4, 2) +
        "-" +
        birth.substr(6, 2);
    },
    spread() {
      var spancontent = document.getElementById("copy").innerHTML;
      if (spancontent == "修改") {
        this.readonly = false;
        document.getElementById("copy").innerHTML = "保存";
      }
      if (spancontent == "保存") {
        this.updatedPatient();
      }
    },
    clickSex() {
      if (this.readonly == true) {
        this.show = false;
      }
      if (this.readonly == false) {
        this.show = true;
      }
    },
    clickPatientSoure() {
      if (this.readonly == true) {
        this.show3 = false;
      }
      if (this.readonly == false) {
        this.show3 = true;
      }
    },
    clickLapseto() {
      if (this.readonly == true) {
        this.show4 = false;
      }
      if (this.readonly == false) {
        this.show4 = true;
      }
    },
    clickDate() {
      if (this.readonly == true) {
        this.show2 = false;
      }
      if (this.readonly == false) {
        this.show2 = true;
      }
    },
    clickDateTwo() {
      if (this.readonly == true) {
        this.show12 = false;
      }
      if (this.readonly == false) {
        this.show12 = true;
      }
    },
    clickPatientType() {
      if (this.readonly == true) {
        this.show14 = false;
      }
      if (this.readonly == false) {
        this.show14 = true;
      }
    },
    clickTreatMethod() {
      if (this.readonly == true) {
        this.show13 = false;
      }
      if (this.readonly == false) {
        this.show13 = true;
      }
    },
    updatedPatient() {
      if (this.patientForm.name === "") {
        this.$toast("姓名不能为空");
        return false;
      }
      if (this.patientForm.sex === "") {
        this.$toast(" 性别不能为空");
        return false;
      }
      if (this.patientForm.idCard === "") {
        this.$toast("身份证不能为空");
        return false;
      }
      if (this.patientForm.birthday === "") {
        this.$toast("出生日期不能为空");
        return false;
      }
      if (this.patientForm.phone === "") {
        this.$toast("手机号码不能为空");
        return false;
      }
      if (this.result.length === 0) {
        this.$toast("患者类型不能为空");
        return false;
      }
      if (this.patientForm.dialysis === "" && this.result.indexOf("1") != -1) {
        this.$toast("透析号不能为空");
        return false;
      }
      if (
        this.patientForm.patientsoure === "" &&
        this.result.indexOf("1") != -1
      ) {
        this.$toast("患者来源不能为空");
        return false;
      }

      if (this.patientForm.lapseto === "" && this.result.indexOf("1") != -1) {
        this.$toast("留置状态不能为空");
        return false;
      }

      if (this.patientForm.lapseto === "") {
        this.patientForm.lapseto = 0;
      }

      if (this.patientForm.patientsoure == "门诊") {
        this.patientForm.patientsoure = 1;
      }
      if (this.patientForm.patientsoure == "住院") {
        this.patientForm.patientsoure = 2;
      }

      if (this.patientForm.lapseto == "留治") {
        this.patientForm.lapseto = 1;
      }

      if (this.patientForm.lapseto == "转出") {
        this.patientForm.lapseto = 2;
      }

      if (this.resultTwo.length === 0) {
        this.patientForm.is_infectious = 1;
      }

      if (this.resultTwo.length > 0) {
        this.patientForm.is_infectious = 2;
      }

      if (this.patientForm.treatmentMethod === undefined) {
        this.patientForm.treatmentMethod = 0;
      }

      if (this.patientForm.patient_type === "尿毒症") {
        this.patientForm.patient_type = 21;
      }
      if (this.patientForm.patient_type === "慢性肾衰竭") {
        this.patientForm.patient_type = 22;
      }
      if (this.patientForm.patient_type === "糖尿病肾病") {
        this.patientForm.patient_type = 23;
      }

      if (this.patientForm.patient_type === "高血压肾病") {
        this.patientForm.patient_type = 24;
      }

      if (this.patientForm.patient_type === "肾病综合征") {
        this.patientForm.patient_type = 25;
      }

      if (this.patientForm.patient_type === "IGA肾病") {
        this.patientForm.patient_type = 26;
      }

      if (this.patientForm.patient_type === "慢性肾炎") {
        this.patientForm.patient_type = 27;
      }

      if (this.patientForm.patient_type === "紫癜性肾炎") {
        this.patientForm.patient_type = 28;
      }

      if (this.patientForm.patient_type === "狼疮性肾炎") {
        this.patientForm.patient_type = 29;
      }
      if (this.patientForm.patient_type === "小儿肾病") {
        this.patientForm.patient_type = 30;
      }
      if (this.patientForm.patient_type === "肾结石") {
        this.patientForm.patient_type = 31;
      }
      if (this.patientForm.patient_type === "其他") {
        this.patientForm.patient_type = 32;
      }

      if (this.patientForm.treatmentMethod === "西医治疗") {
        this.patientForm.treatmentMethod = 1;
      }
      if (this.patientForm.treatmentMethod === "中医治疗") {
        this.patientForm.treatmentMethod = 2;
      }
      if (this.patientForm.treatmentMethod === "血液透析") {
        this.patientForm.treatmentMethod = 3;
      }
      if (this.patientForm.treatmentMethod === "腹膜透析") {
        this.patientForm.treatmentMethod = 4;
      }
      if (this.patientForm.treatmentMethod === "肾移植") {
        this.patientForm.treatmentMethod = 5;
      }

      if (this.patientForm.patient_type === "") {
        this.patientForm.patient_type = 0;
      }

      for (let i = 0; i < this.result.length; i++) {
        if (this.result[i] == 1) {
          this.patientForm.bloodPatient = 1;
        }
        if (this.result[i] == 2) {
          this.patientForm.slowPatient = 1;
        }
        if (this.result[i] == 3) {
          this.patientForm.memberPatient = 1;
        }
      }

      if (!checkMobile(this.patientForm.phone)) {
        this.$toast("请填写正确的手机号");
        return false;
      }

      if (this.patientForm.sex !== "") {
        if (this.patientForm.sex === "男") {
          this.patientForm.sex = 1;
          this.patientForm.avatar =
            "https://images.shengws.com/201809182128111.png";
        }
        if (this.patientForm.sex === "女") {
          this.patientForm.sex = 2;
          this.patientForm.avatar =
            "https://images.shengws.com/201809182128222.png";
        }
      }
      if (this.patientForm.patientsoure === "") {
        this.patientForm.patientsoure = 0;
      }
      if (this.patientForm.patientsoure !== "") {
        if (this.patientForm.patientsoure === "门诊") {
          this.patientForm.patientsoure = 1;
        }
        if (this.patientForm.patientsoure === "住院") {
          this.patientForm.patientsoure = 2;
        }
      }
      if (this.patientForm.lapseto !== "") {
        if (this.patientForm.lapseto === "留治") {
          this.patientForm.lapseto = 1;
        }
        if (this.patientForm.lapseto === "转出") {
          this.patientForm.lapseto = 2;
        }
      }
      for (let i = 0; i < this.illnesslist.length; i++) {
        if (
          this.illnesslist[i].illness_name === this.patientForm.patient_type
        ) {
          this.patientForm.patient_type = this.illnesslist[i].id;
        }
      }

      const params = {
        id: this.patientForm.id,
        name: this.patientForm.name,
        sex: this.patientForm.sex,
        idCard: this.patientForm.idCard,
        birthday: this.patientForm.birthday,
        phone: this.patientForm.phone,
        result: this.result,
        dialysis: this.patientForm.dialysis,
        patientsoure: this.patientForm.patientsoure,
        lapseto: this.patientForm.lapseto,
        resultTwo: this.resultTwo,
        admissionNumber: this.patientForm.admissionNumber,
        fistDate: this.patientForm.fistDate,
        diagnose: this.patientForm.diagnose,
        bloodPatient: this.patientForm.bloodPatient,
        slowPatient: this.patientForm.slowPatient,
        memberPatient: this.patientForm.memberPatient,
        avatar: this.patientForm.avatar,
        requipmentId: this.patientForm.requipmentId, // 慢病信息
        resultThree: this.resultThree,
        resultFour: this.resultFour,
        patientType: this.patientForm.patient_type,
        memberFistDate: this.patientForm.memberFistDate,
        treatmentMethod: this.patientForm.treatmentMethod,
        is_infectious: this.patientForm.is_infectious
      };
      updatedPatient(params).then(response => {
        if (response.data.state === 1) {
          var msg = response.data.data.msg;
          console.log("msg", msg);
          if (msg === "身份证号码已存在") {
            this.$toast("身份证号码已存在");
            if (this.patientForm.sex === 1) {
              this.patientForm.sex = "男";
            }
            if (this.patientForm.sex === 2) {
              this.patientForm.sex = "女";
            }
            if (this.patientForm.patientsoure === 1) {
              this.patientForm.patientsoure = "门诊";
            }
            if (this.patientForm.patientsoure === 2) {
              this.patientForm.patientsoure = "住院";
            }
            if (this.patientForm.lapseto === 1) {
              this.patientForm.lapseto = "留治";
            }
            if (this.patientForm.lapseto === 2) {
              this.patientForm.lapseto = "转出";
            }
            return false;
          }
          if (msg == "手机号码已存在") {
            this.$toast("手机号码已存在");
            if (this.patientForm.sex === 1) {
              this.patientForm.sex = "男";
            }
            if (this.patientForm.sex === 2) {
              this.patientForm.sex = "女";
            }
            if (this.patientForm.patientsoure === 1) {
              this.patientForm.patientsoure = "门诊";
            }
            if (this.patientForm.patientsoure === 2) {
              this.patientForm.patientsoure = "住院";
            }
            if (this.patientForm.lapseto === 1) {
              this.patientForm.lapseto = "留治";
            }
            if (this.patientForm.lapseto === 2) {
              this.patientForm.lapseto = "转出";
            }
            return false;
          }
          if (msg === "透析号码已存在") {
            this.$toast("透析号码已存在");
            if (this.patientForm.sex === 1) {
              this.patientForm.sex = "男";
            }
            if (this.patientForm.sex === 2) {
              this.patientForm.sex = "女";
            }
            if (this.patientForm.patientsoure === 1) {
              this.patientForm.patientsoure = "门诊";
            }
            if (this.patientForm.patientsoure === 2) {
              this.patientForm.patientsoure = "住院";
            }
            if (this.patientForm.lapseto === 1) {
              this.patientForm.lapseto = "留治";
            }
            if (this.patientForm.lapseto === 2) {
              this.patientForm.lapseto = "转出";
            }
            return false;
          }

          if (msg === undefined) {
            this.$toast("修改成功");
            var patients = response.data.data.patients;
            this.$router.push("/patientdetail?patientid=" + patients.id);
          }
        }
      });
    },
    changRadio() {
      if (this.radio === "1") {
        this.showOne = false;
      }
      if (this.radio === "2") {
        this.showOne = true;
      }
    }
  },
  created() {
    setRem();
    setHeight();
    var patientid = this.$route.query.patientid;
    this.patient_id = patientid;
    this.GetPatientDetail(patientid);
    this.GetIllnessList();
  }
};
</script>

<style lang="scss" scoped>
.page_editPatients {
  overflow-y: auto;
  height: 100%;
  background: #fafafa;
  .addPatientsTitle {
    height: 3.125rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 1.125rem;
    background: #fff;
    span {
      font-size: 1rem;
    }
  }
  .jiantou {
    font-size: 1.5rem;
    font-weight: 600;
    margin-right: 1.25rem;
  }
  .titleName {
    font-size: 1.125rem !important;
    font-weight: 600;
  }
  .basicTitle {
    font-size: 0.75rem;
    color: #989898;
    padding: 0 1rem;
    height: 1.875rem;
    line-height: 1.875rem;
  }
  .basicBox {
    .van-cell__value {
      display: flex;
    }
    .van-field__body {
      width: 100%;
    }
  }
  .custom-title::before {
    position: absolute;
    left: 8px;
    color: #ee0a24;
    font-size: 14px;
    content: "*";
  }
  .van-cell__title {
    display: flex;
  }
  .van-checkbox-group {
    display: flex;
    flex-wrap: wrap;
  }
  .van-checkbox {
    width: 48%;
    margin-bottom: 0.625rem;
  }
  .van-radio-group {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }
  .van-radio {
    width: 48%;
  }
  .autoGeneration {
    width: 5rem;
    height: 1.875rem;
    line-height: 1.875rem;
    background: #338afb;
    border-radius: 0.9375rem;
    text-align: center;
  }
  .van-button--info {
    border-radius: 0.9375rem;
  }
  .van-button--small {
    min-width: 3.75rem !important;
    height: 1.875rem;
    padding: 0 0.5rem;
    font-size: 0.75rem !important;
    line-height: 1.75rem;
  }
  .moreInfo {
    text-align: center;
    font-size: 0.75rem;
    color: #338afb;
    margin: 0.625rem 0 4.5rem;
  }
  .van-cell {
    align-items: center;
  }
  .turnOut {
    height: 2.8125rem;
    line-height: 2.8125rem;
    text-align: center;
    background: #fff;
    margin-top: 0.75rem;
  }
}
::-webkit-scrollbar {
  width: 0;
}
</style>

<style lang="scss">
.page_editPatients {
  .changeColor {
    .van-field__control {
      color: #9b9b9b !important;
    }
  }
  .basicBox {
    .van-cell__value {
      font-size: 1rem;
    }
    .van-cell__title {
      font-size: 1rem;
    }
  }
  .xtBox {
    .van-cell__value {
      font-size: 1rem;
    }
    .van-cell__title {
      font-size: 1rem;
    }
  }
}
</style>
