<template>
    <div class='remarks'>
        <el-table :data='data' border style='width: 100%;' height='400'>
            <el-table-column type='index' width='50' label='序号'></el-table-column>
            <el-table-column prop='pushTime' label='策略推送时间' width='105'>
                <template
                    slot-scope='{row}'
                >{{row.pushTime?timestamp2String(row.pushTime).slice(8,10)+":"+timestamp2String(row.pushTime).slice(10,12) : '--'}}</template>
            </el-table-column>
            <el-table-column prop='executeTime' label='策略执行时间' width='105'>
                <template slot-scope='{row}' v-if="row.onTime">{{row.onTime?row.onTime.slice(0,2)+":"+row.onTime.slice(2,4):"--"}}</template>
                <template slot-scope='{row}' v-else-if="row.offTime">{{row.offTime?row.offTime.slice(0,2)+":"+row.offTime.slice(2,4):"--"}}</template>
                <template slot-scope='{row}' v-else>{{row.executeTime?row.executeTime.slice(8,10)+":"+row.executeTime.slice(10,12):"--"}}</template>
            </el-table-column>
            <el-table-column prop label='冷水机组开启台数' min-width='85'>
                <template
                    slot-scope='{row}'
                >{{Number(formatterRes(row.chillerNumSetL,true,0))+'&nbsp;大'+Number(formatterRes(row.chillerNumSetS,true,0))+'&nbsp;小'}}</template>
            </el-table-column>
            <el-table-column prop='chillWaterOutTempSet' label='出水温度设定值' min-width='75'>
                <template slot-scope='{row}'>{{formatterRes(row.chillWaterOutTempSet,false,1)}}</template>
            </el-table-column>
            <el-table-column prop label='冷冻泵开启台数' min-width='75'>
                <template
                    slot-scope='{row}'
                >{{Number(formatterRes(row.coolPumpNumSetL,true,0))+'&nbsp;大'+Number(formatterRes(row.coolPumpNumSetS,true,0))+'&nbsp;小'}}</template>
            </el-table-column>
            <el-table-column prop label='冷却泵开启台数' min-width='75'>
                <template
                    slot-scope='{row}'
                >{{Number(formatterRes(row.chillPumpNumSetL,true,0))+'&nbsp;大'+Number(formatterRes(row.chillPumpNumSetS,true,0))+'&nbsp;小'}}</template>
            </el-table-column>
            <el-table-column prop label='冷却塔开启组数' min-width='75'>
                <template
                    slot-scope='{row}'
                >{{Number(formatterRes(row.coolTowerNumSetL,true,0))+'&nbsp;大'+Number(formatterRes(row.coolTowerNumSetS,true,0))+'&nbsp;小'}}</template>
            </el-table-column>
            <el-table-column prop='zip' label='通风策略' width='80'>
                <template slot-scope='{row}'>无</template>
            </el-table-column>
            <el-table-column label='执行情况' width='80'>
                <template slot-scope='{row}'>
                    <div v-if='row.isExecuted==0' style='display: flex;align-items: center;'>
                        <span style='display: inline-block;width:6px;height:6px;background:#F54E45;border-radius: 3px;margin-right: 5px;'></span>
                        <span>未执行</span>
                    </div>
                    <div v-else style='display: flex;align-items: center;'>
                        <span style='display: inline-block;width:6px;height:6px;background:#34C724;border-radius: 3px;margin-right: 5px;'></span>
                        <span>已执行</span>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label='操作' width='90'>
                <template slot-scope='scope'>
                    <el-button @click='handleClick(scope.row)' type='text' size='small'>备注</el-button>
                    <el-button @click='dumpAduit(scope.row)' v-if='isShow(scope.row)' type='text' size='small'>申诉</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-dialog title='备注' :visible.sync='dialogVisible' width='30%'>
            <el-input type='textarea' :autosize='{ minRows: 2, maxRows: 4}' placeholder='请填写备注内容' v-model='remarks'></el-input>
            <span slot='footer' class='dialog-footer'>
                <el-button @click='dialogVisible = false'>关闭</el-button>
                <el-button type='primary' @click='saveCommand'>保存</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { updateCommand } from '@/api/strategy/strategy.js'
import { timestamp2String } from '@/utils/helper.js'
import { queryWorkflow } from '@/api/appeal/appeal.js'

export default {
    data() {
        return {
            timestamp2String,
            dialogVisible: false,
            remarks: '',
            row: '',
            newData: []
        }
    },
    props: ['data', 'idArr'],
    methods: {
        formatterRes(res, type, num) {
            if (res == '-9999') {
                return 'x'
            } else if (res == '-9998') {
                if (type) {
                    return 0
                } else {
                    return '--'
                }
            } else {
                if (res != undefined) {
                    res = res.toFixed(num)
                } else {
                    return '--'
                }
                return res
            }
        },
        isShow(data) {
            let isShow = false
            if (this.newData.length) {
                this.newData.forEach(el => {
                    if (data.appealId == el.id) {
                        if (el.status == 301 || el.status == 305) {
                            isShow = true
                        }
                    }
                })
            }
            return isShow
        },
        appealsIng(id) {
            let params = {
                postParams: {
                    criteria: {
                        id: id
                    },
                    withColumns: ['customAttribute']
                }
            }
            queryWorkflow(params).then(res => {
                this.newData = res.content ? res.content : []
                console.log(res)
                // let arr = [];
                // arr = res.content ? res.content : [];
                // if (arr.length > 0) {
                //   arr.forEach(item => {
                //     arr.push(item.commandId);
                //     this.newArr.push(item);
                //   });
                //   this.queryExecute(arr);
                // }
            })
        },
        handleClick(row) {
            console.log(row)
            this.row = row
            this.remarks = row.remarks
            this.dialogVisible = true
        },
        saveCommand(row) {
            this.dialogVisible = false
            let postParams = {
                id: this.row.id,
                remarks: this.remarks
            }
            updateCommand({ postParams }).then(res => {
                if (res.result == 'success') {
                    this.$message.success('添加备注成功！')
                }
            })
        },
        dumpAduit(row) {
            console.log(row)
            this.$router.push({
                path: '/appeal/appealDetails',
                query: { item: JSON.stringify(row) }
            })
        }
    },
    mounted() {
        if (this.data && this.idArr) {
            this.appealsIng(this.idArr)
        }
    }
}
</script>

<style lang='scss' >
.remarks {
    .el-dialog {
        margin-top: 30vh !important;
        z-index: 999999 !important;
    }
}
.v-modal {
    z-index: 1 !important;
    background: #fff !important;
}
</style>