<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 :sm="6">-->
<!--            <a-form-item label="备件编号">-->
<!--              <a-input v-decorator="['code']" placeholder="请输入备件编号"  ></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :span="6">
            <a-form-item label="备件名称" >
              <a-input v-decorator="['name']" placeholder="请输入备件名称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="备件型号" >
              <a-input v-decorator="['typeId']" placeholder="请输入备件型号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
              <a-button style="margin-left: 8px" type="primary" @click="TextMethodNow">测试</a-button>
              </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 @click="handleTest" type="primary" >过欠压检测测试</a-button>-->
<!--      <a-button @click="handleTests" type="primary" >断网测试</a-button>-->
<!--      <a-button @click="handleTest6" type="primary" >温湿度</a-button>-->
<!--      <a-button @click="handleTest7" type="primary" >噪声</a-button>-->
<!--      <a-button @click="handleTest8" type="primary" >烟雾</a-button>-->
<!--      <a-button @click="handleTest9" type="primary" >缺相</a-button>-->
<!--      <a-button @click="handleTest10" type="primary" >不平衡度</a-button>-->
<!--      <a-button @click="handleTest11" type="primary" >功率</a-button>-->
<!--      <a-button @click="handleTest12" type="primary" >时长次数</a-button>-->
<!--      <a-button @click="handleTest13" type="primary" >电池电压</a-button>-->
<!--      <a-button @click="handleTest14" type="primary" >振动分析</a-button>-->
<!--      <a-button @click="handleTest15" type="primary" >开关机时间</a-button>-->
<!--      <a-button @click="handleTest16" type="primary" >未读异常</a-button>-->
<!--      <a-button @click="handleTest17" type="primary" >轴承分析测试</a-button>-->
<!--      <a-button @click="handleTest1" type="primary" >士翌启动</a-button>-->
<!--      <a-button @click="handleTest2" type="primary" icon="plus">士翌停止</a-button>-->
<!--      <a-button @click="handleTest3" type="primary" icon="plus">衡简启动</a-button>-->
<!--      <a-button @click="handleTest4" type="primary" icon="plus">衡简停止</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"> 批量操作 <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>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</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-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <bu-spare-part-modal ref="modalForm" @ok="modalFormOk"></bu-spare-part-modal>
  </a-card>
</template>

