<template>
  <view class="HomeItem">
    <view class="goWorkAll">
			<view class="title">{{optData.deptName}}-{{optData.handoverType.name}}</view>
			<view class="goWorkSelect history">
			  <view class="goWorkSelect-head">总数量：{{optData.totalNum}}</view>
			  <view class="goWorkSelect-list" v-for="(item, i) in optData.data">
					{{item.deptName}}: {{item.num}}
				</view>
			</view>
    </view>
    <view class="foot_btn_spe">
      <view class="btn1" @click="submit()">{{optData.handoverType.value==1 ? '确认中转' : '确认交接'}}</view>
      <view class="btn3" @click="goBack">取消</view>
    </view>
    <!-- 填写交接人工号弹窗 -->
    <selectAccount v-if="hosModels.disjunctor" :disjunctor="hosModels.disjunctor" @ok="hosOk"
      @cancel="hosCancel">
    </selectAccount>
		
		<!-- 中转 -->
		<uni-popup ref="alertDialog" type="dialog" :mask-click="false">
			<uni-popup-dialog type="info" cancelText="取消" confirmText="确定" title="提示" content="您确认中转吗？" @confirm="dialogConfirm"
				@close="dialogClose"></uni-popup-dialog>
		</uni-popup>
  </view>
</template>

