<!--
  @description: 订单管理-订单查询详情
  @author: lxl
  @date： 2021-1-8 10:30:12
-->
<template>
  <div>
    <!-- 订单行项目信息 -->
    <!-- <section v-if="isBack" class="title title_border p0-16">
      <i class="iconfont icon-fanhui pointer" @click="back()" />
      订单查询详情
    </section> -->
    <div class="p0-16">
      <!-- 订单基本信息 -->
      <procurementOrderBasicCompDetail
        :order-info-data="detailInfoData.orderInfoList"
      />
      <!-- 订单行项目信息 -->
      <template>
        <procurementOrderLineItemCompDetail
          :line-item-info-data="detailInfoData.lineItemInfoList"
          :line-data="lineData"
        />
        <pagination :pagination-data="paginationLineData" @change="getLineItemData" />
      </template>

      <!-- 订单发货信息 -->
      <template>
        <procurementOrderDeliverCompDetail
          :delivery-info-data="detailInfoData.deliveryInfoList"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click.stop="viewReceipts(scope.row)"
            >
              [查看]
            </el-link>
          </template>
        </procurementOrderDeliverCompDetail>
        <pagination :pagination-data="paginationDeliverData" @change="getDeliveryData" />
      </template>

      <!-- 订单收款信息 -->
      <template>
        <procurementOrderCollectionCompDetail
          :collection-info-data="detailInfoData.collectionInfoList"
        >
          <!-- 收款表操作按钮 -->
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click.stop="viewCollection(scope.row)"
            >
              [查看]
            </el-link>
          </template>
        </procurementOrderCollectionCompDetail>
        <pagination :pagination-data="paginationCollectionData" @change="getCollectionData" />
      </template>
      <table v-if="orderStatus === '08'" class="tableData mb10 mt10">
        <tr>
          <td>
            退回意见
          </td>
          <td colspan="3">
            {{ detailInfoData.orderInfoList.releaseReason }}
          </td>
        </tr>
      </table>
      <flowAuditList v-if="orderStatus === '08'" class="mb10 mt10" :biz-id="orderId" flow-type="00" />
    </div>
  </div>
</template>
<script>
/*  api*/
import {
  queryProcurementOrderInfo, // 基本信息
  listProcurementOrderProductPages, // 行项目
  listSupplierProcurementSendGoodsPages, // 发货信息
  listSupplierConsigneeApplicationPages // 收款信息
} from '@/api/procurement/procurementOrder'
/* 组件*/
import procurementOrderBasicCompDetail from '@/views/procurement/procurementOrder/procurementOrderInfo/procurementOrderBasicComp-detail.vue' // 订单的基本信息组件
import procurementOrderLineItemCompDetail from '@/views/procurement/procurementOrder/procurementOrderInfo/procurementOrderLineItemComp-detail.vue' // 订单行项目信息列表组件
import procurementOrderDeliverCompDetail from '@/views/procurement/procurementOrder/procurementOrderInfo/procurementOrderDeliverComp-detail.vue' // 订单发货列表组件
import procurementOrderCollectionCompDetail from '@/views/procurement/procurementOrder/procurementOrderInfo/procurementOrderCollectionComp-detail.vue' // 收款申请信息列表组件
import flowAuditList from '@views/work/process/flowAudit-list' // 审核列表
/* 公用*/
import pagination from '@comp/common/pagination/pagination' // 分页组件

export default {
  name: 'TakeOrderLineDetail',
  components: {
    procurementOrderLineItemCompDetail,
    procurementOrderBasicCompDetail,
    procurementOrderDeliverCompDetail,
    procurementOrderCollectionCompDetail,
    flowAuditList,
    pagination
  },
  data() {
    return {
      orderStatus: this.$route.params.orderStatus, // 订单状态
      orderId: this.$route.params.orderId,
      detailInfoData: {
        orderInfoList: {}, // 订单基本信息
        lineItemInfoList: [], // 行项目信息
        deliveryInfoList: [], // 发货信息
        collectionInfoList: [] // 收款信息
      },
      // 行项目信息金额数据
      lineData: {
        currency: '', // 币种
        orderTotalMoney: '', // 订单净总价
        orderTotalTaxMoney: '' // 含税总价
      },
      // 行项目分页信息
      paginationLineData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      // 发货信息分页信息
      paginationDeliverData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      // 收款信息行项目分页信息
      paginationCollectionData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  created() {
    // 初始化返回按钮状态
    this.getBaseInfoData() // 基础信息
    this.getLineItemData() // 行项目信息
    this.getDeliveryData() // 发货信息
    this.getCollectionData() // 收款信息
  },
  methods: {
    // 收货详情
    viewReceipts(row) {
      this.$router.push({
        name: 'takeOrderReceiveDetail',
        params: {
          goodsId: row.id,
          orderId: this.orderId,
          isBack: '00'// 初始化返回按钮状态
        }
      })
    },
    // 收款确认详情
    viewCollection(row) {
      this.$router.push({
        name: 'takeOrderCollectionConfirmDetail',
        params: {
          conAppliId: row.id, // 订单Id
          isBack: '00' // 初始化返回按钮状态
        }
      })
    },
    // 基本信息
    getBaseInfoData() {
      const params = {
        orderId: this.orderId
      }
      queryProcurementOrderInfo(params).then((response) => {
        this.detailInfoData.orderInfoList = response.data
        this.lineData.currency = response.data.currency // 币种
        this.lineData.orderTotalMoney = response.data.orderTotalMoney // 订单净总价
        this.lineData.orderTotalTaxMoney = response.data.orderTotalTaxMoney // 订单含税总价
      })
    },
    // 获取行项目信息
    getLineItemData() {
      const params = {
        orderId: this.orderId,
        pageNo: this.paginationLineData.pageNo,
        pageSize: this.paginationLineData.pageSize
      }
      const status = this.$route.params.orderStatus
      switch (status) {
        case '08':
          params.releaseFlag = '03'
          break
        case '10':
          params.releaseFlag = '02'
          break
        default:
          params.releaseFlag = ''
      }
      // 订单退回
      // if (this.$route.params.orderStatus === '10') {
      //   params.releaseFlag = '01'
      // }
      listProcurementOrderProductPages(params).then(response => {
        this.loading = false
        this.detailInfoData.lineItemInfoList = response.data.records
        this.paginationLineData.total = response.data.total
      }).catch(() => {
      })
    },
    // 获取发货信息
    getDeliveryData() {
      const params = {
        orderId: this.orderId,
        pageNo: this.paginationDeliverData.pageNo,
        pageSize: this.paginationDeliverData.pageSize
      }
      listSupplierProcurementSendGoodsPages(params).then(response => {
        this.loading = false
        this.detailInfoData.deliveryInfoList = response.data.records
        this.paginationDeliverData.total = response.data.total
      }).catch(() => {
      })
    },
    // 收款信息
    getCollectionData() {
      const params = {
        orderId: this.orderId,
        pageNo: this.paginationCollectionData.pageNo,
        pageSize: this.paginationCollectionData.pageSize
      }
      listSupplierConsigneeApplicationPages(params).then(response => {
        this.loading = false
        this.detailInfoData.collectionInfoList = response.data.records
        this.paginationCollectionData.total = response.data.total
      }).catch(() => {
      })
    }
    // back() {
    //   this.$router.push({
    //     path: '/procurement/procurementOrderQueryList'
    //   })
    // }
  }
}
</script>
