
<template>
  <base-list>
    <template slot="n_header">
      <el-form v-model="pagerDto" inline>
        <el-form-item label="跟踪单号">
          <el-input v-model="pagerDto._In_TrackingNumber" type="textarea" placeholder="跟踪单号" />
        </el-form-item>
        <el-form-item label="XYY单号">
          <el-input v-model="pagerDto._In_SystemNo" type="textarea" placeholder="XYY单号" />
        </el-form-item>
        <el-form-item label="结算时间">
          <div class="block">
            <el-date-picker
              v-model="customerBillTime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              value-format="yyyy-MM-dd"
              end-placeholder="结束日期"
            />
          </div>
        </el-form-item>
        <el-form-item label="是否抵账">
          <el-select v-model="pagerDto._Eq_Offset" clearable filterable>
            <el-option label="是" value="1" />
            <el-option label="否" value="0" />
          </el-select>
        </el-form-item>
        <el-form-item label="分公司">
          <el-select v-model="pagerDto._Eq_CustomerId" placeholder="分公司" clearable filterable>
            <el-option
              v-for="item in customers"
              :key="item.Id"
              :label="item.CompanyName"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="客户">
          <el-select v-model="pagerDto._Eq_CusCustomerId" placeholder="客户" clearable filterable>
            <el-option
              v-for="item in customers"
              :key="item.Id"
              :label="item.CompanyName"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="服务渠道">
          <el-select v-model="pagerDto._Eq_ChannelId" placeholder="服务渠道" clearable filterable>
            <el-option
              v-for="item in channels"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="下单渠道">
          <el-select v-model="pagerDto._Eq_PublicChannelId" placeholder="下单渠道" clearable filterable>
            <el-option
              v-for="item in publicChannels"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="下单国家">
          <el-select v-model="pagerDto._Eq_CountryCode" placeholder="下单国家" clearable filterable>
            <el-option
              v-for="item in Countries"
              :key="item.Code"
              :label="item.CnName"
              :value="item.Code"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="业务员">
          <el-select v-model="pagerDto._Eq_SalesmanUserId" placeholder="业务员" clearable filterable>
            <el-option
              v-for="item in salesmanUser"
              :key="item.Id"
              :label="item.NickName"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="pagerSerach(1)">
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </template>
    <template>
      <el-table
        v-loading="dataLoading"
        :data="data"
        :summary-method="getSummaries"
        show-summary
        :highlight-current-row="true"
        width="100%"
        border
      >
        <el-table-column label="跟踪单号" prop="TrackingNumber" />
        <el-table-column label="XYY单号" prop="SystemNo" />
        <el-table-column label="结算时间" prop="TransactionTimeStr" />
        <el-table-column label="是否抵账" prop="OffsetStr" />
        <el-table-column label="服务渠道" prop="ChannelName" />
        <el-table-column label="下单渠道" prop="OrderCreateChannelName" />
        <el-table-column label="下单国家" prop="CountryName" />
        <el-table-column label="业务员" prop="Info_NickName" />
        <el-table-column label="分公司名称" prop="CompanyName" />
        <el-table-column label="分公司运费" prop="ShippingFee" />
        <el-table-column label="分公司附加费" prop="AttachFee" />
        <el-table-column label="分公司税费金额" prop="EUTariff" />
        <el-table-column label="分公司利润" prop="Profit" />
        <el-table-column label="客户名称" prop="CusCustomerName" />
        <el-table-column label="客户运费" prop="CusShippingFee" />
        <el-table-column label="客户附加费" prop="CusAttachFee" />
        <el-table-column label="客户税费金额" prop="CusEUTariff" />
      </el-table>
      <el-pagination
        :page-sizes="[10, 20, 40,100, 400]"
        :current-page="pagerDto.PageIndex"
        :page-size.sync="pagerDto.PageSize"
        background
        layout="prev, pager, next ,total ,jumper,sizes,slot "
        :total="pagerDto.total"
        @size-change="changePager"
        @current-change="pagerSerach"
      />
    </template>

  </base-list>
</template>
<script>
import BaseList from '@/components/Xyy/baselist'
import { _getCustomers, _getDeliverChannel, _getAllPublic, _getCountries } from '@/api/baseInfo'
import { _getSalesmanUsers } from '@/api/customer'
import { _queryPage } from '@/api/OrderCharges'
export default {
  name: 'OrderCharges',
  components: { 'base-list': BaseList },
  data() {
    return {
      customers: [],
      channels: [],
      publicChannels: [],
      salesmanUser: [],
      Countries: [],
      customerBillTime: [],
      dialogVisible: false,
      data: [], dataLoading: false, tableCombined: null,
      pagerDto: { PageIndex: 0, PageSize: 10, total: 0,
        QuerySort: [{ Field: 'TransactionTime', IsDesc: true }],
        _In_TrackingNumber: [], _In_SystemNo: []
      }
    }
  },
  mounted() {
    _getCustomers().then(response => {
      this.customers = response
    })
    _getSalesmanUsers().then(response => {
      this.salesmanUser = response
    })
    _getDeliverChannel().then((resp) => {
      this.channels = resp
    })
    _getAllPublic().then((resp) => {
      this.publicChannels = resp
    })
    _getCountries().then((resp) => {
      this.Countries = resp
    })
    // this.pagerSerach(1)
  },
  methods: {
    pagerSerach(index) {
      this.dataLoading = true
      if (index) {
        this.pagerDto.PageIndex = index
      }
      if (this.customerBillTime.length > 0) {
        var dateStart = this.customerBillTime[0]
        var dateEnt = this.customerBillTime[1]
        this.pagerDto._GrE_TransactionTime = dateStart
        this.pagerDto._LeE_TransactionTime = dateEnt
      }

      _queryPage(this.pagerDto).then(res => {
        this.data = res.order_Charges.Result
        this.pagerDto.total = res.order_Charges.TotalCount
        this.tableCombined = res.order_Charges_StatisticalToal
        console.log(res)
      }).finally(res => { this.dataLoading = false })
    },
    changePager(v) {
      this.PageSize = v
      this.pagerSerach(1)
    },
    getSummaries() {
      const sums = []
      sums[10] = '合计:' + this.tableCombined.SystemNoCount + '票'
      sums[11] = '收入:' + this.tableCombined.IncomeCount
      sums[12] = '成本:' + this.tableCombined.CostCount
      sums[13] = '毛利:' + (this.tableCombined.IncomeCount - this.tableCombined.CostCount)
      return sums
    }

  }
}
</script>
