<template>
  <view class="Scanning_ins">
    <view class="Scanning">
      <view class="Scanning_top" id="Scanning_tops" :animation="animationData">
        <view class="Scanning_top_icon">
          <text class="cubeic-ok newicon newicon-duigou"></text>
        </view>
        <view class="Scanning_top_text">
          <view class="text1">扫描成功</view>
          <view class="success_tips">
            (请您评估患者的意识状况、生命体征、配合程度，如有异常请及时联系护士！)
          </view>
        </view>
        <view class="Scanning_cont">
          <view>
            <text>患者姓名 : {{ infoDATA.patientName || "-" }}
							<text v-if="infoDATA.residenceNo">
								({{
								  infoDATA.bedNum || "-"
								}})
							</text>
							<text v-if="!infoDATA.residenceNo">
								({{
								  infoDATA.cardNo || "-"
								}})
							</text>
            </text>
          </view>
          <view v-if="infoDATA.residenceNo">住院号 : {{ infoDATA.residenceNo || "-" }}</view>
					<view v-if="!infoDATA.residenceNo">身份证号 : {{ infoDATA.identityCardNo || "-" }}</view>
          <view v-if="infoDATA.residenceNo">住院科室 : {{ infoDATA.department ? infoDATA.department.dept : "-" }}</view>
          <view>注意事项 : {{ infoDATA.remark || "-" }}</view>
        </view>
      </view>
      <!-- ------------------未完成工单 start----------------- -->
      <view class="page_items" v-if="
          workData.length === 0 && patientOrders && patientOrders.length > 0
        ">
        <view class="page_item" v-for="(infoDATA, i) of patientOrders" :key="i">
          <view class="page_item_top">
            <view class="page_item_top_L">
              <text class="L_text">单号:{{ infoDATA.gdcode }}</text>
            </view>
            <view class="page_item_top_R">
              <button class="L_iocn" @click="notice(infoDATA)">通知</button>
            </view>
            <view class="L"></view>
            <view class="R"></view>
          </view>
          <view class="page_item_cont">
            <view class="page_item_cont_T">
              <view class="page_item_cont_title">
                <text> <text class="starting">起</text> 点科室 </text>
                <text class="text_big">{{ infoDATA.startDept.dept }}</text>
              </view>
            </view>
            <view class="line"></view>
            <view class="page_item_cont_B">
              <template v-if="infoDATA.taskType.associationType.value == 'inspect'">
                <view class="page_item_cont_title" v-for="(dept, i) of infoDATA.middleDept" :key="i">
                  <text> <text class="End">检</text> 查科室 </text>
                  <text class="text_big">{{ dept.dept }}</text>
                  <view></view>
                </view>
              </template>
              <template v-if="infoDATA.taskType.associationType.value != 'inspect'">
                <view class="page_item_cont_title" v-for="(dept, i) of infoDATA.endDepts" :key="i">
                  <text> <text class="End">终</text> 点科室 </text>
                  <text class="text_big">{{ dept.dept }}</text>
                </view>
              </template>
            </view>
          </view>
          <view class="page_item_foot">
            <view class="page_item_foot_text">
              <text class="text1">状态</text>
              <text class="text2" v-if="
                  !(
                    infoDATA.gdState.value == '5' &&
                    infoDATA.taskType.associationType.value == 'inspect'
                  )
                ">{{ infoDATA.gdState.name }}</text>
              <text class="text2" v-if="
                  infoDATA.gdState.value == '5' &&
                  infoDATA.taskType.associationType.value == 'inspect'
                ">待送回</text>
            </view>
            <view class="page_item_foot_text" v-if="infoDATA.taskType.associationType.value == 'inspect'">
              <text class="text1">预约时间</text>
              <text class="text2">{{
                infoDATA.checkList &&
                infoDATA.checkList[0] &&
                infoDATA.checkList[0].yyTime
                  ? infoDATA.checkList[0].yyTime
                  : "-"
              }}</text>
            </view>
          </view>
        </view>
      </view>
      <!-- ------------------未完成工单 end----------------- -->
      <view class="title" v-if="workData && workData.length > 0">
        <text class="span1">工单信息</text>
      </view>
      <view class="page_items" v-if="!workData" style="font-size: 18px; margin-top: 15%">
        <view class="zwsj">
          <image class="zwsj_img" mode="widthFix" src="../../static/img/zanwushuju.png"></image>
          <view class="zwsj_txt">暂无工单</view>
        </view>
      </view>
      <view class="page_items" v-if="workData && workData.length > 0">
        <view class="page_item" v-for="(infoDATA, i) of workData" :key="i">
          <view class="page_item_top">
            <view class="page_item_top_L" @click="ac1(infoDATA, i, acType)">
              <text class="ac">
                <text :class="{ acSpan: idTYPE == infoDATA.id }"></text>
              </text>
              <text class="L_text">单号:{{ infoDATA.gdcode }}</text>
              <!-- emergencyType.value 1是正常,2是急,3是加急 -->
              <view class="page_item_cont_start emergency1" v-if="infoDATA.emergencyType.value == 1">
                <text>
                  <text class="cubeic-star newicon newicon-shiwujiaoxing"></text>
                  {{ infoDATA.emergencyType.name }}
                </text>
              </view>
              <view class="page_item_cont_start emergency" v-if="infoDATA.emergencyType.value == 2">
                <text>
                  <text class="cubeic-star newicon newicon-shiwujiaoxing"></text>
                  {{ infoDATA.emergencyType.name }}
                </text>
              </view>
              <view class="page_item_cont_start emergencys" v-if="infoDATA.emergencyType.value == 3">
                <text>
                  <text class="cubeic-star newicon newicon-shiwujiaoxing"></text>
                  {{ infoDATA.emergencyType.name }}
                </text>
              </view>
            </view>
            <view class="page_item_top_R">
              <text class="L_iocn" v-if="infoDATA.taskType.associationType.value == 'inspect'">患者陪检</text>
              <text class="L_iocn" v-if="
                  infoDATA.taskType.associationType.value == 'patientTransport'
                ">患者转运</text>
            </view>

            <view class="L"></view>
            <view class="R"></view>
          </view>
          <view class="page_item_cont">
            <view class="page_item_cont_T">
              <view class="page_item_cont_title">
                <text> <text class="starting">起</text> 点科室 </text>
                <text class="text_big">{{ infoDATA.startDept.dept }}</text>
              </view>
            </view>
            <view class="line"></view>
            <view class="page_item_cont_B">
              <template v-if="infoDATA.taskType.associationType.value == 'inspect'">
                <view class="page_item_cont_title" v-for="(dept, i) of infoDATA.middleDept" :key="i">
                  <text> <text class="End">检</text> 查科室 </text>
                  <text class="text_big">{{ dept.dept }}</text>
                  <view></view>
                </view>
              </template>
              <template v-if="infoDATA.taskType.associationType.value != 'inspect'">
                <view class="page_item_cont_title" v-for="(dept, i) of infoDATA.endDepts" :key="i">
                  <text> <text class="End">终</text> 点科室 </text>
                  <text class="text_big">{{ dept.dept }}</text>
                </view>
              </template>
            </view>
          </view>
          <view class="page_item_foot">
            <view class="page_item_foot_text">
              <text class="text1">状态</text>
              <text class="text2" v-if="
                  !(
                    infoDATA.gdState.value == '5' &&
                    infoDATA.taskType.associationType.value == 'inspect'
                  )
                ">{{ infoDATA.gdState.name }}</text>
              <text class="text2" v-if="
                  infoDATA.gdState.value == '5' &&
                  infoDATA.taskType.associationType.value == 'inspect'
                ">待送回</text>
            </view>
            <view class="page_item_foot_text" v-if="infoDATA.gdState.value == '2'">
              <text class="text1">预计响应时间</text>
              <text class="text2">{{ infoDATA.estimeResponseTime || '无' }}</text>
            </view>
            <view class="page_item_foot_text" v-if="infoDATA.gdState.value == '5'">
              <text class="text1" v-if="!(infoDATA.taskType.associationType.value == 'inspect')">预计送达时间</text>
              <text class="text1" v-if="infoDATA.taskType.associationType.value == 'inspect'">预计送回时间</text>
              <text class="text2">{{ infoDATA.estimeCompleteTime || '无' }}</text>
            </view>
            <view class="page_item_foot_text" v-if="infoDATA.gdState.value == '4'">
              <text class="text1">预计到达时间</text>
              <text class="text2">{{ infoDATA.estimateArriveTime || '无' }}</text>
            </view>
            <view class="page_item_foot_text">
              <text class="text1">创建时间</text>
              <text class="text2">{{ infoDATA.startTime || '无' }}</text>
            </view>
          </view>
        </view>
      </view>

      <view class="foot_btn1" v-if="infoDATA.residenceNo && batchCreationAndReturn == 1">
				<view class="btn3" @click="scanDept('all')">批量送回病房</view>
				<view class="btn3" @click="getInspectList()">查看检查</view>
      </view>
      <view class="foot_btn2" v-if="workData && workData.length > 0 && isShow">
        <view class="btn1" :class="(!infoDATA.residenceNo && addService==0)?'btn5':''" @click="getInspectAndPatientTransform(typeData)">一键操作</view>
				<view class="btn1" v-if="infoDATA.residenceNo" @click="scanDept()">送回病房</view>
				<view class="btn1" v-if="!infoDATA.residenceNo && addService==1" @click="additional()">追加服务</view>
        <view class="btn2" :class="(!infoDATA.residenceNo && addService==0)?'btn5':''" @click="showAlert">返回</view>
      </view>
      <view class="foot_btn2" v-if="workData && workData.length === 0 && isShow">
        <view class="btn3" v-if="infoDATA.residenceNo" @click="scanDept()">送回病房</view>
				<view class="btn3" v-if="!infoDATA.residenceNo && addService==1" @click="additional()">追加服务</view>
        <view class="btn3" :class="(!infoDATA.residenceNo && addService==0)?'btn4':''" @click="showAlert">返回</view>
      </view>
      <view class="foot_btn2" v-if="!isShow">
				<view class="btn3" v-if="infoDATA.residenceNo" @click="scanDept()">送回病房</view>
				<view class="btn3" v-if="!infoDATA.residenceNo && addService==1" @click="additional()">追加服务</view>
        <view class="btn3" :class="(!infoDATA.residenceNo && addService==0)?'btn4':''" @click="showAlert">返回</view>
      </view>
    </view>
    <showModel :title="models.title" :icon="models.icon" :disjunctor="models.disjunctor" :content="models.content"
      @know="know" :operate="models.operate"></showModel>
    <!-- 送回病房弹窗 -->
    <showModel :title="models1.title" :icon="models1.icon" :disjunctor="models1.disjunctor" :content="models1.content"
      :operate="models1.operate" @ok="ok1" @cancel="cancel1"></showModel>
    <!-- 送回病房建单弹窗 -->
    <showModel :title="models2.title" :icon="models2.icon" :disjunctor="models2.disjunctor" :content="models2.content"
      :operate="models2.operate" @ok="ok2" @cancel="cancel2"></showModel>
    <!-- 送回病房建单弹窗-扫描科室 -->
    <showModel :title="models3.title" :icon="models3.icon" :disjunctor="models3.disjunctor" :content="models3.content"
      :operate="models3.operate" @ok="ok3" @cancel="cancel3"></showModel>
    <!-- 弹窗 -->
    <showModel :title="models4.title" :icon="models4.icon" :disjunctor="models4.disjunctor"
      :radioInspectionDistanceItem="models4.radioInspectionDistanceItem" @ok="ok4" @cancel="cancel4"
      @radioChange="radioChange4" :operate="models4.operate">
    </showModel>
  </view>
