<template>
  <!-- 调拨审批 -->
  <view class="plan-approval-container">
    <uni-nav-bar
      fixed="true"
      statusBar="true"
      left-icon="back"
      title="调拨单审批详情"
      @clickLeft="back"
    ></uni-nav-bar>
    <template>
      <view class="tab-title">
        <view
          class="tab-item"
          :class="0 === pickTabIndex ? 'active' : ''"
          @click="changeChartsTab(0)"
          >基本信息
        </view>
        <view
          class="tab-item"
          :class="1 === pickTabIndex ? 'active' : ''"
          @click="changeChartsTab(1)"
        >
          调拨明细
        </view>
      </view>
    </template>
    <view class="content">
      <!-- 基本信息 -->
      <view class="baseinfo" v-if="pickTabIndex === 0">
        <view class="col">
          <text class="label">调拨单号</text>
          <text class="desc">{{ baseInfo.dialNumber }}</text>
        </view>
        <!-- <view class="col">
					<text class="label">来源类型</text>
					<text class="desc">{{ baseInfo.planName }}</text>
				</view> -->
        <view class="col">
          <text class="label">调拨类型</text>
          <text class="desc">{{ baseInfo.dialType }}</text>
        </view>
        <view class="col">
          <text class="label">调出库</text>
          <text class="desc">{{ baseInfo.warehouseName }}</text>
        </view>

        <view class="col">
          <text class="label">调入库</text>
          <text class="desc">{{ baseInfo.inWarehouseName }}</text>
        </view>

        <view class="col">
          <text class="label">调拨数量</text>
          <text class="desc">{{ planEquiList.length }}</text>
        </view>
        <view class="col">
          <text class="label">申请人</text>
          <text class="desc">{{ baseInfo.createUserName }}</text>
        </view>
        <view class="col">
          <text class="label">创建时间</text>
          <text class="desc">{{ baseInfo.createTime }}</text>
        </view>
        <view class="col">
          <text class="label">提交时间</text>
          <text class="desc">{{ baseInfo.submissionTime }}</text>
        </view>
        <view class="col">
          <text class="label">审核时间</text>
          <text class="desc">{{ baseInfo.auditorTime }}</text>
        </view>
        <view class="col">
          <text class="label">审核说明</text>
          <text class="desc">{{ baseInfo.auditCause }}</text>
        </view>
      </view>
      <view class="equipment" v-if="pickTabIndex === 1">
        <AssetsCard
          v-for="(item, index) in planEquiList"
          class="kd-row"
          type="detail"
          :isApproval="true"
          :key="index"
          :item="item"
        />
        <!-- <view class="info-container" v-for="(item,index) in planEquiList" :key="index">
					<view class="title">
						{{item.assetName}}({{item.assetCode}})
					</view>
					<view class="main-wrap">
						<view class="col">
							<text class="label">批次</text>
							<text class="desc">{{item.batchNo}}</text>
						</view>
						<view class="col">
							<text class="label">牌号/型号</text>
							<text class="desc">{{item.brandNum}}</text>
						</view>
						<view class="col">
							<text class="label">单位</text>
							<text class="desc">{{item.measurementUnit}}{{item.unit}}/{{item.minPackUnit}}</text>
						</view>
						<view class="col">
							<text class="label">桶号</text>
							<text class="desc">{{item.num}}</text>
						</view>
						<view class="col">
							<text class="label">调出:</text>
							<text class="desc">{{  `${item.outWarehouseAreaName}-${item.outWarehouseAreaGoodsCode}-${item.outGoodsAllocationCode}` }}</text>
						</view>
						<view class="col">
							<text class="label">调入:</text>
							
							<text class="desc">{{ `${item.inWarehouseAreaName}-${item.inWarehouseAreaGoodsCode}-${item.inGoodsAllocationCode}` }}</text>
						</view>
					</view>
					
				</view> -->
      </view>
    </view>

    <view
      class="approval-container"
      v-if="isApproval && baseInfo.auditStatus == 1"
    >
      <view class="approval_btn-wrapper">
        <text class="approval-btn refuse" @click="handleRefuse">驳回</text>
        <text class="approval-btn primary" @click="handlePass(true)">通过</text>
      </view>
      <uni-popup ref="inputDialog" type="dialog">
        <uni-popup-dialog
          ref="inputClose"
          mode="input"
          title="驳回原因"
          placeholder="请输入内容"
          :before-close="true"
          @close="handleClose"
          @confirm="timeoutCauseConfirm"
        ></uni-popup-dialog>
      </uni-popup>
    </view>
  </view>
</template>

<script>
import { post, get, postJ } from '@/utils/api.js'
import Approval from '@/components/Approval.vue'
import AssetsCard from '@/pages/warehouse/inventoryAllocation/components/AssetsCard.vue'

