import {DonMessage} from '@/axios/message.js'
const $message = new DonMessage()
import aegleTitle from '../AegleTitle/main.vue'
import aegleDropSel from '../AegleDropSel/main.vue'
import pain from '../AeglePain/main.vue'
import { expireTimeOption01,
  expireTimeOption,
  shapeArr,
  constipationHandleArr,
  diarrheaDict,
  intakeLevel,
  timeOptions,
  numType,
  baseStatus,
  mouthUlcerArr } from 'aegle-sp-components/src/data/validate.js'
import { debounce, cloneDeep } from 'lodash'
import discomfortTemp from '../AegleDiscomfort/main.vue'
import ellipsis from '../AegleEllipsis/main.vue'
import cancerDialog from '../AegleCancerDialog/main.vue'
import aegleImgView from '../AegleImgView/main.vue'
import {
  getFollowList,
  getFollowInfo,
  addTempFollow,
  finishFollow,
} from "@/request/cm.js";
import mixin from './mixin'

export default {
  name: 'AegleFollow',
  components: { aegleTitle, aegleDropSel, pain,discomfortTemp,ellipsis,cancerDialog,aegleImgView },
  mixins: [mixin],
  props: {
    id: [String,Number],
    item: Object,
    doctorInfo: Object,
    patientBase: Object,
    route: String
  },
  data() {
    return {
      visible: false,
      currentImgUrl: [],
      icon: {
        "1": require('@/assets/images/daiwancheng.png'),
        "2": require('@/assets/images/wancheng.png'),
        "3": require('@/assets/images/yuqi.png'),
        "4": require('@/assets/images/zancun.png'),
        "5": require('@/assets/images/daibuchong.png'),
      },
      mouthUlcerArr,
      intakeLevel,
      diarrheaDict,
      shapeArr,
      constipationHandleArr,
      tempDialog: false,
      sourceArr: [],
      type: 1,
      baseInfo: {
        emrTumour: '',//分期
        outpatientDiag: '', //诊断
        phone: '',
        currentStatus: '',
      },
      timeOptions,
      numType,
      // diseaseArr:[],
      diseaseArrCopy: [],
      painPanel: '0',//疼痛的activepanel
      // disease: '',//病种
      diseases: '',//病种修改
      diseaseOther: '',//病种其它
      // diseaseTime: '',//病种周期默认,
      diseaseTimes: '',//病种周期修改
      // cancerObj: {
      //   diseases: '',
      //   diseaseTimes: ''
      // },
      base: {
        protocols: '',//治疗方案
        subject: '',// 随访标题
        followDate: '',//本次随访日期
        contactType: '',//随访形式
        contactContent: '',
        discomfort: '',//不适
        takeMedicineSituation: '',//服药
        badLivingHabits: '',//不良生活习惯
        status: '',//患者状态
        otherStatusContent: '',
        reminder: '',//常规提醒
        otherSupplements: '',
        supplementaryReminder: ''
      },
      followNextDate: '',//下次随访日期
      followIndexStatus: '',
      followId: '',
      followIndexId: '',

      mouthUlcerDTO: {
        mouthUlcer: '',
        mouthUlcerLevel: ''
      },
      decreasedAppetiteDTO: {//食欲降低
        decreasedAppetite: '',
        foodIntakeChange: '',//进食量减少
        foodIntakeChangeNum: '',//减少量
        bodyWeightChange: '',//体重是否下降
        bodyWeightChangeNum: ''//体重下降量
      },
      constipationDTO: {//便秘
        constipation: '',
        constipationDay: '',//tian
        constipationNum: '',//次数
        method: '',//处置
        constipationTakeMedicine: '',//用药
      },
      diarrheaDTO: {//腹泻
        diarrhea: '',
        diarrheaDay: '',//tian
        diarrheaNum: '',//次数
        shape: '',//形状
        processing: '',//处置
        diarrheaTakeMedicine: ''//服用药物
      },
      rashDTO: {
        rash: '',
        rashContent: ''
      },
      discomfortOtherDTO: {
        ditemiscomfortOther: '',
        discomfortOtherContent: ''
      },
      noComform:{
        tired: '1',
        weak: '1',
        mouthUlcer: '1',
        decreasedAppetite: '',
        nausea: '',
        vomit: '',
        constipation: '',
        diarrhea: '',
        rash: '',
        hemorrhage: '',
        numbness: '',
        pain: '',
        discomfortOther: '',
      },
      painDTO: [{
        painLocation: '', //疼痛位置
        painNature: '', //疼痛性质
        score: 0,       //评分
        sleep: '',      //是否影响睡眠 0：否  1：是
        anodyne: '',        //止痛药 0：否  1：是
        drugDose:''    //药物剂量
      }],
      expireTimeOption,
      expireTimeOption01,
      cancerArr: [],
      curFollow: {
        indexId: '',//随访
        resultId: '',//随访的id，
        followId: '',//随访记录的id
        canEdit: true,
      },
      discomfort: {},


      contactType: ["电话", "微信", "其他"],
      curFollowList: [],
      pastFollowList: [],
      baseStatus,
      scheduleIndexStatus: [],
      followInfo: {},
      curEditFollowInfo: "",
      editFollowStatus: "",
      loading:false,
      canEdit: true,
      tableData: [],//病例资料
    };
  },
  watch: {
    item: {
      handler() {
        this.loadCurFollowList();
        this.queryPatientInfo(this.id)
      },
      deep: true,
    }
  },
  created() {
    this.queryPatientInfo(this.id,2 )
  },
  async mounted() {
    await this.loadCurFollowList();
  },
  methods: {
    changeD(e) {
      this.$forceUpdate()
    },
    changeRecord(type,index,d) {
      if(this.curFollow.indexId == d.id) return;
      if(this.canEdit){
        this.cancelFollow(() => {
          this.searchCurFollowInfo(type, index)
        },true)
      } else {
        this.searchCurFollowInfo(type, index)
      }
    },
    showImg(d) {
      if(!d.length) return;
      this.currentImgUrl = d.map(item => {
        return {
          title: item.substring(0,item.lastIndexOf('.')),
          label: item.substring(0,item.lastIndexOf('.')),
          url: item
        }
      })
      this.visible = true
    },
    // 资料查看
    gotoOther(e) {
      if(e.indexOf('http://') != -1 || e.indexOf('https://') != -1){
        window.open(e)
      }
    },
    //住院文件查看
    viewFile(e) {
      if(e == '病案首页' && !this.patientBase?.seeDoctorId){
        this.$message.warning('暂无病案首页数据')
        return
      }
      this.handleOptions(2,{e,patientId: this.id, tab: 'A005'})
      // this.isExistence(e,this.id,'A005')
    },
    //表头样式
    headerCellStyle() {
      return `background: #F3F4F8;font-size: 13px;font-family: PingFangSC, PingFangSC-Medium;font-weight: 500;color: rgba(0,0,0,0.85);padding:0 0 0 2px;height:30px;line-height:30px`
    },
    //获取随访详情
    async getFollowDetail(indexId,resultId) {
      let {data,code,msg} = await getFollowInfo(indexId, resultId || "",this.item?.id);
      if (code !== 0) {
        this.$message.error(msg);
        if(code == 5001) this.canEdit = false;
      }
      this.painPanel = '0';
      this.curFollow.followId = data?.followRecord?.id || '';
      this.curFollow.resultId = data?.recordResult?.id || ''
      //如果患者信息里的状态为死亡，或者上一次随访记录的状态为死亡，或者本次随访为完成，则不可编辑
      if(data?.patientInfo?.patientStatus == 3 ||
        !this.curFollow.canEdit ||
        this.route != '/caseManage/myPatient' ||
        data?.patientInfo?.caseManagerId != this.doctorInfo?.id ||
        (!this.curFollowList.length && !this.pastFollowList.length) ||
        data?.followRecord?.termination){
        this.canEdit = false;
      } else {
        this.canEdit = true
      }
      this.handleOptions(1, this.canEdit)
      // this.canEdit = false
      //赋值处理
      this.setFormData(data)
    },
    handleOptions(type, d) {//1编辑状态2并按3死亡
      this.$emit('handle',type,d)
    },
    //获取随访之后赋值
    setFormData(d) {
      this.tableData = (d?.patientCaseRecords || []).map(item => {
        const arr1 = item.filePath ? item.filePath.split(',') : []
        const imgArr = arr1
        // let imgArr = arr1.filter(z => {
        //   const type = z.substring(z.lastIndexOf(".")+1)
        //   if(['jpg','jpeg','png','gif','bmp'].includes(type)){
        //     return z
        //   }
        // })
        // let otherUrl = arr1.filter(z => {
        //   const type = z.substring(z.lastIndexOf(".")+1)
        //   if(!['jpg','jpeg','png','gif','bmp'].includes(type)){
        //     return z
        //   }
        // })
        let arr2 = item.externalUrl ? item.externalUrl.split(',') : [];
        // arr2 = arr2.concat(otherUrl)
        const arr3 = item?.dcmUrl ? item?.dcmUrl.split(',') : []
        return {
          ...item,
          dcmUrl: arr3,
          externalUrl: arr2,
          imgUrl: imgArr
        }
      })
      this.type = d?.recordResult?.followType
      for(let k in this.base){
        this.base[k] = d?.recordResult[k] || ''
      }
      this.base.subject = d?.recordResult?.subject || d?.followRecord?.subject;
      this.base.followDate = this.type == 2 ? (d?.followRecord?.followDate || '') : (d?.recordResult?.followDate || '');
      this.followNextDate = d?.recordResult?.followNextDate || '';
      this.followIndexStatus = d?.recordResult?.followIndexStatus || '';
      for(let k in this.noComform){
        this.noComform[k] = (d?.discomfort && d?.discomfort[k] != undefined) ? d?.discomfort[k] : ''
      }
      this.noComform.constipation = d?.discomfort?.constipationDTO.constipation
      this.noComform.decreasedAppetite = d?.discomfort?.decreasedAppetiteDTO.decreasedAppetite
      this.noComform.diarrhea = d?.discomfort?.diarrheaDTO.diarrhea
      this.noComform.discomfortOther = d?.discomfort?.discomfortOtherDTO.discomfortOther
      this.noComform.mouthUlcer = d?.discomfort?.mouthUlcerDTO.mouthUlcer
      this.noComform.rash = d?.discomfort?.rashDTO.rash
      this.diseaseTimes = d?.recordResult?.cancerTime || ''
      this.diseases = d?.recordResult?.followCancer || ''
      this.diseaseArrCopy = (d?.recordResult?.cancerProject ? JSON.parse(d?.recordResult?.cancerProject) : []).map(item => {
        return {
          ...item,
          text: item.label,
          edit: true
        }
      })
      this.mouthUlcerDTO = { ...d?.discomfort?.mouthUlcerDTO }
      this.decreasedAppetiteDTO = { ...d?.discomfort?.decreasedAppetiteDTO}
      this.constipationDTO = { ...d?.discomfort?.constipationDTO}
      this.diarrheaDTO = { ...d?.discomfort?.diarrheaDTO}
      this.rashDTO = { ...d?.discomfort?.rashDTO}
      this.discomfortOtherDTO = { ...d?.discomfort?.discomfortOtherDTO}
      let painArr = d?.discomfort?.painDTO?.length ? d?.discomfort?.painDTO : [{
        painLocation: '', //疼痛位置
        painNature: '', //疼痛性质
        score: 0,       //评分
        sleep: '',      //是否影响睡眠 0：否  1：是
        anodyne: '',        //止痛药 0：否  1：是
        drugDose:''    //药物剂量
      }]
      painArr = painArr.map(item => {
        if(item.hasOwnProperty('id')) delete item.id;
        return {
          ...item
        }
      })
      this.painDTO = cloneDeep(painArr)
      // this.baseInfo.phone = d?.patientInfo?.phone || '';
      this.discomfort = {
        ...this.noComform,
        ...this.mouthUlcerDTO,
        ...this.decreasedAppetiteDTO,
        ...this.constipationDTO,
        ...this.diarrheaDTO,
        ...this.rashDTO,
        ...this.discomfortOtherDTO,
        painDTO: cloneDeep(this.painDTO)
      }
    },
    //编辑按钮防抖
    btnClick: debounce(function(type){
      if(this.disabled || !this.canEdit) return;
      if(type == 1){
        if(this.base.status == 3){
          this.diedSure(()=>{
            this.type == 1 ? this.sendPlanFollow(2,true) : this.sendTempFollow(2,true)
          })
        } else {
          this.type == 1 ? this.sendPlanFollow(2,true) : this.sendTempFollow(2,true)
        }
      } else if(type == 2){//取消
        //2是暂存，3是保存
        this.cancelFollow(() => {
          // this.getFollowDetail(this.curFollow.indexId, this.curFollow.resultId);
          this.$emit('close', true)
        })
      } else if(type == 3){//暂存
        this.sendTempFollow(1)
      } else if(type == 4){
        this.sendPlanFollow(1,true)
      }
    },2000,{
      leading: true,
      trailing: false
    }),
    //获取临时随访参数
    getTempParam(type) {
      let diseaseArr = []
      for(let k of this.diseaseArrCopy){
        if(k.label && k.label.trim()){
          diseaseArr.push({
            label: k.label,
            first: k.first
          })
        }
      }
      let param = {
        ...this.base,
        supplementaryReminder: this.base.supplementaryReminder.trim(),
        protocols: this.base.protocols.trim(),
        subject: this.base.subject.trim(),
        followType: this.type,//随访类型（1计划随访 2临时随访）
        contactContent: this.base.contactType == 3 ? this.base.contactContent.trim() : '',
        otherStatusContent: this.base.status == 5 ? this.base.otherStatusContent.trim() : '',
        takeMedicineSituation: this.base.takeMedicineSituation ? this.base.takeMedicineSituation.trim() : '',//服药情况
        badLivingHabits: this.base.badLivingHabits ? this.base.badLivingHabits.trim() : '',
        otherSupplements: this.base.otherSupplements ? this.base.otherSupplements.trim(): '',
        followCancer: this.diseases ? this.diseases.trim() : '',//癌肿
        cancerTime: this.diseaseTimes ? this.diseaseTimes.trim() : '',//时间
        cancerProject: this.base.reminder == 1 ? JSON.stringify(diseaseArr) : '',
        temporaryStorage: type,//是否暂存 1为暂存
        discomfortDTO: {
          pain: this.noComform.pain
        },
        patientBaseId: this.id,
        followIndexId: this.curFollow.indexId,
        followId: this.curFollow.followId
      }
      if(this.curFollow.resultId){
        this.type == 1 ? param.id = this.curFollow.resultId : param.businessId = this.curFollow.followId;
      }
      if(this.type == 1){
        param.supplementaryReminder = this.base.supplementaryReminder ? this.base.supplementaryReminder.trim() : '',
        param.followNextDate = this.followNextDate
      }
      if(param.discomfort == 1){
        let discomfort = {
          tired: this.noComform.tired,
          weak: this.noComform.weak,
          nausea: this.noComform.nausea,
          vomit: this.noComform.vomit,
          hemorrhage: this.noComform.hemorrhage,
          numbness: this.noComform.numbness,
        }
        if(this.noComform.mouthUlcer){
          discomfort.mouthUlcerDTO = {
            ...this.mouthUlcerDTO,
            mouthUlcer: this.noComform.mouthUlcer
          }
        }
        if(this.noComform.decreasedAppetite){
          discomfort.decreasedAppetiteDTO = {
            ...this.decreasedAppetiteDTO,
            decreasedAppetite: this.noComform.decreasedAppetite,
            bodyWeightChangeNum: this.decreasedAppetiteDTO.bodyWeightChangeNum ? Number(this.decreasedAppetiteDTO.bodyWeightChangeNum) : ''
          }
        }
        if(this.noComform.constipation){
          discomfort.constipationDTO = {
            ...this.constipationDTO,
            constipation: this.noComform.constipation
          }
        }
        if(this.noComform.diarrhea){
          discomfort.diarrheaDTO = {
            ...this.diarrheaDTO,
            diarrhea: this.noComform.diarrhea
          }
        }
        if(this.noComform.rash){
          discomfort.rashDTO = {
            ...this.rashDTO,
            rash: this.noComform.rash
          }
        }
        if(this.noComform.discomfortOther){
          discomfort.discomfortOtherDTO = {
            ...this.discomfortOtherDTO,
            discomfortOther: this.noComform.discomfortOther
          }
        }
        if(this.noComform.pain){
          discomfort.pain = this.noComform.pain;
          const arr = cloneDeep(this.painDTO)
          discomfort.painDTO = arr.map(item => {
            return {
              ...item,
              followRecordId: this.curFollow.followId,
              followResultId: this.curFollow.resultId
            }
          })
        }
        param.discomfortDTO = discomfort//不适下面的
      }
      return param
    },
    //临时随访非空验证
    validateTemp(param){
      if(!this.base.protocols || !this.base.protocols.trim()){
        $message.error('治疗方案不能为空')
        return false
      }
      if(!this.base.subject || !this.base.subject.trim()) {
        $message.error('随访标题不能为空')
        return false
      }
      if(!this.base.followDate) {
        $message.error('随访开始时间不能为空')
        return false
      }
      // if(this.type == 1 && !this.followNextDate && (this.followIndexStatus != 2 && this.followIndexStatus !=3)) {
      //   $message.error('下次随访时间不能为空')
      //   return false
      // }
      if(!this.base.contactType) {
        $message.error('随访形式不能为空')
        return false
      }
      if(this.base.contactType == 3 && !this.base.contactContent) {
        $message.error('随访形式其他备注不能为空')
        return false
      }
      if(!this.base.discomfort) {
        $message.error('不适症状不能为空')
        return false
      }
      if(this.base.discomfort == 1) {
        if(!this.noComform.discomfortOther && !this.painText.length) {
          $message.error('请选择不适症状')
          return false
        }
        const p = {
          ...this.mouthUlcerDTO,
          ...this.decreasedAppetiteDTO,
          ...this.constipationDTO,
          ...this.diarrheaDTO,
          ...this.rashDTO,
          ...this.discomfortOtherDTO
        }
        if(this.noComform.mouthUlcer && !p.mouthUlcerLevel) {
          $message.error('口腔溃疡等级不能为空')
          return false
        }
        if(this.noComform.decreasedAppetite && !p.foodIntakeChange) {
          $message.error('进食量是否减少不能为空')
          return false
        }
        if(this.noComform.decreasedAppetite && p.foodIntakeChange == 1 && !p.foodIntakeChangeNum) {
          $message.error('进食量较前减少量不能为空')
          return false
        }
        if(this.noComform.decreasedAppetite && !p.bodyWeightChange) {
          $message.error('体重是否持续下降不能为空')
          return false
        }
        if(this.noComform.decreasedAppetite && p.bodyWeightChange == 1 && !p.bodyWeightChangeNum) {
          $message.error('体重下降量不能为空')
          return false
        }
        if(this.noComform.constipation && (!p.constipationNum || !p.constipationDay)) {
          $message.error('便秘次数不能为空')
          return false
        }
        if(this.noComform.constipation && !p.method) {
          $message.error('便秘处置不能为空')
          return false
        }
        if(this.noComform.constipation && p.method == '2' && (!p.constipationTakeMedicine || !p.constipationTakeMedicine.trim())) {
          $message.error('便秘服用药物不能为空')
          return false
        }
        if(this.noComform.diarrhea && (!p.diarrheaNum || !p.diarrheaDay)) {
          $message.error('腹泻次数不能为空')
          return false
        }
        if(this.noComform.diarrhea && !p.shape) {
          $message.error('大便形状不能为空')
          return false
        }
        if(this.noComform.diarrhea && !p.processing) {
          $message.error('腹泻处置不能为空')
          return false
        }
        if(this.noComform.diarrhea && p.processing == '2' && (!p.diarrheaTakeMedicine || !p.diarrheaTakeMedicine.trim())) {
          $message.error('腹泻服用药物不能为空')
          return false
        }
        if(this.noComform.rash && (!p.rashContent||!p.rashContent.trim())) {
          $message.error('皮疹其他备注不能为空')
          return false
        }
        if(this.noComform.pain) {
          for(let i=0; i < this.painDTO.length; i++){
            const k = this.painDTO[i]
            if(!k.painLocation || !k.painLocation.trim()){
              $message.error(`疼痛部位${numType[i]}不能为空！`)
              return false
            }
            if(!k.painNature){
              $message.error(`${k.painLocation}疼痛性质不能为空！`)
              return false
            }
            if(k.score == 0){
              $message.error(`${k.painLocation}疼痛评分不能为空！`)
              return false
            }
            if(k.sleep === '' || k.sleep === null){
              $message.error(`${k.painLocation}疼痛是否影响睡眠不能为空！`)
              return false
            }
            if(k.anodyne === '' || k.anodyne === null){
              $message.error(`${k.painLocation}疼痛是否吃止疼药不能为空！`)
              return false
            }
            if(k.anodyne && (!k.drugDose || !k.drugDose.trim())){
              $message.error(`${k.painLocation}疼痛药物剂量不能为空！`)
              return false
            }
          }
          
        }
        if(this.noComform.discomfortOther && (!p.discomfortOtherContent||!p.discomfortOtherContent.trim())) {
          $message.error('不适其它备注不能为空！')
          return false
        }
        //不适具体某一项
      }
      if(this.base.status === ''){
        $message.error('患者状态不能为空！')
        return false
      }
      if(this.base.status == 5 && (!this.base.otherStatusContent || !this.base.otherStatusContent.trim())){
        $message.error('患者状态其他备注不能为空！')
        return false
      }
      if(!this.base.reminder){
        $message.error('常规提醒不能为空！')
        return false
      }
      if(this.base.reminder == 1){
        if(!this.diseases){
          $message.error('病种不能为空！')
          return false
        }
        if(!this.diseaseTimes) {
          $message.error('病种时间不能为空！')
          return false
        }
        if(!this.diseaseArrCopy.length){
          $message.error('至少要有一条检查项目')
          return false
        }
        for(let k of this.diseaseArrCopy){
          if(!k.label || !k.label.trim()){
            $message.error('该检查项目不能为空')
            return false
          }
        }
      }
      return true
    },
    //sendTempFollow
    async sendTempFollow(type,temp) {
      if(temp && type ==2){
        const status = this.validateTemp(type)
        if(!status) return;
      }
      const param = this.getTempParam(type)
      this.loading = true;
      const { data, code, msg} = await addTempFollow(param)
      this.loading = false
      if(code == 0){
        if(type ==2){
          $message.success('保存成功！该状态同步到日程')
          if(param.status == 3) await this.getPatientInfo(this.id,d => this.handleOptions(3,d));
        } else if(type == 1) {
          $message.success('暂存成功')
        }
        this.loadCurFollowList()
        this.$emit('close', true)
        // this.$store.commit('patientCm/changeCmCurTimeI', "A004")
      } else {
        $message.error(msg)
      }
    },
    //sendPlanFollow
    async sendPlanFollow(type,temp) {
      const param = this.getTempParam(type)
      if(temp && type ==2){
        const status = this.validateTemp(param)
        if(!status) return;
      }
      this.loading = true;
      const { data, code, msg} = await finishFollow(param)
      this.loading = false
      if(code == 0){
        if(param.status == 3) await this.getPatientInfo(this.id,d => this.handleOptions(3,d));
        $message.success('保存成功！')
        this.$emit('close', true)
        // this.$store.commit('patientCm/changeCmCurTimeI', "A004")
        this.loadCurFollowList()
      } else {
        $message.error(msg)
      }
    },
    //获取左边列表
    async loadCurFollowList() {
      let res = await getFollowList({
        followId: this.item.id,
      });
      if(res.code == 5001){
        this.$message.error(res.msg)
        this.canEdit = false
        this.handleOptions(1, this.canEdit)
        return
      }
      // 根据时间筛选是否是当前的
      this.curFollowList = this.handleFollowList(res.data?.currentIndexList);
      this.pastFollowList = this.handleFollowList(res.data?.pastIndexList);
      if(!this.curFollowList.length && !this.pastFollowList.length) {
        this.canEdit = false
        this.handleOptions(1, this.canEdit)
        return
      }
      if(this.item.hasOwnProperty('isMessage')) {
        //从通知跳转过来需要定位到数据,如果不存在随访id，就展示第一条
        if(this.item.selfId == ''){
          this.type = this.item?.type ? this.item?.type : 1;
          if(this.curFollowList.length){
            this.searchCurFollowInfo('cur', 0)
          } else if(this.pastFollowList.length){
            this.searchCurFollowInfo('past', 0)
          }
          return
        }
        let index = this.curFollowList.findIndex(item => item.id == this.item.selfId);
        if(index > -1) {
          this.searchCurFollowInfo('cur', index)
          return
        }
        index = this.pastFollowList.findIndex(item => item.id == this.item.selfId);
        if(index > -1) {
          this.searchCurFollowInfo('past', index)
          return
        }
      } else {
        // 从随访管理进来，设置默认显示当前或者历史的第一条
        if(this.curFollowList.length){
          this.searchCurFollowInfo('cur', 0)
        } else if(this.pastFollowList.length) {
          this.searchCurFollowInfo('past', 0)
        }
      }
    },
    //处理左边随访列表
    handleFollowList(list) {
      let res = (list || []).map((ele) => {
        let status;
        if (ele.scheduleIndexStatus == '0') {
          status = 0;//待完成
        } else if (ele.scheduleIndexStatus == 1 || ele.scheduleIndexStatus == 3) {
          status = 1;//完成
        } else if (ele.scheduleIndexStatus == 2) {
          status = 2;//逾期
        } else if (ele.scheduleIndexStatus == 4) {
          status = 3;//暂存
        } else if (ele.scheduleIndexStatus == 5) {
          status = 4;//待补充
        }
        return {
          status: this.baseStatus[status],
          userName: ele.username,
          date: ele.date,
          phone: ele.phone,
          username: ele.username,
          contactType: this.contactType[ele.contactType - 1],
          id: ele.indexId,
          resultId: ele.resultId,
          subject: ele.subject
        };
      });
      return res;
    },
    async searchCurFollowInfo(status, i) {;
      this.loading=true;
      this.curEditFollowInfoIndex = i;
      this.editFollowStatus = status;
      let val;
      if (status == "cur") {
        val = this.curFollowList[i];
      } else {
        val = this.pastFollowList[i];
      }
      //保存当前的随访记录id和随访id，用于取消重新加载
      this.curFollow = {
        indexId: val.id,
        resultId: val.resultId || '',
        followId: this.item.id,
        canEdit: val.status.canEdit ? true : false,
      }
      await this.getFollowDetail(val.id,val.resultId)
      this.loading=false;
    },
    async reloadData() {
      await this.loadCurFollowList();
      await this.searchCurFollowInfo(
        this.editFollowStatus,
        this.curEditFollowInfoIndex
      );
    },
  },
};