<!--
  @description: 发货订单管理-订单处理
  @author: 王俊楠
  @routerPath: /procurement/procurementOrderDeliverHandleAdd
  @date： 2020-11-10 17:10:12
-->
<template>
  <div>
    <section 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"
        >
          <el-button
            slot="addHandleBtn"
            :loading="confirmLoading"
            type="primary"
            @click.stop="navDelivery()"
          >
            新增发货单
          </el-button>
          <template />
        </procurementOrderDeliverCompDetail>
        <pagination :pagination-data="paginationDeliverData" @change="getDeliveryData" />
      </template>

      <!-- 订单收款信息 -->
      <template>
        <procurementOrderCollectionCompDetail
          :collection-info-data="detailInfoData.collectionInfoList"
        >
          <el-button
            slot="addDisposeBtn"
            :loading="confirmLoading"
            type="primary"
            @click.stop="addCollection()"
          >
            新增收款单申请
          </el-button>
          <template slot-scope="scope">
            <template v-if="scope.row.status==='01'">
              <el-link
                type="primary"
                @click.stop="editCollection(scope.row,'02')"
              >
                [编辑]
              </el-link>
              <el-link
                type="primary"
                @click.stop="deleteCollection(scope.row)"
              >
                [删除]
              </el-link>
            </template>
          </template>
        </procurementOrderCollectionCompDetail>
        <pagination :pagination-data="paginationCollectionData" @change="getCollectionData" />
      </template>
    </div>
    <!--操作按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but" />
      </div>
    </div>
  </div>
</template>

<script>
/* api接口*/
import {
  queryProcurementOrderInfo, // 基本信息
  listProcurementOrderProductPages, // 行项目
  listSupplierProcurementSendGoodsPages, // 发货信息
  listSupplierConsigneeApplicationPages, // 收款信息
  queryConsigneeApplicationEditOrDelete // 删除编辑
} 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 { ListMixin } from '@/mixins/ListMixin' // 分页
import pagination from '@comp/common/pagination/pagination' // 分页组件

export default {
  name: 'ProcurementOrderDeliverHandleAdd',
  components: {
    procurementOrderBasicCompDetail, // 订单基本信息
    procurementOrderLineItemCompDetail, // 行项目列表组件
    procurementOrderDeliverCompDetail, // 订单发货信息列表组件
    procurementOrderCollectionCompDetail, // 订单收款信息列表组件
    pagination // 分页
  },
  mixins: [],
  data() {
    return {
      // 页面数据
      detailInfoData: {
        orderInfoList: {}, // 订单基本信息
        lineItemInfoList: [], // 行项目信息
        deliveryInfoList: [], // 发货信息
        collectionInfoList: [] // 收款信息
      },
      lineData: {
        orderTotalMoney: '', // 订单净总价
        orderTotalTaxMoney: '', // 订单含税总价
        currency: '' // 币种
      },
      // 行项目分页信息
      paginationLineData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      // 发货信息分页信息
      paginationDeliverData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      // 收款信息行项目分页信息
      paginationCollectionData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      orderId: '', // 获取订单id
      confirmLoading: false // 页面加载
    }
  },
  computed: {
  },
  watch: {
  },
  created() {
    this.sessSet()
    // 获取路由传参 订单Id
    this.getInfoData()
  },
  methods: {
  // 参数存储
    sessSet() {
      const orderid = this.$route.params.orderId
      if (orderid) {
        this.orderId = orderid
        sessionStorage.setItem('orderId', orderid)
      } else {
        this.orderId = sessionStorage.getItem('orderId')
      }
    },
    // 返回发货订单处理详情页面
    back() {
      this.$router.push({
        path: '/procurement/procurementOrderDeliverList'
      })
    },
    async getInfoData() {
      this.getBaseInfoData() // 基础信息
      this.getLineItemData() // 行项目信息
      this.getDeliveryData() // 发货信息
      this.getCollectionData() // 收款信息
    },
    // 跳转发货订单管理-新增发货
    navDelivery() {
      this.$router.push({
        name: 'ProcurementOrderDeliverAdd',
        params: {
          orderId: this.orderId
        }
      })
    },
    // 发货订单管理--收款申请订单
    addCollection() {
      this.$router.push({
        name: 'ProcurementOrderCollectionAdd',
        params: {
          orderId: this.orderId,
          orderCode: this.detailInfoData.orderInfoList.orderCode,
          paymentDepartName: this.detailInfoData.orderInfoList.purchaseDepartName,
          winningDepartName: this.detailInfoData.orderInfoList.winningDepartName,
          status: '01'
        }
      })
    },
    // 发货订单管理-收款申请订单
    editCollection(row, key) {
      this.$router.push({
        name: 'ProcurementOrderCollectionAdd',
        params: {
          conAppliId: row.id,
          status: key // status 01 新增 02 编辑
        }
      })
    },
    // 删除收款订单
    deleteCollection(row) {
      this.$confirm('确定删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const params = {
          conAppliId: row.id,
          status: '03'
        }
        queryConsigneeApplicationEditOrDelete(params).then(() => {
          this.getInfoData()
        })
      })
      this.confirmLoading = false
    },
    // 获取处理基本信息
    getBaseInfoData() {
      const params = {
        orderId: this.orderId
      }
      queryProcurementOrderInfo(params).then((response) => {
        this.detailInfoData.orderInfoList = response.data
        this.lineData.currency = response.data.currency // 币种
        this.lineData.orderTotalTaxMoney = response.data.orderTotalTaxMoney // 订单含税总价
        this.lineData.orderTotalMoney = response.data.orderTotalMoney // 订单净总价
      })
    },
    // 获取行项目信息
    getLineItemData() {
      const params = {
        orderId: this.orderId,
        pageNo: this.paginationLineData.pageNo,
        pageSize: this.paginationLineData.pageSize
      }
      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(() => {
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>

