<template>
  <view class="Scanning_Result">
    <view class="Scanning_top">
      工单总数量：<text class="green">{{orderList.length}}</text>
    </view>

    <view class="Scanning_cont">
      <scroll-view scroll-y class="scrollContent">
        <view class="column" v-for="(item, index) in orderList" :key="item.id">
          <view class="top">
            <text class="">
              <text class="orders green">{{index + 1}}</text>
              <text class="gdcode">{{item.gdcode}}</text>
            </text>
            <text class="taskName">{{item.taskType.taskName}}</text>
          </view>
          <view class="bottom">
            <view class="name">备注：</view>
            <view class="value">{{item.workOrderRemark}}</view>
          </view>
          <view class="bottom">
            <view class="name">{{item.patient.patientName}}（{{item.patient.residenceNo}}）</view>
          </view>
        </view>
      </scroll-view>
    </view>

    <view class="foot_btn_spe">
      <view class="column">
        <view class="btn" @click="goBack()">取消</view>
        <view class="btn" @click="orderSignAll()" v-if="orderList.length">一键签到</view>
      </view>
    </view>
  </view>
</template>
<script>
  import {
    get,
    post,
    SM,
    webHandle
  } from "@/http/http.js";
  export default {
    data() {
      return {
        hosId: uni.getStorageSync("userData").user.currentHospital.id,
        orderList: [],//工单列表
        queryObj: {}, //路由传递过来的数据
      };
    },
    methods: {
      goBack(){
        uni.navigateBack();
      },
      // 一键签到
      orderSignAll(){
        uni.showModal({
          title: "提示",
          content: "您确定一键签到吗？",
          success: (res) => {
            if (res.confirm) {
              console.log("用户点击确定");
              uni.showLoading({
                mask: true,
                title: '加载中'
              })
              let postData = {
                "deptCode": this.queryObj.code,
                "ids": this.orderList.map(v => v.id),
              };
              console.log(this.orderList);
              post("/workerOrder/handleInsAndTrans", postData).then((res) => {
                console.log(res)
                uni.hideLoading();
                if (res.status == 200) {
                  uni.showToast({
                    icon: 'success',
                    title: '工单签到成功',
                    duration: 2000,
                    mask: true,
                  });
                  setTimeout(() => {
                    uni.navigateTo({
                      url: `/pages/receiptpage/receiptpage`,
                    });
                  }, 2000)
                } else {
                  uni.showToast({
                    icon: "none",
                    title: res.msg || "接口获取数据失败！",
                  });
                }
              })
            } else if (res.cancel) {
              console.log("用户点击取消");
            }
          },
        });
      },
      // 获取工单列表
      getOrderList(){
        uni.showLoading({
          mask: true,
          title: '加载中'
        })
        let postData = {
          "deptId": +this.queryObj.deptId,
        };

        post("/workerOrder/patientIntelligentScan", postData).then((res) => {
          console.log(res)
          uni.hideLoading();
          if (res.status == 200) {
            this.orderList = res.data || [];
          } else {
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        })
      }
    },
    onLoad(options) {
      console.log(options, "options");
      this.queryObj = options;
      this.getOrderList();
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less" scoped>
  .green{
    color:#49b856;
  }
  .Scanning_Result {
    background: #EBEBEB;
    display: flex;
    flex-direction: column;
    height: 100vh;

    .Scanning_top {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 63rpx;
      font-size: 28rpx;
      font-weight: bold;
      background-color: #fff;
      margin-top: 16rpx;
    }

    .Scanning_cont {
      flex: 1;
      min-height: 0;
      display: flex;
      flex-direction: column;
      .scrollContent{
        flex: 1;
        min-height: 0;
      }
      .column{
        padding: 24rpx;
        font-size: 26rpx;
        margin-top: 16rpx;
        background-color: #fff;
        .top,.bottom{
          display: flex;
          align-items: center;
          .name{
            flex-shrink: 0;
          }
          .value{
            word-break: break-all;
          }
        }
        .top{
          .orders{
            font-size: 28rpx;
            font-weight: bold;
            margin-right: 24rpx;
          }
          .gdcode{
            font-weight: bold;
          }
          .taskName{
            flex: 1;
            text-align: right;
          }
        }
        .bottom{
          margin-top: 16rpx;
        }
      }
    }

    .foot_btn_spe {
      padding: 24rpx;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 24rpx;
      font-weight: bold;

      .column{
        width: 100%;
        height: 78rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 24rpx;

        .btn {
          height: 100%;
          flex: 1;
          background: linear-gradient( 90deg, #6FC073 0%, #3DB197 100%);
          color: #fff;
          border-radius: 4rpx;
          font-size: 30rpx;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
  }
</style>
