<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="船舶名称">
              <j-input placeholder="请输入船舶名称" v-model="queryParam.shipName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="故障时间">
              <a-range-picker
                style="width: 230px"
                v-model="faultTimeRange"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="onFaultTimeChange"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="预计修复时间">
              <a-range-picker
                style="width: 230px"
                v-model="reverseTimeRange"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="onReverseTimeChange"
              />
            </a-form-item>
          </a-col>
          <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-button type="primary" icon="download" @click="handleExportXls('故障报告')" style="margin-left: 8px">导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        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="uploadFile(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-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

        <span slot="faultCause" slot-scope="text">
          <j-ellipsis :value="text" :length="15" />
        </span>
        <span slot="detail" slot-scope="text">
          <j-ellipsis :value="text" :length="15" />
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JDate from '@/components/jeecg/JDate.vue'
  import JInput from '@/components/jeecg/JInput'
  import JEllipsis from "@/components/jeecg/JEllipsis"

  export default {
    name: "AdShipFaultReportList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDate,
      JInput,
      JEllipsis
    },
    data () {
      return {
        description: '故障报告管理页面',
        faultTimeRange: [],
        reverseTimeRange: [],
        // 表头
        columns: [
          {
            title:'船舶名称',
            align:"center",
            dataIndex: 'shipName'
          },
          {
            title:'联系方式',
            align:"center",
            dataIndex: 'contactWay'
          },
          {
            title:'故障原因',
            align:"center",
            dataIndex: 'faultCause',
            scopedSlots: {customRender: 'faultCause'},
          },
          {
            title:'故障详情',
            align:"center",
            dataIndex: 'detail',
            scopedSlots: {customRender: 'detail'},
          },
          {
            title:'故障时间',
            align:"center",
            dataIndex: 'faultTime'
          },
          {
            title:'预计修复时间',
            align:"center",
            dataIndex: 'reverseTime'
          },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   // fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/ad/adShipFaultReport/list",
          exportXlsUrl: "/ad/adShipFaultReport/exportXls",
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      onFaultTimeChange: function(value, dateString) {
        this.queryParam.faultTime_begin = dateString[0]
        this.queryParam.faultTime_end = dateString[1]
      },
      onReverseTimeChange: function(value, dateString) {
        this.queryParam.reverseTime_begin = dateString[0]
        this.queryParam.reverseTime_end = dateString[1]
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>