<template>
  <view class="Scanning_Result">
    <view class="Scanning_cont">
      <scroll-view scroll-y class="scrollContent">
        <view class="column" v-for="item in drugsBagList" :key="item.id" @click="toDetail(item.id)">
          <view class="head">
            <view class="name">{{item.packid}}</view>
            <view class="value">{{item.drugsState ? item.drugsState.name : ''}}</view>
          </view>
          <view class="body">
            <view class="bodyColumn" v-if="queryObj.showPatientInfo==1">
              <view class="name">姓名：{{item.patientNames ? item.patientNames : ''}}</view>
            </view>
						<view class="bodyColumn" v-if="config.showDrugsBagTypeCount == 1">
						  <view class="name">种类数：{{item.drugsTypeCount}}</view>
						  <view class="value">总数：{{item.drugsCount}}</view>
						</view>
            <view class="bodyColumn">
              <view class="name">收取人：<template v-if="item.startLog">{{item.startLog.username}}</template></view>
              <view class="value">收取时间：<template v-if="item.startLog">{{item.startLog.operationTime | formatDate('yyyy-MM-dd hh:mm')}}</template></view>
            </view>
            <view class="bodyColumn">
              <view class="name">送达人：<template v-if="item.endLog">{{item.endLog.username}}</template></view>
              <view class="value">送达时间：<template v-if="item.endLog">{{item.endLog.operationTime | formatDate('yyyy-MM-dd hh:mm')}}</template></view>
            </view>
            <view class="bodyColumn">
              <view class="name">收取交接人：<template v-if="item.startLog">{{item.startLog.handoverName}}</template></view>
              <view class="name">送达交接人：<template v-if="item.endLog">{{item.endLog.handoverName}}</template></view>
            </view>
          </view>
        </view>
      </scroll-view>
    </view>
    <view class="foot_btn_spe">
      <view class="column">
        <view class="btn" @click="goBack()">返回</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,
        drugsBagList: [], //药包列表
        queryObj: {}, //路由传递过来的数据
        workOrder: {}, //工单信息
        config: {}, //配置
      };
    },
    methods: {
      // 返回
      goBack(){
        uni.navigateBack()
      },
      // 详情
      toDetail(drugsBagId){
        if(this.config.showDrugsBagDetails != 1){
          return;
        }
        uni.navigateTo({
          url: `/pages/newDrug/detail?drugsBagType=${this.queryObj.drugsBagType}&drugsBagId=${drugsBagId}&showPatientInfo=${this.queryObj.showPatientInfo}`,
        });
      },
      //获取页面信息
      getInfo(){
        uni.showLoading({
          title: "加载中",
          mask: true,
        });

        let info$ = post(`/transflow/extra`, {type: this.queryObj.drugsBagType, extraType: 'orderInfo', orderId: +this.queryObj.orderId});
        let config$ = post(`/simple/data/fetchDataList/taskTypeConfig`, {
            "idx": 0,
            "sum": 1,
            "taskTypeConfig": {
                "taskTypeDTO": {
                    "hosId": {
                        "id": this.hosId
                    },
                    "ordinaryField": {
                        "key": "ordinary_field",
                        "value": this.queryObj.drugsBagType
                    }
                }
            }
        });

        Promise.all([info$, config$]).then(result => {
          uni.hideLoading();
          let [info, config] = result || [];

          if(info.state == 200){
            if(info.data){
              this.drugsBagList = info.data.drugsBagList || [];
              this.workOrder = info.data.workOrder || {};
            }
          }else{
            uni.showToast({
              icon: "none",
              title: info.msg || "接口获取数据失败！",
            });
          }

          if(config.status == 200){
            let list  = config.list || [];
            this.config = list.length ? list[0] : {};
          }else{
            uni.showToast({
              icon: "none",
              title: config.msg || "接口获取数据失败！",
            });
          }
        })
      },
    },
    onLoad(options) {
      console.log(options, "options");
      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 {
    background: #F7F7F7;
    display: flex;
    flex-direction: column;
    height: 100vh;

    .Scanning_top {
      margin: 32rpx auto;
      .Scanning_top_icon {
        font-size: 30rpx;
        font-weight: bold;
        .newicon{
          margin: 0 32rpx;
        }
      }
    }
    .Scanning_top_tips{
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 28rpx;
      margin-bottom: 32rpx;
      gap: 64rpx;
    }

    .Scanning_cont {
      flex: 1;
      min-height: 0;
      display: flex;
      flex-direction: column;
      .scrollContent{
        flex: 1;
        min-height: 0;
        overflow: hidden;
      }
      .column{
        background: #FFFFFF;
        font-size: 24rpx;
        margin-bottom: 16rpx;
        .head{
          padding: 24rpx;
          display: flex;
          justify-content: space-between;
          align-content: center;
          border-bottom: 1rpx solid #D2D2D2;
          font-weight: bold;
        }
        .body{
          padding: 24rpx;
          .bodyColumn{
            display: flex;
            justify-content: space-between;
            align-content: center;
            margin-top: 24rpx;
            &:first-of-type{
              margin-top: 0;
            }
            .value{
              text-align: left;
            }
          }
        }
      }
    }

    .foot_btn_spe {
      padding: 0 24rpx;
      margin: 24rpx 0;
      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>
