<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="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="供应商">
                <a-input placeholder="请输入供应商信息" v-model="queryParam.supplier"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="物料组">
                <a-input placeholder="请输入物料组" v-model="queryParam.itemGroup"/>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16" hidden="hidden" >
              <a-form-item label="物料">
                <a-input placeholder="请输入物料" v-model="queryParam.item" disabled="disabled"/>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="物料描述">
                <a-input placeholder="请输入物料描述" v-model="queryParam.itemDescription"/>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="仓储地点">
                <a-input placeholder="请选择仓储地点" v-model="queryParam.unitWasteWarehouseCodeId"/>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="存储仓位">
                <a-input placeholder="请选择存储仓位" v-model="queryParam.freightSpace"/>
              </a-form-item>
            </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-range-picker
                  style="width: 180px"
                  format="YYYY-MM-DD"
                  :placeholder="['开始时间', '结束时间']"
                  @change="onDateChange"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="入库批次">
                <a-input placeholder="请选择批次" v-model="queryParam.batch"/>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="保质期">
                <a-input placeholder="请选择保质期" v-model="queryParam.expirationDate"/>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16">
              <a-form-item label="入库时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-range-picker
                  style="width: 210px"
                  format="YYYY-MM-DD"
                  :placeholder="['开始时间', '结束时间']"
                  @change="onDateChangeinboundTime"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="16" style="margin-left: 30px">
              <a-form-item label="入库人">
                <a-input placeholder="请选择入库人" v-model="queryParam.librarySign"/>
              </a-form-item>
            </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <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-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>


    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </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="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>

    <process-supplies-stronger-modal ref="modalForm" @ok="modalFormOk"></process-supplies-stronger-modal>
  </a-card>
</template>

<script>

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


  export default {
    name: 'ProcessSuppliesStrongerLists',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDate,
      JSearchSelectTag,
      ProcessSuppliesStrongerModal,
      JSuperQuery,
    },
    data () {
      return {
        queryParam: {
          supplier: null,
          itemGroup: null,
          materialsNumber: this.$route.params.item,
          itemDescription: null,
          unitWasteWarehouseCodeId: null,
          freightSpace: null,
          productionTime: null,
          batch: null,
          expirationDate: null,
          inboundTime: null,
          librarySign: null,
        },
        description: '物资总库管理详情页面',
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'流程表单号',
            align:"center",
            dataIndex: 'processId'
          },
          {
            title:'供应商',
            align:"center",
            dataIndex: 'supplierName'
          },
          // {
          //   title:'供应商描述',
          //   align:"center",
          //   dataIndex: 'supplierDescription'
          // },
          {
            title:'物料组',
            align:"center",
            dataIndex: 'descriptionName'
          },
          {
            title:'物料编号',
            align:"center",
            dataIndex: 'materialsNumber'
          },
          {
            title:'物料描述',
            align:"center",
            dataIndex: 'merchandiseName'
          },
          {
            title:'计量单位',
            align:"center",
            dataIndex: 'unitMeasurement'
          },
          {
            title:'数量',
            align:"center",
            dataIndex: 'amount'
          },
          {
            title:'单价',
            align:"center",
            dataIndex: 'price'
          },
          {
            title:'金额',
            align:"center",
            dataIndex: 'rates'
          },
          {
            title:'仓储地点',
            align:"center",
            dataIndex: 'unitWasteWarehouseCodeId'
          },
          {
            title:'存储仓位',
            align:"center",
            dataIndex: 'freightSpace'
          },
          {
            title:'生产时间',
            align:"center",
            dataIndex: 'productionTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'保质期',
            align:"center",
            dataIndex: 'expirationDate'
          },
          {
            title:'批次',
            align:"center",
            dataIndex: 'batch'
          },
          {
            title:'是否到货',
            align:"center",
            dataIndex: 'arrivalNotice'
          },
          {
            title:'入库时间',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'入库人',
            align:"center",
            dataIndex: 'librarySign'
          },
          {
            title:'核算属性',
            align:"center",
            dataIndex: 'accountingAttributes_dictText'
          }
        ],
        url: {
          list: "/suppliesstronger/processSuppliesStronger/lists",
          delete: "/suppliesstronger/processSuppliesStronger/delete",
          deleteBatch: "/suppliesstronger/processSuppliesStronger/deleteBatch",
          exportXlsUrl: "/suppliesstronger/processSuppliesStronger/exportXls",
          importExcelUrl: "suppliesstronger/processSuppliesStronger/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        labelCol: {
          xs: { span: 4 },
          sm: { span: 4 },
        },
        wrapperCol: {
          xs: { span: 20 },
          sm: { span: 20 },
        },
      }
    },
    created() {
      // 判断路由上是否存在参数，如果没有则跳转回帐外物资管理页面
      this.judgeRouterParam();
      this.getSuperFieldList();
    },
    watch: {
      $route() {
        this.queryParam.materialsNumber = this.$route.params.item
        this.loadData()
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      onDateChange: function (value, dateString) {
        this.queryParam.productDateBegin=dateString[0];
        this.queryParam.productDateEnd=dateString[1];
      },
      onDateChangeinboundTime: function (value, dateString) {
        this.queryParam.inboundDateBegin=dateString[0];
        this.queryParam.inboundDateEnd=dateString[1];
      },
      searchReset(){
        this.queryParam = {
          supplier: null,
            itemGroup: null,
            item: this.$route.params.item,
            itemDescription: null,
            unitWasteWarehouseCodeId: null,
            freightSpace: null,
            productionTime: null,
            batch: null,
            expirationDate: null,
            inboundTime: null,
            librarySign: null,
            del_flag: 0
        },
          getAction(this.url.list,this.queryParam).then((res)=>{
            if(res.success){
              console.log("res.result----------",res.result)
              this.dataSource=res.result.records;
            }
          });
      },
      judgeRouterParam(){
        if (this.$route.params.item == null){
          this.$router.go(-1);
        }
      },
      initDictConfig(){
      },
      loadData(){
        getAction(this.url.list,this.queryParam).then((res)=>{
          console.log(res.result);
          if(res.success){
            this.dataSource=res.result.records;
          }
        });
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'processId',text:'流程表单号',dictCode:''})
        fieldList.push({type:'string',value:'supplier',text:'供应商',dictCode:''})
        fieldList.push({type:'string',value:'supplierDescription',text:'供应商描述',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'string',value:'itemGroup',text:'物料组',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'string',value:'item',text:'物料',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'string',value:'itemDescription',text:'物料描述',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'string',value:'unitMeasurement',text:'计量单位',dictCode:''})
        fieldList.push({type:'int',value:'amount',text:'数量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'price',text:'单价',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'rates',text:'金额',dictCode:''})
        fieldList.push({type:'string',value:'unitWasteWarehouseCodeId',text:'仓储地点',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'string',value:'freightSpace',text:'存储仓位',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'date',value:'productionTime',text:'生产时间'})
        fieldList.push({type:'String',value:'expirationDate',text:'保质期'})
        fieldList.push({type:'string',value:'batch',text:'批次',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'int',value:'arrivalNotice',text:'是否到货',dictCode:''})
        fieldList.push({type:'date',value:'inboundTime',text:'入库时间'})
        fieldList.push({type:'string',value:'librarySign',text:'入库人',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'int',value:'accountingAttributes',text:'核算属性',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>