<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="动力品牌" prop="brand">
        <el-select v-model="queryParams.brand" placeholder="请输入动力品牌" clearable size="small"
          @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in searchOption[0]" :key="index" :value="item" :label="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="auto" label="发动机主功率(kw)区间" prop="powerKwMax">
            <el-input v-model.number="queryParams.powerKwMin" placeholder="请选择主功率(kw)" clearable size="small"
              @keyup.enter.native="handleQuery">

            </el-input>
          </el-form-item>
          <el-form-item label-width="auto" label="到" prop="powerKwMin">
            <el-input v-model.number="queryParams.powerKwMax" placeholder="请选择主功率(kw)" clearable size="small"
              @keyup.enter.native="handleQuery">

            </el-input>
          </el-form-item>
      <!-- <el-form-item label="型号" prop="model">
        <el-input
          v-model="queryParams.model"
          placeholder="请输入型号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="发动机主要功率(1500RPM  50HZ)" prop="enginePowerMajor1500rpm">
        <el-input
          v-model="queryParams.enginePowerMajor1500rpm"
          placeholder="请输入发动机主要功率(1500RPM  50HZ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发动机备用功率(1500RPM  50HZ)" prop="enginePowerMinor1500rpm">
        <el-input
          v-model="queryParams.enginePowerMinor1500rpm"
          placeholder="请输入发动机备用功率(1500RPM  50HZ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐机组主要功率(1500RPM  50HZ)" prop="unitPowerMajor1500rpm">
        <el-input
          v-model="queryParams.unitPowerMajor1500rpm"
          placeholder="请输入推荐机组主要功率(1500RPM  50HZ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐机组备用功率(1500RPM  50HZ)" prop="unitPowerMinor1500rpm">
        <el-input
          v-model="queryParams.unitPowerMinor1500rpm"
          placeholder="请输入推荐机组备用功率(1500RPM  50HZ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发动机主要功率(1800RPM  60HZ)" prop="enginePowerMajor1800rpm">
        <el-input
          v-model="queryParams.enginePowerMajor1800rpm"
          placeholder="请输入发动机主要功率(1800RPM  60HZ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发动机备用功率(1800RPM  60HZ)" prop="enginePowerMinor1800rpm">
        <el-input
          v-model="queryParams.enginePowerMinor1800rpm"
          placeholder="请输入发动机备用功率(1800RPM  60HZ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐机组主要功率(1800RPM  60HZ)" prop="unitPowerMajor1800rpm">
        <el-input
          v-model="queryParams.unitPowerMajor1800rpm"
          placeholder="请输入推荐机组主要功率(1800RPM  60HZ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐机组备用功率(1800RPM  60HZ)" prop="unitPowerMinor1800rpm">
        <el-input
          v-model="queryParams.unitPowerMinor1800rpm"
          placeholder="请输入推荐机组备用功率(1800RPM  60HZ)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油泵形式" prop="oilForm">
        <el-input
          v-model="queryParams.oilForm"
          placeholder="请输入油泵形式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进气方式" prop="airIntakeMode">
        <el-input
          v-model="queryParams.airIntakeMode"
          placeholder="请输入进气方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电压" prop="voltage">
        <el-input
          v-model="queryParams.voltage"
          placeholder="请输入电压"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排量 " prop="displacement">
        <el-input
          v-model="queryParams.displacement"
          placeholder="请输入排量 "
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油耗" prop="oilConsumption">
        <el-input
          v-model="queryParams.oilConsumption"
          placeholder="请输入油耗"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="水箱重量(Kg)" prop="tankWeight">
        <el-input
          v-model="queryParams.tankWeight"
          placeholder="请输入水箱重量(Kg)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="动力尺寸L*W*H(mm)" prop="powerSize">
        <el-input
          v-model="queryParams.powerSize"
          placeholder="请输入动力尺寸L*W*H(mm)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="水箱尺寸L*W*H(mm)" prop="tankSize">
        <el-input
          v-model="queryParams.tankSize"
          placeholder="请输入水箱尺寸L*W*H(mm)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排放标准" prop="
