<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.materialName"/>
            </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="createScrapTime"
                :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.descriptionId"/>
            </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.affiliation"/>
            </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.depositary" dict=",,"/>
              </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.createBy" dict=",,"/>
            </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-button type="primary" icon="download" @click="handleExportXls('废旧物资库表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button @click="handleInto" type="primary">电缆</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-waste-modal ref="modalForm" @ok="modalFormOk"></process-waste-modal>
  </a-card>
</template>

<script>

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

  export default {
    name: 'ProcessWasteList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDate,
      JSearchSelectTag,
      ProcessWasteModal,
      JSuperQuery,
      ProcessWasteListCable,
    },
    data () {
      return {
        createScrapTime: [],
        description: '废旧物资库表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'物料码',
            align:"center",
            dataIndex: 'descriptionId'
          },
          {
            title:'品牌',
            align:"center",
            dataIndex: 'brand'
          },
          {
            title:'名称',
            align:"center",
            dataIndex: 'materialName'
          },
          {
            title:'型号规格',
            align:"center",
            dataIndex: 'typeSpecification'
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'unit'
          },
          {
            title:'数量',
            align:"center",
            dataIndex: 'number'
          },
          {
            title:'存放地点',
            align:"center",
            dataIndex: 'depositary'
          },
          {
            title:'报废原因',
            align:"center",
            dataIndex: 'scrappedBecause'
          },
          {
            title:'所属单位',
            align:"center",
            dataIndex: 'affiliation'
          },
          {
            title:'报废日期',
            align:"center",
            dataIndex: 'scrapDate',
          }
        ],
        url: {
          list: "/waste/processWaste/list",
          delete: "/waste/processWaste/delete",
          deleteBatch: "/waste/processWaste/deleteBatch",
          exportXlsUrl: "/waste/processWaste/exportXls",
          importExcelUrl: "waste/processWaste/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        labelCol: {
          xs: { span: 4 },
          sm: { span: 4 },
        },
        wrapperCol: {
          xs: { span: 20 },
          sm: { span: 20 },
        },
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      searchReset(){
        this.createScrapTime = []
        getAction(this.url.list).then((res)=>{
          if(res.success){
            this.dataSource=res.result.records;
          }
        });
      },
      handleInto() {
        this.$router.push({name:'src-views-waste-ProcessWasteListCable'})
      },
      onDateChange: function (value, dateString) {
        this.createScrapTime = value;
        this.queryParam.scrapDateBegin=dateString[0];
        this.queryParam.scrapDateEnd=dateString[1];
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'sel_search',value:'createBy',text:'创建人',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'sel_search',value:'descriptionId',text:'物料码',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'string',value:'brand',text:'品牌',dictCode:''})
        fieldList.push({type:'sel_search',value:'materialName',text:'名称',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'string',value:'typeSpecification',text:'型号规格',dictCode:''})
        fieldList.push({type:'sel_search',value:'unit',text:'单位',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'int',value:'number',text:'数量',dictCode:''})
        fieldList.push({type:'sel_search',value:'depositary',text:'存放位置',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'string',value:'scrappedBecause',text:'报废原因',dictCode:''})
        fieldList.push({type:'sel_search',value:'affiliation',text:'所属单位',dictTable:'', dictText:'', dictCode:''})
        fieldList.push({type:'date',value:'scrapDate',text:'报废日期'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>