<template>
  <!-- 订单外部统计表-->
  <div id="externalStatistics">
    <!-- 查询区域 -->
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="8">
              <a-form-item label="起始年月">
                <a-range-picker
                  style="width: 100%"
                  v-model="queryParam.timeRange"
                  placeholder="['开始年月', '结束年月']"
                  format="YYYY-MM"
                  :mode="mode2"
                  :value="value"
                  @panelChange="handlePanelChange"
                  @change="handleChange"
                />
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="8">
              <a-form-item label="部门">
                <a-input placeholder="请输入订单号" v-model="queryParam.department"></a-input>
                <!-- <a-select placeholder="请选择部门" v-model="queryParam.">
                  <a-select-option :value="''">请选择</a-select-option>
                  <a-select-option :value="0">业务一部</a-select-option>
                  <a-select-option :value="1">业务二部</a-select-option>
                </a-select> -->
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="8">
              <a-form-item label="客户">
                <a-input placeholder="请输入客户" v-model="queryParam.customer"></a-input>

                <!-- <a-select placeholder="请选择客户" v-model="queryParam.customer">
                  <a-select-option :value="''">请选择</a-select-option>
                  <a-select-option :value="0">FD</a-select-option>
                  <a-select-option :value="1">PMK</a-select-option>
                </a-select> -->
              </a-form-item>
            </a-col>

            <template v-if="toggleSearchStatus"></template>

            <a-col :md="6" :sm="8">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>

    <!-- 引入 echarts -->
    <a-card :bordered="false" style="marginTop:10px;">
      <div class="chart">
        <!-- 部门 "-->
        <div class="departmentChart" style="background:rgba(255, 165, 0,.08);">
          <departmentChart />
        </div>
        <!-- 客户 -->
        <div class="customerChart" style="background:rgba(134, 151, 201,.08);">
          <customerChart />
        </div>
      </div>
    </a-card>

    <!-- table rowKey="id" :scroll="{ x: 1500 }"-->
    <a-card :bordered="false" style="marginTop:10px;">
      <a-table
        bordered
        :row-key="record => record.id"
        :columns="externalStatisticsColumns"
        :data-source="externalStatisticsData"
        :loading="loading"
        :pagination="pagination"
        @change="handleTableChange"
      >
      </a-table>
    </a-card>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import moment from 'moment'
import departmentChart from '@views/reportForms/order-statistics/chart/external/departmentChart'
import customerChart from '@views/reportForms/order-statistics/chart/external/customerChart.vue'

import { external } from '@api/reportForms/order-statistics.js'

export default {
  name: 'ExternalStatistics', // 订单外部统计表
  mixins: [JeecgListMixin],
  components: { JEllipsis, moment, departmentChart, customerChart },

  data() {
    // let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} /> // 省略
    return {
      description: '订单外部统计表',
      externalStatisticsColumns: [
        {
          title: '部门',
          width: 140,
          dataIndex: 'department',
          className: 'replacecolor'
        },
        {
          title: '供应商分类',
          width: 120,
          dataIndex: 'supplierType',
          className: 'replacecolor'
          // customRender: function(text) {
          //   if (text == '1') {
          //     return '销售类型1'
          //   }
          //   if (text == '2') {
          //     return '销售类型2'
          //   }
          //   if (text == '3') {
          //     return '销售类型3'
          //   }
          //   if (text == '4') {
          //     return '销售类型4'
          //   }
          // }
        },
        {
          title: '供应商',
          width: 140,
          dataIndex: 'supplier',
          className: 'replacecolor'
        },
        {
          title: '计划到货月份',
          width: 120,
          dataIndex: 'planDeliveryMonth',
          customRender: text => {
            return moment(text).format('YYYY-MM')
          },
          className: 'replacecolor'
        },
        { title: '含税单价', width: 120, dataIndex: 'priceInTax', className: 'replacecolor' },
        {
          title: '实际数量',
          width: 120,
          dataIndex: 'realQuantity',
          className: 'replacecolor'
        },
        { title: '本币金额', width: 150, dataIndex: 'localMoney', className: 'replacecolor' }
      ],
      externalStatisticsData: [],
      loading: false, // 表格加载

      // 查询条件
      queryParam: {
        vendorType: '外部',
        startYearMonth: '',
        endYearMonth: '',
        // timeRange: [],
        department: '',
        customer: ''
      },

      pagination: {
        // total: '', //总条数
        // current: '', //当前页
        // pageSize: '' //一页多少
      },
      mode2: ['month', 'month'],
      value: []
      // dateFormat: 'YYYY-MM-DD'
    }
  },
  created() {
    this.getExternalData()
  },
  methods: {
    getExternalData() {
      this.$nextTick(() => {
        external(this.queryParam).then(res => {
          if (res.success) {
            this.ExternalData = res.result.records
            console.log('订单外部列表', this.ExternalData)
            this.pagination = {
              total: res.result.total,
              current: 1,
              pageSize: res.result.size
            }
          }
        })
      })
    },
    // 日期面板变化时的回调
    handlePanelChange(value, mode) {
      this.value = value
      this.mode2 = [mode[0] === 'date' ? 'month' : mode[0], mode[1] === 'date' ? 'month' : mode[1]]
      console.log('this.mode2', this.mode2)

      console.log('value.dateString[0]', moment(value[0]))
      console.log('value.dateString[1]', moment(value[0]))
      // this.queryParam.startYearMonth = dateString[0]
      // this.queryParam.endYearMonth = dateString[1]
    },
    // onDateChange(value, dateString) {
    //   console.log('起年月', dateString[0], '始年月', dateString[1])
    //   this.queryParam.startYearMonth = dateString[0]
    //   this.queryParam.endYearMonth = dateString[1]
    // }
    // 时间发生变化的回调，发生在用户选择时间时
    handleChange(value) {
      console.log('?', value)
      this.value = value
      console.log('this.value', this.value)
    },
    searchQuery() {
      this.getExternalData()
    },
    searchReset() {
      this.queryParam = {}
      this.getExternalData()
    },

    // 分页、排序、筛选变化时触发
    handleTableChange(pagination, filters, sorter) {
      // console.log('当前页信息>>>>',pagination)
      this.queryParam.pageNo = pagination.current
      this.getExternalData()
    }
  },
  computed: {},
  mounted() {}
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@assets/less/overwriter.less';
/deep/ .ant-table-thead > tr > th {
  text-align: center;
  // font-weight: 700;
}

/deep/ .ant-table-tbody {
  text-align: center;
}

// /deep/ th.replacecolor {
//   background-color: #ccc;
// }

.departmentChart,
.customerChart {
  // width: 100%;
  height: 600px;
  text-align: center;
  padding-top: 10px;
}
.departmentChart {
  margin-bottom: 20px;
}
</style>