<script>
  import * as commonFun from '../../tools/commonFun.js';
  import {
    pathUrl
  } from "../../tools/photograph.js";
  import selectAccount from "../../components/selectAccount/selectAccount.vue";
  import {
    get,
    post,
    webHandle
  } from "../../http/http.js";
  export default {
    components: {
      selectAccount,
    },
    data() {
      return {
				list:[],
				optData:null,
        tips: '',
        currentIndex: undefined,
        // 填写交接人工号弹窗model
        hosModels: {
          disjunctor: false,
        },
        currentCode: '', //当前拍照使用的科室二维码
        currentData: {}, //当前小扫描的工单对象
        orderId: undefined,
        order: {},
				digitalNum:null,
				// 数字交接
				digitalHandoverSwitch: false,
        // 拍照动作开关
        actionPhotoSwitch: false,
        // 确认动作开关
        actionConfirmSwitch: false,
        // 确认动作模式开关
        actionConfirmType: false,
        // 参数
        options: {},
        //动作列表
        actions: [],
        //图片列表
        imageValue: [],
      };
    },
    methods: {
      // 其他临床服务-运输过程-终点科室是否开通备注填写
      isOpenTransportationProcessRemarks(data, accountObj, funName){
        const tasktype = data.taskType;
        console.log(tasktype, data);
        if(tasktype.associationType.value === 'other' && tasktype.carryingCourses[this.currentIndex].logSwitch && data.gdState.value == 5){
          uni.navigateTo({
            url: `../../pages/transportationProcessRemarks/transportationProcessRemarks?data=${data ? encodeURIComponent(JSON.stringify(data)) : ''}&accountObj=${accountObj ? encodeURIComponent(JSON.stringify(accountObj)) : ''}&currentCode=${this.currentCode}&funName=${funName}&actions=${this.actions ? encodeURIComponent(JSON.stringify(this.actions)) : ''}&imageValue=${this.imageValue ? encodeURIComponent(JSON.stringify(this.imageValue)) : ''}`
          })
        }else{
          commonFun[funName](this, data, accountObj);
        }
      },
      // 填写交接人工号-确认
      hosOk(data) {
        console.log(data);
        const {
          accountName,
          account,
          accountId
        } = data;
        if (!accountName && !account) {
          //没有填写交接人
          uni.showModal({
            title: '提示',
            content: "请填写交接人工号！",
            showCancel: false,
            success: function(res) {
              if (res.confirm) {
                console.log('用户点击确定');
              } else if (res.cancel) {
                console.log('用户点击取消');
              }
            }
          });
          return;
        } else if (!accountName && account || accountName && !account) {
          //没有填写交接人
          uni.showModal({
            title: '提示',
            content: "请填写正确的交接人工号！",
            showCancel: false,
            success: function(res) {
              if (res.confirm) {
                console.log('用户点击确定');
              } else if (res.cancel) {
                console.log('用户点击取消');
              }
            }
          });
          return;
        }
				uni.showLoading({
				  title: "加载中",
				  mask: true,
				});
				let postData = {
					ids: this.optData.orderIds,
					handoverTypeValue: this.optData.handoverType.value,
					deptId: this.optData.deptId,
					handoverUserId: accountId
				}
        this.hosModels.disjunctor = false;
        post("/business/confirmHandover", postData).then((res) => {
					uni.hideLoading();
          if(res.status == 200){
            uni.showToast({
              icon: "none",
              title: "操作成功",
            });
            setTimeout(_=>{
            	uni.redirectTo({
            		url:'/pages/receiptpage/receiptpage'
            	})
            },1000)
          } else {
            uni.showToast({
              icon: "none",
              title: res.info || "接口获取数据失败！",
            });
          }
        });
      },
      // 填写交接人工号-取消
      hosCancel() {
        this.hosModels.disjunctor = false;
      },
      // 填写交接人工号弹窗
      showSelectAccount() {
        this.hosModels = {
          disjunctor: true,
        }
      },
			// 确定中转
			submit(){
				// 1:中转 2:终点
				if(this.optData.handoverType.value==1){
					this.$refs.alertDialog.open()
				}else{
					if(this.optData.taskType.carryingCourses[1].handoverSwitch){
						this.showSelectAccount();
					}else{
						this.$refs.alertDialog.open()
					}
				}
			},
			// 确定中转
			dialogConfirm(){
				uni.showLoading({
				  title: "加载中",
				  mask: true,
				});
				let url = null
				let postData = {
					ids: this.optData.orderIds,
					handoverTypeValue: this.optData.handoverType.value,
					deptId: this.optData.deptId
				}
				if(this.optData.handoverType.value==1){
					url = post("/business/confirmHandover", postData)
				}else{
					url = post("/business/confirmHandover", postData)
				}
				url.then((res) => {
				  if(res.status == 200){
						uni.hideLoading();
						this.$refs.alertDialog.close()
				    uni.showToast({
				      icon: "none",
				      title: "操作成功",
				    });
				    setTimeout(_=>{
				    	uni.redirectTo({
				    		url:'/pages/receiptpage/receiptpage'
				    	})
				    },1000)
				  } else {
            uni.showToast({
              icon: "none",
              title: res.info || "接口获取数据失败！",
            });
          }
				});
			},
			// 取消
			dialogClose(){
				this.$refs.alertDialog.close()
			},
      // 返回
      goBack() {
        uni.navigateBack();
      },
      // 选择动作
      checkboxChange: function (e) {
        let items = this.actions;
        let values = [];
        if(this.actionConfirmType == 1 || this.actionConfirmType == 2){
          values = e.detail.value || [];
        }else if(this.actionConfirmType == 3){
          values = [e.detail.value];
        }
        for (let i = 0, lenI = items.length; i < lenI; ++i) {
          const item = items[i]
          if(values.includes(item.value)){
            this.$set(item,'checked',true)
          }else{
            this.$set(item,'checked',false)
          }
        }
      },
      // 获取上传状态
      selectFile(e) {
        console.log('选择文件：', e)
        this.imageValue = this.imageValue.concat(e.tempFiles);
      },
      
      // 移除
      deleteFile(e) {
        console.log('移除：', e);
      },
    },
    onLoad(options) {
      this.options = options;
      if(options.data){
        this.optData = JSON.parse(options.data);
				console.log(this.optData);
      }
    },
  };
</script>

<style scoped>
	/deep/ .uni-button-color{
		color: #64BD7B;
	}
