<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.coding"></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.supplierName"></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.rank"></a-input>-->
                <a-select v-model="queryParam.rank" placeholder="请选择级别"  @mouseenter="getRake" >
                  <a-select-option v-for="(item,index) in bigId" :key="index" :value="item.rank">{{item.rank}}</a-select-option>
                </a-select>
<!--                <a-auto-complete-->
<!--                  :data-source="bigId"-->
<!--                  style="width: 200px"-->
<!--                  placeholder="请选择级"-->
<!--                  :filter-option="filterOption"-->
<!--                />-->

              </a-form-item>
            </a-col>
<!--          <template v-if="toggleSearchStatus">-->
<!--          </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-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('供应商信息')">导出</a-button>
      <a-button type="primary" icon="download" @click="downloadFile('http://182.92.73.21:9090/file/temp/供应商名称及编码_1668003417087.xlsx')">供应商导入模板</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-upload-->
<!--        name="file"-->
<!--        :multiple="false"-->
<!--        :action="minioUploadAction"-->
<!--        :headers="tokenHeader"-->
<!--        :showUploadList="false"-->
<!--        :beforeUpload="beforeUpload"-->
<!--        @change="handleChange">-->
<!--        <a-button>-->
<!--          <a-icon type="upload"/>-->
<!--          MINIO上传签名照-->
<!--        </a-button>-->
<!--      </a-upload>-->

      <!-- 高级查询区域 -->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <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="{ y:460}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @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>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
<!--          <a  @click="handleDelete(record.id)">删除</a>-->
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
<!--              <a-menu-item>-->
<!--                <a @click="handleDetail(record)">详情</a>-->
<!--              </a-menu-item>-->
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

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

<script>

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

  export default {
    name: 'ProcessSupplierList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ProcessSupplierModal,
      JSuperQuery,
    },
    data () {
      return {
        fileList: [],
        bigId:[],
        headers: {
          authorization: 'authorization-text',
        },
        description: '供应商信息管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'供应商编码',
            align:"center",
            dataIndex: 'coding'
          },
          {
            title:'供应商名称',
            align:"center",
            dataIndex: 'supplierName'
          },
          {
            title:'级别',
            align:"center",
            dataIndex: 'rank',
            // customRender:function (t,r,index) {
            //   // console.log(t,r,index);
            //   let name = '';
            //   if(r.rank === 0){
            //     name = "一级物资供应商";
            //   }else if(r.rank === 1){
            //     name = "非集中采购物资供应商";
            //   }
            //   return name;
            // }
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'state',
            customRender:function (t,r,index) {
              // console.log(t,r,index);
              let name = '';
              if(r.state === 0){
                name = "正常";
              }else if(r.state === 1){
                name = "停用";
              }
              return name;
            }
          },
          // {
          //   title:'删除标志',
          //   align:"center",
          //   dataIndex: 'delFlag'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/supplier/processSupplier/list",
          delete: "/supplier/processSupplier/delete",
          deleteBatch: "/supplier/processSupplier/deleteBatch",
          exportXlsUrl: "/supplier/processSupplier/exportXls",
          importExcelUrl: "supplier/processSupplier/importExcel",
          minioUpload: "/sys/upload/uploadMinio",
          supplierRake: "/supplier/processSupplier/supplierRake",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    // this.getRake();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      minioUploadAction() {
        return window._CONFIG['domianURL'] + this.url.minioUpload;
      },
    },

    methods: {
      beforeUpload(file) {
        var fileType = file.type;
        if (fileType === 'image') {
          if (fileType.indexOf('image') < 0) {
            this.$message.warning('请上传图片');
            return false;
          }
        } else if (fileType === 'file') {
          if (fileType.indexOf('image') >= 0) {
            this.$message.warning('请上传文件');
            return false;
          }
        }
        return true
      },
      handleChange(info) {
        if (info.file.status === 'done') {
          if (info.file.response.success) {
            this.loadData()
            this.$message.success(`${info.file.name} 上传成功!`);
          } else {
            this.$message.error(`${info.file.response.message}`);
          }
        } else if (info.file.status === 'error') {
          this.$message.error(`${info.file.response.message}`);
        }
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'coding',text:'供应商编码',dictCode:''})
        fieldList.push({type:'string',value:'supplierName',text:'供应商名称',dictCode:''})
        fieldList.push({type:'int',value:'rank',text:'级别',dictCode:''})
        fieldList.push({type:'int',value:'state',text:'状态',dictCode:''})
        fieldList.push({type:'int',value:'delFlag',text:'删除标志',dictCode:''})
        this.superFieldList = fieldList;

      },
      getRake(){
        this.bigId = [];
        getAction(this.url.supplierRake,null).then((res)=>{
          if(res.success){
            console.log(res.result);
            this.bigId =  res.result;
          }
        });
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>