<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 :md="6" :sm="8">
            <a-form-item label="是否执行">
              <a-select v-model="queryParam.isExecute" 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="6" :sm="8">
            <a-form-item label="计划类型">
              <a-select v-model="queryParam.planType" placeholder="请选择">
                <a-select-option value="0">日计划</a-select-option>
                <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="6" :sm="8">
            <a-form-item label="检查类型">
              <a-select v-model="queryParam.checkType" placeholder="请选择">
                <a-select-option value="0">巡检</a-select-option>
                <a-select-option value="1">点检</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <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-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" >
<!--                @click="handleMenuClick">-->
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
<!--          <a-menu-item key="2">-->
<!--            <a-icon type="lock" @click="handleIssue(record)"/>下发</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 @click="handleIssue(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-check-plan-modal ref="modalForm" @ok="modalFormOk"></bu-check-plan-modal>
    <bu-check-plan-issue-modal ref="issuemodalForm" @ok="modalFormOk"></bu-check-plan-issue-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BuCheckPlanModal from './modules/BuCheckPlanModal'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import BuCheckPlanIssueModal from '@views/plan/modules/BuCheckPlanIssueModal'

  export default {
    name: 'BuCheckPlanList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BuCheckPlanIssueModal,
      BuCheckPlanModal,
      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: 'planName'
          },
          {
            title:'计划类型',
            align:"center",
            dataIndex: 'planType_dictText'
          },
          {
            title:'检查类型',
            align:"center",
            dataIndex: 'checkType_dictText'
          },
          {
            title:'检查设备',
            align:"center",
            dataIndex: 'deviceRange_dictText'
          },
          {
            title:'是否执行',
            align:"center",
            dataIndex: 'isExecute_dictText'
          },
          {
            title:'计划内容',
            align:"center",
            dataIndex: 'planContent'
          },
          // {
          //   title:'发起人',
          //   align:"center",
          //   dataIndex: 'initiateId_dictText'
          // },
          {
            title:'开始时间',
            align:"center",
            dataIndex: 'startTime',
          },
          // {
          //   title:'计划结束时间',
          //   align:"center",
          //   dataIndex: 'planEndTime',
          // },
          {
            title:'执行人',
            align:"center",
            dataIndex: 'performId_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/plan/buCheckPlan/list",
          delete: "/plan/buCheckPlan/delete",
          deleteBatch: "/plan/buCheckPlan/deleteBatch",
          exportXlsUrl: "/plan/buCheckPlan/exportXls",
          importExcelUrl: "plan/buCheckPlan/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'planName',text:'计划名称',dictCode:''})
        fieldList.push({type:'string',value:'planType',text:'计划类型',dictCode:''})
        fieldList.push({type:'string',value:'deviceRange',text:'检查设备',dictCode:''})
        fieldList.push({type:'string',value:'planStatus',text:'计划状态',dictCode:''})
        fieldList.push({type:'string',value:'planContent',text:'计划内容',dictCode:''})
        fieldList.push({type:'string',value:'initiateId',text:'发起人id',dictCode:''})
        fieldList.push({type:'date',value:'startTime',text:'开始时间'})
        // fieldList.push({type:'date',value:'planEndTime',text:'结束时间'})
        fieldList.push({type:'string',value:'performId',text:'执行人id',dictCode:''})
        this.superFieldList = fieldList
      },
      handleAdd: function () {
        this.$refs.modalForm.add();
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.disableSubmit = false;
      },
      handleIssue(record){
        if(record.isExecute!=="1"){
          this.$message.warning("只有可执行计划才能下发！");
          return;
        }
          this.$refs.issuemodalForm.edit(record);
          this.$refs.issuemodalForm.title = "下发";
          this.$refs.issuemodalForm.disableSubmit = false;
      },
    //   handleMenuClick(e) {
    //   if (e.key == 1) {
    //     this.batchDel();
    //   } else if (e.key == 2) {
    //     this.handleIssue(record);
    //   }
    // },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>