index.vue 8.19 KB
<template>
  <div class="app-container">
    <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="['service:depotStatus: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="['service:depotStatus: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="['service:depotStatus: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="['service:depotStatus:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="检查点" align="center" prop="depotId" :formatter="depotIdFormat"/>
      <el-table-column label="监测时间" align="center" prop="checkTime" />
      <el-table-column label="湿度%" align="center" prop="humidity" />
      <el-table-column label="温度°C" align="center" prop="temperature" />
      <el-table-column label="采取措施" align="center" prop="mark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:depotStatus:edit']"
          >编辑</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:depotStatus: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="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-form-item label="监测点" prop="depotId">
          <el-select v-model="form.depotId" placeholder="监测点" :disabled="edit">
            <el-option
              v-for="depot in depotOptions"
              :key="depot.id"
              :label="depot.depotName"
              :value="depot.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="监测时间" prop="checkTime">
          <el-date-picker
            v-model="form.checkTime" type="datetime" placeholder="选择时间" value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="湿度值" prop="humidity">
          <el-input-number v-model="form.humidity" controls-position="right" :min="0"  />
        </el-form-item>
        <el-form-item label="湿度值" prop="temperature">
          <el-input-number v-model="form.temperature" controls-position="right" :min="0"  />
        </el-form-item>
        <el-form-item label="采取措施" >
          <el-input v-model="form.mark" />
        </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 {listPost, delPost, addPost, updatePost } from "@/api/service/depotStatus";
import {getDepots} from "@/api/service/depot";
export default {
  name: "depotStatus",
  dicts: ['archivesLevel','selectType1','selectType2'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        depotId: [
          { required: true, message: "请选择监测点", trigger: "blur" }
        ],
        checkTime: [
          { required: true, message: "检测时间不能为空", trigger: "blur" }
        ],
        humidity: [
          { required: true, message: "湿度不能为空", trigger: "blur" }
        ],
        temperature: [
          { required: true, message: "温度不能为空", trigger: "blur" }
        ]
      },
      depotOptions:[],
      edit:false,
      depotList:[]
    };
  },
  created() {
    this.getList();
    this.getDepots();
  },
  methods: {
    getList() {
      this.loading = true;
      listPost(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        depotId: undefined,
        checkTime: undefined,
        humidity: undefined,
        temperature:undefined,
        factor: undefined,
        mark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.edit=false;
      this.reset();
      getDepots().then(response => {
        this.depotOptions = response.depotList;
        this.open = true;
        this.title = "登记";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.edit=true;
      this.reset();
      this.form = row;
      this.open = true;
      this.title = "编辑";
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.edit) {
            updatePost(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPost(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除数据?').then(function() {
        return delPost(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('service/depotStatus/export', {
        ...this.queryParams
      }, `depot_status_${new Date().getTime()}.xlsx`)
    },
    getDepots(){
      getDepots().then(response=>{
        this.depotList=response.depotList;
      })
    },
    depotIdFormat(row) {
      for(let i in this.depotList){
        let depot=this.depotList[i]
        if (depot.id == row.depotId) {
          return depot.depotName;
        }
      }
    }
  }
};
</script>