<template>
  <view class="Scanning_Result">
    <view class="Scanning_top">
      <view class="Scanning_top_icon">
        <text class="cubeic-ok newicon newicon-duigou"></text>
        <view class="text1"> 签到成功 </view>
      </view>
      <view class="Scanning_top_text">
        您已到达{{queryObj.deptName}}，请确认以下信息
      </view>
    </view>

    <view class="Scanning_cont">
      <view class="Scanning_cont_head">
        <view class="Scanning_cont_head_item" :class="{active: parentIndex == i}" v-for="(item, i) in tabNames" :key="item.id" @click="tabClick(i)">
          {{item.name}}
        </view>
      </view>

      <view class="Scanning_cont_list">
        <view class="Scanning_cont_list_item Scanning_cont_list_head">
          <view class="name">
            {{parentIndex === 0 ? '科室名称' : '类型名称'}}<text class="red">({{nameTotal}})</text>
          </view>
          <view class="value">
            <view>
              袋数<text class="red">({{countTotal}})</text>
            </view>
          </view>
          <view class="value">
            <view>
              重量<text class="red">({{weightTotal}})</text>
            </view>
          </view>
        </view>
        <scroll-view scroll-y="true" class="Scanning_cont_list_scroll" v-if="dataList[parentIndex]">
          <view class="Scanning_cont_list_item" @click="clickRow(item, parentIndex === 0 ? 'dept' : 'waste')" v-for="(item, j) in dataList[parentIndex]" :key="j">
            <view class="name">
              {{item.name}}
            </view>
            <view class="value">
              <view>
                {{item.wasteCount}}
              </view>
            </view>
            <view class="value">
              <view>
                {{item.wasteWeight}}
              </view>
            </view>
          </view>
        </scroll-view>
      </view>
    </view>

    <view class="foot_btn">
      <view class="btn" @click="goBack()"> 取消 </view>
      <view class="btn" @click="onClick()" v-if="gdIds"> 确认交接 </view>
    </view>
    <!-- 弹窗 -->
    <showModel :title="models1.title" :icon="models1.icon" :disjunctor="models1.disjunctor" :content="models1.content"
      @ok="ok1" @cancel="cancel1" :operate="models1.operate"></showModel>
  </view>
