<template>
  <view class="mainBox">
    <uni-nav-bar
      fixed="true"
      statusBar="true"
      left-icon="back"
      title="调拨详情"
      @clickLeft="back"
    >
    </uni-nav-bar>
    <view class="view-container">
      <DetailView
        :baseInfo="baseInfo.conventionalStockTransferReq"
        :list="baseInfo.detailReqList"
      />
    </view>
    <view
      class="footer"
      v-if="baseInfo.conventionalStockTransferReq.auditStatus === 1"
    >
      <u-button type="primary" @tap="handleDraft">撤为草稿</u-button>
    </view>
    <view
      class="footer"
      v-if="baseInfo.conventionalStockTransferReq.auditStatus === 0"
    >
      <u-button type="primary" @tap="handleReCommit">重新提交</u-button>
    </view>
  </view>
</template>

<script>
import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
import DetailView from './components/DetailView.vue'
import { post, postJ, get, getJ } from '@/utils/api.js'
export default {
  components: { DetailView, baTreePicker },
  data () {
    return {
      activeName: 1,
      baseInfo: {
        conventionalStockTransferReq: {}
      },
      deptList: [],
      userList: [],
      loading: false
    }
  },
  onLoad ({ id }) {
    if (id) {
      this._getDetail(id)
    }
  },
  methods: {
    async handleDraft () {
      const params = {
        handleResult: 3,
        handleStatus: 0,
        bizId: this.baseInfo.conventionalStockTransferReq.id
      }
      const res = await postJ(
        this.apiUrl + `/conventionalStockTransfer/changeStatus`,
        params
      )
      if (res?.success) {
        uni.showToast({
          title: '撤回成功!',
          icon: 'none'
        })

        uni.navigateBack({
          delta: 1
        })
      }
    },
    handleReCommit () {
      uni.navigateTo({
        url:
          '/pages/warehouse/inventoryAllocation/edit?id=' +
          this.baseInfo.conventionalStockTransferReq.id
      })
    },
    async _getDetail (id) {
      const res = await get(
        this.apiUrl +
          `/conventionalStockTransfer/details/conventionalStockTransfer/${id}`
      )
      if (res?.success) {
        res.data.stockTransferInfoList.forEach(item => {
          item.batchNum = item.batchNo
        })
        this.baseInfo.conventionalStockTransferReq =
          res.data.conventionalStockTransfer
        this.baseInfo.detailReqList = res.data.stockTransferInfoList

        console.log(this.baseInfo, '222')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.tabs {
  position: fixed;
  width: 100vw;
  background-color: rgba(242, 242, 242, 0.792156862745098);
  padding-top: 20rpx;

  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 20rpx;

  .tab-item {
    width: 200rpx;
    display: flex;
    justify-content: center;
    align-items: center;

    &.active {
      background: linear-gradient(
        180deg,
        rgba(75, 121, 2, 1) 0%,
        rgba(255, 255, 255, 1) 12%
      );
    }
  }
}
.view-container {
  padding-bottom: 200rpx;
}
.footer {
  position: fixed;
  bottom: 0;
  width: 100vw;
  left: 0;
  .verify-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10rpx;
    /deep/.u-input {
      border: 1rpx solid #ccc;
    }

    .dept {
      margin-right: 30rpx;
    }
  }
}
</style>
