<template>
<a-row :gutter="10">
<a-col :md="leftColMd" :sm="24" style="margin-bottom: 20px">
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="5" :sm="7">
            <a-form-item label="设备编号">
              <a-input placeholder="请输入设备编号" v-model="queryParam.deviceCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="7">
            <a-form-item label="设备类型">
              <a-select placeholder="请选择设备类型"  v-model="queryParam.deviceTypeId">
                <a-select-option v-for="d in deviceTypes" :key="d.id" :value="d.id" >
                  {{d.typeName}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="7">
            <a-form-item label="设备名称">
              <a-input placeholder="请输入设备名称" v-model="queryParam.deviceName"></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :md="6" :sm="8">-->
<!--            <a-form-item label="运行状态">-->
<!--              <j-dict-select-tag placeholder="请选择运行状态" dictCode="device_use"-->
<!--                                 v-model="queryParam.deviceUse"/>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :md="6" :sm="8">-->
<!--            <a-form-item label="设备类型">-->
<!--              <j-dict-select-tag v-model="queryParam.deviceType" placeholder="请选择设备类型" dict-code="device_Type" ></j-dict-select-tag>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :md="6" :sm="8">-->
<!--            <a-form-item label="使用状态">-->
<!--              <j-dict-select-tag v-model="queryParam.useStatus" placeholder="请选择使用状态" dict-code="use_status" ></j-dict-select-tag>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :md="6" :sm="8">-->
<!--            <a-form-item label="设备状态">-->
<!--              <a-select v-model="queryParam.deviceStatus" placeholder="请选择设备状态">-->
<!--                <a-select-option value="1">正常</a-select-option>-->
<!--                <a-select-option value="2">故障</a-select-option>-->
<!--              </a-select>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :md="5" :sm="7">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" >查询</a-button>
              <a-button @click="searchReset"  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" v-has="'device:add'">新增</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>
      <!-- 高级查询区域 -->
<!--      <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" v-has="'device:muldel'"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>
    <div v-show="this.qrcodeStatus">
      <img :src="this.qrCodeBase64" alt="QR Code" />
    </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="imgSlot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getImgView(text)" />
          </div>
        </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="handleArch(record)">一机一档</a>
          <a-divider type="vertical" />

          <a @click="handleEdit(record)" v-has="'device:edit'">编辑</a>
          <a-divider type="vertical" />
          <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 @click="handleAddPart(record)">添加子项</a>-->
<!--              </a-menu-item>-->
<!--              <a-menu-item>-->
<!--                <a @click="handleGenerate(record)">二维码生成</a>-->
<!--              </a-menu-item>-->
              <a-menu-item v-has="'device:del'">
                <a-popconfirm title="确定删除吗?" :overlayStyle="{width:'144px'}" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <bu-device-modal ref="modalForm" @ok="modalFormOk"></bu-device-modal>
    <DeviceArchives :device-id="currentDeviceId" :visible="avisible" @close="avisible = false"/>
<!--    <part-modal ref="partModalForm" @ok="modalFormOk"></part-modal>-->
  </a-card>
  </a-col>
</a-row>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BuDeviceModal from './modules/BuDeviceModal'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import SelectUserModal from '../system/modules/SelectUserModal'
  import DeviceOnlineModal from './modules/BuDeviceOnlineModal'
  import {getAction} from "../../api/manage";
  import PartModal from '@views/device/modules/PartModal.vue'
  import DeviceArchives from '@views/device/component/DeviceArchives/DeviceArchives.vue'

  export default {
    name: 'BuDeviceList',
    mixins :[JeecgListMixin, mixinDevice],
    components: {
      DeviceArchives,
      BuDeviceModal,
      JSuperQuery,
      DeviceOnlineModal,
      SelectUserModal,
    },
    data () {
      return {
        model1: {},
        model2: {},
        currentDeviceId:'',
        rightcolval:0,
        queryParam1: {},
        queryParamOnline: {},
        selectedRowKeys1: [],
        selectedRowKeysOnline: [],
        selectionRows1: [],
        selectionRows2: [],
        dataSourceOnline: [],
        loadingOnline:false,
        description: '设备信息表管理页面',
        ipaginationOnline: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        // 高级查询参数
        superQueryParamsOnline: '',
        // 高级查询拼接条件
        superQueryMatchTypeOnline: 'and',
        url: {
          list: "/device/buDevice/list",
          delete: "/device/buDevice/delete",
          deleteBatch: "/device/buDevice/deleteBatch",
          exportXlsUrl: "/device/buDevice/exportXls",
          importExcelUrl: "device/buDevice/importExcel",
          listOnline: "/device/buDeviceOnline/listByDevice",
          addDeviceOnline: '/device/buDeviceOnline/add',
          qrCode:"/qrcode/getQRCodeBase64"
        },
        dictOptions:{},
        superFieldList:[],
        isorterOnline: {
          column: 'createTime',
          order: 'desc'
        },
        filtersOnline: {
          col: "col.dataIndex !== 'deviceId' "
        },
        qrCodeBase64:"",
        qrcodeStatus:false,
        jsonString: '',
        deviceTypes:[],
        avisible: false,
      }
    },
    created() {
      this.getSuperFieldList();
      this.loadAllDeviceType();
    // this.columnsOnline = this.columnsOnline.filter(col=>col.dataIndex!=='deviceId')
    },
    computed: {
        columns(){
        return [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'设备编号',
            align:"center",
            dataIndex: 'deviceCode'
          },
          {
            title:'设备类型',
            align:"center",
            dataIndex: 'deviceTypeId_dictText'
          },
          {
            title:'设备名称',
            align:"center",
            dataIndex: 'deviceName'
          },
          {
            title: '图片',
            align: "center",
            width: 80,
            dataIndex: 'img',
            scopedSlots: {customRender: "imgSlot"}
          },
          {
            title:'规格型号',
            align:"center",
            dataIndex: 'typeId'
          },
          // {
          //   title:'运行状态',
          //   align:"center",
          //   dataIndex: 'deviceUse_dictText'
          // },
          // {
          //   title:'使用状态',
          //   align:"center",
          //   dataIndex: 'useStatus_dictText'
          // },
          // {
          //   title:'设备状态',
          //   align:"center",
          //   dataIndex: 'deviceStatus_dictText'
          // },
          // {
          //   title:'状态改变原因',
          //   align:"center",
          //   dataIndex: 'statusChange'
          // },
          {
            title:'设备用途',
            align:"center",
            dataIndex: 'usageId'
          },
          // {
          //   title:'安装时间',
          //   align:"center",
          //   dataIndex: 'setupTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          // {
          //   title:'负责人',
          //   align:"center",
          //   dataIndex: 'directorId_dictText'
          // },
          // {
          //   title:'包机人',
          //   align:"center",
          //   dataIndex: 'userJi_dictText'
          // },
          // {
          //   title:'包修人',
          //   align:"center",
          //   dataIndex: 'userXiu_dictText'
          // },
          {
            title:'供应商',
            align:"center",
            dataIndex: 'supplierId_dictText'
          },
          {
            title:'所在位置',
            align:"center",
            dataIndex: 'location_dictText'
          },
          {
            title:'启用时间',
            align:"center",
            dataIndex: 'enableTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          // {
          //   title: '所属检修线',
          //   align: "center",
          //   dataIndex: 'repairLine'
          // },
          // {
          //   title:'图片',
          //   align:"center",
          //   dataIndex: 'img',
          //   scopedSlots: {customRender: "imgSlot"}
          // },
          // {
          //   title:'二维码',
          //   align:"center",
          //   dataIndex: 'code',
          //   scopedSlots: {customRender: "imgSlot"}
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ]
      },
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      leftColMd() {
        return this.selectedRowKeys1.length === 0 ? 24 : 12
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'deviceCode',text:'设备编号',dictCode:''})
        fieldList.push({type:'string',value:'deviceName',text:'设备名称',dictCode:''})
        fieldList.push({type:'string',value:'typeId',text:'规格型号',dictCode:''})
        fieldList.push({type:'string',value:'deviceUse',text:'运行状态',dictCode:''})
        fieldList.push({type:'string',value:'usageId',text:'设备用途',dictCode:''})
        fieldList.push({type:'date',value:'setupTime',text:'安装时间'})
        fieldList.push({type:'string',value:'directorId',text:'负责人id',dictCode:''})
        fieldList.push({type:'string',value:'supplierId',text:'供应商id',dictCode:''})
        fieldList.push({type:'string',value:'location',text:'安装地点',dictCode:''})
        fieldList.push({type:'date',value:'enableTime',text:'启用时间'})
        fieldList.push({type:'string',value:'userJi',text:'包机人',dictCode:''})
        fieldList.push({type:'string',value:'userXiu',text:'包修人',dictCode:''})
        this.superFieldList = fieldList
      },
      loadAllDeviceType() {
        getAction("/device/buDeviceType/list/all", {calss: '1'}).then((res) => {
          if (res.success) {
            this.deviceTypes = res.result
          } else {
            this.$message.error(res.message)
          }
        })
      },
      handleArch(record){
        this.currentDeviceId = record.id;
        this.avisible = true;
      },
      // handleAddPart(record) {
      //   this.$refs.partModalForm.add(record);
      //   this.$refs.partModalForm.title = "新增";
      //   this.$refs.partModalForm.disableSubmit = false;
      // },
      // handleEditPart(record) {
      //   this.$refs.partModalForm.edit(record);
      //   this.$refs.partModalForm.title = "编辑";
      //   this.$refs.partModalForm.disableSubmit = false;
      // }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>