<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="入仓号">
              <a-input placeholder="请输入入仓号" v-model="queryParam.receiving_no"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="散货柜编号">
              <a-input placeholder="请输入散货柜编号" v-model="queryParam.bulk_no"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="仓库名称">
                <j-search-select-tag placeholder="请输入仓库名称" v-model="queryParam.store_name" dict="iost_storage,name,name"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="发票号">
                <a-input placeholder="请输入发票号" v-model="queryParam.invoice_number"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户姓名">
                <j-search-select-tag placeholder="请输入客户姓名" v-model="queryParam.customer_name" dict="iost_customer,name_chs,name_chs"/>
              </a-form-item>
            </a-col>
            <a-col :xl="9" :lg="7" :md="8" :sm="24">
              <a-form-item label="日期">
                  <j-date placeholder="请选择开始日期" v-model="queryParam.日期_begin"></j-date> ~ 
                  <j-date placeholder="请选择结束日期" v-model="queryParam.日期_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="送货状态">
                <j-search-select-tag placeholder="请输入送货状态" v-model="queryParam.deliver_status" dict="delivery_status"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <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>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-row :gutter="24">
        <a-col :xl="3" :lg="7" :md="8" :sm="24">
          <a-button type="primary" icon="download" @click="handleExportXls('商品类别')">导出</a-button>
        </a-col>
        <a-col :xl="3" :lg="7" :md="8" :sm="24" v-if="selectedRowKeys.length > 0">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{selectedRowKeys.length}}</a>项
        </a-col>
        <a-col :xl="3" :lg="7" :md="8" :sm="24" v-if="selectedRowKeys.length > 0">
          总体积：{{totleVolume}}
        </a-col>
        <a-col :xl="3" :lg="7" :md="8" :sm="24" v-if="selectedRowKeys.length > 0">
          总重量：{{totleWeight}}
        </a-col>
        <a-col :xl="3" :lg="7" :md="8" :sm="24" v-if="selectedRowKeys.length > 0">
          总件数：{{totleNum}}
        </a-col>
      </a-row>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="linkSlot" slot-scope="text">
          <a @click="handleDetail(text)">{{ text }}</a>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

      </a-table>
    </div>

    <iost-receiving-note-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin4Report } from '@/mixins/JeecgListMixin4Report'
  import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
  import JDate from '@/components/jeecg/JDate.vue'
  import IostReceivingNoteModal from './modules/IostReceivingNoteModal'
  import { getAction } from '@/api/manage'

  export default {
    name: 'IostCustomerCheckoutList',
    components: {JSearchSelectTag, JDate, IostReceivingNoteModal},
    mixins:[JeecgListMixin4Report, mixinDevice],
    data () {
      return {
        description: '客户出货报表',
        totleVolume:0,
        totleWeight:0,
        totleNum:0,
        // 表头
        columns: [
            {
              "title": "客户姓名",
              "align": "center",
              "sorter": "true",
              "dataIndex": "customer_name",
            }, {
              "title": "入仓号",
              "align": "center",
              "sorter": "true",
              "dataIndex": "receiving_no"
            }, {
              "title": "散货柜编号",
              "align": "center",
              "sorter": "true",
              "dataIndex": "bulk_no"
            }, {
              "title": "仓库名称",
              "align": "center",
              "sorter": "true",
              "dataIndex": "store_name"
            },{
              "title": "发票号",
              "align": "center",
              "sorter": "true",
              "dataIndex": "invoice_number",
              scopedSlots: { customRender: 'linkSlot' },
            }, {
              "title": "实际件数",
              "align": "center",
              "sorter": "true",
              "dataIndex": "实际件数"
            }, {
              "title": "总体积",
              "align": "center",
              "sorter": "true",
              "dataIndex": "总体积"
            }, {
              "title": "总重量",
              "align": "center",
              "sorter": "true",
              "dataIndex": "总重量"
            }, {
              "title": "日期",
              "align": "center",
              "sorter": "true",
              "dataIndex": "日期"
            }, {
              "title": "送货状态",
              "align": "center",
              "sorter": "true",
              "dataIndex": "deliver_status_name"
            }
        ],
        url: {
          list: "/online/cgreport/api/getColumnsAndData/1326825388158644225",
          exportXlsUrl: "/online/cgreport/api/exportXls/1326825388158644225",
        },
        dictOptions:{},
      }
    },
    created() {
    },
    methods: {
      initDictConfig(){
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
        this.totleVolume = 0;
        this.totleWeight = 0;
        this.totleNum = 0;
        for(let selectIndex in selectionRows)
        {
            let selectionRow = selectionRows[selectIndex]
            let fValue = Number.parseFloat(selectionRow.总体积)
            this.totleVolume = this.FloatAdd(this.totleVolume, fValue)
            fValue = Number.parseFloat(selectionRow.总重量)
            this.totleWeight = this.FloatAdd(this.totleWeight, fValue)
            fValue = Number.parseFloat(selectionRow.实际件数)
            this.totleNum = this.FloatAdd(this.totleNum, fValue)
        }
      },
      handleDetail(text)
      {
          let url = `${window._CONFIG['domianURL']}/basedata/iostReceivingNote/list`;
          getAction(url, {invoiceNumber:text}).then((res) => {
            if (res.success) {
              let record = res.result.records[0];
              console.log(res)
              this.$refs.modalForm.edit(record);
              this.$refs.modalForm.title="详情";
              this.$refs.modalForm.disableSubmit = true;
            }
            else
            {
              that.$message.warning(res.message)
            }
            that.loading = false;
          })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>