<template>
  <div class="productInfoList-wrap">
    <!-- 列表 -->
    <s-table
      class="sTable"
      ref="table"
      size="small"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      :showPagination="false"
      :scroll="{ y: tableHeight-120 }"
      :defaultLoadData="false"
      bordered>
      <template slot="footer">
        <a-row>
          <a-col span="2">合计：</a-col>
          <a-col span="22">
            <a-row>
              <a-col span="4">期初结存数量：{{ (totalData && (totalData.beginQty || totalData.beginQty==0)) ? totalData.beginQty : '--' }}</a-col>
              <a-col span="4">期初结存单价：{{ (totalData && (totalData.beginPrice || totalData.beginPrice==0)) ? toThousands(totalData.beginPrice) : '--' }}</a-col>
              <a-col span="4">期初结存金额：{{ (totalData && (totalData.beginAmount || totalData.beginAmount==0)) ? toThousands(totalData.beginAmount) : '--' }}</a-col>
              <a-col span="4">本期收入数量：{{ (totalData && (totalData.putQty || totalData.putQty==0)) ?totalData.putQty : '--' }}</a-col>
              <a-col span="4">本期收入单价：{{ (totalData && (totalData.putPrice || totalData.putPrice==0)) ? toThousands(totalData.putPrice) : '--' }}</a-col>
              <a-col span="4">本期收入金额：{{ (totalData && (totalData.putAmount || totalData.putAmount==0)) ? toThousands(totalData.putAmount) : '--' }}</a-col>
              <a-col span="4">本期发出数量：{{ (totalData && (totalData.outQty || totalData.outQty==0)) ? totalData.outQty : '--' }}</a-col>
              <a-col span="4">本期发出单价：{{ (totalData && (totalData.outPrice || totalData.outPrice==0)) ? toThousands(totalData.outPrice) : '--' }}</a-col>
              <a-col span="4">本期发出金额：{{ (totalData && (totalData.outAmount || totalData.outAmount==0)) ? toThousands(totalData.outAmount) : '--' }}</a-col>
              <a-col span="4">本期结存数量：{{ (totalData && (totalData.endQty || totalData.endQty==0)) ? totalData.endQty : '--' }}</a-col>
              <a-col span="4">本期结存单价：{{ (totalData && (totalData.endPrice || totalData.endPrice==0)) ? toThousands(totalData.endPrice) : '--' }}</a-col>
              <a-col span="4">本期结存金额：{{ (totalData && (totalData.endAmount || totalData.endAmount==0)) ? toThousands(totalData.endAmount) : '--' }}</a-col>
            </a-row>
          </a-col>
        </a-row>
      </template>
    </s-table>
  </div>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { queryGroupByprodTypeReportPage } from '@/api/reportData'
import { STable, VSelect } from '@/components'
export default {
  name: 'QueryPart',
  mixins: [commonMixin],
  components: { STable, VSelect },
  props: {
    newLoading: Boolean,
    queryParam: {
      type: Object,
      default: function () {
        return {}
      }
    },
    tableHeight: {
      type: Number,
      default: 0
    },
    totalData: {
      type: Object,
      default: function () {
        return null
      }
    }
  },
  data () {
    return {
      columns: [
        { title: '二级分类', dataIndex: 'productTypeName2', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '三级分类', dataIndex: 'productTypeName3', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '品牌', dataIndex: 'productBrandName', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '期初结存数量', dataIndex: 'beginQty', width: '12%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '期初结存单价', dataIndex: 'beginPrice', width: '12%', align: 'center', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') },
        { title: '期初结存金额', dataIndex: 'beginAmount', width: '12%', align: 'center', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') },
        { title: '本期收入数量', dataIndex: 'putQty', width: '12%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '本期收入单价', dataIndex: 'putPrice', width: '12%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') },
        { title: '本期收入金额', dataIndex: 'putAmount', width: '12%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') },
        { title: '本期发出数量', dataIndex: 'outQty', width: '12%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '本期发出单价', dataIndex: 'outPrice', width: '12%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') },
        { title: '本期发出金额', dataIndex: 'outAmount', width: '12%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') },
        { title: '期末结存数量', dataIndex: 'endQty', width: '12%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '期末结存单价', dataIndex: 'endPrice', width: '12%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') },
        { title: '期末结存金额', dataIndex: 'endAmount', width: '12%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') }
      ],
      disabled: false, //  查询、重置按钮是否可操作
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        const params = Object.assign(parameter, this.queryParam)
        return queryGroupByprodTypeReportPage(params).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            this.disabled = false
          }
          this.spinning = false
          return data
        })
      }
    }
  },
  methods: {
    pageInit (buyerSn) {
      this.resetCurForm()
    },
    // 刷新当前页面
    resetCurForm () {
      this.$refs.table.refresh()
    },
    resetTable () {
      this.$refs.table.clearTable()
    }
  }
}
</script>
<style lang="less" scoped>
  .productInfoList-wrap{
    .ellipsisCon{
      display: flex;
      justify-content: space-between;
      align-items: center;
      .ellipsisText{
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        display: box;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
      }
    }
  }
</style>