import Info from './components/Info'
import Content from './components/Content'
export default {
  components: {
    AssetsCard,
    Approval,
    Content,
    Info
  },
  data () {
    return {
      pickTabIndex: 0,
      accordionVal: '',
      options: {
        id: '',
        workOrderId: '',
        planType: '',
        devOpsType: ''
      },
      baseInfo: '',
      planEquiList: [],
      isApproval: false,
      dict: {
        bizScene: {
          1: '生产调拨',
          2: '采购调拨',
          3: '赠送调拨',
          4: '借用调拨',
          5: '退还调拨',
          6: '其他调拨'
        },
        urgent: {
          1: '普通',
          2: '重要',
          3: '紧急'
        }
      }
    }
  },
  onLoad (options) {
    this.options = options
    this.isApproval = options.type === 'approval'
  },
  onShow () {
    this.getInfo()
  },
  methods: {
    //切换选项卡
    changeChartsTab (index) {
      this.pickTabIndex = index
    },
    getInfo () {
      get(
        this.apiUrl +
          `/conventionalStockTransfer/details/conventionalStockTransfer/${this.options.workOrderId}`
      ).then(res => {
        if (res?.success) {
          this.baseInfo = res.data.conventionalStockTransfer || {}
          this.planEquiList = res.data.stockTransferInfoList
        }
      })
    },
    // 审批
    handleRefuse () {
      this.$refs.inputDialog.open()
    },
    handleClose () {
      this.$refs.inputDialog.close()
    },
    handlePass (checked, cause) {
      const params = {
        approlId: this.options.id,
        handleResult: checked ? 2 : 0,
        bizId: this.options.workOrderId,
        handleCause: cause,
        handleStatus: 1
      }

      postJ(
        this.apiUrl + '/conventionalStockTransfer/changeStatus',
        params
      ).then(res => {
        if (res?.success) {
          uni.navigateTo({
            url: `/pages/home/backlog/result?type=${
              checked ? 'approve' : 'refuse'
            }&status=${this.devOpsType}`
          })
        }
      })
    },
    timeoutCauseConfirm (value) {
      if (!value) {
        uni.showToast({
          title: '请输入驳回原因',
          icon: 'none'
        })
        return
      }

      this.handlePass(false, value)
      this.$refs.inputDialog.close()
    }
    // 审批end
  }
}
</script>

<style lang="scss" scoped>
.tab-title {
  width: 100%;
  padding: 0 30rpx;
  margin-bottom: 12rpx;
  display: flex;
  height: $tab-height;
  line-height: $tab-height;
  background-color: #ffffff;
  border-bottom: 1px solid #f2f2f2;
  box-sizing: border-box;

  .tab-item {
    width: 30%;
    text-align: center;
    font-size: 32rpx;
    color: $uni-text-color-grey;
  }

  .tab-item.active {
    color: $j-primary-border-green;
    border-bottom: 1px solid $j-primary-border-green;
  }
}

.plan-approval-container {
  display: flex;
  flex-direction: column;
  padding-bottom: 80rpx;

  /deep/.uni-collapse-item {
    background-color: rgba(21, 122, 44, 0.372549019607843);
  }

  .content {
    flex: 1;
    overflow: auto;

    .baseinfo {
      padding: 0 22rpx;
      font-size: 28rpx;

      .col {
        display: flex;
        padding: 10rpx 0;
        border-bottom: 1rpx dashed #d7d7d7;

        .label {
          display: inline-block;
          width: 200rpx;
          text-align: right;
          margin-right: 20rpx;
          font-weight: bold;
        }

        .desc {
          flex: 1;
          word-break: break-all;
        }
      }
    }
  }

  .collapse-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 28rpx;
    height: 80rpx;
    padding: 8rpx;
    box-sizing: border-box;
  }

  .collapse-item-wrapper {
    padding: 12rpx;

    .info-container {
      margin-bottom: 20rpx;
      display: flex;
      flex-wrap: wrap;
      .col {
        width: 50%;
        &.row {
          width: 100%;
        }
      }
    }
  }
}

.pd-list-item {
  padding: 10rpx;
  border-bottom: 1px solid #d7d7d7;

  .item {
    display: flex;
    font-size: 28rpx;
    justify-content: space-between;
    padding: 10rpx;
  }
}

.info-container {
  padding: 20rpx;
  border-bottom: 1px solid #f2f2f2;
  .title {
    font-size: 32rpx;
    color: #555;
  }
  .main-wrap {
    display: flex;
    flex-wrap: wrap;
    .col {
      color: #555;
      font-size: 28rpx;
      width: 50%;
      display: flex;
      padding: 20rpx 0;
      .label {
        margin-right: 10rpx;
      }
    }
  }
}
.approval-container {
  width: 100vw;
  height: 80rpx;

  .approval_btn-wrapper {
    display: flex;
    position: fixed;
    bottom: 0;
    width: 100vw;
    height: 80rpx;
    background-color: #fff;
  }

  .approval-btn {
    flex: 1;
    line-height: 78rpx;
    text-align: center;
    border: 1rpx solid $j-primary-border-green;
    &.refuse {
      color: red;
    }
    &.primary {
      background-color: $j-primary-border-green;
      color: #fff;
    }
  }
}
</style>