</template>
<script>
  import showModel from "../../components/showModel/showModel.vue";
  import {
    get,
    post,
    SM,
    webHandle
  } from "../../http/http.js";
  export default {
    data() {
      return {
        isInspectAndPatientTransform: false, //是否是一键操作
        selectRadio: [], //单选框选中的数据，第一项是qrcode，第二项是名称
        // 单选框弹窗model1
        models4: {
          disjunctor: false,
        },
        currentCode: '', //当前小扫描的科室二维码
        SMFlag: true,
        options: {},
        // wechatFocusSwitch: 0,
        hosId: "",
        // 弹窗model
        models: {
          disjunctor: false,
        },
        // 送回病房弹窗model
        models1: {
          disjunctor: false,
        },
        // 送回病房建单弹窗model
        models2: {
          disjunctor: false,
        },
        // 送回病房建单弹窗model-扫描科室
        models3: {
          disjunctor: false,
        },
        infoDATA: {},
        workData: [],
        patientOrders: [],
        acType: Number,
        tabType: 1,
        idTYPE: "",
        userId: {
          ids: [],
        },
        typeData: null,
        types: false,
        code: "",
        animationData: {}, //动画
        isShow: true, //是否显示“一键操作”
        currentStartDept: {}, //扫描的起点科室
				addService:null, //是否开启允许追加服务
				batchCreationAndReturn:null //批量建立送回
      };
    },
    methods: {
      // 获取是否需要选择陪检方式
      getInspectAndPatientTransformSend() {
        let infoDATA = JSON.parse(this.options.infoDATA);
        const postData = {
          "idx": 0,
          "sum": 1,
          "taskTypeConfig": {
            "taskTypeDTO": {
              "hosId": {
                "id": this.hosId
              },
              "associationType": {
                "key": "association_types",
                "value": "inspect",
              },
            },
          },
        };
        uni.showLoading({
          mask: true,
          title: '加载中'
        })
        post("/simple/data/fetchDataList/taskTypeConfig", postData).then((res) => {
          console.log(res)
          if (res.status == 200) {
            res.list = res.list || [];
            if (res.list[0] && res.list[0].signTypeIds) {
              // 如果开启
              const postData = {
                "idx": 0,
                "sum": 9999,
                "workOrderInspectScore": {
                  "hosId": this.hosId,
                },
              };
              post("/simple/data/fetchDataList/workOrderInspectScore", postData).then((res) => {
                console.log(res)
                uni.hideLoading();
                if (res.status == 200) {
                  res.list = res.list || [];
                  let radioInspectionDistanceItem = res.list.map(v => ({
                    id: v.id + "__" + v.inspectMode,
                    inspectMode: v.inspectMode
                  }));
                  this.models4 = {
                    disjunctor: true,
                    title: "请选择陪检方式",
                    radioInspectionDistanceItem,
                    icon: "",
                    operate: {
                      ok: "确定",
                      cancel: "取消",
                    },
                  };
                } else {
                  uni.showToast({
                    icon: "none",
                    title: res.msg || "接口获取数据失败！",
                  });
                }
              })
            } else {
              this.ok3Result();
            }
          } else {
            uni.hideLoading();
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        })
      },
      // 获取是否需要选择陪检方式
      getInspectAndPatientTransform() {
        this.isInspectAndPatientTransform = true;
        console.log(this.typeData);
        if (this.typeData) {
          const postData = {
            "idx": 0,
            "sum": 1,
            "taskTypeConfig": {
              "taskTypeDTO": {
                "hosId": {
                  "id": this.hosId
                },
                "associationType": {
                  "key": "association_types",
                  "value": "inspect",
                },
              },
            },
          };
          uni.showLoading({
            mask: true,
            title: '加载中'
          })
          post("/simple/data/fetchDataList/taskTypeConfig", postData).then((res) => {
            console.log(res)
            if (res.status == 200) {
              res.list = res.list || [];
              if (res.list[0] && res.list[0].signTypeIds && this.typeData.gdState.value == 4) {
                // 如果开启并且工单状态是待到达
                const postData = {
                  "idx": 0,
                  "sum": 9999,
                  "workOrderInspectScore": {
                    "hosId": this.hosId,
                  },
                };
                post("/simple/data/fetchDataList/workOrderInspectScore", postData).then((res) => {
                  console.log(res)
                  uni.hideLoading();
                  if (res.status == 200) {
                    res.list = res.list || [];
                    let radioInspectionDistanceItem = res.list.map(v => ({
                      id: v.id + "__" + v.inspectMode,
                      inspectMode: v.inspectMode
                    }));
                    this.models4 = {
                      disjunctor: true,
                      title: "请选择陪检方式",
                      radioInspectionDistanceItem,
                      icon: "",
                      operate: {
                        ok: "确定",
                        cancel: "取消",
                      },
                    };
                  } else {
                    uni.showToast({
                      icon: "none",
                      title: res.msg || "接口获取数据失败！",
                    });
                  }
                })
              } else {
                this.allStart(this.typeData);
              }
            } else {
              uni.hideLoading();
              uni.showToast({
                icon: "none",
                title: res.msg || "接口获取数据失败！",
              });
            }
          })
        } else {
          this.models = {
            disjunctor: true,
            content: "请选择工单",
            icon: "warn",
            operate: {
              know: "返回",
            },
          };
        }
      },
      // 选中单选框
      radioChange4(item) {
        console.log(item);
        this.selectRadio = item.split("__");
      },
      // 确定
      ok4() {
        console.log(this.selectRadio);
        if (!this.selectRadio.length) {
          return;
        }
        this.models4.disjunctor = false;
        // 判断是一键操作还是送回病房
        if(this.isInspectAndPatientTransform){
          this.allStart(this.typeData);
        }else{
          this.ok3Result();
        }
      },
      cancel4() {
        this.models4.disjunctor = false;
      },
      ok2() {
        this.models2.disjunctor = false;
        this.getInspectAndPatientTransformSend();
      },
      cancel2() {
        this.models2.disjunctor = false;
      },
      ok3Result() {
        uni.showLoading({
          mask: true,
          title: '加载中'
        })
        let userId = uni.getStorageSync("userData").user.id;
        let postData = {
          "workOrder": [{
            sourceId: 4,
            "hosId": this.hosId,
            "startDept": {
              "id": this.options.id || this.currentStartDept.id
            },
            "createDept": this.options.id || this.currentStartDept.id,
            "patient": {
              "patientCode": this.infoDATA.patientCode
            },
            "worker": {
              "id": userId
            },
          }],
          "inspectMode": this.selectRadio.length > 0 ? this.selectRadio[0] : undefined,
        };
        post("/workerOrder/returnSickRoom", postData).then((res) => {
          console.log(res)
          uni.hideLoading();
          if (res.status == 200) {
            uni.showToast({
              icon: 'success',
              title: '建单成功',
            });
          } else {
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        })
      },
      ok3() {
        this.models3.disjunctor = false;
        this.getInspectAndPatientTransformSend();
      },
      cancel3() {
        this.models3.disjunctor = false;
      },
      // 送回病房-建单
      sendBuild() {
        let infoDATA = JSON.parse(this.options.infoDATA);
        this.models2 = {
          disjunctor: true,
          title: "提示",
          content: `您选择的起点科室为【${this.options.dept}】，您将从【${this.options.dept}】把【${infoDATA.patientName}】送回【${infoDATA.department.dept}】，如您确认请点击“确认建单”。`,
          icon: "warn",
          operate: {
            ok: "确认建单",
            cancel: "取消",
          },
        };
      },
			// 追加服务
			additional(){
			  uni.navigateTo({
			    url: `/pages/outpatient/outpatientEndTaskType/outpatientEndTaskType?model=${encodeURIComponent(JSON.stringify(this.infoDATA))}`,
			  });
			},
      // 送回病房-扫描科室
      scanDept(type = '') {
				if(type === 'all'){
				  // 批量送回
				  let infoDATA = JSON.parse(this.options.infoDATA);
				  uni.navigateTo({
				    url: `/pages/newSendBack/sendBackPatient/sendBackPatient?patientId=${infoDATA.id}&patientName=${infoDATA.patientName}&patientResidenceNo=${infoDATA.residenceNo}&patientCode=${infoDATA.patientCode}`,
				  });
					return;
				}
        this.isInspectAndPatientTransform = false;
        if (!this.SMFlag) {
          return;
        }
        this.SMFlag = false;
        let infoDATA = JSON.parse(this.options.infoDATA);
        let code = "";
        SM().then((ress1) => {
          uni.showLoading({
            title: "加载中",
            mask: true,
          });
          //检验二维码的有效性
          post("/dept/scanning", {
            content: ress1,
          }).then((result) => {
            this.SMFlag = true;
            if (result.state == 200 || result.state == 201) {
              let ress = result.code;
              if (ress) {
                code = ress;
                // 科室扫描
                let postData = {
                  "type": "query",
                  "qrCode": code,
                  "patientCode": infoDATA.patientCode,
                };
                post("/dept/scanChangeDept", postData).then((res) => {
                  uni.hideLoading();
                  if (res.status == 200) {
                    if (res.data) {
                      if(res.data.deptDTO){
                        this.currentStartDept = res.data.deptDTO;
                      }else{
                        this.currentStartDept = res.data;
                      }
                      this.models3 = {
                        disjunctor: true,
                        title: "提示",
                        content: `您选择的起点科室为【${this.currentStartDept.dept}】，您将从【${this.currentStartDept.dept}】把【${infoDATA.patientName}】送回【${infoDATA.department.dept}】，如您确认请点击“确认建单”。`,
                        icon: "warn",
                        operate: {
                          ok: "确认建单",
                          cancel: "取消",
                        },
                      };
                    } else {
                      uni.hideLoading();
                      uni.showToast({
                        icon: "none",
                        title: "请扫描正确的科室码！",
                      });
                    }
                  } else if(res.status == 400){
                    // 校验患者是否没有住院科室
                    uni.showToast({
                      icon: "none",
                      title: res.msg,
                    });
                  } else {
                    uni.hideLoading();
                    uni.showToast({
                      icon: "none",
                      title: res.msg || "接口获取数据失败！",
                    });
                  }
                });
              }
            } else {
              uni.hideLoading();
              uni.showToast({
                icon: "none",
                title: result.info || "接口获取数据失败！",
              });
            }
          });
        }).catch(err => {
          this.SMFlag = true;
        });
      },
      // 送回病房-选择起点科室
      sendBack() {
        let infoDATA = JSON.parse(this.options.infoDATA);
        this.models1 = {
          disjunctor: true,
          title: "提示",
          content: `您好，您是要将【${infoDATA.patientName}】送回病房吗？如确认请您点击“选择起点科室”建立工单。`,
          icon: "warn",
          operate: {
            ok: "选择起点科室",
            cancel: "取消",
          },
        };
      },
      ok1() {
        this.models1.disjunctor = false;
        uni.navigateTo({
          url: `../search/search?type=sendBack&code=${this.options.code}&infoDATA=${this.options.infoDATA}&patientOrders=${this.options.patientOrders}&workData=${this.options.workData}`,
        });
      },
      cancel1() {
        this.models1.disjunctor = false;
      },
      // 查看检查
      getInspectList() {
        // uni.navigateTo({
        //   url: `../inspectList/inspectList?id=${this.infoDATA.department.id}&dept=${this.infoDATA.department.dept}&patientCode=${this.infoDATA.patientCode}`,
        // });
        uni.navigateTo({
          url: `../patientInformationInfo/patientInformationInfo?patientCode=${this.infoDATA.patientCode}`,
        });
      },
      // 通知
      notice(info) {
        let postData = {
          wechatConfigType: "hsms",
          userIds: info.worker.id + "",
          content: `您负责护送的患者${info.patient.patientName}(${info.patient.bedNum})已经检查完毕，请尽快执行工单的下一步。`,
        };
        post("/wechat/sendCustomMessage", postData).then((res) => {
          if (res.status == 200) {
            uni.showToast({
              title: "通知成功",
              duration: 2000,
            });
          } else {
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        });
      },
      //需要帮助、无需帮助
      // help() {
      //   this.models = {
      //     disjunctor: true,
      //     title: "提示",
      //     content: this.infoDATA.focusPatient == 1 ?
      //       "如设置为“无需帮助”则后期此患者检查将不会自动进行建单，可通过“需要帮助”设置自动建单" : "如设置为“需要帮助”则后期此患者检查会自动进行建单，可通过“无需帮助”取消设置",
      //     icon: "warn",
      //     operate: {
      //       ok: "确定",
      //       cancel: "取消",
      //     },
      //   };
      // },
      //需要帮助，无需帮助确定
      // ok() {
      //   this.models.disjunctor = false;
      //   post("/nurse/updData/patient", {
      //     patient: {
      //       id: this.infoDATA.id,
      //       focusPatient: this.infoDATA.focusPatient == 1 ? 0 : 1,
      //     },
      //   }).then((res) => {
      //     let msg = "设置失败";
      //     let icon = "error";
      //     if (res.status == 200) {
      //       msg = "设置成功";
      //       icon = "success";
      //       this.infoDATA.focusPatient = res.data.focusPatient;
      //     }
      //     this.models = {
      //       disjunctor: true,
      //       content: msg,
      //       icon: icon,
      //       operate: {
      //         know: "返回",
      //       },
      //     };
      //   });
      // },
      //需要帮助，无需帮助取消
      // cancel() {
      //   this.models.disjunctor = false;
      // },
      //返回
      know() {
        this.models.disjunctor = false;
      },
      // 返回
      showAlert() {
        uni.navigateTo({
          url: "../receiptpage/receiptpage",
        });
      },
      //一键操作
      allStart(data) {
        console.log(data)
        let list = {};
        if (data) {
          let type = "";
          if (data.gdState.value == "8") {
            if (!this.SMFlag) {
              return;
            }
            this.SMFlag = false;
            SM().then((ress1) => {
              // ----------------
              uni.showLoading({
                title: "加载中",
                mask: true,
              });
              //检验二维码的有效性
              post("/dept/scanning", {
                content: ress1,
              }).then((result) => {
                this.SMFlag = true;
                this.currentCode = result.code;
                if (result.state == 200 || result.state == 201) {
                  let ress = result.code;
                  if (ress) {
                    var ids = [];
                    ids.push(data.id);
                    type = "orderSign/" + ress;
                    list = {
                      ids
                    };
                    // 科室签到
                    post("/workerOrder/" + type, list).then((res) => {
                      uni.hideLoading();
                      if (res.status == 200) {
                          // model: JSON.stringify(res), //签到返回的信息
                          // type: data.taskType.associationType.value, //关联类型
                          // code: ress, //二维码code
                          // ids //科室ID数组
                          uni.navigateTo({
                            url: `../scanning_djEnd/scanning_djEnd?type=${
                            data.taskType.associationType.value
                          }&code=${ress}&ids=${ids}&model=${encodeURIComponent(
                            JSON.stringify(res)
                          )}`,
                          });
                      } else {
                        uni.navigateTo({
                          url: `../scanning_djEnd/scanning_djEnd?model=${encodeURIComponent(
                          JSON.stringify(res)
                        )}&qrcode=${this.currentCode}`,
                        });
                      }
                    });
                  }
                } else {
                  uni.hideLoading();
                  uni.showToast({
                    icon: "none",
                    title: result.info || "接口获取数据失败！",
                  });
                }
              });
              // ------------------------------
            }).catch(err => {
              this.SMFlag = true;
            });
          } else {
            if (data.taskType.associationType.value == "patientTransport") {
              type = "handleTrans";
              let data = {
                ids: this.userId.ids,
                // "11789558|51131895|7|黄石城乡|陈琛|女|19981003|20180803081051|Z消化内科Ⅰ"
                code: this.code,
                inspectMode: this.selectRadio.length > 0 ? this.selectRadio[0] : undefined,
              };
              list = data;
            }
            if (data.taskType.associationType.value == "inspect") {
              type = "handleIns";
              let data = {
                ids: this.userId.ids,
                // "11789558|51131895|7|黄石城乡|陈琛|女|19981003|20180803081051|Z消化内科Ⅰ"
                code: this.code,
                inspectMode: this.selectRadio.length > 0 ? this.selectRadio[0] : undefined,
              };
              list = data;
            }
            uni.showLoading({
              title: "加载中",
              mask: true,
            });
            post("/workerOrder/" + type, list).then((res) => {
							console.log(1111,res)
              uni.hideLoading();
              if (res.status == 200) {
                if(data.gdState.value == 4 && data.taskType.associationType.value === 'patientTransport'){
                  // 门诊服务点
                  if(res.orderList){
                    uni.navigateTo({
                      url: `/pages/outpatient/outpatientStartSignIn/outpatientStartSignIn?model=${encodeURIComponent(JSON.stringify(res))}`,
                    });
                  }else{
                    uni.navigateTo({
                      url: `../scanning_insEnd/scanning_insEnd?type=${
                      data.taskType.associationType.value
                    }&model=${encodeURIComponent(JSON.stringify(res))}`,
                    });
                  }
                }else{
                  uni.navigateTo({
                    url: `../scanning_insEnd/scanning_insEnd?type=${
                    data.taskType.associationType.value
                  }&model=${encodeURIComponent(JSON.stringify(res))}`,
                  });
                }
              } else {
                uni.navigateTo({
                  url: `../scanning_insEnd/scanning_insEnd?model=${encodeURIComponent(
                  JSON.stringify(res)
                )}`,
                });
              }
            }).catch(err=>{
							console.log(9999,err)
						})
          }
        } else {
          this.models = {
            disjunctor: true,
            content: "请选择工单",
            icon: "warn",
            operate: {
              know: "返回",
            },
          };
        }
      },
      //选中
      ac(data, i, type) {
        this.idTYPE = "";
      },
      //未选中
      ac1(data, i, type) {
        if (this.idTYPE == data.id) {
          //显示
          this.isShow = true;
          this.idTYPE = "";
          this.userId.ids = [];
          this.typeData = null;
        } else {
          if (data.gdState.value >= 5) {
            //隐藏
            this.isShow = false;
          } else {
            //显示
            this.isShow = true;
          }
          this.idTYPE = data.id;
          this.typeData = data;
          this.userId.ids[0] = this.idTYPE;
        }
      },
      texiao() {
        if (this.workData && this.workData.length > 0) {
          setTimeout(() => {
            this.animation.height(0).opacity(0).step();
            this.animationData = this.animation.export();
          }, 15000);
        }
      },
      // 获取需要帮助权限
      // getWechatFocusSwitch() {
      //   let postData = {
      //     idx: 0,
      //     sum: 1,
      //     taskType: {
      //       hosIds: this.hosId,
      //       associationType: {
      //         id: 260,
      //       },
      //     },
      //   };
      //   post("/configuration/fetchDataList/taskType", postData).then((res) => {
      //     if (res.status == 200) {
      //       this.wechatFocusSwitch = res.list[0].wechatFocusSwitch || 0;
      //     } else {
      //       uni.showToast({
      //         icon: "none",
      //         title: res.msg || "接口获取数据失败！",
      //       });
      //     }
      //   });
      // },
			// 获取检查页面控制
			getTaskTypeConfig(){
			  uni.showLoading({
			    title: "加载中",
			    mask: true,
			  });
			  post("/simple/data/fetchDataList/taskTypeConfig", {
			      "idx": 0,
			      "sum": 10,
			      "taskTypeConfig": {
			          "taskTypeDTO": {
			              "hosId": {
			                  "id": this.hosId
			              },
			              "associationType": {
			                  "key": "association_types",
			                  "value": "inspect"
			              }
			          }
			      }
			  }).then((result) => {
			    uni.hideLoading();
			    if (result.status == 200) {
			      let configs = result.list || [];
			      if(configs.length){
			        this.addService = configs[0].addService;
			        this.batchCreationAndReturn = configs[0].batchCreationAndReturn;
			      }
			    } else {
			      uni.showToast({
			        icon: "none",
			        title: result.msg || "接口获取数据失败！",
			      });
			    }
			  });
			}
    },
    onLoad(options) {
      console.log(options);
      this.options = options;
      // 送回病房建单 start
      if (options.id && options.dept) {
        this.sendBuild();
      }
      // 送回病房建单 end
      this.hosId = uni.getStorageSync("userData").user.currentHospital.id;
      // this.getWechatFocusSwitch();
			this.getTaskTypeConfig()
      this.infoDATA = JSON.parse(options.infoDATA);
      console.log(this.infoDATA);
      this.workData = JSON.parse(options.workData);
      if (options.patientOrders != 'undefined') {
        this.patientOrders = JSON.parse(options.patientOrders);
      }
      this.code = options.code;

      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
    onShow() {
      this.SMFlag = true;
      // 创建动画
      this.animation = uni.createAnimation({
        duration: 500,
        timingFunction: "ease",
        delay: 2000,
      });
      setTimeout(() => {
        this.texiao();
      }, 500);
    },
    onHide() {
      this.animationData = {};
    },
    onUnload() {
      // 页面关闭后清空数据
      this.animationData = {};
    },
  };
</script>
<style lang="less">
  ::-webkit-scrollbar {
    width: 0px;
  }

  ::-webkit-scrollbar-track {
    background-color: none;
  }

  ::-webkit-scrollbar-thumb {
    background-color: none;
  }

  ::-webkit-scrollbar-thumb:hover {
    background-color: none;
  }

  ::-webkit-scrollbar-thumb:active {
    background-color: none;
  }

  .Scanning_ins {
    .title {
      font-size: 36rpx;
      margin-top: 20rpx;
      margin-bottom: 20rpx;
      font-weight: 700;
      position: relative;
      height: 40rpx;

      .span1 {
        position: absolute;
        left: 0;
        font-weight: 700;
      }

      .span2 {
        position: absolute;
        right: 20%;
        color: rgb(73, 184, 86);
      }

      .span3 {
        position: absolute;
        right: 0;
        color: rgb(73, 184, 86);
      }
    }

    .Scanning {
      padding: 0 20rpx;

      .Scanning_top {
        // height: 500rpx;

        .Scanning_top_icon {
          width: 140rpx;
          height: 140rpx;
          margin: 0 auto;
          margin-top: 36rpx;
          border-radius: 50%;
          line-height: 140rpx;

          .cubeic-ok {
            font-size: 140rpx;
            color: #35b34a;
          }
        }

        .Scanning_top_text {
          .text1 {
            margin-top: 30rpx;
            font-size: 48rpx;
            text-align: center;
          }

          .success_tips {
            color: red;
            font-size: 30rpx;
          }
        }

        .Scanning_cont {
          font-size: 32rpx;
          margin-top: 16rpx;

          view {
            margin-bottom: 8rpx;
            display: flex;
            justify-content: center;
            align-items: center;

            button {
              font-size: 32rpx;
              height: 52rpx;
              line-height: 52rpx;
              margin: 0;
              color: rgb(7, 134, 60);
              font-weight: 700;
            }
          }

          .text {
            margin-top: 24rpx;
            color: #35b34a;
          }

          .text1 {
            margin-top: 24rpx;
            color: #ff3b53;
          }
        }
      }

      .page_items {
        padding-bottom: 200rpx;

        .zwsj {
          margin-top: 180rpx;
          display: flex;
          flex-direction: column;
          align-items: center;

          .zwsj_txt {
            font-size: 36rpx;
            font-weight: 700;
            margin-top: 20rpx;
          }

          .zwsj_img {
            width: 582rpx;
          }
        }

        .page_item {
          margin-top: 16rpx;
          min-height: 310rpx;
          background: #fff;
          border-radius: 8rpx;
          overflow: hidden;
          padding: 0 16rpx;
          border: 2rpx solid #e5e9ed;

          .L {
            width: 40rpx;
            height: 40rpx;
            border-radius: 50%;
            background: #f9fafb;
            position: relative;
            left: -50rpx;
            top: 66rpx;
          }

          .R {
            width: 40rpx;
            height: 40rpx;
            border-radius: 50%;
            background: #f9fafb;
            position: relative;
            float: right;
            right: -50rpx;
            top: 26rpx;
          }

          .starting {
            width: 50rpx;
            height: 50rpx;
            color: #fff;
            background: #49b856;
            display: inline-block;
            border-radius: 50%;
            text-align: center;
            line-height: 46rpx;
            font-size: 32rpx;
            margin-right: 6rpx;
          }

          .End {
            width: 50rpx;
            height: 50rpx;
            color: #fff;
            background: #39b199;
            display: inline-block;
            border-radius: 50%;
            text-align: center;
            line-height: 46rpx;
            font-size: 32rpx;
            margin-right: 6rpx;
          }

          .page_item_top {
            height: 86rpx;
            border-bottom: 2rpx dashed #e5e9ed;
            padding: 0 16rpx;

            .page_item_top_L {
              height: 100%;
              float: left;
              line-height: 88rpx;
              display: flex;
              align-items: center;

              .ac {
                width: 32rpx;
                height: 32rpx;
                border: 2rpx solid #ccc;
                display: flex;
                justify-content: center;
                align-items: center;
                position: relative;

                .acSpan {
                  width: 24rpx;
                  height: 24rpx;
                  background: #39b199;
                  display: block;
                }
              }

              .ac1 {
                width: 32rpx;
                height: 32rpx;
                border: 2rpx solid #ccc;
                display: inline-block;
                position: relative;
              }

              .emergencys {
                background: #ff3b53 !important;
                width: 124rpx !important;
              }

              .emergency {
                background: #ff3b53 !important;
              }

              .emergency1 {
                background: #49b856 !important;
              }

              .page_item_cont_start {
                text-align: center;
                height: 44rpx;
                width: 104rpx;
                line-height: 44rpx;
                border-radius: 8rpx;
                background: #49b856;
                color: #fff;
                display: inline-block;
                font-size: 28rpx;
              }

              .L_time {
                color: #6cc076;
                font-size: 32rpx;
              }

              .L_text {
                font-size: 32rpx;
                display: inline-block;
                font-weight: 700;
              }
            }

            .page_item_top_R {
              height: 60rpx;
              float: right;
              padding-top: 20rpx;
              font-size: 32rpx;
              position: absolute;
              right: 50rpx;

              .L_iocn {
                display: inline-block;
                height: 52rpx;
                line-height: 48rpx;
                color: rgb(7, 134, 60);
                font-size: 36rpx;
                font-weight: 700;
              }
            }
          }

          .page_item_cont {
            min-height: 180rpx;
            max-height: 424rpx;
            padding: 0 16rpx;
            text-align: left;
            position: relative;

            .text_big {
              font-size: 32rpx;
              position: absolute;
              right: 16rpx;
              font-weight: 700;
              margin-top: 10rpx;
            }

            .text_big2 {
              font-size: 32rpx;
              position: absolute;
              right: 16rpx;
              font-weight: 700;
            }

            .line {
              height: 20rpx;
              width: 2rpx;
              border-left: 2rpx solid #e5e9ed;
              position: absolute;
              top: 82rpx;
              left: 40rpx;
            }

            .lines {
              height: 40%;
              width: 2rpx;
              border-left: 2rpx solid #e5e9ed;
              position: absolute;
              top: 23%;
              left: 36rpx;
            }

            .page_item_cont_T {
              padding-top: 28rpx;
              font-size: 28rpx;

              .page_item_cont_title {
                height: 100%;
                font-size: 32rpx;
              }
            }

            .page_item_cont_B {
              padding-top: 28rpx;
              margin-bottom: 28rpx;

              .page_item_cont_title {
                height: 60rpx;
                font-size: 32rpx;
              }

              .page_item_cont_title1 {
                height: 60rpx;
                line-height: 60rpx;
                font-size: 32rpx;
                padding-left: 64rpx;
              }
            }
          }

          .page_item_foot {
            border-top: 2rpx dashed #e5e9ed;
            border-bottom: 2rpx dashed #e5e9ed;
            padding: 28rpx 16rpx;
            text-align: left;

            .page_item_foot_text {
              height: 48rpx;
              font-size: 32rpx;
              line-height: 48rpx;
              margin-bottom: 20rpx;

              .text1 {
                color: rgb(102, 102, 102);
              }

              .text2 {
                float: right;
                font-weight: 700;
              }
            }
          }

          #infos {
            display: none;
          }

          .page_item_infos {
            padding-bottom: 20rpx;
            border-bottom: 2rpx dashed #e5e9ed;

            .page_item_info2 {
              text-align: left;
              line-height: 60rpx;
              font-size: 32rpx;
              padding-left: 16rpx;

              .page_item_foot_text {
                height: 48rpx;
                font-size: 32rpx;
                line-height: 48rpx;
                margin-bottom: 20rpx;

                .text1 {
                  color: rgb(102, 102, 102);
                }

                .text2 {
                  float: right;
                  font-weight: 700;
                }
              }
            }
          }
        }
      }

      .foot_btn1 {
        position: fixed;
        bottom: 84rpx;
        right: 20rpx;
        left: 20rpx;
        line-height: 66rpx;
        height: 100rpx;
        border-top: 2rpx solid #e5e9ed;
        background: #f9fafb;
        display: flex;
        justify-content: space-between;

        .btn1,
        .btn2,
        .btn3,
        .btn4,
        .btn5 {
          height: 66rpx;
          flex: 1;
          background-image: linear-gradient(to right, #72c172, #3bb197);
          color: #fff;
          border-radius: 8rpx;
          font-size: 32rpx;
          margin: 16rpx 1% 0;
          text-align: center;
        }
      }
      .foot_btn2 {
        position: fixed;
        bottom: 0;
        right: 20rpx;
        left: 20rpx;
        line-height: 66rpx;
        height: 100rpx;
        background: #f9fafb;
        display: flex;
        justify-content: space-between;

        .btn1,
        .btn2,
        .btn3,
        .btn4,
        .btn5 {
          height: 66rpx;
          flex: 1;
          background-image: linear-gradient(to right, #72c172, #3bb197);
          color: #fff;
          border-radius: 8rpx;
          font-size: 32rpx;
          margin: 16rpx 1% 0;
          text-align: center;
        }
      }
    }
  }
</style>