<script>

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

  export default {
    name: 'BuSparePartList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BuSparePartModal,
      JSuperQuery,
    },
    data () {
      return {
        description: '备品备件表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          // {
          //   title:'备件编号',
          //   align:"center",
          //   dataIndex: 'code'
          // },
          {
            title:'备件名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'备件型号',
            align:"center",
            dataIndex: 'typeId'
          },
          // {
          //   title:'备件类型',
          //   align:"center",
          //   dataIndex: 'classId_dictText'
          // },
          // {
          //   title:'供应商',
          //   align:"center",
          //   dataIndex: 'supplierId_dictText'
          // },
          {
            title:'开始时间',
            align:"center",
            dataIndex: 'minStock'
          },
          {
            title:'间隔时间（天）',
            align:"center",
            dataIndex: 'unit'
          },
          {
            title:'提醒信息',
            align:"center",
            dataIndex: 'remind'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/spare/buSparePart/list",
          delete: "/spare/buSparePart/delete",
          deleteBatch: "/spare/buSparePart/deleteBatch",
          exportXlsUrl: "/spare/buSparePart/exportXls",
          importExcelUrl: "/spare/buSparePart/importExcel",
          textMethodNow: "bigScreen/getTextMethodNow",

          testMethod: "/bigScreen/getFaultAnalysis",
          testMethod2: "/bigScreen/getGatewayOnline",
          testMethod6: "/bigScreen/getHumiture",
          testMethod7: "/bigScreen/getNoise",
          testMethod8: "/bigScreen/getSmoke",
          testMethod9: "/bigScreen/getPhase",
          testMethod10: "/bigScreen/textTable",
          testMethod11: "/bigScreen/getActivePower",
          testMethod12: "/bigScreen/getDeviceData",
          testMethod13: "/bigScreen/getBatteryVoltage",
          testMethod14: "/bigScreen/getFaultAnalysis",
          testMethod15: "/bigScreen/getOpenTime",
          testMethod16: "/bigScreen/getRemindStatus",
          testMethod17: "/bigScreen/getBearingAnalysis",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      TextMethodNow(){
        getActions(this.url.textMethodNow,'get').then(res => {
          console.log(res);
        })
      },
      handleTest(){
        let url = '/mqtt/syqt?deviceId=' + this.deviceName;;
        let param = {deviceName: "柴油机翻转架"};
        this.getTest(url,param);
        },
      handleTests(){
        let url = this.url.testMethod2;
        let param = {deviceName: "起重机"};
        this.getTest(url,param);
      },
      handleTest6(){
        let url = this.url.testMethod6;
        let param = {deviceName: "起重机"};
        this.getTest(url,param);
      },
      handleTest7(){
        let url = this.url.testMethod7;
        let param = {deviceName: "架车机"};
        this.getTest(url,param);
      },
      handleTest8(){
        let url = this.url.testMethod8;
        let param = {deviceName: "起重机"};
        this.getTest(url,param);
      },
      handleTest9(){
        let url = this.url.testMethod9;
        let param = {deviceName: "架车机"};
        this.getTest(url,param);
      },
      handleTest10(){
        let url = this.url.testMethod10;
        let param = {};
        this.getTest(url,param);
      },
      handleTest11(){
        let url = this.url.testMethod11;
        let param = {deviceName: "起重机"};
        this.getTest(url,param);
      },
      handleTest12(){
        let url = this.url.testMethod12;
        let param = {deviceName: "起重机"};
        this.getTest(url,param);
      },
      handleTest13(){
        let url = this.url.testMethod13;
        let param = {deviceName: "起重机"};
        this.getTest(url,param);
      },
      handleTest14(){
        let url = this.url.testMethod14;
        let param = {deviceName: "架车机"};
        this.getTest(url,param);
      },
      handleTest15(){
        let url = this.url.testMethod15;
        let param = {deviceName: "打风机"};
        this.getTest(url,param);
      },
      handleTest16(){
        let url = this.url.testMethod16;
        let param = {deviceName: "起重机"};
        this.getTest(url,param);
      },
      handleTest17(){
        let url = this.url.testMethod17;
        let param = {deviceName: "架车机"};
        this.getTest(url,param);
      },
      getTest(url,param){
        controlhttpAction(url,param,'get').then(res => {
          console.log(res);
        })
      },
      // handleTest1(){
      //   let url = '/mqtt/syq';
      //   controlhttpAction(url,{},'get').then((res)=>{
      //     if(res === true){
      //       this.$message.success("操作成功!");
      //     }else{
      //       this.$message.warning(res.msg);
      //     }
      //   }).finally(() => {
      //   })
      // },
      // handleTest2(){
      //   let url = '/mqtt/syqt';
      //   controlhttpAction(url,{},'get').then((res)=>{
      //     if(res === true){
      //       this.$message.success("操作成功!");
      //     }else{
      //       this.$message.warning(res.msg);
      //     }
      //   }).finally(() => {
      //   })
      // },
      // handleTest3(){
      //   let url = '/mqtt/hxml';
      //   controlhttpAction(url,{},'get').then((res)=>{
      //     if(res === true){
      //       this.$message.success("操作成功!");
      //     }else{
      //       this.$message.warning(res.msg);
      //     }
      //   }).finally(() => {
      //   })
      // },
      // handleTest4(){
      //   let url = '/mqtt/hxtz';
      //   controlhttpAction(url,{},'get').then((res)=>{
      //     if(res === true){
      //       this.$message.success("操作成功!");
      //     }else{
      //       this.$message.warning(res.msg);
      //     }
      //   }).finally(() => {
      //   })
      // },



    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>