emissionStandard">
        <el-input
          v-model="queryParams.emissionStandard"
          placeholder="请输入排放标准"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="配置说明" prop="configurationDescription">
        <el-input
          v-model="queryParams.configurationDescription"
          placeholder="请输入配置说明"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入价格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="水箱价格" prop="tankPrice">
        <el-input
          v-model="queryParams.tankPrice"
          placeholder="请输入水箱价格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="cyan" 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 v-hasPermi="['engine:info:add']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['engine:info:update']" type="success" icon="el-icon-edit" size="mini" :disabled="single"
          @click="handleUpdate">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['engine:info:remove']" type="danger" icon="el-icon-delete" size="mini" :disabled="multiple"
          @click="handleDelete">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-upload
          v-hasPermi="['engine:info:import']"
          :show-file-list="false"
          class="upload-demo"
          with-credentials
          :headers="{
            Authorization: 'Bearer ' + token,
          }"
          action="https://xxgl.zzxcx.net/stage-api/engine/info/import"
          :on-success="handleSuccess"
          multiple
          accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
          :file-list="fileList"
        >
          <el-button
            type="warning"
            icon="el-icon-bottom"
            size="mini"
            v-hasPermi="['engine:info:import']"
            >导入</el-button
          >
        </el-upload>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table  size="mini" v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column  label="动力品牌" :width="'100px'"  align="center" prop="brand" >
      
      </el-table-column>
      <el-table-column fixed label="型号" align="center" prop="model" />
      <el-table-column fixed label="发动机主要功率(1500RPM  50HZ)" align="center" prop="enginePowerMajor1500rpm" />
      <el-table-column label="发动机备用功率(1500RPM  50HZ)" align="center" prop="enginePowerMinor1500rpm" />
      <el-table-column label="推荐机组主要功率(1500RPM  50HZ)" align="center" prop="unitPowerMajor1500rpm" />
      <el-table-column label="推荐机组备用功率(1500RPM  50HZ)" align="center" prop="unitPowerMinor1500rpm" />
      <el-table-column label="发动机主要功率(1800RPM  60HZ)" align="center" prop="enginePowerMajor1800rpm" />
      <el-table-column label="发动机备用功率(1800RPM  60HZ)" align="center" prop="enginePowerMinor1800rpm" />
      <el-table-column label="推荐机组主要功率(1800RPM  60HZ)" align="center" prop="unitPowerMajor1800rpm" />
      <el-table-column label="推荐机组备用功率(1800RPM  60HZ)" align="center" prop="unitPowerMinor1800rpm" />
      <el-table-column label="油泵形式" align="center" prop="oilForm" />
      <el-table-column label="进气方式" align="center" prop="airIntakeMode" />
      <el-table-column label="电压" align="center" prop="voltage" />
      <el-table-column label="排量 " align="center" prop="displacement" />
      <el-table-column label="油耗" align="center" prop="oilConsumption" />
      <el-table-column label="排放标准" align="center" prop="emissionStandard" />
      <el-table-column label="动力价格" align="center" prop="enginePrice" />
      <el-table-column label="动力重量" align="center" prop="engineWeight" />
      <el-table-column label="动力尺寸L*W*H(mm)" align="center" prop="powerSize" />
      <!-- <el-table-column label="水箱重量(Kg)" align="center" prop="tankWeight" /> -->
 

      <el-table-column label="水箱40度铝价格" align="center" prop="tank40LvPrice" />
      <el-table-column label="水箱40度铜价格" align="center" prop="tank40TongPrice" />
      <el-table-column label="水箱50度铝价格" align="center" prop="tank50LvPrice" />
      <el-table-column label="水箱50度铜价格" align="center" prop="tank50TongPrice" />

      <el-table-column label="水箱40度铝重量" align="center" prop="tank40LvWeight" />
      <el-table-column label="水箱40度铜重量" align="center" prop="tank40TongWeight" />
      <el-table-column label="水箱50度铝重量" align="center" prop="tank50LvWeight" />
      <el-table-column label="水箱50度铜重量" align="center" prop="tank50TongWeight" />


      <el-table-column label="水箱尺寸L*W*H(mm)" align="center" prop="tankSize" />
     
      <el-table-column label="配置说明" align="center" prop="configurationDescription" />
      <el-table-column label="水箱价格" align="center" prop="tankPrice" />

      <el-table-column label="操作" align="center" width="150px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <div style="display:flex">
            <el-button v-hasPermi="['engine:info:update']" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
            <el-button v-hasPermi="['engine:info:remove']" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
            <el-button @click="() => {
              $router.push('/gallery?id=' + scope.row.id + '&type=2')
            
            }" size="mini" type="text" icon="el-icon-picture-outline">图片</el-button>
          </div>

        </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="brand">
          <el-input v-model="form.brand" placeholder="请输入动力品牌" />
        </el-form-item>
        <el-form-item label="型号" prop="model">
          <el-input v-model="form.model" placeholder="请输入型号" />
        </el-form-item>
        <el-form-item label="发动机主要功率(1500RPM  50HZ)" prop="enginePowerMajor1500rpm">
          <el-input v-model="form.enginePowerMajor1500rpm" placeholder="请输入发动机主要功率(1500RPM  50HZ)" />
        </el-form-item>
        <el-form-item label="发动机备用功率(1500RPM  50HZ)" prop="enginePowerMinor1500rpm">
          <el-input v-model="form.enginePowerMinor1500rpm" placeholder="请输入发动机备用功率(1500RPM  50HZ)" />
        </el-form-item>
        <el-form-item label="推荐机组主要功率(1500RPM  50HZ)" prop="unitPowerMajor1500rpm">
          <el-input v-model="form.unitPowerMajor1500rpm" placeholder="请输入推荐机组主要功率(1500RPM  50HZ)" />
        </el-form-item>
        <el-form-item label="推荐机组备用功率(1500RPM  50HZ)" prop="unitPowerMinor1500rpm">
          <el-input v-model="form.unitPowerMinor1500rpm" placeholder="请输入推荐机组备用功率(1500RPM  50HZ)" />
        </el-form-item>
        <el-form-item label="发动机主要功率(1800RPM  60HZ)" prop="enginePowerMajor1800rpm">
          <el-input v-model="form.enginePowerMajor1800rpm" placeholder="请输入发动机主要功率(1800RPM  60HZ)" />
        </el-form-item>
        <el-form-item label="发动机备用功率(1800RPM  60HZ)" prop="enginePowerMinor1800rpm">
          <el-input v-model="form.enginePowerMinor1800rpm" placeholder="请输入发动机备用功率(1800RPM  60HZ)" />
        </el-form-item>
        <el-form-item label="推荐机组主要功率(1800RPM  60HZ)" prop="unitPowerMajor1800rpm">
          <el-input v-model="form.unitPowerMajor1800rpm" placeholder="请输入推荐机组主要功率(1800RPM  60HZ)" />
        </el-form-item>
        <el-form-item label="推荐机组备用功率(1800RPM  60HZ)" prop="unitPowerMinor1800rpm">
          <el-input v-model="form.unitPowerMinor1800rpm" placeholder="请输入推荐机组备用功率(1800RPM  60HZ)" />
        </el-form-item>
        <el-form-item label="油泵形式" prop="oilForm">
          <el-input v-model="form.oilForm" placeholder="请输入油泵形式" />
        </el-form-item>
        <el-form-item label="进气方式" prop="airIntakeMode">
          <el-input v-model="form.airIntakeMode" placeholder="请输入进气方式" />
        </el-form-item>
        <el-form-item label="电压" prop="voltage">
          <el-input v-model="form.voltage" placeholder="请输入电压" />
        </el-form-item>
        <el-form-item label="排量 " prop="displacement">
          <el-input v-model="form.displacement" placeholder="请输入排量 " />
        </el-form-item>
        <el-form-item label="油耗" prop="oilConsumption">
          <el-input v-model="form.oilConsumption" placeholder="请输入油耗" />
        </el-form-item>
        <el-form-item label="水箱重量(Kg)" prop="tankWeight">
          <el-input v-model="form.tankWeight" placeholder="请输入水箱重量(Kg)" />
        </el-form-item>
        <el-form-item label="动力尺寸L*W*H(mm)" prop="powerSize">
          <el-input v-model="form.powerSize" placeholder="请输入动力尺寸L*W*H(mm)" />
        </el-form-item>
        <el-form-item label="水箱尺寸L*W*H(mm)" prop="tankSize">
          <el-input v-model="form.tankSize" placeholder="请输入水箱尺寸L*W*H(mm)" />
        </el-form-item>
        <el-form-item label="排放标准" prop="emissionStandard">
          <el-input v-model="form.emissionStandard" placeholder="请输入排放标准" />
        </el-form-item>
        <el-form-item label="配置说明" prop="configurationDescription">
          <el-input v-model="form.configurationDescription" placeholder="请输入配置说明" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="水箱价格" prop="tankPrice">
          <el-input v-model="form.tankPrice" 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 { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo, getFieldName } from "@/api/price/engine";
