<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="travelLength">
        <el-input
          v-model="queryParams.travelLength"
          placeholder="请输入行程变量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="箱体" prop="boxType">
        <el-select
          v-model="queryParams.boxType"
          placeholder="请选择箱体层数"
          clearable
          @change="handleQuery"
        >
          <el-option label="S(单层)" value="S" />
          <el-option label="D(双层)" value="D" />
          <el-option label="T(三层)" value="T" />
        </el-select>
      </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="['system:spec80r: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="['system:spec80r: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="['system:spec80r: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="['system:spec80r:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" border :data="spec80rList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="行程" align="center" prop="travelLength" />
      <el-table-column label="类型" align="center" prop="itemType" />
      <el-table-column label="箱体" align="center" prop="boxType" />
      <el-table-column label="v1" align="center" prop="v1" />
      <el-table-column label="v2" align="center" prop="v2" />
      <el-table-column label="v3" align="center" prop="v3" />
      <el-table-column label="v5" align="center" prop="v5" />
      <el-table-column label="v6" align="center" prop="v6" />
      <el-table-column label="v8" align="center" prop="v8" />
      <el-table-column label="g1" align="center" prop="g1" />
      <el-table-column label="v9" align="center" prop="v9" />
      <el-table-column label="g2" align="center" prop="g2" />
      <el-table-column label="v10" align="center" prop="v10" />
      <el-table-column label="g5" align="center" prop="g5" />
      <el-table-column label="v11" align="center" prop="v11" />
      <el-table-column label="v12" align="center" prop="v12" />
      <el-table-column label="g6" align="center" prop="g6" />
      <el-table-column label="v13" align="center" prop="v13" />
      <el-table-column label="v14" align="center" prop="v14" />
      <el-table-column label="g7" align="center" prop="g7" />
      <el-table-column label="v15" align="center" prop="v15" />
      <el-table-column label="v41" align="center" prop="v41" />
      <el-table-column label="v42" align="center" prop="v42" />
      <el-table-column label="v43" align="center" prop="v43" />
      <el-table-column label="v44" align="center" prop="v44" />
      <el-table-column label="v45" align="center" prop="v45" />
      <el-table-column label="v46" align="center" prop="v46" />
      <el-table-column label="v47" align="center" prop="v47" />
      <el-table-column label="v48" align="center" prop="v48" />
      <el-table-column label="v49" align="center" prop="v49" />
      <el-table-column label="v50" align="center" prop="v50" />
      <el-table-column label="v51" align="center" prop="v51" />
      <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:spec80r:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:spec80r: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"
    />

    <!-- 添加或修改80R设备规格参数对话框 -->
    <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="travelLength">
          <el-input v-model="form.travelLength" placeholder="请输入行程变量" />
        </el-form-item>
        <el-form-item label="v1" prop="v1">
          <el-input v-model="form.v1" placeholder="请输入v1" />
        </el-form-item>
        <el-form-item label="v2" prop="v2">
          <el-input v-model="form.v2" placeholder="请输入v2" />
        </el-form-item>
        <el-form-item label="v3" prop="v3">
          <el-input v-model="form.v3" placeholder="请输入v3" />
        </el-form-item>
        <el-form-item label="v5" prop="v5">
          <el-input v-model="form.v5" placeholder="请输入v5" />
        </el-form-item>
        <el-form-item label="v6" prop="v6">
          <el-input v-model="form.v6" placeholder="请输入v6" />
        </el-form-item>
        <el-form-item label="v8" prop="v8">
          <el-input v-model="form.v8" placeholder="请输入v8" />
        </el-form-item>
        <el-form-item label="g1" prop="g1">
          <el-input v-model="form.g1" placeholder="请输入g1" />
        </el-form-item>
        <el-form-item label="v9" prop="v9">
          <el-input v-model="form.v9" placeholder="请输入v9" />
        </el-form-item>
        <el-form-item label="g2" prop="g2">
          <el-input v-model="form.g2" placeholder="请输入g2" />
        </el-form-item>
        <el-form-item label="v10" prop="v10">
          <el-input v-model="form.v10" placeholder="请输入v10" />
        </el-form-item>
        <el-form-item label="g5" prop="g5">
          <el-input v-model="form.g5" placeholder="请输入g5" />
        </el-form-item>
        <el-form-item label="v11" prop="v11">
          <el-input v-model="form.v11" placeholder="请输入v11" />
        </el-form-item>
        <el-form-item label="v12" prop="v12">
          <el-input v-model="form.v12" placeholder="请输入v12" />
        </el-form-item>
        <el-form-item label="g6" prop="g6">
          <el-input v-model="form.g6" placeholder="请输入g6" />
        </el-form-item>
        <el-form-item label="v13" prop="v13">
          <el-input v-model="form.v13" placeholder="请输入v13" />
        </el-form-item>
        <el-form-item label="v14" prop="v14">
          <el-input v-model="form.v14" placeholder="请输入v14" />
        </el-form-item>
        <el-form-item label="g7" prop="g7">
          <el-input v-model="form.g7" placeholder="请输入g7" />
        </el-form-item>
        <el-form-item label="v15" prop="v15">
          <el-input v-model="form.v15" placeholder="请输入v15" />
        </el-form-item>
        <el-form-item label="v41" prop="v41">
          <el-input v-model="form.v41" placeholder="请输入v41" />
        </el-form-item>
        <el-form-item label="v42" prop="v42">
          <el-input v-model="form.v42" placeholder="请输入v42" />
        </el-form-item>
        <el-form-item label="v43" prop="v43">
          <el-input v-model="form.v43" placeholder="请输入v43" />
        </el-form-item>
        <el-form-item label="v44" prop="v44">
          <el-input v-model="form.v44" placeholder="请输入v44" />
        </el-form-item>
        <el-form-item label="v45" prop="v45">
          <el-input v-model="form.v45" placeholder="请输入v45" />
        </el-form-item>
        <el-form-item label="v46" prop="v46">
          <el-input v-model="form.v46" placeholder="请输入v46" />
        </el-form-item>
        <el-form-item label="v47" prop="v47">
          <el-input v-model="form.v47" placeholder="请输入v47" />
        </el-form-item>
        <el-form-item label="v48" prop="v48">
          <el-input v-model="form.v48" placeholder="请输入v48" />
        </el-form-item>
        <el-form-item label="v49" prop="v49">
          <el-input v-model="form.v49" placeholder="请输入v49" />
        </el-form-item>
        <el-form-item label="v50" prop="v50">
          <el-input v-model="form.v50" placeholder="请输入v50" />
        </el-form-item>
        <el-form-item label="v51" prop="v51">
          <el-input v-model="form.v51" placeholder="请输入v51" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSpec80r, getSpec80r, delSpec80r, addSpec80r, updateSpec80r } from "@/api/system/spec80r";

