<template>
  <div class="div-new-box-new">
    <div class="content-new-content">
      <div class="div-line"></div>
      <div class="title"> 出货未开票分析</div>
      <div style="float: right;">
        <departmentSalesperson ref="departmentSalesperson" class="inline-16" @depSelect="depSelect" @personSelect="personSelect"></departmentSalesperson>
      </div>
    </div>
    <div class="chart">
      <div id="shippingUninvoiceAnalysisChart" style="height: 400px;"></div>
    </div>
    <div style="height:400px">
      <tableTemplate  ref="table" :layout="tablecols" :data="list" :opwidth="200" :custom="true" height="356px" fixedName="operation">
        <template v-slot:customcol="scope">
          <p v-if="scope.column.columnname === 'total'">
                <span v-if="scope.column.data[scope.column.columnname]">
                  ¥{{tool.formatAmount(scope.column.data[scope.column.columnname],2)}}
                </span>
            <span v-else>--</span>
          </p>
          <p v-else-if="scope.column.columnname === 'zerotothree'">
                <span v-if="scope.column.data[scope.column.columnname]">
                  ¥{{tool.formatAmount(scope.column.data[scope.column.columnname],2)}}
                </span>
            <span v-else>--</span>
          </p>
          <p v-else-if="scope.column.columnname === 'threetosix'">
                <span v-if="scope.column.data[scope.column.columnname]">
                  ¥{{tool.formatAmount(scope.column.data[scope.column.columnname],2)}}
                </span>
            <span v-else>--</span>
          </p>
          <p v-else-if="scope.column.columnname === 'sixtotwelve'">
                <span v-if="scope.column.data[scope.column.columnname]">
                  ¥{{tool.formatAmount(scope.column.data[scope.column.columnname],2)}}
                </span>
            <span v-else>--</span>
          </p>
          <p v-else-if="scope.column.columnname === 'twelveup'">
                <span v-if="scope.column.data[scope.column.columnname]">
                  ¥{{tool.formatAmount(scope.column.data[scope.column.columnname],2)}}
                </span>
            <span v-else>--</span>
          </p>
          <p v-else-if="scope.column.columnname === 'operation'"></p>
          <p v-else>{{scope.column.data[scope.column.columnname]?scope.column.data[scope.column.columnname]:'--'}}</p>
        </template>
        <template v-slot:opreation="scope">
          <shippingUninvoiceDetail :dataid="param.content.dataid" :type="param.content.type" :sys_enterpriseid="scope.data.sys_enterpriseid" :data="scope.data"></shippingUninvoiceDetail>
        </template>
      </tableTemplate>
      <div  class="container normal-panel" style="text-align:right;float: right;">
        <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :pager-count="7"
            :page-sizes="[20, 50,100, 200]"
            :page-size="20"
            layout="total,sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import departmentSalesperson from "@/views/salesData/components/departmentSalesperson";
import tableTemplate from '@/views/salesData/components/table';
import shippingUninvoiceDetail from "@/views/salesData/components/shippingUninvoiceDetail";
import {Bar} from "@antv/g2plot";
export default {
  name: "shippingUninvoiceAnalysis",
  components:{tableTemplate,departmentSalesperson,shippingUninvoiceDetail},
  data(){
    return {
      chartBar:null,
      param:{
        "id": 20231016163904,
        "content": {
          "type": 0,
          "dataid": 54,
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "uninvicetype":""
          }
        }
      },
      tablecols:[],
      list:[],
      currentPage:0,
      total:0,
      chartData:[],
      hoverData:[],
    }
  },
  methods:{
    async listData(val){
      this.renderPie(val)
    },
    async queryModel(val){
      this.param.content.dataid = val || this.dataid
      const res = await this.$api.requested(this.param)
      if (res.data.length === 1){
        if (res.data[0].isEmpty == '1'){
          this.list = []
          this.total = 0
          this.currentPage = 0
        }else {
          this.list = res.data
          this.total = res.total
          this.currentPage = res.pageNumber
        }
      }else {
        this.list = res.data
        this.total = res.total
        this.currentPage = res.pageNumber
      }
      this.chartData = res.data[0].Trend
      this.chartData = this.chartData.map(item=>{
        return {
          "value": Math.round(((item.value)*100)/100),
          "key": item.key,
          "type":"出货未开票金额"
        }
      })
      this.chartBar.changeData(this.chartData)
    },
    renderPie(val){
      this.chartBar = new Bar('shippingUninvoiceAnalysisChart',{
        data:this.chartData,
        xField: 'value',
        yField: 'key',
        seriesField: 'type',
        legend: {
          position: 'top-left',
        },
        tooltip: {
          formatter: (datum) => {
            return {
              name:datum.key,
              value:'¥'+this.tool.formatAmount(datum.value,2)
            }
          }
        }
      })
      /*this.chartBar.on('plot:click',ev=>{
        const states = this.chartBar.getStates()
        this.param.content.where.uninvicetype = states.length === 0 ? '': ev.data.data.key
        this.param.content.pageNumber = 1
        this.queryTable(this.param.content.dataid)
      })*/
      this.chartBar.render()
      this.queryModel(val)
    },
    async queryTable(val){
      this.param.content.dataid = val || this.dataid
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    /*选择部门*/
    depSelect(val){
      this.param.content.type = 1
      this.param.content.dataid = val
      this.queryModel(val)
    },
    /*选择业务员*/
    personSelect(val){
      this.param.content.type = 0
      this.param.content.dataid = val
      this.queryModel(val)
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.queryTable(this.param.content.dataid)
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.queryTable(this.param.content.dataid)
    },
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).shipmentUninvoicedTable.tablecols
  }
}
</script>

<style scoped>

</style>
