<!-- 维保 -->
<template>
    <div class='rcwb-list'>
        <div class='eq-list-top'>
            <el-input
                @keyup.enter.native='getList'
                @blur='getList'
                clearable
                placeholder='搜索设备名称编号'
                size='small'
                prefix-icon='el-icon-search'
                v-model='sbjc'
                style='margin-right:12px;width:192px;'
            ></el-input>
            <el-input
                @keyup.enter.native='getList'
                @blur='getList'
                clearable
                placeholder='搜索事项记录描述'
                size='small'
                prefix-icon='el-icon-search'
                v-model='matters'
                style='margin-right:12px;width:192px;'
            ></el-input>
            <el-input
                @keyup.enter.native='getList'
                @blur='getList'
                clearable
                placeholder='搜索任务编号'
                size='small'
                prefix-icon='el-icon-search'
                v-model='rwbh'
                style='margin-right:12px;width:192px;'
            ></el-input>
            <Select
                @change='getList'
                width='160'
                tipPlace='top'
                v-model='status'
                caption='任务状态：'
                v-if='status.length>=0'
                :selectdata='statusOption'
                :placeholder='""'
            ></Select>
            <Select
                @change='getList'
                width='160'
                tipPlace='top'
                v-model='ischange'
                caption='是否正常：'
                :selectdata='changeOption'
                :placeholder='""'
                style='margin-right:12px'
            ></Select>
            <div class='picker-box'>
                <span class='picker-span'>任务开始日期：</span>
                <el-date-picker
                    style='width:180px'
                    v-model='reportdate'
                    value-format='yyyyMMdd'
                    type='daterange'
                    @change='getList'
                    size='mini'
                    range-separator='-'
                    start-placeholder
                    end-placeholder
                ></el-date-picker>
            </div>
            <input-dialog :type='6' @confirm='confirm'></input-dialog>
        </div>
        <div ref='tableBox' style='height: calc(100% - 115px);'>
            <el-table :data='tableData' :max-height='tableMaxHeight' :border='true' style='width: 100%' @row-click='innerTable'>
                <el-table-column type='index' label='序号' width='60' :index='indexMethod'></el-table-column>
                <el-table-column prop label='设备名称' show-overflow-tooltip resizable min-width='150'>
                    <template slot-scope='{row}'>{{row.sbmc||'--'}}</template>
                </el-table-column>
                <el-table-column prop label='设备内码' :show-overflow-tooltip='true' width='80'>
                    <template slot-scope='{row}'>{{row.assetnum||'--'}}</template>
                </el-table-column>
                <el-table-column prop label='核心维保事项记录' :show-overflow-tooltip='true' min-width='150'>
                    <template slot-scope='{row}'>{{row.matters||'--'}}</template>
                </el-table-column>
                <el-table-column prop label='现场照片' :show-overflow-tooltip='true' width='80'>
                    <template slot-scope='{row}'>
                        <div
                            v-if='row.glsmsImage'
                            style='cursor:pointer;color: #0091ff;'
                            @click.stop='clickPic(row.glsmsImage)'
                        >{{row.glsmsImage.length+'张'}}</div>
                        <div v-else>{{'--'}}</div>
                    </template>
                </el-table-column>
                <el-table-column prop label='维保任务' align='center'>
                    <el-table-column prop label='任务编号' :show-overflow-tooltip='true'>
                        <template slot-scope='{row}'>
                            <div style='cursor:pointer;color: #0091ff;'>{{row.wb_gzglid||'--'}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column prop label='维保任务名称' :show-overflow-tooltip='true' min-width='340'>
                        <template slot-scope='{row}'>{{row.wbrwmc || '--'}}</template>
                    </el-table-column>
                    <el-table-column prop label='任务状态' :show-overflow-tooltip='true'>
                        <template slot-scope='{row}'>{{row.status||'--'}}</template>
                    </el-table-column>
                    <el-table-column prop label='开始时间' :show-overflow-tooltip='true' width='130'>
                        <template slot-scope='{row}'>{{row.sjkssj?formatter(row.sjkssj):'--'}}</template>
                    </el-table-column>
                    <el-table-column prop label='完成时间' :show-overflow-tooltip='true' width='130'>
                        <template slot-scope='{row}'>{{row.sjwcsj?formatter(row.sjwcsj):'--'}}</template>
                    </el-table-column>
                    <el-table-column prop label='执行耗时（天）' :show-overflow-tooltip='true' min-width='130' :sortable='true'>
                        <template slot-scope='{row}'>{{row.sjcxsjt||'--'}}</template>
                    </el-table-column>
                </el-table-column>
                <el-table-column prop label='是否正常' :show-overflow-tooltip='true' width='80'>
                    <template slot-scope='{row}'>{{row.zt||'--'}}</template>
                </el-table-column>
                <el-table-column prop label='异常工单' align='center'>
                    <el-table-column prop label='异常工单编号' :show-overflow-tooltip='true' min-width='110'>
                        <template slot-scope='{row}'>
                            <div @click='ycgd(row)'>{{row.wonum||'--'}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column prop label='描述' :show-overflow-tooltip='true' width='900'>
                        <template slot-scope='{row}'>{{row.description||'--'}}</template>
                    </el-table-column>
                    <el-table-column prop label='填报时间' :show-overflow-tooltip='true' width='130'>
                        <template slot-scope='{row}'>{{row.reportdate?formatter(row.reportdate):'--'}}</template>
                    </el-table-column>
                    <el-table-column prop label='验收时间' :show-overflow-tooltip='true' width='130'>
                        <template slot-scope='{row}'>{{row.sjjssj?formatter(row.sjjssj):'--'}}</template>
                    </el-table-column>
                </el-table-column>
            </el-table>
        </div>
        <div class='foot'>
            <el-pagination
                background
                layout='prev, pager, next'
                :total='total'
                :page-size='size'
                @prev-click='pageChanged'
                @next-click='pageChanged'
                @current-change='pageChanged'
            ></el-pagination>
            <pic-large :imgUrl='imgUrl' ref='picLargeOpen'></pic-large>
        </div>
    </div>
</template>
<script>
import { queryWbsms } from '@/api/equipmentList.js'
import { mapGetters } from 'vuex'
import { Select } from 'meri-design'
import inputDialog from './inputDIalog'
import { formatterTime, number_format } from '@/utils/format.js'
export default {
    components: { Select, inputDialog },
    data() {
        return {
            tableData: [],
            total: 0,
            currentPage: 1,
            size: 10,
            // sjjssj: '',
            reportdate: '',
            ischange: '2',
            sbjc: '',
            formatterTime,
            number_format,
            changeOption: [
                {
                    id: '2',
                    name: '全部',
                },
                {
                    id: '1',
                    name: '是',
                },
                {
                    id: ' 0',
                    name: '否',
                },
            ],
            statusOption: [],
            status: '',
            rwbh: '',
            imgUrl: [],
            matters: '',
            bill: '',
            ycgdtbsj: '',
            complete: '',
            ycgdyssj: '',
            tableMaxHeight: 0,
        }
    },
    props: ['smsxt', 'major', 'diff', 'tabLabel'],
    computed: {
        ...mapGetters(['floorSelect']),
    },
    methods: {
        //序号的方法
        indexMethod(index) {
            return (this.currentPage - 1) * this.size + index + 1
        },
        //工单详情
        innerTable(row) {
            console.log(row)
            if (row.apptype == '外委' || row.apptype == '自维') {
                if (row.wb_gzglid) {
                    window.open(`http://gcgl.wanda.cn/maximo/ui/?event=loadapp&value=WB_GZGL&uniqueid=${row.wb_gzglid}`)
                }
            } else if (row.apptype == '安全维保') {
                window.open(`http://gcgl.wanda.cn/maximo/ui/?event=loadapp&value=AQ_WB_GZGL&uniqueid=${row.wb_gzglid}`)
            }
        },
        // 工单
        ycgd(row) {
            if (row.apptype == '外委' || row.apptype == '自维') {
                if (row.wb_gzglid) {
                    window.open(`http://gcgl.wanda.cn/maximo/ui/?event=loadapp&value=WB_GZGL&uniqueid=${row.wb_gzglid}`)
                }
            } else if (row.apptype == '安全维保') {
                window.open(`http://gcgl.wanda.cn/maximo/ui/?event=loadapp&value=WB_GZGL&uniqueid=${row.wb_gzglid}`)
            }
        },
        //多余输入框监听
        confirm(complete, bill, ycgdtbsj, ycgdyssj) {
            this.complete = complete
            this.bill = bill
            this.ycgdtbsj = ycgdtbsj
            this.ycgdyssj = ycgdyssj
            this.getList()
        },
        pageChanged(page) {
            this.currentPage = page
            this.getList()
        },
        getList() {
            let getParams = {
                data: {
                    smsxt: this.smsxt,
                    diff: this.diff,
                    plazaId: this.$store.state.plazaId,
                    page: this.currentPage,
                    size: this.size,
                },
            }
            //下拉
            if (this.ischange && this.ischange != 2) {
                // getParams.data.ischangepj = this.ischange
                getParams.data.ismodel = this.ischange
            }
            //工单填报时间
            if (this.ycgdtbsj) {
                getParams.data.sjjssjStartDate = this.ycgdtbsj[0] + '000000'
                getParams.data.sjjssjEndDate = this.ycgdtbsj[1] + '000000'
            }
            //工单验收时间
            if (this.ycgdyssj) {
                getParams.data.reportdateStartDate = this.ycgdyssj[0] + '000000'
                getParams.data.reportdateEndDate = this.ycgdyssj[1] + '000000'
            }
            //任务开始时间
            if (this.reportdate) {
                getParams.data.reportdate = this.reportdate[0] + '000000'
                getParams.data.reportdate = this.reportdate[1] + '000000'
            }
            //任务完成时间
            if (this.complete) {
                getParams.data.reportdateStartDate = this.complete[0] + '000000'
                getParams.data.reportdateEndDate = this.complete[1] + '000000'
            }
            //输入框
            getParams.data.keyword = ''
            if (this.sbjc) {
                getParams.data.keyword += `${this.sbjc}:sbmc,assetnum;`
            }
            if (this.matters) {
                getParams.data.keyword += `${this.matters}:description,matters;`
            }
            if (this.gzglid) {
                getParams.data.keyword += `${this.gzglid}:wb_gzglid;`
            }
            if (getParams.data.keyword == '') {
                delete getParams.data.keyword
            }
            queryWbsms(getParams).then((res) => {
                this.tableData = res.data || []
                this.total = res.count
            })
        },
        clickPic(row) {
            this.imgUrl = []
            if (row) {
                row.forEach((el) => {
                    let obj = {
                        name: el.description,
                        url: el.url,
                    }
                    this.imgUrl.push(obj)
                })
            }
            this.$refs.picLargeOpen.open(this.imgUrl)
        },
    },
    watch: {
        diff(newV, oldV) {
            if (newV !== oldV) {
                this.getList()
            }
        },
        tabLabel(newV, oldV) {
            if (newV !== oldV) {
                // this.tabFind()
                this.getList()
                this.$nextTick(() => {
                    // 页面渲染完成后的回调
                    this.tableMaxHeight = this.$refs.tableBox.offsetHeight
                })
            }
        },
        ischange() {
            this.getList()
        },
    },
    mounted() {
        this.getList()
        this.$nextTick(() => {
            // 页面渲染完成后的回调
            this.tableMaxHeight = this.$refs.tableBox.offsetHeight
        })
    },
}
</script>
<style lang="less" scoped>
.rcwb-list {
    .eq-list-top {
        display: flex;
        margin-bottom: 12px;
        .picker-box {
            display: flex;
            align-items: center;
            background: #fff;
            padding: 0 6px;
            border: 1px solid #dcdfe6;
            border-radius: 4px;
            height: 32px;
            box-sizing: border-box;
            margin-right: 12px;
            .picker-span {
                margin-right: 6px;
                color: rgba(0, 0, 0, 0.65);
            }
        }
    }
    td {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .foot {
        height: 32px;
        display: flex;
        justify-content: flex-end;
        margin-top: 28px;
    }
}
</style>
<style lang="less" >
.rcwb-list {
    .picker-box {
        .el-input__inner {
            border: none;
        }
        .el-range-editor.el-input__inner {
            padding: 3px 0px;
        }
        .el-icon-date {
            display: none;
        }
        .el-range__close-icon {
            position: absolute;
            right: 0px;
            top: 2px;
        }
        .el-range-editor--mini .el-range-input {
            font-size: 14px;
            color: rgb(31, 36, 41);
        }
    }
    /deep/.el-table td {
        cursor: pointer;
    }
}
</style>