<template>
  <div>
    <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.supplier"></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.supplierDescription"></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.materialGroup"></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.materialNumber" ></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.materialDescription"></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.theirTeam"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="10">
              <a-form-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-range-picker
                  style="width: 210px"
                  format="YYYY-MM-DD"
                  :value="createProductTime"
                  :placeholder="['开始时间', '结束时间']"
                  @change="onDateChange"
                />
              </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.expirationDate"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="入库时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-range-picker
                  style="width: 210px"
                  format="YYYY-MM-DD"
                  :value = "createInnerTime"
                  :placeholder="['开始时间', '结束时间']"
                  @change="onDateChangeinboundTime"
                />
              </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.materialsState"></a-input>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>


        <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
        <a-button type="primary" @click="searchReset" icon="reload">重置</a-button>
      </div>
      <!-- 查询区域-END -->

      <!-- 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-waste-materials-modal ref="modalForm" @ok="modalFormOk"></process-waste-materials-modal>
    </a-card>
  </div>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ProcessWasteMaterialsModal from '@views/wastematerials/modules/ProcessWasteMaterialsModal'
  import { httpAction, getAction } from '@/api/manage'
  import JDate from '@/components/jeecg/JDate.vue'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import ProcessWasteMaterialsList from '@views/wastematerials/ProcessWasteMaterialsList'
  import {filterDictTextByCache} from '@/components/dict/JDictSelectUtil'
  import { ajaxGetDictItems, getDictItemsFromCache } from '@api/api'

  export default {
    name: 'ProcessWasteMaterialsLists',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ProcessWasteMaterialsList,
      JDate,
      ProcessWasteMaterialsModal,
      JSuperQuery,
    },
    data () {
      return {
        descriptionId: this.$route.params.materialStorageId,
        queryParam:{
          supplier: null,
          supplierDescription: null,
          materialGroup : null,
          materialNumber : null,
          materialDescription: null,
          theirTeam: null,
          productionDate: null,
          expirationDate: null,
          storageTime: null,
          materialsState: null,
          merchandiseNewsId: this.$route.params.merchandiseNewsId,
          materialStorageId: this.$route.params.materialStorageId,
          descriptionId: null,
          del_flag: 0
        },

        createProductTime:[],
        createInnerTime:[],

        description: '账外物资库管理页面',
        dataSource:[],
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            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: 'materialStorageId'
          },
          {
            title:'库存仓位',
            align:"center",
            dataIndex: 'freightSpace'
          },
          {
            title:'计量单位',
            align:"center",
            dataIndex: 'materialsUnit'
          },
          {
            title:'数量',
            align:"center",
            dataIndex: 'materialQuantity'
          },
          {
            title:'单价(元)',
            align:"center",
            dataIndex: 'materialPrice'
          },
          {
            title:'金额(元)',
            align:"center",
            dataIndex: 'rates'
          },
          {
            title:'生产日期',
            align:"center",
            dataIndex: 'productionDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'保质期',
            align:"center",
            dataIndex: 'expirationDate'
          },
          {
            title:'入库时间',
            align:"center",
            dataIndex: 'storageTime'
          },
          {
            title:'入库人',
            align:"center",
            dataIndex: 'librarySign'
          },
          {
            title: '核算属性',
            align: "center",
            dataIndex: 'accountingAttributes_dictText',
          }
        ],
        url: {
          list: "/wastematerials/processWasteMaterials/lists",
          delete: "/wastematerials/processWasteMaterials/delete",
          deleteBatch: "/wastematerials/processWasteMaterials/deleteBatch",
          exportXlsUrl: "/wastematerials/processWasteMaterials/exportXls",
          importExcelUrl: "wastematerials/processWasteMaterials/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.merchandiseNewsId = this.$route.params.merchandiseNewsId;
        this.queryParam.materialStorageId = this.$route.params.materialStorageId;
        this.loadData()
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      onDateChange: function (value, dateString) {
        this.createProductTime = value;
        this.queryParam.productDateBegin=dateString[0];
        this.queryParam.productDateEnd=dateString[1];
      },
      onDateChangeinboundTime: function (value, dateString) {
        this.createInnerTime = value,
        this.queryParam.inboundDateBegin=dateString[0];
        this.queryParam.inboundDateEnd=dateString[1];
      },
      judgeRouterParam(){
        if (this.$route.params.merchandiseNewsId == null){
          this.$router.go(-1);
        }
      },
      initDictConfig(){
      },
      searchQuery(){
        getAction(this.url.list,this.queryParam).then((res)=>{
          if(res.success){
            // console.log("resultsearch ：")
            // console.log(res.result);
            // console.log(this.queryParam)
            this.dataSource=res.result.records;
          }
        });
      },
      searchReset(){
        this.createProductTime = [],
        this.createInnerTime = [],
        this.queryParam = {
            descriptionId: this.$route.params.descriptionId,
            del_flag: 0
        },
        getAction(this.url.list,this.queryParam).then((res)=>{
          if(res.success){
            // console.log("resultsearch ：")
            // console.log(res.result);
            // console.log(this.queryParam)
            this.dataSource=res.result.records;
          }
        });
      },
      loadData(){
        getAction(this.url.list,this.queryParam).then((res)=>{
          if(res.success){
            console.log("result ：")
            console.log(res.result)
            console.log(this.queryParam)
            this.dataSource=res.result.records;
          }
        });
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'supplier',text:'供应商',dictCode:''})
        fieldList.push({type:'string',value:'supplierDescription',text:'供应商描述',dictCode:''})
        fieldList.push({type:'string',value:'materialGroup',text:'物料组',dictCode:''})
        fieldList.push({type:'string',value:'materialNumber',text:'物料',dictCode:''})
        fieldList.push({type:'string',value:'materialDescription',text:'物料描述',dictCode:''})
        fieldList.push({type:'string',value:'materialStorageId',text:'库存位置',dictCode:''})
        fieldList.push({type:'string',value:'freightSpace',text:'库存仓位',dictCode:''})
        fieldList.push({type:'string',value:'materialsUnit',text:'计量单位',dictCode:''})
        fieldList.push({type:'int',value:'materialQuantity',text:'数量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'materialPrice',text:'单价',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'materialAmount',text:'金额',dictCode:''})
        fieldList.push({type:'date',value:'productionDate',text:'生产日期'})
        fieldList.push({type:'String',value:'expirationDate',text:'保质期'})
        fieldList.push({type:'date',value:'storageTime',text:'入库时间',dictCode:''})
        fieldList.push({type:'string',value:'librarySign',text:'入库人',dictCode:''})
        fieldList.push({type:'int',value:'accountingAttributes',text:'核算属性',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>