<template>
  <view class="pharmacyDetails">
    <view class="pharmacyDetails_title">
      <view class="pharmacyDetails_tab" :class="{ 'active': selectedLabelSlots === item.id }" v-for="item in tabs"
        :key="item.id" @click="clickHandler(item.id)">
        <view class="pharmacyDetails_label">
          {{ item.label }}
        </view>
      </view>
    </view>
    <view class="page_item_wrap">
      <view class="page_item">
        <view class="page_item_top">
          <view class="page_item_top-inner" v-show="selectedLabelSlots == 1">
            <view class="page_item_top_L">
              <text class="L_text">请领单：{{ infoDATA.packid }}</text>
            </view>
            <view class="page_item_top_R">
              <text class="L_iocn">{{
                infoDATA.drugsState && infoDATA.drugsState.name
              }}</text>
            </view>
          </view>
        </view>
        <view class="page_item_cont" v-show="selectedLabelSlots == 1">
          <view class="page_item_cont_B">
            <view class="page_item_cont_title">
              <text>记账时间</text>
              <text class="text_big">
                <text>{{ infoDATA.creatTime }}</text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>请领科室</text>
              <text class="text_big">
                <text>{{ infoDATA.target && infoDATA.target.dept }}</text>
              </text>
            </view>
          </view>
        </view>
        <scroll-view scroll-y class="page_item_cont" v-show="selectedLabelSlots == 2">
          <view class="page_item_cont_C" v-for="(item,i) in queryProcessList" :key="i">
            <view class="page_item_cont_title_C">
              <text style="width: 5em;">{{item.operationTime}}</text>
              <text style="flex: 1;">{{item.operationType?item.operationType.name:''}}</text>
              <view class="text_big" style="text-align: center;max-width: 10em;flex: 1;">
                <text>{{ item.username || '暂无' }}</text>
                <view v-if="item.operatorAccount" style="white-space: nowrap;text-overflow: ellipsis;overflow: hidden;">({{ item.operatorAccount }})</view>
              </view>
            </view>
          </view>
        </scroll-view>
        <view class="L"></view>
        <view class="R"></view>
      </view>
      <view class="L-l"></view>
      <view class="R-l"></view>
    </view>
    <button class="cube-toolbar-item" @click="goto()">
      返回
    </button>
  </view>
</template>
<script>
  import {
    get,
    post,
    SM,
    webHandle
  } from "../../http/http.js";
  export default {
    data() {
      return {
        selectedLabelSlots: 2,
        tabs: [{
            id: 1,
            label: "基础信息",
          },
          {
            id: 2,
            label: "流程信息",
          }
        ],
        infoDATA: [],
        isLoading: false,
        isTLoading: false,
        isOLoading: false,
        loginUser: {}, //当前登录用户
        queryProcessList: [],
      };
    },
    methods: {
      // 返回
      goto() {
        uni.navigateBack();
      },
      // tab切换
      clickHandler(id) {
        this.selectedLabelSlots = id;
        if (id == 1) {
          this.queryBase(this.queryObj);
        } else if (id == 2) {
          this.queryProcess(this.queryObj);
        }
      },
      //基础信息查询
      queryBase(options) {
        //扫码进入详情
        let qrcode = options.qrcode;
        if (qrcode) {
          uni.showLoading({
            title: "加载中",
            mask: true,
          });
          post("/drugsBag/getDrugsBagByQr", {
            qrcode,
          }).then((result) => {
            uni.hideLoading();
            if (result.state == 200) {
              this.infoDATA = result.result;
              if (this.loginUser.dept.id != this.infoDATA.launch.id) {
                uni.showModal({
                  title: '提示',
                  content: "您现在所在的科室是【" + this.loginUser.dept.dept + "】,药包所在的科室是【" + this.infoDATA.launch.dept +
                    "】,您不能进行操作",
                  showCancel: false,
                  success: function(res) {
                    if (res.confirm) {
                      console.log('用户点击确定');
                    } else if (res.cancel) {
                      console.log('用户点击取消');
                    }
                  }
                });
              }
            } else {
              uni.showToast({
                icon: "none",
                title: "请求失败！",
              });
            }
          });
        }
        // 点击列表进入详情
        let id = options.id;
        if (id) {
          uni.showLoading({
            title: "加载中",
            mask: true,
          });
          get("/api/fetchData/drugsBag/" + id).then((res) => {
            uni.hideLoading();
            if (res.status == 200) {
              this.infoDATA = res.data;
              if (this.loginUser.dept.id != this.infoDATA.launch.id) {
                uni.showModal({
                  title: '提示',
                  content: "您现在所在的科室是【" + this.loginUser.dept.dept + "】,药包所在的科室是【" + this.infoDATA.launch.dept +
                    "】,您不能进行操作",
                  showCancel: false,
                  success: function(res) {
                    if (res.confirm) {
                      console.log('用户点击确定');
                    } else if (res.cancel) {
                      console.log('用户点击取消');
                    }
                  }
                });
              }
            } else {
              uni.showToast({
                icon: "none",
                title: "请求失败！",
              });
            }
          });
        }
      },
      // 流程信息查询
      queryProcess(options) {
        //扫码进入详情
        let qrcode = options.qrcode;
        if (qrcode) {
          uni.showLoading({
            title: "加载中",
            mask: true,
          });
          let postData = {
            idx: 0,
            sum: 9999,
            drugsBagOperationLog: {
              qrcode,
              hosId: this.loginUser.currentHospital.id
            }
          }
          post("/simple/data/fetchDataList/drugsBagOperationLog", postData).then((result) => {
            uni.hideLoading();
            if (result.status == 200) {
              result.list.forEach(v => {
                if (v.operationTime) {
                  v.operationTime = (new Date(v.operationTime)).Format("MM-dd hh:mm:ss");
                }
              });
              this.queryProcessList = result.list;
            } else {
              uni.showToast({
                icon: "none",
                title: "请求失败！",
              });
            }
          });
        }
        // 点击列表进入详情
        let packid = options.packid;
        if (packid) {
          uni.showLoading({
            title: "加载中",
            mask: true,
          });
          let postData = {
            idx: 0,
            sum: 9999,
            drugsBagOperationLog: {
              drugsBagId: options.id,
              hosId: this.loginUser.currentHospital.id
            }
          }
          post("/simple/data/fetchDataList/drugsBagOperationLog", postData).then((res) => {
            uni.hideLoading();
            if (res.status == 200) {
              res.list.forEach(v => {
                if (v.operationTime) {
                  v.operationTime = (new Date(v.operationTime)).Format("MM-dd hh:mm:ss");
                }
              });
              this.queryProcessList = res.list;
            } else {
              uni.showToast({
                icon: "none",
                title: "请求失败！",
              });
            }
          });
        }
      }
    },
    onLoad(options) {
      this.loginUser = uni.getStorageSync("userData").user;
      console.log(this.loginUser, 'loginUserloginUser')
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
      this.queryObj = options;
      this.queryProcess(this.queryObj);
    },
  };
