<template>
  <view class="changeSpeNum" v-show="disjunctor">
    <view class="changeSpeNum__wrap">
      <view class="changeSpeNum__header" v-if="title">
        {{ title }}
      </view>
      <view class="changeSpeNum__article">
        <view class="tips" v-html="content" v-if="content"></view>
        <view class="tips-l" v-if="modifyReason">修改原因:{{modifyReason}}</view>
        <view class="uni-list-cell">
          <view class="uni-list-cell-left">
            标本数量:
          </view>
          <view class="uni-list-cell-db">
            <uni-number-box v-model="speNum" :max="9999"></uni-number-box>
          </view>
        </view>
        <view class="uni-list-cell" v-if="isFirstShowReason || (!isFirstShowReason && speNum != num)">
          <view class="uni-list-cell-left">
            修改原因:
          </view>
          <view class="uni-list-cell-db-text">
            <textarea placeholder="请填写修改原因" v-model="reason" />
          </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 class="changeSpeNum__footer">
        <view v-if="operate.ok" class="changeSpeNum__ok" @click="ok" hover-class="seimin-btn-hover">
          {{ operate.ok || "" }}
        </view>
        <view v-if="operate.check" class="changeSpeNum__ok" @click="check" hover-class="seimin-btn-hover">
          {{ operate.check || "" }}
        </view>
        <view v-if="operate.cancel" class="changeSpeNum__cancel" @click="cancel" hover-class="seimin-btn-hover">
          {{ operate.cancel || "" }}
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    post
  } from "../../http/http.js";
  export default {
    data() {
      return {
        imageValue: [], //图片列表
        speNum: 0, //修改后的数量
        reason: '标本\n单子\n其他', //修改原因
        loading: false,
        userData: null,
        hosId: null,
        timer: null,
      };
    },
    watch: {
      disjunctor(newValue) {
        if (newValue && this.operate.know == "知道了") {
          this.time = 5;
          this.timer = setInterval(() => {
            this.time--;
            if (this.time <= 0) {
              clearInterval(this.timer);
              this.know();
            }
          }, 1000);
        }
      },
    },
    props: {
      // 显示隐藏
      disjunctor: {
        type: Boolean,
        default: false,
      },
      // 标题
      title: {
        type: String,
        default: "提示",
      },
      // 提示
      content: {
        type: String,
        default: "",
      },
      // 操作按钮文字
      operate: {
        type: Object,
        default: () => {
          return {
            ok: "确认数量",
            check: "",
            cancel: "取消",
          };
        },
      },
      num: {
        type: Number,
        default: 0
      },
      modifyReason: {
        type: String,
        default: ''
      },
      isFirstShowReason: {
        type: Boolean,
        default: true
      },
    },
    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);
      },
      // 确定
      ok() {
        this.$emit("ok", {
          speNum: this.speNum,
          reason: this.reason,
          imageValue: this.imageValue,
        });
      },
      // 详细核对
      check() {
        this.$emit("check");
      },
      // 取消
      cancel() {
        this.$emit("cancel");
      },
    },
    created() {
      this.speNum = this.num;
      this.hosId = uni.getStorageSync('userData').user.currentHospital.id;
    }
  };
</script>

<style lang="less" scoped>
  .changeSpeNum {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.2);
    z-index: 999;

    .tips {
      text-align: center;
    }

    .tips-l {
      text-align: left;
      color: #000;
    }

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

    .changeSpeNum__wrap {
      width: 90vw;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      background-color: #fff;
      border-radius: 12rpx;
      color: #666;

      .changeSpeNum__header {
        font-size: 36rpx;
        color: #000;
        height: 84rpx;
        display: flex;
        justify-content: center;
        align-items: center;
      }

      .changeSpeNum__article {
        width: 90%;
        margin: 0 auto 25rpx;
        padding: 48rpx 0;
        background-color: rgb(249, 250, 251);
        border: 2rpx solid rgb(229, 233, 237);
        border-radius: 12rpx;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        &.p0 {
          padding: 0;
        }

        .changeSpeNum__icon {
          font-size: 138rpx;
          margin-bottom: 32rpx;

          &.changeSpeNum__icon--success {
            color: rgb(52, 179, 73);
          }

          &.changeSpeNum__icon--warn {
            color: rgb(245, 165, 35);
          }

          &.changeSpeNum__icon--error {
            color: rgb(255, 58, 82);
          }
        }

        .changeSpeNum__content {
          font-size: 36rpx;
        }

        .changeSpeNum__info {
          font-size: 32rpx;
          color: rgb(102, 102, 102);
        }

        .specialCloseFlag {
          width: 90%;
          height: 100%;
          padding: 16rpx;
        }

        .radio-wrap {
          .radio-item {
            margin-top: 16rpx;

            /deep/ .uni-radio-input-checked {
              background-color: #49b856 !important;
              border-color: #49b856 !important;
            }
          }
        }
      }

      .changeSpeNum__footer {
        box-sizing: border-box;
        height: 100rpx;
        border-top: 2rpx solid rgb(229, 233, 237);
        display: flex;
        align-items: center;

        view {
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 36rpx;
          color: rgb(102, 102, 102);
          position: relative;

          &::before {
            content: "";
            position: absolute;
            left: 0;
            bottom: 0;
            width: 2rpx;
            height: 87rpx;
            background-color: rgb(229, 233, 237);
          }

          &:first-of-type::before {
            display: none;
          }
        }

        .changeSpeNum__ok {
          flex: 1;
          color: rgb(73, 184, 86);
        }

        .changeSpeNum__cancel {
          flex: 1;
        }

        .changeSpeNum__know {
          flex: 1;
          color: rgb(73, 184, 86);
        }
      }
    }
  }
</style>