<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">
				<checkbox-group @change="checkboxChange">
        <view class="column" v-for="(item, index) in orderList" :key="item.id">
          <view class="top">
            <text class="">
							<checkbox :value="item.id" :checked="item.checked"/>
              <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>
				</checkbox-group>
      </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: {
			checkboxChange (e) {
				var items = this.orderList,
					values = e.detail.value;
				for (var i = 0, lenI = items.length; i < lenI; ++i) {
					const item = items[i]
					if(values.includes(item.id)){
						this.$set(item,'checked',true)
					}else{
						this.$set(item,'checked',false)
					}
				}
				console.log(8888,this.orderList)
			},
      goBack(){
        uni.navigateBack();
      },
      // 一键签到
      orderSignAll(){
				let isList = this.orderList.filter(i=>i.checked)
				if(isList.length==0){
					uni.showToast({
					  icon: 'error',
					  title: '请勾选工单',
					  duration: 2000,
					});
					return
				}
        uni.showModal({
          title: "提示",
          content: "您确定一键签到吗？",
          success: (res) => {
            if (res.confirm) {
              console.log("用户点击确定");
              uni.showLoading({
                mask: true,
                title: '加载中'
              })
              let postData = {
                "deptCode": this.queryObj.code,
                "ids": isList.map(v => v.id),
              };
              console.log(isList);
              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) {
						for(let i of res.data){
							i.checked = true
						}
            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{
					/deep/ .uni-checkbox-input.uni-checkbox-input-checked{
						 color: #fff !important;
						 background: #49b856 !important;
						 border-color: #49b856 !important;
					}
          .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>
