<!-- 维保 -->
<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:190px'
                    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'>
            <el-table :data='tableData' :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='434'>
                    <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='225'>
                    <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='360'>
                        <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?formatterTime(row.sjkssj):'--'}}</template>
                    </el-table-column>
                    <el-table-column prop label='完成时间' :show-overflow-tooltip='true' width='130'>
                        <template slot-scope='{row}'>{{row.sjwcsj?formatterTime(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?formatterTime(row.reportdate):'--'}}</template>
                    </el-table-column>
                    <el-table-column prop label='验收时间' :show-overflow-tooltip='true' width='130'>
                        <template slot-scope='{row}'>{{row.sjjssj?formatterTime(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 { queryWb } from '@/api/room.js'
import { mapGetters } from 'vuex'
import { Select } from 'meri-design'
import inputDialog from './inputDIalog'
import { formatterTime, number_format } from '@/utils/format.js'
import { querySelect } from '@/api/public.js'
export default {
    components: { Select, inputDialog },
    data() {
        return {
            tableData: [],
            total: 0,
            currentPage: 1,
            reportdate: '',
            ischange: '全部',
            sbjc: '',
            formatterTime,
            number_format,
            changeOption: [
                {
                    id: '2',
                    name: '全部',
                },
                {
                    id: '1',
                    name: '是',
                },
                {
                    id: ' 0',
                    name: '否',
                },
            ],
            statusOption: [],
            status: '全部',
            rwbh: '',
            imgUrl: [],
            allArr: [
                {
                    id: '全部',
                    name: '全部',
                },
            ],
            matters: '',
            bill: '',
            ycgdtbsj: '',
            complete: '',
            ycgdyssj: '',
        }
    },
    props: ['smsxt', 'diff', 'tabLabel', 'size', 'assetnum'],
    computed: {
        ...mapGetters(['floorSelect', 'plazaId']),
    },
    methods: {
        //序号的方法
        indexMethod(index) {
            return (this.currentPage - 1) * this.size + index + 1
        },
        //工单详情
        innerTable(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()
        },
        // 下拉框数据
        changeSelect() {
            this.department = []
            let postParams = [
                {
                    columnName: { status: 'status', zt: 'zt' },
                    tableName: 'sms_wbzy',
                },
            ]
            let data = {
                plazaId: this.plazaId,
            }
            if(this.smsxt!='1008'){
                data.onlyMainAsset = true
            }
            querySelect({ data, postParams }).then((res) => {
                let status = [],
                    zt = [],
                    arr = [],
                    arr1 = []

                status = res.data.data.sms_wbzy.status ? res.data.data.sms_wbzy.status : []
                zt = res.data.data.sms_wbzy.zt ? res.data.data.sms_wbzy.zt : []
                if (status.length > 0) {
                    status.forEach((el) => {
                        let obj = {
                            id: el.key,
                            name: el.value,
                        }
                        arr.push(obj)
                    })
                    this.statusOption = this.allArr.concat(arr)
                }
                if (zt.length > 0) {
                    zt.forEach((el) => {
                        let obj = {
                            id: el.key,
                            name: el.value == '正常' ? '是' : '否',
                        }
                        arr1.push(obj)
                    })
                    this.changeOption = this.allArr.concat(arr1)
                }
            })
        },
        getList() {
            let data = {
                smsxt: this.smsxt,
                plazaId: this.plazaId,
                page: this.currentPage,
                size: this.size,
                orderBy: 'wb_gzglid,0;assetnum,1;reportedby,0;',
            }
            //区分主要设备和全部设备
            if(this.smsxt != '1008'){
                data.onlyMainAsset = true
            }
            if (this.assetnum) {
                data.assetnum = this.assetnum
            }
            //下拉
            if (this.ischange && this.ischange != '全部') {
                data.zt = this.ischange
            }
            if (this.status && this.status != '全部') {
                data.status = this.status
            }
            //工单填报时间
            if (this.ycgdtbsj) {
                data.reportdateStartDate = this.ycgdtbsj[0] + '000000'
                data.reportdateEndDate = this.ycgdtbsj[1] + '000000'
            }
            //工单验收时间
            if (this.ycgdyssj) {
                data.sjjssjStartDate = this.ycgdyssj[0] + '000000'
                data.sjjssjEndDate = this.ycgdyssj[1] + '000000'
            }
            //任务开始时间
            if (this.reportdate) {
                data.sjkssjStartDate = this.reportdate[0] + '000000'
                data.sjkssjEndDate = this.reportdate[1] + '000000'
            }
            //任务完成时间
            if (this.complete) {
                data.sjwcsjStartDate = this.complete[0] + '000000'
                data.sjwcsjEndDate = this.complete[1] + '000000'
            }
            //输入框
            data.keyword = ''
            if (this.sbjc) {
                data.keyword += `${this.sbjc}:sbmc,assetnum;`
            }
            if (this.matters) {
                data.keyword += `${this.matters}:description,matters;`
            }
            if (this.rwbh) {
                data.keyword += `${this.rwbh}:wb_gzglid;`
            }
            if (this.bill) {
                data.keyword += `${this.bill}:wonum;`
            }
            if (data.keyword == '') {
                delete data.keyword
            }
            queryWb({ getParams: data }).then((res) => {
                this.total = res.count
                this.tableData = res.data ? res.data : []
            })
        },
        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)
        },
        startMethods() {
            this.changeSelect()
            this.getList()
        },
    },
    watch: {
        diff(newV, oldV) {
            if (newV !== oldV) {
                this.getList()
            }
        },
        tabLabel(newV, oldV) {
            if (newV !== oldV) {
                this.changeSelect()
                this.getList()
            }
        },
        ischange() {
            this.getList()
        },
    },
    mounted() {
        console.log(this.assetnum)
        this.startMethods()
    },
}
</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>