<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:towerDataRun: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:towerDataRun: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:towerDataRun: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:towerDataRun:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="towerDataRunList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="总包单位" align="center" prop="deptName" />
      <el-table-column label="设备序列号" align="center" prop="deviceKey" />
      <el-table-column label="设备来源" align="center" prop="deviceSource" />
      <el-table-column label="当前高度" align="center" prop="height" />
      <el-table-column label="当前幅度" align="center" prop="range" />
      <el-table-column label="回转" align="center" prop="rotation" />
      <el-table-column label="当前吊重" align="center" prop="load" />
      <el-table-column label="风速" align="center" prop="windSpeed" />
      <el-table-column label="水平倾角" align="center" prop="leanAngleX" />
      <el-table-column label="垂直倾角" align="center" prop="leanAngleY" />
      <el-table-column label="重量百分比" align="center" prop="loadPercent" />
      <el-table-column label="力矩百分比" align="center" prop="momentPercent" />
      <el-table-column label="风速等级" align="center" prop="windSpeedPercent" />
      <el-table-column label="倾斜百分比" align="center" prop="leanAnglePercent" />
      <el-table-column label="警报信息" align="center" prop="warnings" />
      <el-table-column label="倍率" align="center" prop="rate" />
      <el-table-column label="回转传感器状态" align="center" prop="rotationSensorState" />
      <el-table-column label="重量传感器状态" align="center" prop="loadSensorState" />
      <el-table-column label="风速传感器状态" align="center" prop="windSpeedSensorState" />
      <el-table-column label="倾角传感器状态" align="center" prop="leanAngleSensorState" />
      <el-table-column label="幅度传感器状态" align="center" prop="rangeSensorState" />
      <el-table-column label="高度传感器状态" align="center" prop="heightSensorState" />
      <el-table-column label="控制状态" align="center" prop="brakingStatus" />
      <el-table-column label="时间戳" align="center" prop="timeLongs" />
      <el-table-column label="是否有效" align="center" prop="isDel">
        <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}') }}</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:towerDataRun:edit']"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['device:towerDataRun: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="height">
          <el-input v-model="form.height" placeholder="请输入当前高度" />
        </el-form-item>
        <el-form-item label="当前幅度" prop="range">
          <el-input v-model="form.range" placeholder="请输入当前幅度" />
        </el-form-item>
        <el-form-item label="回转" prop="rotation">
          <el-input v-model="form.rotation" placeholder="请输入回转" />
        </el-form-item>
        <el-form-item label="当前吊重" prop="load">
          <el-input v-model="form.load" placeholder="请输入当前吊重" />
        </el-form-item>
        <el-form-item label="风速" prop="windSpeed">
          <el-input v-model="form.windSpeed" placeholder="请输入风速" />
        </el-form-item>
        <el-form-item label="水平倾角" prop="leanAngleX">
          <el-input v-model="form.leanAngleX" placeholder="请输入水平倾角" />
        </el-form-item>
        <el-form-item label="垂直倾角" prop="leanAngleY">
          <el-input v-model="form.leanAngleY" placeholder="请输入垂直倾角" />
        </el-form-item>
        <el-form-item label="重量百分比" prop="loadPercent">
          <el-input v-model="form.loadPercent" placeholder="请输入重量百分比" />
        </el-form-item>
        <el-form-item label="力矩百分比" prop="momentPercent">
          <el-input v-model="form.momentPercent" placeholder="请输入力矩百分比" />
        </el-form-item>
        <el-form-item label="风速等级" prop="windSpeedPercent">
          <el-input v-model="form.windSpeedPercent" placeholder="请输入风速等级" />
        </el-form-item>
        <el-form-item label="倾斜百分比" prop="leanAnglePercent">
          <el-input v-model="form.leanAnglePercent" 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="rate">
          <el-input v-model="form.rate" placeholder="请输入倍率" />
        </el-form-item>
        <el-form-item label="回转传感器状态" prop="rotationSensorState">
          <el-input v-model="form.rotationSensorState" placeholder="请输入回转传感器状态" />
        </el-form-item>
        <el-form-item label="重量传感器状态" prop="loadSensorState">
          <el-input v-model="form.loadSensorState" placeholder="请输入重量传感器状态" />
        </el-form-item>
        <el-form-item label="风速传感器状态" prop="windSpeedSensorState">
          <el-input v-model="form.windSpeedSensorState" placeholder="请输入风速传感器状态" />
        </el-form-item>
        <el-form-item label="倾角传感器状态" prop="leanAngleSensorState">
          <el-input v-model="form.leanAngleSensorState" placeholder="请输入倾角传感器状态" />
        </el-form-item>
        <el-form-item label="幅度传感器状态" prop="rangeSensorState">
          <el-input v-model="form.rangeSensorState" placeholder="请输入幅度传感器状态" />
        </el-form-item>
        <el-form-item label="高度传感器状态" prop="heightSensorState">
          <el-input v-model="form.heightSensorState" placeholder="请输入高度传感器状态" />
        </el-form-item>
        <el-form-item label="时间戳" prop="timeLongs">
          <el-input v-model="form.timeLongs" 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 { listTowerDataRun, getTowerDataRun, delTowerDataRun, addTowerDataRun, updateTowerDataRun } from "@/api/device/towerDataRun";

export default {
  name: "TowerDataRun",
  dicts: ['sys_common_isdel'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 塔机实时数据表格数据
      towerDataRunList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        projectName: null,
        deptId: null,
        deptName: null,
        deviceKey: null,
        deviceSource: 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];
      }
      listTowerDataRun(this.queryParams).then(response => {
        this.towerDataRunList = 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,
        height: null,
        range: null,
        rotation: null,
        load: null,
        windSpeed: null,
        leanAngleX: null,
        leanAngleY: null,
        loadPercent: null,
        momentPercent: null,
        windSpeedPercent: null,
        leanAnglePercent: null,
        warnings: null,
        rate: null,
        rotationSensorState: null,
        loadSensorState: null,
        windSpeedSensorState: null,
        leanAngleSensorState: null,
        rangeSensorState: null,
        heightSensorState: null,
        brakingStatus: null,
        timeLongs: 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
      getTowerDataRun(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) {
            updateTowerDataRun(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTowerDataRun(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 delTowerDataRun(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('device/towerDataRun/export', {
        ...this.queryParams
      }, `towerDataRun_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
