<template>
  <view class="specimenCheckingDetail">
    <view class="page_tab">
      <view class="page_tab_bar active">
        <picker class="more_picker" @change="execFilter($event)" :value="index" :range="array" range-key="nameNum">
          <view class="more_picker_text">{{ array[index].name }}<text class="tab_num">( {{ array[index].total }} )</text></view>
          <view class="more"></view>
        </picker>
      </view>
    </view>
    <view class="zwsj" v-if="list.length == 0">
      <image class="zwsj-img" mode="widthFix" src="../../static/img/zanwushuju.png"></image>
      <view class="zwsj-txt">暂无数据</view>
    </view>
    <view class="page_item_wrap" v-for="item in list" :key="item.id">
      <view class="page_item">
        <view class="page_item_top">
          <view class="page_item_top-inner">
            <view class="page_item_top_L">
              <view class="L_text">{{ item.scode }}<text v-if="item.stype">({{item.stype.name}})</text></view>
            </view>
            <view class="page_item_top_R">
              <text :style="{color:item.urgent == 1?'red':'green'}">{{item.urgent == 1 ? "急" : "普"}}</text>
            </view>
          </view>
        </view>
        <view class="page_item_cont">
          <view class="page_item_cont_T">
            <view class="page_item_cont_title">
              <view> 检验项目 </view>
              <view class="text_big">{{ item.specimenDesc || "无" }}</view>
            </view>
            <view class="page_item_cont_title">
              <view> 患者姓名 </view>
              <view class="text_big">{{ item.patientName }}<text v-if="item.bedNum">({{item.bedNum}})</text></view>
            </view>
            <view class="page_item_cont_title">
              <view> 住院号 </view>
              <view class="text_big">{{item.residenceNo||'无'}}</text></view>
            </view>
            <view class="page_item_cont_title">
              <view> 收取人 </view>
              <view class="text_big">{{item.receiverName||'无'}}</text></view>
            </view>
            <view class="page_item_cont_title">
              <view> 收取时间 </view>
              <view class="text_big">{{item.arriveTime||'无'}}</text></view>
            </view>
            <view class="page_item_cont_title">
              <view class="text_big">{{
                item.sickRoom ? item.sickRoom.dept : "无"
              }}</view>
              <text style="width: 4em;text-align: center;" class="icon_transport transport-arrow-right-full"></text>
              <view class="text_big">{{
                item.checkDept ? item.checkDept.dept : "无"
              }}</view>
            </view>
          </view>
        </view>
        <view class="L"></view>
        <view class="R"></view>
      </view>
      <view class="L-l"></view>
      <view class="R-l"></view>
    </view>
    <view class="foot_btn2">
      <view class="btn2" @click="goto()">返回</view>
    </view>
  </view>
</template>
<script>
  import {
    get,
    post,
    webHandle
  } from "../../http/http.js";
  export default {
    data() {
      return {
        id: 0,
        index: 0,
        arrayKey: 0,
        array: [
          { id: 0, name: '全部', total: '', nameNum: ''}
        ],
        
        idx: 0,
        workOrderId: 0,
        associationTypeValue: '',
        list: [],
      };
    },
    methods: {
      // 筛选
      execFilter({
        detail: {
          value
        }
      }) {
        this.index = value;
        this.arrayKey = this.array[value].id;
        this.getList();
      },
      // 获取标本类型
      // getSpecimenType(){
      //   let array = [{ id: 0, name: '全部'}];
      //   post(`/common/common/getDictionary`, {"type":"list","key":"specimen_type"}).then((res) => {
      //     this.array = array.concat(res) || array;
      //   });
      // },
      // 获取检验项目
      getSpecimenDesc(){
        post(`/api/specimenDesc/specimenCount`, {
          "hosId": uni.getStorageSync('userData').user.currentHospital.id,
          "gdId": this.workOrderId,
          }).then((res) => {
          res.data = res.data || [];
          let array = [{ id: 0, name: '全部', total: '', nameNum: ''}];
          array[0].total = res.total;
          array[0].nameNum = `全部(${res.total})`;
          this.array = array.concat(res.data.map( v=> ({id: --this.id, name: v[0] || '', nameNum: `${v[0] || ''}(${v[1]})`, total: v[1]})));
        });
      },
      // 获取标本列表
      getList(isAccumulate = false) {
        uni.showLoading({
          mask: true,
          title: "加载中",
        });
        let postData = {
          "idx": isAccumulate ? ++this.idx : 0,
          "sum": 20,
          "specimen": {
            "gdid": this.workOrderId,
            "hosId": uni.getStorageSync('userData').user.currentHospital.id,
            // "stype": this.array[this.index].id ? { id: this.array[this.index].id } : undefined,
            "specimenDesc": this.array[this.index].id ? this.array[this.index].name : undefined,
            "orderBy": 'arrive_time desc',
          }
        };
        post(`/simple/data/fetchDataList/specimen`, postData).then((res) => {
          uni.hideLoading();
          uni.stopPullDownRefresh();
          if (res.status == 200) {
            if(isAccumulate){
               this.list = this.list.concat(res.list);
               if(!res.list.length){
                 uni.showToast({
                   icon: 'none',
                   title: '没有更多数据了',
                 })
               }
            }else{
              this.list = res.list;
            }
          } else {
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败!",
            });
          }
        });
      },
      // 返回
      goto() {
        uni.navigateBack();
      },
    },
    onLoad(options) {
      console.log(options, "标本详情");
      this.workOrderId = options.workOrderId;
      this.associationTypeValue = options.associationTypeValue;
      this.getList();
      this.getSpecimenDesc();
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
    onPullDownRefresh() {
      this.getList();
    },
    // 上拉加载
    onReachBottom(){
      console.log('到底了');
      this.getList(true);
    }
  };