export default {
  name: "Spec80r",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 80R设备规格参数表格数据
      spec80rList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        travelLength: undefined,
        itemType: undefined,
        axialType: undefined,
        boxType: undefined,
        v1: undefined,
        v2: undefined,
        v3: undefined,
        v5: undefined,
        v6: undefined,
        v8: undefined,
        g1: undefined,
        v9: undefined,
        g2: undefined,
        v10: undefined,
        g5: undefined,
        v11: undefined,
        v12: undefined,
        g6: undefined,
        v13: undefined,
        v14: undefined,
        g7: undefined,
        v15: undefined,
        v41: undefined,
        v42: undefined,
        v43: undefined,
        v44: undefined,
        v45: undefined,
        v46: undefined,
        v47: undefined,
        v48: undefined,
        v49: undefined,
        v50: undefined,
        v51: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "id不能为空", trigger: "blur" }
        ],
        travelLength: [
          { required: true, message: "行程变量不能为空", trigger: "blur" }
        ],
        itemType: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
        axialType: [
          { required: true, message: "轴向不能为空", trigger: "change" }
        ],
        boxType: [
          { required: true, message: "箱体不能为空", trigger: "change" }
        ],
        v1: [
          { required: true, message: "v1不能为空", trigger: "blur" }
        ],
        v2: [
          { required: true, message: "v2不能为空", trigger: "blur" }
        ],
        v3: [
          { required: true, message: "v3不能为空", trigger: "blur" }
        ],
        v5: [
          { required: true, message: "v5不能为空", trigger: "blur" }
        ],
        v6: [
          { required: true, message: "v6不能为空", trigger: "blur" }
        ],
        v8: [
          { required: true, message: "v8不能为空", trigger: "blur" }
        ],
        g1: [
          { required: true, message: "g1不能为空", trigger: "blur" }
        ],
        v9: [
          { required: true, message: "v9不能为空", trigger: "blur" }
        ],
        g2: [
          { required: true, message: "g2不能为空", trigger: "blur" }
        ],
        v10: [
          { required: true, message: "v10不能为空", trigger: "blur" }
        ],
        g5: [
          { required: true, message: "g5不能为空", trigger: "blur" }
        ],
        v11: [
          { required: true, message: "v11不能为空", trigger: "blur" }
        ],
        v12: [
          { required: true, message: "v12不能为空", trigger: "blur" }
        ],
        g6: [
          { required: true, message: "g6不能为空", trigger: "blur" }
        ],
        v13: [
          { required: true, message: "v13不能为空", trigger: "blur" }
        ],
        v14: [
          { required: true, message: "v14不能为空", trigger: "blur" }
        ],
        g7: [
          { required: true, message: "g7不能为空", trigger: "blur" }
        ],
        v15: [
          { required: true, message: "v15不能为空", trigger: "blur" }
        ],
        v41: [
          { required: true, message: "v41不能为空", trigger: "blur" }
        ],
        v42: [
          { required: true, message: "v42不能为空", trigger: "blur" }
        ],
        v43: [
          { required: true, message: "v43不能为空", trigger: "blur" }
        ],
        v44: [
          { required: true, message: "v44不能为空", trigger: "blur" }
        ],
        v45: [
          { required: true, message: "v45不能为空", trigger: "blur" }
        ],
        v46: [
          { required: true, message: "v46不能为空", trigger: "blur" }
        ],
        v47: [
          { required: true, message: "v47不能为空", trigger: "blur" }
        ],
        v48: [
          { required: true, message: "v48不能为空", trigger: "blur" }
        ],
        v49: [
          { required: true, message: "v49不能为空", trigger: "blur" }
        ],
        v50: [
          { required: true, message: "v50不能为空", trigger: "blur" }
        ],
        v51: [
          { required: true, message: "v51不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询80R设备规格参数列表 */
    getList() {
      this.loading = true;
      listSpec80r(this.queryParams).then(response => {
        this.spec80rList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        travelLength: undefined,
        itemType: undefined,
        axialType: undefined,
        boxType: undefined,
        v1: undefined,
        v2: undefined,
        v3: undefined,
        v5: undefined,
        v6: undefined,
        v8: undefined,
        g1: undefined,
        v9: undefined,
        g2: undefined,
        v10: undefined,
        g5: undefined,
        v11: undefined,
        v12: undefined,
        g6: undefined,
        v13: undefined,
        v14: undefined,
        g7: undefined,
        v15: undefined,
        v41: undefined,
        v42: undefined,
        v43: undefined,
        v44: undefined,
        v45: undefined,
        v46: undefined,
        v47: undefined,
        v48: undefined,
        v49: undefined,
        v50: undefined,
        v51: undefined,
        createTime: undefined,
        updateTime: undefined,
        createBy: undefined,
        updateBy: 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.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加80R设备规格参数";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getSpec80r(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改80R设备规格参数";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateSpec80r(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addSpec80r(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除80R设备规格参数编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delSpec80r(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/spec80r/export', {
        ...this.queryParams
      }, `spec80r_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
