<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="5" :sm="6">
            <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="5" :sm="6">
            <a-form-item label="计划状态">
              <a-select v-model="queryParam.planStatus" placeholder="请选择">
                <a-select-option value="1">下发计划</a-select-option>
                <a-select-option value="2">实行计划</a-select-option>
                <a-select-option value="3">完成计划</a-select-option>
                <a-select-option value="4">结束计划</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-item label="日期">-->
<!--              <a-range-picker :placeholder="['开始日期', '结束日期']" format="YYYY-MM-DD"-->
<!--                :value="dateValue" :mode="dateMode" @change="handleDate"/>-->
<!--            </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>
              </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">-->
<!--          <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 @click="handleDispatch(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-record-modal ref="modalForm" @ok="modalFormOk"></bu-check-record-modal>
<!--    <bu-check-record-dispatch-modal ref="dispatchModalForm" @ok="modalFormOk"></bu-check-record-dispatch-modal>-->
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BuCheckRecordModal from './modules/BuCheckRecordModal'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import JDate from '@/components/jeecg/JDate'
  import { getAction } from '@api/manage'
  import moment from 'moment'
  import BuCheckRecordDispatchModal from '@views/plan/modules/BuCheckRecordDispatchModal'

  export default {
    name: 'BuCheckRecordList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      BuCheckRecordModal,
      JSuperQuery,
      JDate,
      BuCheckRecordDispatchModal
    },
    data() {
      return {
        description: '检查记录表管理页面',
        queryParam: {
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '计划名称',
            align: "center",
            dataIndex: 'planId'
          },
          {
            title: '计划类型',
            align: "center",
            dataIndex: 'planType_dictText'
          },
          {
            title: '检查类型',
            align: "center",
            dataIndex: 'checkType_dictText'
          },
          {
            title: '设备名称',
            align: "center",
            dataIndex: 'deviceId_dictText'
          },
          {
            title: '计划创建时间',
            align: "center",
            dataIndex: 'planCreateTime',
          },
          {
            title: '计划状态',
            align: "center",
            dataIndex: 'planStatus_dictText'
          },
          {
            title: '检查人',
            align: "center",
            dataIndex: 'checkId_dictText'
          },
          {
            title: '检查人部门',
            align: "center",
            dataIndex: 'orgCode'
          },
          // {
          //   title:'检查项目',
          //   align:"center",
          //   dataIndex: 'checkItem'
          // },
          // {
          //   title:'检查方法',
          //   align:"center",
          //   dataIndex: 'checkMethod'
          // },
          {
            title: '计划内容',
            align: "center",
            dataIndex: 'planContent'
          },
          {
            title: '开始时间',
            align: "center",
            dataIndex: 'beginTime',
            customRender: function (text) {
              return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
            }
          },
          {
            title: '计划结束时间',
            align: "center",
            dataIndex: 'planEndTime',
            customRender: function (text) {
              return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
            }
          },
          {
            title: '结束时间',
            align: "center",
            dataIndex: 'endTime',
            customRender: function (text) {
              return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
            }
          },
//          {
//            title:'故障描述',
//            align:"center",
//            dataIndex: 'faultDes'
//          },
          {
            title: '检查记录',
            align: "center",
            dataIndex: 'checkRecord'
          },
          {
            title: '检查结果',
            align: "center",
            dataIndex: 'checkResult'
          },
          {
            title: '现场拍照',
            align: "center",
            dataIndex: 'img'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            fixed: "right",
            width: 147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/plan/buCheckRecord/list",
          select: "/plan/buCheckRecord/selectList",
          delete: "/plan/buCheckRecord/delete",
          deleteBatch: "/plan/buCheckRecord/deleteBatch",
          exportXlsUrl: "/plan/buCheckRecord/exportXls",
          importExcelUrl: "plan/buCheckRecord/importExcel",
        },
        dictOptions: {},
        superFieldList: [],
        dateValue:[],
        dateMode:['date','date'],
      }
    },
    created() {
      // this.getSuperFieldList();
        var startDate=new Date();
        var endDate=new Date();
        startDate.setMonth(endDate.getMonth()-1);
        this.dateValue=[moment(startDate),moment(endDate)];
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig() {
      },
      searchQuery1() {
        this.loadData1();
      },
      loadData1(arg) {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!")
          return
        }
        if (!this.dateValue.length) {
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        params.startDate=this.dateValue[0].format('YYYY-MM-DD HH:mm:ss');
        params.endDate=this.dateValue[1].format('YYYY-MM-DD HH:mm:ss');
        this.loading = true;
        getAction(this.url.selectList, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result;
            this.$nextTick(() => {
              this.initChart();
            })
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            }
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      // searchReset(){
      //   var startDate=new Date();
      //   var endDate=new Date();
      //   startDate.setMonth(endDate.getMonth()-1);
      //   this.dateValue=[moment(startDate),moment(endDate)];
      //   this.loadData();
      // },

      // getSuperFieldList() {
      //   let fieldList = [];
      //   fieldList.push({ type: 'string', value: 'planName', text: '计划名称', dictCode: '' })
      //   fieldList.push({ type: 'string', value: 'deviceId', text: '设备id', dictCode: '' })
      //   fieldList.push({ type: 'date', value: 'planCreateTime', text: '计划创建时间' })
      //   fieldList.push({ type: 'string', value: 'planStatus', text: '计划状态', dictCode: '' })
      //   fieldList.push({ type: 'string', value: 'checkId', text: '检查人id', dictCode: '' })
      //   fieldList.push({ type: 'date', value: 'beginTime', text: '开始时间' })
      //   fieldList.push({ type: 'date', value: 'endTime', text: '结束时间' })
      //   fieldList.push({ type: 'date', value: 'planEndTime', text: '计划结束时间' })
      //   fieldList.push({ type: 'string', value: 'faultDes', text: '故障描述', dictCode: '' })
      //   fieldList.push({ type: 'string', value: 'checkResult', text: '检查结果', dictCode: '' })
      //   fieldList.push({ type: 'string', value: 'repairRecord', text: '维修记录', dictCode: '' })
      //   fieldList.push({ type: 'string', value: 'img', text: '现场拍照', dictCode: '' })
      //   this.superFieldList = fieldList
      // },
      handleDate(value,mode){
        console.log(value);
        this.dateValue=value;
      },

      // handleDispatch(record){
      //   if(record.planStatus!=="1"){
      //     this.$message.warning("只有下发计划可以派工！");
      //     return;
      //   }
      //   this.$refs.dispatchmodalForm.dispatch(record);
      //   this.$refs.dispatchmodalForm.title = "派工";
      //   this.$refs.dispatchmodalForm.disableSubmit = false;
      // },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>