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

    <el-table v-loading="loading" :data="towerDataLocalList" @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="towerId" />
      <el-table-column label="近端幅度标定AD定值" align="center" prop="rangeNearEndAdValue" />
      <el-table-column label="近端幅度标定实际值" align="center" prop="rangeNearEndRealityValue" />
      <el-table-column label="远端幅度标定AD定值" align="center" prop="rangeFarEndAdValue" />
      <el-table-column label="远端幅度标定实际值" align="center" prop="rangeFarEndRealityValue" />
      <el-table-column label="高度近端标定AD定值" align="center" prop="highNearEndAdValue" />
      <el-table-column label="高度近端标定实际值" align="center" prop="highNearEndRealityValue" />
      <el-table-column label="高度远端标定AD定值" align="center" prop="highFarEndAdValue" />
      <el-table-column label="高度远端标定实际值" align="center" prop="highFarEndRealityValue" />
      <el-table-column label="空载重量AD值" align="center" prop="emptyWeightAdValue" />
      <el-table-column label="空载重量实际值" align="center" prop="emptyWeightRealityValue" />
      <el-table-column label="负载重量AD值" align="center" prop="loadWeightAdValue" />
      <el-table-column label="负载重量实际值" align="center" prop="loadWeightRealityValue" />
      <el-table-column label="回转起点AD值" align="center" prop="rotationStartAdValue" />
      <el-table-column label="回转起点实际角度" align="center" prop="rotationStartRealityValue" />
      <el-table-column label="回转终点AD值" align="center" prop="rotationEndAdValue" />
      <el-table-column label="回转终点实际角度" align="center" prop="rotationEndRealityValue" />
      <el-table-column label="风速校准系数" align="center" prop="windSpeedFactor" />
      <el-table-column label="倾斜校准系数" align="center" prop="tiltFactor" />
      <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} {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:towerDataLocal:edit']"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['device:towerDataLocal: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="近端幅度标定AD定值" prop="rangeNearEndAdValue">
          <el-input v-model="form.rangeNearEndAdValue" placeholder="请输入近端幅度标定AD定值" />
        </el-form-item>
        <el-form-item label="近端幅度标定实际值" prop="rangeNearEndRealityValue">
          <el-input v-model="form.rangeNearEndRealityValue" placeholder="请输入近端幅度标定实际值" />
        </el-form-item>
        <el-form-item label="远端幅度标定AD定值" prop="rangeFarEndAdValue">
          <el-input v-model="form.rangeFarEndAdValue" placeholder="请输入远端幅度标定AD定值" />
        </el-form-item>
        <el-form-item label="远端幅度标定实际值" prop="rangeFarEndRealityValue">
          <el-input v-model="form.rangeFarEndRealityValue" placeholder="请输入远端幅度标定实际值" />
        </el-form-item>
        <el-form-item label="高度近端标定AD定值" prop="highNearEndAdValue">
          <el-input v-model="form.highNearEndAdValue" placeholder="请输入高度近端标定AD定值" />
        </el-form-item>
        <el-form-item label="高度近端标定实际值" prop="highNearEndRealityValue">
          <el-input v-model="form.highNearEndRealityValue" placeholder="请输入高度近端标定实际值" />
        </el-form-item>
        <el-form-item label="高度远端标定AD定值" prop="highFarEndAdValue">
          <el-input v-model="form.highFarEndAdValue" placeholder="请输入高度远端标定AD定值" />
        </el-form-item>
        <el-form-item label="高度远端标定实际值" prop="highFarEndRealityValue">
          <el-input v-model="form.highFarEndRealityValue" placeholder="请输入高度远端标定实际值" />
        </el-form-item>
        <el-form-item label="空载重量AD值" prop="emptyWeightAdValue">
          <el-input v-model="form.emptyWeightAdValue" placeholder="请输入空载重量AD值" />
        </el-form-item>
        <el-form-item label="空载重量实际值" prop="emptyWeightRealityValue">
          <el-input v-model="form.emptyWeightRealityValue" placeholder="请输入空载重量实际值" />
        </el-form-item>
        <el-form-item label="负载重量AD值" prop="loadWeightAdValue">
          <el-input v-model="form.loadWeightAdValue" placeholder="请输入负载重量AD值" />
        </el-form-item>
        <el-form-item label="负载重量实际值" prop="loadWeightRealityValue">
          <el-input v-model="form.loadWeightRealityValue" placeholder="请输入负载重量实际值" />
        </el-form-item>
        <el-form-item label="回转起点AD值" prop="rotationStartAdValue">
          <el-input v-model="form.rotationStartAdValue" placeholder="请输入回转起点AD值" />
        </el-form-item>
        <el-form-item label="回转起点实际角度" prop="rotationStartRealityValue">
          <el-input v-model="form.rotationStartRealityValue" placeholder="请输入回转起点实际角度" />
        </el-form-item>
        <el-form-item label="回转终点AD值" prop="rotationEndAdValue">
          <el-input v-model="form.rotationEndAdValue" placeholder="请输入回转终点AD值" />
        </el-form-item>
        <el-form-item label="回转终点实际角度" prop="rotationEndRealityValue">
          <el-input v-model="form.rotationEndRealityValue" placeholder="请输入回转终点实际角度" />
        </el-form-item>
        <el-form-item label="风速校准系数" prop="windSpeedFactor">
          <el-input v-model="form.windSpeedFactor" placeholder="请输入风速校准系数" />
        </el-form-item>
        <el-form-item label="倾斜校准系数" prop="tiltFactor">
          <el-input v-model="form.tiltFactor" 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 { listTowerDataLocal, getTowerDataLocal, delTowerDataLocal, addTowerDataLocal, updateTowerDataLocal } from "@/api/device/towerDataLocal";

export default {
  name: "TowerDataLocal",
  dicts: ['sys_common_isdel'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 塔机定位信息表格数据
      towerDataLocalList: [],
      // 弹出层标题
      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];
      }
      listTowerDataLocal(this.queryParams).then(response => {
        this.towerDataLocalList = 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,
        rangeNearEndAdValue: null,
        rangeNearEndRealityValue: null,
        rangeFarEndAdValue: null,
        rangeFarEndRealityValue: null,
        highNearEndAdValue: null,
        highNearEndRealityValue: null,
        highFarEndAdValue: null,
        highFarEndRealityValue: null,
        emptyWeightAdValue: null,
        emptyWeightRealityValue: null,
        loadWeightAdValue: null,
        loadWeightRealityValue: null,
        rotationStartAdValue: null,
        rotationStartRealityValue: null,
        rotationEndAdValue: null,
        rotationEndRealityValue: null,
        windSpeedFactor: null,
        tiltFactor: 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
      getTowerDataLocal(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) {
            updateTowerDataLocal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTowerDataLocal(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 delTowerDataLocal(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('device/towerDataLocal/export', {
        ...this.queryParams
      }, `towerDataLocal_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
