<template>
  <view class="checkNumberPage">
    <view class="title">请填写本次您送达的标本数量！</view>
    <view class="page_item_wrap">
      <view class="changeSpeNum__article">
        <view class="uni-list-cell">
          <view class="uni-list-cell-left">
            标本数量：
          </view>
          <view class="uni-list-cell-db">
            <uni-number-box v-model="speNum"></uni-number-box>
          </view>
        </view>
        <view class="uni-list-cell" v-if="speNum != num">
          <view class="uni-list-cell-left">
            上传图片：
          </view>
          <view class="uni-list-cell-db">
            <uni-file-picker :auto-upload="false" :limit="3" title="最多选择3张图片" v-model="imageValue" fileMediatype="image"
              mode="grid" @select="selectFile" @delete="deleteFile"></uni-file-picker>
          </view>
        </view>
      </view>
    </view>
    <view class="foot_btn2">
      <view class="btn2" @click="createOrder">确认数量</view>
      <view class="btn2" @click="goto()">查看标本</view>
    </view>
  </view>
</template>
<script>
  import {
    get,
    post,
    webHandle
  } from "../../http/http.js";
  export default {
    data() {
      return {
        options: {},
        imageValue: [], //图片列表
        speNum: 0, //修改后的数量
        num: 0,
        reason: undefined, //修改原因
        msg: {}, //页面展示信息
      };
    },
    methods: {
      // 获取上传状态
      selectFile(e) {
        console.log('选择文件：', e)
        this.imageValue = this.imageValue.concat(e.tempFiles);
      },

      // 移除
      deleteFile(e) {
        console.log('移除：', e);
        this.imageValue = this.imageValue.filter(v => v.uuid != e.tempFile.uuid);
      },
      // 获取信息
      getInfo() {
        uni.showLoading({
          mask: true,
          title: '加载中'
        })
        let postData = {
          deptId: this.options.deptId,
          gdId: this.msg.id
        };
        post(`/api/getStartDeptSpecimensNum`, postData).then((res) => {
          uni.hideLoading();
          if (res.status == 200) {
            this.speNum = res.deptSpecimensNum;
          } else {
            uni.showToast({
              icon: "none",
              title: "请求失败！",
            });
          }
        });
      },
      // 查看标本
      goto() {
        uni.navigateTo({
          url: `../../pages/checkNumberDetail/checkNumberDetail?startDeptId=${this.msg.startDept.id}&deptId=${this.options.deptId}`,
        });
      },
      // 确认数量并建单
      createOrder() {
        uni.showModal({
          title: '提示',
          content: "您确认建单吗？",
          success: (res) => {
            if (res.confirm) {
              console.log('用户点击确定');
              uni.showLoading({
                mask: true,
                title: '加载中'
              })
              get(`/workerOrder/createQuickOrder/${this.msg.id}`, {}).then((res) => {
                console.log(res)
                uni.hideLoading();
                if (res.status == 200) {
                  if (res.type === 'plan-spe-ddd-2') {
                    //需要扫描标本
                    uni.navigateTo({
                      url: `../../pages/scanning_code/scanning_code?type=${res.associationTypeName}&type1=${res.type}&id=${res.id}&deptCode=${res.deptCode}&dept=${res.deptName}&accountObj=undefined`,
                    });
                  } else {
                    uni.navigateTo({
                      url: "../receiptpage/receiptpage",
                    });
                  }
                } else {
                  uni.showToast({
                    icon: "none",
                    title: "请求失败！",
                  });
                }
              });
            } else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        });
      },
    },
    onLoad(options) {
      console.log(options, "快捷建单");
      this.options = options;
      this.msg = JSON.parse(options.infoDATA);
      this.getInfo();
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less" scoped>
  .checkNumberPage {
    padding-bottom: 100rpx;

    .title {
      font-size: 48rpx;
      margin-top: 24rpx;
      margin-bottom: 24rpx;
      text-align: center;
    }

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

      .uni-list-cell {
        width: 94%;
        display: flex;
        flex-direction: row;
        justify-content: space-evenly;
        align-items: center;
        text-align: center;
        margin-top: 32rpx;

        .uni-list-cell-left {
          flex: 2;
          font-size: 32rpx;
          color: #666;
        }

        .uni-list-cell-db {
          padding: 16rpx 0;
          flex: 5;
        }

        .uni-list-cell-db-text {
          border: 1px solid #e5e9ed;
          background-color: #fff;
          flex: 5;
          text-align: left;

          textarea {
            width: 100%;
            box-sizing: border-box;
            padding: 0 8rpx;
            max-height: 150rpx;
          }
        }
      }
    }

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