</template>
<script>
  import {
    get,
    post,
    SM,
    webHandle
  } from "../../../http/http.js";
  import Big from 'big.js';
  export default {
    data() {
      return {
        gdIds: '',
        tabNames: [
          {id: -1, name: '科室交接'},
          {id: -2, name: '医废类型交接'},
        ],
        SMFlag: true,
        hosId: uni.getStorageSync('userData').user.currentHospital.id,
        queryObj: {}, //路由传递过来的数据
        dataList: [[],[]],
        parentIndex: 0,
        nameTotal: 0,
        countTotal: 0,
        weightTotal: 0,
        // 弹窗model
        models1: {
          disjunctor: false,
        },
      };
    },
    methods: {
      //确定
      ok1() {
        this.models1.disjunctor = false;
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        post("/medicalWaste/complete", {
          endDeptId: +this.queryObj.deptId,
          gdIds: this.gdIds,
          hosId: this.hosId,
        }).then((res) => {
          uni.hideLoading();
          if (res.status == 200) {
            uni.showModal({
              title: "提示",
              content: "操作成功",
              showCancel: false,
              success: (result) => {
                if (result.confirm) {
                  console.log("用户点击确定");
                  uni.navigateTo({
                    url: `/pages/receiptpage/receiptpage`,
                  });
                }
              },
            });
          }else{
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        });
      },
      //取消
      cancel1() {
        this.models1.disjunctor = false;
      },
      // 被服回收弹窗
      showModel1() {
        this.models1 = {
          disjunctor: true,
          title: "提示",
          content: `您确认交接吗？`,
          icon: "warn",
          operate: {
            ok: "确定",
            cancel: "取消",
          },
        };
      },
      tabClick(i){
        this.parentIndex = i;
        this.nameTotal = this.dataList[i].length;
        this.countTotal = this.dataList[i].reduce((pre, cur) => Big(pre).plus(cur.wasteCount), 0);
        this.weightTotal = this.dataList[i].reduce((pre, cur) => Big(pre).plus(cur.wasteWeight), 0);
      },
      goBack(){
        uni.navigateBack();
      },
      onClick(){
        this.showModel1();
      },
      clickRow(data, type){
        uni.navigateTo({
          url: `/pages/medicalWaste/medicalWasteSignInList/medicalWasteSignInList?id=${data.id}&type=${type}`,
        });
      },
      getInfo(){
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        post("/medicalWaste/complete", {
          code: this.queryObj.code,
          hosId: this.hosId,
        }).then((result) => {
          uni.hideLoading();
          if (result.status == 200) {
            this.$set(this.dataList,'0',result.deptData || []);
            this.$set(this.dataList,'1',result.wasteTypeData || []);
            this.gdIds = result.gdIds;

            this.nameTotal = this.dataList[this.parentIndex].length;
            this.countTotal = this.dataList[this.parentIndex].reduce((pre, cur) => Big(pre).plus(cur.wasteCount), 0);
            this.weightTotal = this.dataList[this.parentIndex].reduce((pre, cur) => Big(pre).plus(cur.wasteWeight), 0);
          } else {
            uni.showToast({
              icon: "none",
              title: result.msg || "接口获取数据失败！",
            });
          }
        });
      },
    },
    onLoad(options) {
      console.log(options, "result");
      this.queryObj = options;
      this.getInfo();
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less" scoped>
  .Scanning_Result {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #fafbfd;
    .Scanning_top {
      flex-shrink: 0;
      .Scanning_top_icon {
        padding-top: 26rpx;
        display: flex;
        justify-content: center;
        align-items: center;

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

        .text1 {
          font-size: 48rpx;
          font-weight: bold;
        }
      }
      .Scanning_top_text{
        text-align: center;
        font-size: 28rpx;
        font-weight: bold;
        padding: 8rpx 0 23rpx 0;
      }
    }

    .Scanning_cont {
      flex: 1;
      min-height: 0;
      display: flex;
      flex-direction: column;
      width: 710rpx;
      margin: 0 20rpx;
      background-color: #fff;

      .Scanning_cont_head{
        flex-shrink: 0;
        height: 78rpx;
        display: flex;
        border-top: 1rpx solid #EEEEEE;
        border-bottom: 1rpx solid #EEEEEE;
        .Scanning_cont_head_item{
          flex: 1;
          font-size: 32rpx;
          font-weight: bold;
          display: flex;
          justify-content: center;
          align-items: center;
          position: relative;
          &.active{
            color: #49B856;
            &::before{
              content: '';
              width: 70rpx;
              height: 10rpx;
              background-color: #49B856;
              position: absolute;
              left: 50%;
              bottom: 8rpx;
              transform: translateX(-50%);
              border-radius: 6rpx;
            }
          }
          &::after{
            content: '';
            width: 2rpx;
            height: 44rpx;
            background-color: #D1D1D1;
            position: absolute;
            right: 0;
            top: 50%;
            transform: translateY(-50%);
          }
          &:last-of-type::after{
            opacity: 0;
          }
        }
      }

      .Scanning_cont_list{
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        .Scanning_cont_list_scroll{
          flex: 1;
          min-height: 0;
        }
        .Scanning_cont_list_item{
          height: 70rpx;
          display: flex;
          align-items: center;
          font-size: 28rpx;
          border-bottom: 1rpx solid #ccc;
          &.Scanning_cont_list_head{
            font-weight: bold;
            font-size: 28rpx;
            border-bottom: none;
            flex-shrink: 0;
          }
          .name,
          .value{
            padding: 0 10rpx;
            flex: 1;
            text-align: center;
            line-height: 70rpx;
            height: 100%;
            // border-right: 1rpx solid #272727;
            .red{
              color: red;
            }
          }
          .value {
            view{
              // width: 4em;
              text-align: center;
            }
          }
        }
      }
    }

    .foot_btn {
      margin: 57rpx 20rpx 10rpx;
      flex-shrink: 0;
      display: flex;
      justify-content: center;

      .btn {
        height: 88rpx;
        line-height: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        flex: 1;
        margin-right: 32rpx;
        background-image: linear-gradient(to right, #72c172, #3bb197);
        color: #fff;
        border-radius: 8rpx;
        font-size: 34rpx;
        font-weight: bold;
        &:last-of-type{
          margin-right: 0;
        }
      }
    }
  }
</style>