</style>
<style lang="less" scoped>
  .HomeItem {
    .foot_btn_spe {
      width: 100%;
      position: fixed;
      bottom: 30rpx;
      left: 0;
      line-height: 88rpx;
      height: 88rpx;
      text-align: center;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
    
      &::after {
        content: '';
        flex: 1;
      }
    
      view {
        height: 88rpx;
        width: 48%;
        margin: 0 1%;
        background-image: linear-gradient(to right, #72c172, #3bb197);
        color: #fff;
        border-radius: 8rpx;
        font-size: 32rpx;
        margin-top: 16rpx;
      }
    }

    .login {
      height: 420rpx;
      padding: 0 32rpx;
      padding-top: 164rpx;
      position: relative;
      z-index: 999;

      .savePassword {
        margin-top: 32rpx;
      }

      /deep/ uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
        border-color: #42b983 !important;
      }

      .login_input {
        margin-top: 32rpx;
        background-color: #ffffff;
        height: 72rpx;
        box-sizing: border-box;
        padding: 16rpx;
      }

      .title {
        font-size: 36rpx;
        color: #42b983;
        text-align: center;
      }

      .tips {
        font-size: 28rpx;
        color: red;
        margin-top: 16rpx;
      }

      .page_item_btn {
        height: 88rpx;
        background-image: linear-gradient(to right, #72c172, #3bb197);
        border-radius: 8rpx;
        line-height: 88rpx;
        color: #fff;
        font-size: 36rpx;
        font-weight: 700;
        margin-top: 64rpx;
        text-align: center;
      }
    }

    //上班页面
    .goWorkAll {
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      /deep/ .uni-radio-input-checked {
        background-color: #42b983 !important;
        border-color: #42b983 !important;
      }
      /deep/ .uni-checkbox-input-checked {
        color: #42b983 !important;
      }
			
			.title{
				text-align: center;
				color: #64BD7B;
				line-height: 80rpx;
				border-bottom: 1rpx solid #E5E5E5;
				position: absolute;
				top: 0;
				width: 100%;
				height: 80rpx;
				background: #fff;
			}
			
      .goWorkSelect {
        &.history {
          height: 81vh;
					overflow-y: auto;
					margin-top: 80rpx;
          padding-bottom: 16rpx;
        }

        &.combination {
          .goWorkSelect-head {}

          .goWorkSelect-list {}
        }

        .goWorkSelect-head {
          font-size: 28rpx;
          line-height: 80rpx;
          border-bottom: 2rpx solid #E5E5E5;
          text-align: center;
        }

        .goWorkSelect-list {
          padding: 16rpx;
					
					.input-num {
					  height: 60rpx;
					  border: 2rpx solid #E5E5E5;
					  border-radius: 5rpx;
					  // width: 100%;
					  padding-left: 10rpx;
					  // padding-right: 10rpx;
					}
					
          .goWorkSelect-item {
            height: 52rpx;
            display: flex;
            align-items: center;
            border-bottom: 2rpx solid #e5e9ed;
            padding: 16rpx;

            &.relative {
              position: relative;

              .picker {
                position: absolute;
                width: 100%;
                padding-left: 64rpx;
              }
            }

            button {
              font-size: 32rpx;
              height: 52rpx;
              line-height: 52rpx;
              margin: 0;
              margin-left: 16rpx;
              color: rgb(7, 134, 60);
              font-weight: 700;
            }
          }
        }
      }
    }

    .goWork {
      margin: 0 auto 48rpx;
      width: 240rpx;
      height: 240rpx;

      .goWork_btn_E {
        width: 100%;
        height: 100%;
        background: #bee1a7;
        border-radius: 30%;

        .goWork_btn_W {
          width: 75%;
          height: 75%;
          background-image: linear-gradient(to right, #72c172, #3bb197);
          border-radius: 30%;
          margin: 0 auto;
          position: relative;
          top: 12.5%;
          line-height: 180rpx;
          color: #fff;
          font-size: 36rpx;
          text-align: center;
        }
      }
    }

    .goWork_text {
      width: 100%;

      view {
        text-align: center;
      }

      .goWork_text-p {
        font-size: 36rpx;
        margin-bottom: 48rpx;
      }
    }

    .botImg {
      height: 600rpx;
      width: 100%;
      position: fixed;
      bottom: 0;

      .img {
        height: 100%;
        background: url("../../static/img/BG.png") no-repeat center center;
        background-size: 100% 100%;
      }
    }
  }
</style>
