<template>
  <!-- 订单内部统计表-->
  <div id="interiorStatistics">
    <!-- 查询区域 -->
    <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%"
                  placeholder="['开始年月', '结束年月']"
                  format="YYYY-MM"
                  :mode="mode2"
                  :value="value"
                  @panelChange="handlePanelChange"
                  @change="monthChange"
                />
              </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.department">
                  <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="interiorColumns"
        :data-source="interiorData"
        :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/interior/departmentChart'
import customerChart from '@views/reportForms/order-statistics/chart/interior/customerChart.vue'

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

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

  data() {
    // let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} /> // 省略
    return {
      interiorColumns: [
        {
          title: '部门',
          width: 140,
          dataIndex: 'cDepName',
          className: 'replacecolor'
        },
        {
          title: '供应商分类',
          width: 120,
          dataIndex: 'cCusCode',
          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: 'cVenAbbName',
          className: 'replacecolor'
        },
        {
          title: '计划到货月份',
          width: 120,
          dataIndex: 'yearMonth',
          customRender: text => {
            return moment(text).format('YYYY-MM')
          },
          className: 'replacecolor'
        },
        { title: '含税单价', width: 120, dataIndex: 'iNatUnitPrice', className: 'replacecolor' },
        {
          title: '实际数量',
          width: 120,
          dataIndex: 'iQuantity',
          className: 'replacecolor'
        },
        { title: '本币金额', width: 150, dataIndex: 'iNatMoney', className: 'replacecolor' }
      ],

      interiorData: [
        {
          department: '业务八部',
          supplierType: '成衣厂',
          supplier: '国云森',
          planDeliveryMonth: '2021-04',
          priceInTax: '87.89',
          realQuantity: '90,120,0000',
          LocalMoney: '301,929,04'
        }
      ],
      loading: false, // 表格加载

      // 查询条件
      queryParam: {
        vendorType: '内部',
        startYearMonth: '',
        endYearMonth: '',
        department: '',
        customer: ''
      },
      pagination: {
        // total: '', //总条数
        // current: '', //当前页
        // pageSize: '' //一页多少
      },
      mode2: ['month', 'month'],
      value: [], //起始月份
      dateFormat: 'YYYY-MM-DD'
    }
  },
  created() {
    this.getInteriorData()
  },
  methods: {
    getInteriorData() {
      this.$nextTick(() => {
        // external(this.queryParam).then(res => {
        //   if (res.success) {
        //     this.interiorData = res.result.records
        //     console.log('订单外部列表', this.interiorData)
        //     this.pagination = {
        //       total: res.result.total,
        //       current: 1,
        //       pageSize: res.result.size
        //     }
        //     // console.log('分页器赋值:', this.pagination.total, this.pagination.current, this.pagination.pageSize)
        //   }
        // })
      })
    },

    // 日期面板变化时的回调
    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)
      this.queryParam.startYearMonth = value[0].format('YYYY-MM')
      this.queryParam.endYearMonth = value[1].format('YYYY-MM')
      console.log('开始年月:', this.queryParam.startYearMonth)
      console.log('结束年月:', this.queryParam.endYearMonth)
      setFieldsValue({
        timeRange: value
      })
    },

    // 时间发生变化的回调，发生在用户选择时间时
    monthChange(value) {
      this.value = value
      console.log('what------monthChange')
    },
    searchQuery() {
      this.getInteriorData()
    },
    searchReset() {
      this.queryParam = {}
      this.value = [] //起始年月重置
      this.getInteriorData()
    },

    handleTableChange(pagination, filters, sorter) {
      this.queryParam.pageNo = pagination.current
      this.getInteriorData()
    }
  },
  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 {
  margin-bottom: 20px;
}
</style>
