import {DonMessage} from '@/axios/message.js'
const $message = new DonMessage()
import { getDicList } from "@/request/common";
import { handleMdtShare,updateLookRecord, closeMeeting,getSourceList,uploadMdtSource } from '@/request/mdt.js'

import { copyContent, newDownLoad, getNameText} from "aegle-sp-components/src/utils/index";
export default {
	inject: ['topObj'],
  methods: {
		 // 表头样式
		 mdtTheadClass() {
			return "text-align: left;background:#F3F4F8; color:#000; padding-left:10px;line-height: 42px;height: 42px;padding: 0 0 0 15px";
		},
		// 表格-行样式
		mdtTrowClass() {
				return "text-align: left; line-height: 40px;height: 40px;padding:0 0 0 15px";
		},
      // 会议地点
    async getRoomList() {
      const {data,msg,code} = await getDicList('005');
      if (code === 0) {
        this.roomList = data.cdict.map((item) => {
          return {
            label: item.descCn,
            value: item.code,
          };
        });
      } else {
        this.$message.error(msg);
        this.roomList = [];
      }
    },
		//获取会议资料
    async getSourceList(id) {
      const {code, data} = await getSourceList(id)
      if(code == 0 && data) {
        this.allFileData = data.cmFileUrl.concat(data.otherFileUrl)
      }
    },
		//文件预览
    preview(d,type) {
      // this.urlList = []
      let param = {}
      if(type == 1 || type == 2) {
        updateLookRecord(d.id).then(res => {})
        param.src = type == 1 ? (d.meetingType == 'MDT会议' ? this.item?.mdtMeeting?.pdfReportUrl : this.item?.mdtMeeting?.tboardPdfUrl) : d.opinionPdfUrl
      } else {
        param.src = d.pdfFileUrl
      }
      // const p = {
      //   label: getNameText(param.src),
      //   url: param.src,
      //   isSucceed: true
      // }
      
      // this.urlList.push(p)
      // this.showImgView = true;
      this.$refs.preview1.open(param)
    },
		//复制链接
    copyUrl(d) {
      const param = {
        type: d.meetingType,
        id: d.id,
        docId: this.topObj.doctorInfo.id
      }
      handleMdtShare(param).then(res => {})
      copyContent(param,() => {},this.topObj.setting)
    },
		//导出
    download(d,type) {
      const src = type == 1 ? (d?.meetingType == 'MDT会议' ? d?.pdfReportUrl : d?.tboardPdfUrl) : d?.opinionPdfUrl;
      newDownLoad(src)
    },
		//清空
    clearData() {
      this.mdtForm = {
        doctorList: [],
        endTime: "",
        meetingType: "",
        patientBaseId: "",
        patientCase: "",
        purpose: "",
        roomInfo: "",
        roomTypeCode: "",
        startTime: "",
        subject: "",
        patientSource: "",
        writeSourceTime: ""
      }
      this.date_ = '';
      this.dateTime = '';
      this.existId = '';
    },
		//准备会议
    goMeeting() {
      if (!this.mdtForm.subject) {
        $message.error("会议标题不能为空！");
        return;
      } else if (!this.date_) {
        $message.error("会议时间不能为空！");
        return;
      } else if (!this.mdtForm.meetingType) {
        $message.error("会议分类不能为空！");
        return;
      } else if (!this.mdtForm.roomTypeCode) {
        $message.error("会议地点不能为空！");
        return;
      } else if (!this.memberList.length) {
        $message.error("参会人员不能为空！");
        return;
      } else if (
        !this.mdtForm.patientCase || !this.mdtForm.patientCase.trim()
      ) {
        $message.error("患者病情概述不能为空！");
        return;
      } else if (!this.mdtForm.purpose || !this.mdtForm.purpose.trim()) {
        $message.error("患者诉求不能为空！");
        return;
      }else if (!this.mdtForm.writeSourceTime) {
        $message.error("患者信息收集时间不能为空！");
        return;
      } else if (!this.mdtForm.patientSource.trim()) {
        $message.error("信息收集来源不能为空！");
        return;
      }
      this.saveMeeting();
    },
		//取消会议请求
    async cancleMeeting(param, call) {
      if (!this.closeReason || !this.closeReason.trim()) {
        this.$message.error("请输入会议取消原因!");
        return;
      }
      // let param = {
      //   doctor: this.doctorInfo?.nicknames,
      //   reason: this.closeReason.trim(),
      //   id: this.topObj.mdtId,
      //   patientBaseId: this.topObj.patientId,
      //   del: 0
      // }
      let {code, msg} = await closeMeeting(param)
      if (code === 0) {
        this.$message({
          type: "success",
          message: "取消成功！",
        });
        this.closeDialog = false;
				call()
        this.$emit('refresh')
      } else {
        this.$message({
          type: "error",
          message: msg ? msg : "取消失败！",
        });
      }
    },
		limitWord(type) {
      if(type == 'subject'){
        const str = this.mdtForm.subject ? this.mdtForm.subject.trim() : '';
        if(str.length > 100){
          this.$message.error('标题已超过最高限制100字')
          this.mdtForm.subject = str.substring(0,100)
        }
      } else if(type == 'patientSource') {
        const str = this.mdtForm.patientSource ? this.mdtForm.patientSource.trim() : '';
        if(str.length > 20){
          this.$message.error('最多可输入20字')
          this.mdtForm.patientSource = str.substring(0,20)
        }
      }
    },
		//文件上传确定
    async sureUpload(files,mdtId) {
			const param = {
					id: '',
					roleName: '',
					mdtId,
					sort: 100
			}
			let formData = new window.FormData()
			formData.append('files', files[0])
			this.topObj.handleOption(1,{ pointLoading: true,pointText: "上传中，请耐心等待~"})
			const {code,msg} = await uploadMdtSource(param, formData)
			this.topObj.handleOption(1,{ pointLoading: false })
			if(code == 0){
					this.$message.success('该文件已上传成功！');
					this.getSourceList(mdtId)
			} else {
					this.$message.error(msg);
			}
		},
		//改变会议结点，非请求
		handleMeeting(n,status) {
			this.$emit('changeStep', {step:n,status: status || 0})
		}
  }
}