</script>
<style lang="less">
  .pharmacyDetails {
    background-color: rgb(249, 250, 251);
    padding-top: 32rpx;

    .pharmacyDetails_title {
      height: 100rpx;
      display: flex;
      align-items: center;
      background-color: #fff;

      .pharmacyDetails_tab {
        flex: 1;
        display: flex;
        align-items: center;

        .pharmacyDetails_label {
          display: flex;
          justify-content: center;
          align-items: center;
          font-size: 40rpx;
          width: 100%;
          height: 66rpx;
          border-radius: 32rpx;
          color: #666;
        }

        &.active {
          .pharmacyDetails_label {
            color: #333;
            background-color: #e5e9ed;
          }
        }
      }
    }

    .page_item_wrap {
      position: relative;
      margin-top: 32rpx;

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

        .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 {
              .L_text {
                font-size: 32rpx;
                font-weight: 700;
              }
            }

            .page_item_top_R {
              font-size: 32rpx;

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

        .page_item_cont {
          box-sizing: border-box;
          min-height: 180rpx;
          max-height: calc(100vh - 534rpx);
          padding: 0 16rpx;
          text-align: left;
          position: relative;

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

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

          .line {
            height: 20rpx;
            width: 2rpx;
            border-left: 2rpx solid #e5e9ed;
            position: absolute;
            top: 82rpx;
            left: 40rpx;
          }

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

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

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

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

          .page_item_cont_C {
            margin-top: 14rpx;
            margin-bottom: 14rpx;

            .page_item_cont_title_C {
              font-size: 32rpx;
              display: flex;
              justify-content: space-between;
              align-items: center;
            }
          }

          #infos {
            display: none;
          }
        }
      }

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

    .cube-toolbar-item {
      width: 710rpx;
      height: 68rpx;
      line-height: 68rpx;
      position: fixed;
      left: 20rpx;
      bottom: 160rpx;
      border-radius: 8rpx;
      background: linear-gradient(to right, #72c172, #3bb197);
      font-size: 36rpx;
      color: #fff;
      text-align: center;
    }

    .btn-wrap {
      width: 100%;
      display: flex;
      justify-content: space-between;
      position: fixed;
      left: 0;
      bottom: 160rpx;
    }

    .cube-toolbar-item1 {
      flex: 1;
      height: 68rpx;
      line-height: 68rpx;
      border-radius: 8rpx;
      margin: 0 1%;
      background: linear-gradient(to right, #72c172, #3bb197);
      font-size: 36rpx;
      color: #fff;
      text-align: center;
    }
  }
</style>
