<template>
  <view class="pharmacyDetails">
    <view class="pharmacyDetails_title">请领信息</view>
    <view class="page_item_wrap">
      <view class="page_item">
        <view class="page_item_top">
          <view class="page_item_top-inner">
            <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">
          <view class="page_item_cont_T">
            <view class="page_item_cont_title">
              <text>批次号</text>
              <text class="text_big">{{ infoDATA.batchNo }}</text>
            </view>
          </view>
          <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>
        <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"
      :loading="isLoading"
      :disabled="isLoading"
      @click="dispensing(1)"
      v-if="infoDATA.drugsState && infoDATA.drugsState.name == '待配药'"
    >
      开始配药
    </button>
    <button
      class="cube-toolbar-item"
      :loading="isLoading"
      :disabled="isLoading"
      @click="dispensing(2)"
      v-if="infoDATA.drugsState && infoDATA.drugsState.name == '配药中'"
    >
      完成配药
    </button>
  </view>
</template>
<script>
import { get, post, SM, webHandle } from "../../http/http.js";
export default {
  data() {
    return {
      infoDATA: [],
      isLoading: false,
    };
  },
  methods: {
    // 开始配药,完成配药,,,1是待配药,2是配药中
    dispensing(type) {
      this.isLoading = true;
      if (type == 1) {
        post("/drugsBag/changeToIng", {
          id: this.infoDATA.id,
        }).then((result) => {
          if (result.state == 200) {
            let data = {
              launchId: this.infoDATA.launch.id,
              drugsBagId: this.infoDATA.id,
            };
            post("/drugsBag/autoDrugsBags", data).then((result1) => {
              this.isLoading = false;
              if (result1.status == 200) {
                uni.showToast({
                  title: "操作成功！",
                  success() {
                    // setTimeout(() => {
                    uni.navigateTo({
                      url: "../pharmacy/pharmacy",
                    });
                    // }, 3000)
                  },
                });
              }else if(result1.status == 501){
                uni.showToast({
                  icon: "none",
                  title: result1.error,
                });
              }else {
                uni.showToast({
                  icon: "none",
                  title: "请求失败！",
                });
              }
            });
          } else {
            this.isLoading = false;
            uni.showToast({
              icon: "none",
              title: "请求失败！",
            });
          }
        });
      } else if (type == 2) {
        post("/drugsBag/changeToCheck", {
          id: this.infoDATA.id,
        }).then((result) => {
          this.isLoading = false;
          if (result.state == 200) {
            uni.showToast({
              title: "操作成功！",
              success() {
                // setTimeout(() => {
                uni.navigateTo({
                  url: "../pharmacy/pharmacy",
                });
                // }, 3000)
              },
            });
          } else {
            uni.showToast({
              icon: "none",
              title: "请求失败！",
            });
          }
        });
      }
    },
  },
  onLoad(options) {
    // #ifdef APP-PLUS
    webHandle("no", "app");
    // #endif
    // #ifdef H5
    webHandle("no", "wx");
    // #endif
    //扫码进入详情
    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;
        } 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;
        } else {
          uni.showToast({
            icon: "none",
            title: "请求失败！",
          });
        }
      });
    }
  },
};
</script>
<style lang="less">
.pharmacyDetails {
  background-color: rgb(249, 250, 251);
  padding-top: 10%;

  .pharmacyDetails_title {
    font-size: 46rpx;
    font-weight: 550;
    text-align: center;
  }

  .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 {
        min-height: 180rpx;
        max-height: 424rpx;
        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-bottom: 28rpx;

          .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: 32rpx;
    border-radius: 8rpx;
    background: linear-gradient(to right, #72c172, #3bb197);
    font-size: 36rpx;
    color: #fff;
    text-align: center;
  }
}
</style>