import { mapGetters } from 'vuex'
import { getToken } from "@/utils/auth";
export default {
  name: "Info",
  data() {
    return {
      token: getToken(),
      searchOption: [[], [], [], []],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报价表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brand: null,
        model: null,
        enginePowerMajor1500rpm: null,
        enginePowerMinor1500rpm: null,
        unitPowerMajor1500rpm: null,
        unitPowerMinor1500rpm: null,
        enginePowerMajor1800rpm: null,
        enginePowerMinor1800rpm: null,
        unitPowerMajor1800rpm: null,
        unitPowerMinor1800rpm: null,
        oilForm: null,
        airIntakeMode: null,
        voltage: null,
        displacement: null,
        oilConsumption: null,
        tankWeight: null,
        powerSize: null,
        tankSize: null,
        powerKwMax:"",
        powerKwMin:"",
        emissionStandard: null,
        configurationDescription: null,
        price: null,
        tankPrice: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getSearchOption()
    this.getList();
  },
  computed: {
    ...mapGetters(['permissions', 'roles', 'tableColumnWidth','tableColumnWidthMedium','tableColumnWidthSamll','tableColumnWidthMini'])
  },
  methods: {
    getSearchOption() {
      getFieldName('brand').then(response => {
        this.$set(this.searchOption, 0, response.data);

      })


    },
    handleSuccess() {
      this.msgSuccess("上传成功");
      this.getSearchOption();
      this.getList()
    },

    /** 查询报价列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        brand: null,
        model: null,
        enginePowerMajor1500rpm: null,
        enginePowerMinor1500rpm: null,
        unitPowerMajor1500rpm: null,
        unitPowerMinor1500rpm: null,
        enginePowerMajor1800rpm: null,
        enginePowerMinor1800rpm: null,
        unitPowerMajor1800rpm: null,
        unitPowerMinor1800rpm: null,
        oilForm: null,
        airIntakeMode: null,
        voltage: null,
        displacement: null,
        oilConsumption: null,
        tankWeight: null,
        powerSize: null,
        tankSize: null,

        emissionStandard: null,
        configurationDescription: null,
        price: null,
        tankPrice: null,
        createTime: null,
        updateTime: null
      };
      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.reset();
      const id = row.id || this.ids
      getInfo(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) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除报价编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有报价数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportInfo(queryParams);
      }).then(response => {
        this.download(response.data);
      })
    }
  }
};
</script>