<template>
  <div class="app-container">
    <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.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="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="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['device:towerDataLimit:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['device:towerDataLimit:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['device:towerDataLimit:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['device:towerDataLimit:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="towerDataLimitList" @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="windSpeedWarning" width="120" />
      <el-table-column label="风速报警" align="center" prop="windSpeedAlarm" width="120" />
      <el-table-column label="超载预警" align="center" prop="loadWarning" width="120" />
      <el-table-column label="超载报警" align="center" prop="loadAlarm" width="120" />
      <el-table-column label="力矩预警" align="center" prop="momentWarning" width="120" />
      <el-table-column label="力矩报警" align="center" prop="momentAlarm" width="120" />
      <el-table-column label="高限位预警" align="center" prop="highLimitWarning" width="150" />
      <el-table-column label="高限位报警" align="center" prop="highLimitAlarm" width="150" />
      <el-table-column label="低限位预警" align="center" prop="lowLimitWarning" width="150"/>
      <el-table-column label="低限位报警" align="center" prop="lowLimitAlarm" width="150"/>
      <el-table-column label="左限位预警" align="center" prop="leftLimitWarning" width="150"/>
      <el-table-column label="左限位报警" align="center" prop="leftLimitAlarm" width="150"/>
      <el-table-column label="右限位预警" align="center" prop="rightLimitWarning" width="150"/>
      <el-table-column label="右限位报警" align="center" prop="rightLimitAlarm" width="150"/>
      <el-table-column label="前限位预警" align="center" prop="frontLimitWarning" width="150"/>
      <el-table-column label="前限位报警" align="center" prop="frontLimitAlarm" width="150"/>
      <el-table-column label="后限位预警" align="center" prop="backLimitWarning" width="150"/>
      <el-table-column label="后限位报警" align="center" prop="backLimitAlarm" width="150"/>
      <el-table-column label="防碰角度预警" align="center" prop="collisionAngleWarning" width="160"/>
      <el-table-column label="防碰角度报警" align="center" prop="collisionAngleAlarm" width="160"/>
      <el-table-column label="防碰距离预警" align="center" prop="collisionDistanceWarning" width="160"/>
      <el-table-column label="防碰距离报警" align="center" prop="collisionDistanceAlarm" width="160"/>
      <el-table-column label="水平距离预警值" align="center" prop="hDistanceWarning" width="180"/>
      <el-table-column label="水平距离报警值" align="center" prop="hDistanceAlarm" width="180"/>
      <el-table-column label="垂直距离预警值" align="center" prop="vDistanceWarning" width="180"/>
      <el-table-column label="垂直距离报警值" align="center" prop="vDistanceAlarm" width="180"/>
      <el-table-column label="倾斜预警值" align="center" prop="leanWarning" width="160"/>
      <el-table-column label="倾斜报警值" align="center" prop="leanAlarm" width="160"/>
      <el-table-column label="幅度限位起点值" align="center" prop="rangeLimitStart" width="180"/>
      <el-table-column label="幅度限位终点值" align="center" prop="rangeLimitEnd" width="180"/>
      <el-table-column label="高度限位起点值" align="center" prop="heightLimitStart" width="180"/>
      <el-table-column label="高度限位终点值" align="center" prop="heightLimitEnd" width="180"/>
      <el-table-column label="回转限位起点值" align="center" prop="rotationLimitStart" width="180"/>
      <el-table-column label="回转限位终点值" align="center" prop="rotationLimitEnd" width="180"/>
      <el-table-column label="是否有效" align="center" prop="isDel" width="100">
        <template slot-scope="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 slot-scope="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 slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['device:towerDataLimit:edit']"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['device:towerDataLimit:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改塔机限位信息对话框 -->
    <el-dialog :title="title" :visible.sync="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="towerId">
          <el-input v-model="form.towerId" placeholder="请输入塔机编号" />
        </el-form-item>
        <el-form-item label="风速预警" prop="windSpeedWarning">
          <el-input v-model="form.windSpeedWarning" placeholder="请输入风速预警" />
        </el-form-item>
        <el-form-item label="风速报警" prop="windSpeedAlarm">
          <el-input v-model="form.windSpeedAlarm" placeholder="请输入风速报警" />
        </el-form-item>
        <el-form-item label="超载预警" prop="loadWarning">
          <el-input v-model="form.loadWarning" placeholder="请输入超载预警" />
        </el-form-item>
        <el-form-item label="超载报警" prop="loadAlarm">
          <el-input v-model="form.loadAlarm" placeholder="请输入超载报警" />
        </el-form-item>
        <el-form-item label="力矩预警" prop="momentWarning">
          <el-input v-model="form.momentWarning" placeholder="请输入力矩预警" />
        </el-form-item>
        <el-form-item label="力矩报警" prop="momentAlarm">
          <el-input v-model="form.momentAlarm" placeholder="请输入力矩报警" />
        </el-form-item>
        <el-form-item label="高限位预警" prop="highLimitWarning">
          <el-input v-model="form.highLimitWarning" placeholder="请输入高限位预警" />
        </el-form-item>
        <el-form-item label="高限位报警" prop="highLimitAlarm">
          <el-input v-model="form.highLimitAlarm" placeholder="请输入高限位报警" />
        </el-form-item>
        <el-form-item label="低限位预警" prop="lowLimitWarning">
          <el-input v-model="form.lowLimitWarning" placeholder="请输入低限位预警" />
        </el-form-item>
        <el-form-item label="低限位报警" prop="lowLimitAlarm">
          <el-input v-model="form.lowLimitAlarm" placeholder="请输入低限位报警" />
        </el-form-item>
        <el-form-item label="左限位预警" prop="leftLimitWarning">
          <el-input v-model="form.leftLimitWarning" placeholder="请输入左限位预警" />
        </el-form-item>
        <el-form-item label="左限位报警" prop="leftLimitAlarm">
          <el-input v-model="form.leftLimitAlarm" placeholder="请输入左限位报警" />
        </el-form-item>
        <el-form-item label="右限位预警" prop="rightLimitWarning">
          <el-input v-model="form.rightLimitWarning" placeholder="请输入右限位预警" />
        </el-form-item>
        <el-form-item label="右限位报警" prop="rightLimitAlarm">
          <el-input v-model="form.rightLimitAlarm" placeholder="请输入右限位报警" />
        </el-form-item>
        <el-form-item label="前限位预警" prop="frontLimitWarning">
          <el-input v-model="form.frontLimitWarning" placeholder="请输入前限位预警" />
        </el-form-item>
        <el-form-item label="前限位报警" prop="frontLimitAlarm">
          <el-input v-model="form.frontLimitAlarm" placeholder="请输入前限位报警" />
        </el-form-item>
        <el-form-item label="后限位预警" prop="backLimitWarning">
          <el-input v-model="form.backLimitWarning" placeholder="请输入后限位预警" />
        </el-form-item>
        <el-form-item label="后限位报警" prop="backLimitAlarm">
          <el-input v-model="form.backLimitAlarm" placeholder="请输入后限位报警" />
        </el-form-item>
        <el-form-item label="防碰角度预警" prop="collisionAngleWarning">
          <el-input v-model="form.collisionAngleWarning" placeholder="请输入防碰角度预警" />
        </el-form-item>
        <el-form-item label="防碰角度报警" prop="collisionAngleAlarm">
          <el-input v-model="form.collisionAngleAlarm" placeholder="请输入防碰角度报警" />
        </el-form-item>
        <el-form-item label="防碰距离预警" prop="collisionDistanceWarning">
          <el-input v-model="form.collisionDistanceWarning" placeholder="请输入防碰距离预警" />
        </el-form-item>
        <el-form-item label="防碰距离报警" prop="collisionDistanceAlarm">
          <el-input v-model="form.collisionDistanceAlarm" placeholder="请输入防碰距离报警" />
        </el-form-item>
        <el-form-item label="水平距离预警值" prop="hDistanceWarning">
          <el-input v-model="form.hDistanceWarning" placeholder="请输入水平距离预警值" />
        </el-form-item>
        <el-form-item label="水平距离报警值" prop="hDistanceAlarm">
          <el-input v-model="form.hDistanceAlarm" placeholder="请输入水平距离报警值" />
        </el-form-item>
        <el-form-item label="垂直距离预警值" prop="vDistanceWarning">
          <el-input v-model="form.vDistanceWarning" placeholder="请输入垂直距离预警值" />
        </el-form-item>
        <el-form-item label="垂直距离报警值" prop="vDistanceAlarm">
          <el-input v-model="form.vDistanceAlarm" placeholder="请输入垂直距离报警值" />
        </el-form-item>
        <el-form-item label="倾斜预警值" prop="leanWarning">
          <el-input v-model="form.leanWarning" placeholder="请输入倾斜预警值" />
        </el-form-item>
        <el-form-item label="倾斜报警值" prop="leanAlarm">
          <el-input v-model="form.leanAlarm" placeholder="请输入倾斜报警值" />
        </el-form-item>
        <el-form-item label="幅度限位起点值" prop="rangeLimitStart">
          <el-input v-model="form.rangeLimitStart" placeholder="请输入幅度限位起点值" />
        </el-form-item>
        <el-form-item label="幅度限位终点值" prop="rangeLimitEnd">
          <el-input v-model="form.rangeLimitEnd" placeholder="请输入幅度限位终点值" />
        </el-form-item>
        <el-form-item label="高度限位起点值" prop="heightLimitStart">
          <el-input v-model="form.heightLimitStart" placeholder="请输入高度限位起点值" />
        </el-form-item>
        <el-form-item label="高度限位终点值" prop="heightLimitEnd">
          <el-input v-model="form.heightLimitEnd" placeholder="请输入高度限位终点值" />
        </el-form-item>
        <el-form-item label="回转限位起点值" prop="rotationLimitStart">
          <el-input v-model="form.rotationLimitStart" placeholder="请输入回转限位起点值" />
        </el-form-item>
        <el-form-item label="回转限位终点值" prop="rotationLimitEnd">
          <el-input v-model="form.rotationLimitEnd" 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="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 { listTowerDataLimit, getTowerDataLimit, delTowerDataLimit, addTowerDataLimit, updateTowerDataLimit } from "@/api/device/towerDataLimit";

export default {
  name: "TowerDataLimit",
  dicts: ['sys_common_isdel'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 塔机限位信息表格数据
      towerDataLimitList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        projectName: null,
        deptId: null,
        deptName: null,
        deviceKey: null,
        deviceSource: null,
        towerId: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询塔机限位信息列表 */
    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];
      }
      listTowerDataLimit(this.queryParams).then(response => {
        this.towerDataLimitList = 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,
        towerId: null,
        windSpeedWarning: null,
        windSpeedAlarm: null,
        loadWarning: null,
        loadAlarm: null,
        momentWarning: null,
        momentAlarm: null,
        highLimitWarning: null,
        highLimitAlarm: null,
        lowLimitWarning: null,
        lowLimitAlarm: null,
        leftLimitWarning: null,
        leftLimitAlarm: null,
        rightLimitWarning: null,
        rightLimitAlarm: null,
        frontLimitWarning: null,
        frontLimitAlarm: null,
        backLimitWarning: null,
        backLimitAlarm: null,
        collisionAngleWarning: null,
        collisionAngleAlarm: null,
        collisionDistanceWarning: null,
        collisionDistanceAlarm: null,
        hDistanceWarning: null,
        hDistanceAlarm: null,
        vDistanceWarning: null,
        vDistanceAlarm: null,
        leanWarning: null,
        leanAlarm: null,
        rangeLimitStart: null,
        rangeLimitEnd: null,
        heightLimitStart: null,
        heightLimitEnd: null,
        rotationLimitStart: null,
        rotationLimitEnd: 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
      getTowerDataLimit(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) {
            updateTowerDataLimit(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTowerDataLimit(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 delTowerDataLimit(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('device/towerDataLimit/export', {
        ...this.queryParams
      }, `towerDataLimit_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