</script>
<style lang="less" scoped>
  .specimenCheckingDetail {
    padding-top: 96rpx;
    padding-bottom: 100rpx;
    
    .page_tab {
      width: 100%;
      height: 96rpx;
      display: flex;
      position: fixed;
      left: 0;
      top: 0;
      z-index: 999;
      
      .more {
        position: absolute;
        right: 20rpx;
        width: 40rpx;
        height: 4rpx;
        border-top: 2px solid #49b856;
        border-bottom: 2px solid #49b856;
        background-color: #49b856;
        padding: 5px 0;
        background-clip: content-box;
        z-index: 9999;
        top: 50%;
        transform: translateY(-50%);
      }
      
      .more_picker {
        position: absolute;
        right: 0;
        width: 100%;
        height: 100%;
        z-index: 9999;
        
        .more_picker_text{
          height: 100%;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    
      .page_tab_bar {
        flex: 1;
        font-size: 36rpx;
        background: #fff;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
    
        &:after {
          content: "";
          position: absolute;
          left: 0;
          bottom: 0;
          height: 2rpx;
          width: 100%;
          background-color: transparent;
        }
    
        .tab_num {
          color: #ff3b53;
          margin-left: 8rpx;
        }
    
        &.active {
          color: #49b856;
    
          &:after {
            background-color: #49b856;
          }
        }
      }
    }

    .page_header {
      margin: 20rpx;
      padding: 16rpx;
      border: 2rpx solid #e5e9ed;
      background: #fff;
      border-radius: 8rpx;

      .page_header_item {
        margin-bottom: 16rpx;

        .page_header_title {
          margin-bottom: 8rpx;
          font-weight: bold;
        }

        .page_header_content {
          display: flex;

          image {
            height: 100rpx;
            width: 30%;
            margin: 0 8rpx;
          }
        }
      }
    }
    
    .zwsj {
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    
      .zwsj-img {
        width: 560rpx;
      }
    
      .zwsj-txt {
        font-size: 36rpx;
        font-weight: 700;
        margin-top: 20rpx;
        text-align: center;
      }
    }

    .page_item_wrap {
      width: 100%;
      height: auto;
      box-sizing: border-box;
      position: relative;
      margin-bottom: 16rpx;

      .page_item {
        margin-top: 16rpx;
        margin-bottom: 124rpx;
        background: #fff;
        border-radius: 8rpx;
        margin: 0 20rpx;
        border: 2rpx solid #e5e9ed;
        position: relative;
        overflow: hidden;
        padding: 0 16rpx;

        .L {
          width: 40rpx;
          height: 40rpx;
          border-radius: 50%;
          background: #f9fafb;
          position: absolute;
          left: -20rpx;
          top: 68rpx;
          border: 2rpx solid #e5e9ed;
        }

        .R {
          width: 40rpx;
          height: 40rpx;
          border-radius: 50%;
          background: #f9fafb;
          position: absolute;
          float: right;
          right: -20rpx;
          top: 68rpx;
          border: 2rpx solid #e5e9ed;
        }

        .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: 88rpx;
          border-bottom: 2rpx dashed #e5e9ed;
          padding: 0 16rpx;

          .page_item_top-inner {
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 100%;

            .page_item_top_L {
              .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;
              }

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

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

            .page_item_top_R {
              font-size: 32rpx;

              .back {
                background-color: #49b856;
              }

              .L_iocn {
                color: rgb(7, 134, 60);
                font-size: 36rpx;
                font-weight: 700;
              }
            }
          }
        }

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

          .text_big {
            font-size: 32rpx;
            font-weight: 700;
            margin-top: 10rpx;

            p {
              font-weight: 700;
              line-height: 1.5;
            }
          }

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

            .page_item_cont_title {
              height: 100%;
              font-size: 32rpx;
              display: flex;
              justify-content: space-between;
              align-items: center;
            }
          }

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

            .page_item_cont_title {
              font-size: 32rpx;
              display: flex;
              justify-content: space-between;
            }

            .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 {
            font-size: 32rpx;
            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 {
              font-size: 32rpx;
              margin-bottom: 20rpx;

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

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

      .L-l {
        width: 2rpx;
        height: 40rpx;
        background: #f9fafb;
        position: absolute;
        left: 20rpx;
        top: 72rpx;
      }

      .R-l {
        width: 2rpx;
        height: 40rpx;
        background: #f9fafb;
        position: absolute;
        right: 20rpx;
        top: 72rpx;
      }
    }

    .foot_btn2 {
      position: fixed;
      bottom: 0;
      width: 100vw;
      padding: 0 20rpx;
      box-sizing: border-box;
      line-height: 66rpx;
      height: 100rpx;
      border-top: 2rpx solid #e5e9ed;
      background: #f9fafb;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;

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