<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="projectParameters">
        <el-input
          v-model="queryParams.projectParameters"
          placeholder="请输入项目参数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重量" prop="weight">
        <el-input
          v-model="queryParams.weight"
          placeholder="请输入重量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报价" prop="quote">
        <el-input
          v-model="queryParams.quote"
          placeholder="请输入报价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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:quote: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:quote: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:quote: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:quote:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- <el-row>
      <el-col :span="4" v-for="(item, index) in quoteList" :key="index" :offset="index > 0 ? 2 : 0">
        <el-card :body-style="{ padding: '0px' }">
          <div style="padding: 14px;">
            <span>{{ item.name }}</span>
            <div class="bottom clearfix">
              <el-button type="text" class="button">編輯</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row> -->

    <div class="title">
      <h1>升降台快速报价工具表</h1>
      <h3>(所有长度单位为m，重量单位为kg，功率为kW)</h3>
    </div>


    <el-tabs type="border-card" @tab-click="handleClick">
      <!-- 将结果展示到表格中   -->
      <el-tabs v-model="activeName" type="border-card">

        <el-tab-pane  v-for="(item, index) in quoteList" :key="index" :label="item.name">
          <h2 class="name">{{ item.name }}</h2>
          <div class="params">
            <h3 v-for="(keyItem,keyIndex) in Object.keys(quoteList[index])" :key="keyIndex">{{ item[Object.keys(item)[keyIndex + 1]] }}</h3>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-tabs>

    <!-- 添加或修改项目报价对话框 -->
    <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="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目参数" prop="projectParameters">
          <el-input v-model="form.projectParameters" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="重量" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入重量" />
        </el-form-item>
        <el-form-item label="报价" prop="quote">
          <el-input v-model="form.quote" placeholder="请输入报价" />
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </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>
<style>
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.title{
  width: 100%;
}

.title>h1,.title>h3{
  text-align: center;
  color: #4169E1;
  font-weight: bolder;
}

.name{
  font-weight: bolder;
}

.params{
  margin: 20px;
}
</style>


<script>
import { listQuote, getQuote, delQuote, addQuote, updateQuote } from "@/api/system/quote";

export default {
  name: "Quote",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目报价表格数据
      quoteList: [],
      //键
      keys:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: undefined,
        projectParameters: undefined,
        weight: undefined,
        quote: undefined,
        createdBy: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "主键ID不能为空", trigger: "blur" }
        ],
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        projectParameters: [
          { required: true, message: "项目参数不能为空", trigger: "blur" }
        ],
        weight: [
          { required: true, message: "重量不能为空", trigger: "blur" }
        ],
        quote: [
          { required: true, message: "报价不能为空", trigger: "blur" }
        ],
        createdBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "修改时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询项目报价列表 */
    getList() {
      this.loading = true;
      // listQuote(this.queryParams).then(response => {
      //   this.quoteList = response.rows;
      //   this.total = response.total;
      //   this.loading = false;
      // });
      this.quoteList = [
        {
          "name":"台体+底座",
          "route":"行程：0",
          "length":1200,
          "width":200,
          "weight":0,
          "addBedWeght":0,
          "quote":0
        },{
          "name":"剪臂",
          "route":"行程：0",
          "length":-0.3,
          "width":-0.3,
          "lengthWeight":-5.76,
          "widthWeight":-5.76,
          "lengthCrossNum":1,
          "shortSlabCrossNum":1,
          "weight":-46.08,
          "quote":-1198.08
        },{
          "name":"刚性链",
          "route":"行程：0",
          "dynamicLoad":0,
          "weight":0,
          "mesaAndShearArm":-23.04,
          "num":2,
          "dynamicLoadCount":-23.04,
          "load":0,
          "quote":0
        },{
          "name":"全栈工程师",
          "route":"行程：0",
          "dynamicLoad":0,
          "weight":0,
          "mesaAndShearArm":-23.04,
          "num":2,
          "dynamicLoadCount":-23.04,
          "load":0,
          "quote":0
        }
      ]
      // this.getKeys(0)
    },
    //通过下标获取所有键名
    getKeys(index){
      var keys = Object.keys(this.quoteList[index])
      for (let i = 0; i < keys.length; i++) {
        const key = "{{ item." + keys[i] + " }}";
        this.keys.push(key)
      }
    },
    //标签页选中事件
    handleClick(tab) {
        this.getKeys(tab.paneName)
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        projectName: undefined,
        projectParameters: undefined,
        weight: undefined,
        quote: undefined,
        createdBy: undefined,
        updateBy: undefined,
        createTime: undefined,
        updateTime: 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 = "添加项目报价";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getQuote(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改项目报价";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateQuote(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addQuote(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('是否确认删除项目报价编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delQuote(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/quote/export', {
        ...this.queryParams
      }, `quote_${new Date().getTime()}.xlsx`)
    }
  }
};

</script>
