<template>
    <div class="app-container tower-data-round">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="项目名称" prop="projectName">
                <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="单位名称" prop="deptName">
                <el-input v-model="queryParams.deptName" placeholder="请输入单位名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="创建时间">
                <el-date-picker v-model="daterangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd"
                    type="daterange" range-separator="-" start-placeholder="开始日期"
                    end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="small" :disabled="multiple"
                    @click="handleDelete" v-hasPermi="['device:towerDataRound:remove']">删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="Download" size="small" @click="handleExport"
                    v-hasPermi="['device:towerDataRound:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="towerDataRoundList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="项目名称" align="center" prop="projectName" width="200" />
            <el-table-column label="总包单位" align="center" prop="deptName" width="200" />
            <el-table-column label="设备序列号" align="center" prop="deviceKey" width="200" />
            <el-table-column label="工作循环开始" align="center" prop="workStartTime" width="180" />
            <el-table-column label="工作循环结束" align="center" prop="workEndTime" width="180" />
            <el-table-column label="警报信息" align="center" prop="warnings" width="200">
                <template #default="scope">
                    <div class="tag-group">
                        <dict-tag :options="dict.type.device_tower_warning"
                            :value="scope.row.warnings ? scope.row.warnings.split(',') : '0'" />
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="工作循环最小高度" align="center" prop="minHeight" width="200" />
            <el-table-column label="工作循环最大高度" align="center" prop="maxHeight" width="200" />
            <el-table-column label="工作循环最小幅度" align="center" prop="minRange" width="200" />
            <el-table-column label="工作循环最大幅度" align="center" prop="maxRange" width="200" />
            <el-table-column label="工作循环开始高度" align="center" prop="startHeight" width="200" />
            <el-table-column label="工作循环结束高度" align="center" prop="endHeight" width="200" />
            <el-table-column label="工作循环开始幅度" align="center" prop="startRange" width="200" />
            <el-table-column label="工作循环结束幅度" align="center" prop="endRange" width="200" />
            <el-table-column label="工作循环开始回转角度" align="center" prop="startRotation" width="220" />
            <el-table-column label="工作循环结束回转角度" align="center" prop="endRotation" width="220" />
            <el-table-column label="工作循环最大吊重" align="center" prop="maxLoad" width="200" />
            <el-table-column label="工作循环最大重量" align="center" prop="maxLoadPercent" width="200" />
            <el-table-column label="工作循环最大力矩" align="center" prop="maxMoment" width="200" />
            <el-table-column label="工作循环最大力矩百分比" align="center" prop="maxMomentPercent" width="240" />
            <el-table-column label="工作循环开始风速" align="center" prop="startWindSpeed" width="200" />
            <el-table-column label="工作循环结束风速" align="center" prop="endWindSpeed" width="200" />
            <el-table-column label="工作循环开始风速等级" align="center" prop="startWindSpeedPercent" width="220" />
            <el-table-column label="工作循环结束风速等级" align="center" prop="endWindSpeedPercent" width="220" />
            <el-table-column label="工作循环开始水平倾角" align="center" prop="startLeanAngleX" width="220" />
            <el-table-column label="工作循环结束水平倾角" align="center" prop="endLeanAngleX" width="220" />
            <el-table-column label="工作循环开始垂直倾角" align="center" prop="startLeanAngleY" width="220" />
            <el-table-column label="工作循环结束垂直倾角" align="center" prop="endLeanAngleY" width="220" />
            <el-table-column label="是否有效" align="center" prop="isDel" width="100">
                <template #default="scope">
                    <dict-tag :options="dict.type.sys_common_isdel" :value="scope.row.isDel" />
                </template>
            </el-table-column>
            <el-table-column label="创建时间" align="center" prop="createTime" width="180">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}:{s}") }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100" fixed="right">
                <template #default="scope">
                    <el-button size="small" text icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['device:towerDataRound:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getList" />

        <!-- 添加或修改塔机工作循环对话框 -->
        <el-dialog :title="title" v-model="open" width="500px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="项目主键" prop="projectId">
                    <el-input v-model="form.projectId" placeholder="请输入项目主键" />
                </el-form-item>
                <el-form-item label="总包单位主键" prop="deptId">
                    <el-input v-model="form.deptId" placeholder="请输入总包单位主键" />
                </el-form-item>
                <el-form-item label="设备序列号" prop="deviceKey">
                    <el-input v-model="form.deviceKey" placeholder="请输入设备序列号" />
                </el-form-item>
                <el-form-item label="设备来源" prop="deviceSource">
                    <el-input v-model="form.deviceSource" placeholder="请输入设备来源" />
                </el-form-item>
                <el-form-item label="数据编号" prop="dataId">
                    <el-input v-model="form.dataId" placeholder="请输入数据编号" />
                </el-form-item>
                <el-form-item label="工作循环开始" prop="workStartTime">
                    <el-input v-model="form.workStartTime" placeholder="请输入工作循环开始" />
                </el-form-item>
                <el-form-item label="工作循环结束" prop="workEndTime">
                    <el-input v-model="form.workEndTime" placeholder="请输入工作循环结束" />
                </el-form-item>
                <el-form-item label="工作循环最小高度" prop="minHeight">
                    <el-input v-model="form.minHeight" placeholder="请输入工作循环最小高度" />
                </el-form-item>
                <el-form-item label="工作循环最大高度" prop="maxHeight">
                    <el-input v-model="form.maxHeight" placeholder="请输入工作循环最大高度" />
                </el-form-item>
                <el-form-item label="工作循环最小幅度" prop="minRange">
                    <el-input v-model="form.minRange" placeholder="请输入工作循环最小幅度" />
                </el-form-item>
                <el-form-item label="工作循环最大幅度" prop="maxRange">
                    <el-input v-model="form.maxRange" placeholder="请输入工作循环最大幅度" />
                </el-form-item>
                <el-form-item label="工作循环开始高度" prop="startHeight">
                    <el-input v-model="form.startHeight" placeholder="请输入工作循环开始高度" />
                </el-form-item>
                <el-form-item label="工作循环结束高度" prop="endHeight">
                    <el-input v-model="form.endHeight" placeholder="请输入工作循环结束高度" />
                </el-form-item>
                <el-form-item label="工作循环开始幅度" prop="startRange">
                    <el-input v-model="form.startRange" placeholder="请输入工作循环开始幅度" />
                </el-form-item>
                <el-form-item label="工作循环结束幅度单位米" prop="endRange">
                    <el-input v-model="form.endRange" placeholder="请输入工作循环结束幅度单位米" />
                </el-form-item>
                <el-form-item label="工作循环开始回转角度单位度" prop="startRotation">
                    <el-input v-model="form.startRotation" placeholder="请输入工作循环开始回转角度单位度" />
                </el-form-item>
                <el-form-item label="工作循环结束回转角度单位度" prop="endRotation">
                    <el-input v-model="form.endRotation" placeholder="请输入工作循环结束回转角度单位度" />
                </el-form-item>
                <el-form-item label="工作循环最大吊重单位吨" prop="maxLoad">
                    <el-input v-model="form.maxLoad" placeholder="请输入工作循环最大吊重单位吨" />
                </el-form-item>
                <el-form-item label="工作循环最大重量百分比" prop="maxLoadPercent">
                    <el-input v-model="form.maxLoadPercent" placeholder="请输入工作循环最大重量百分比" />
                </el-form-item>
                <el-form-item label="工作循环最大力矩" prop="maxMoment">
                    <el-input v-model="form.maxMoment" placeholder="请输入工作循环最大力矩" />
                </el-form-item>
                <el-form-item label="工作循环最大力矩百分比" prop="maxMomentPercent">
                    <el-input v-model="form.maxMomentPercent" placeholder="请输入工作循环最大力矩百分比" />
                </el-form-item>
                <el-form-item label="工作循环开始风速" prop="startWindSpeed">
                    <el-input v-model="form.startWindSpeed" placeholder="请输入工作循环开始风速" />
                </el-form-item>
                <el-form-item label="工作循环结束风速" prop="endWindSpeed">
                    <el-input v-model="form.endWindSpeed" placeholder="请输入工作循环结束风速" />
                </el-form-item>
                <el-form-item label="工作循环开始风速等级" prop="startWindSpeedPercent">
                    <el-input v-model="form.startWindSpeedPercent" placeholder="请输入工作循环开始风速等级" />
                </el-form-item>
                <el-form-item label="工作循环结束风速等级" prop="endWindSpeedPercent">
                    <el-input v-model="form.endWindSpeedPercent" placeholder="请输入工作循环结束风速等级" />
                </el-form-item>
                <el-form-item label="工作循环开始水平倾角" prop="startLeanAngleX">
                    <el-input v-model="form.startLeanAngleX" placeholder="请输入工作循环开始水平倾角" />
                </el-form-item>
                <el-form-item label="工作循环结束水平倾角" prop="endLeanAngleX">
                    <el-input v-model="form.endLeanAngleX" placeholder="请输入工作循环结束水平倾角" />
                </el-form-item>
                <el-form-item label="工作循环开始垂直倾角" prop="startLeanAngleY">
                    <el-input v-model="form.startLeanAngleY" placeholder="请输入工作循环开始垂直倾角" />
                </el-form-item>
                <el-form-item label="工作循环结束垂直倾角" prop="endLeanAngleY">
                    <el-input v-model="form.endLeanAngleY" placeholder="请输入工作循环结束垂直倾角" />
                </el-form-item>
                <el-form-item label="警报信息" prop="warnings">
                    <el-input v-model="form.warnings" placeholder="请输入警报信息" />
                </el-form-item>
                <el-form-item label="是否有效" prop="isDel">
                    <el-select v-model="form.isDel" placeholder="请选择是否有效">
                        <el-option v-for="dict in dict.type.sys_common_isdel" :key="dict.value" :label="dict.label"
                            :value="parseInt(dict.value)"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" placeholder="请输入备注" />
                </el-form-item>
            </el-form>
            <div slot-slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {
    listTowerDataRound,
    getTowerDataRound,
    delTowerDataRound,
    addTowerDataRound,
    updateTowerDataRound,
} from "@/api/device/towerDataRound";
import useUserStore from '@/store/modules/user'
import { findMyProjectList } from "@/api/publics";
export default {
    name: "TowerDataRound",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 塔机工作循环表格数据
            towerDataRoundList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 备注时间范围
            daterangeCreateTime: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                projectId: null,
                projectName: null,
                deptId: null,
                deptName: null,
                deviceKey: null,
                deviceSource: null,
                dataId: null,
                createTime: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {},
            dict: {
                sys_common_isdel: [],
                device_tower_warning: []
            },
            userStore: {},
            isAdmin: false,
            projects: [],
            currentPrjId: null,
        };
    },
    created() {
        this.dict = this.useDict('sys_common_isdel', 'device_tower_warning');
        this.userStore = useUserStore()
        this.isAdmin = this.userStore.isAdmin;
        this.queryParams.projectId = this.userStore.currentPrjId;
        this.queryParams.comId = this.userStore.currentComId;
        this.currentPrjId = this.userStore.currentPrjId;
        this.getList();
        this.getProjectList();
    },
    methods: {
        /** 查询项目列表 */
        getProjectList() {
            findMyProjectList({ pageNum: 1, pageSize: 100 }).then(response => {
                this.projects = response.rows;
            });
        },
        /** 查询塔机工作循环列表 */
        getList() {
            this.loading = true;
            this.queryParams.params = {};
            if (null != this.daterangeCreateTime && "" != this.daterangeCreateTime) {
                this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
                this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
            }
            listTowerDataRound(this.queryParams).then((response) => {
                this.towerDataRoundList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                projectId: null,
                deptId: null,
                deviceKey: null,
                deviceSource: null,
                dataId: null,
                workStartTime: null,
                workEndTime: null,
                minHeight: null,
                maxHeight: null,
                minRange: null,
                maxRange: null,
                startHeight: null,
                endHeight: null,
                startRange: null,
                endRange: null,
                startRotation: null,
                endRotation: null,
                maxLoad: null,
                maxLoadPercent: null,
                maxMoment: null,
                maxMomentPercent: null,
                startWindSpeed: null,
                endWindSpeed: null,
                startWindSpeedPercent: null,
                endWindSpeedPercent: null,
                startLeanAngleX: null,
                endLeanAngleX: null,
                startLeanAngleY: null,
                endLeanAngleY: null,
                warnings: null,
                isDel: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                remark: null,
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.daterangeCreateTime = [];
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.id);
            this.single = selection.length !== 1;
            this.multiple = !selection.length;
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加塔机工作循环";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids;
            getTowerDataRound(id).then((response) => {
                this.form = response.data;
                this.open = true;
                this.title = "修改塔机工作循环";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    if (this.form.id != null) {
                        updateTowerDataRound(this.form).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addTowerDataRound(this.form).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal
                .confirm('是否确认删除塔机工作循环编号为"' + ids + '"的数据项？')
                .then(function () {
                    return delTowerDataRound(ids);
                })
                .then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                })
                .catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                "manage/device/towerDataRound/export",
                {
                    ...this.queryParams,
                },
                `towerDataRound_${new Date().getTime()}.xlsx`
            );
        },
    },
};
</script>

<style lang="scss">
.tower-data-round {}
</style>