<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]" :value="item" :key="index">{{ item }}</el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="auto" label="机组功率(kw)区间" prop="unitPowerKwMin">
        <el-select v-model="queryParams.unitPowerKwMin" placeholder="请选择机组功率(kw)" clearable size="small"
          @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in searchOption[1]" :value="item" :key="index">{{ item }}</el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="auto" label="到" prop="unitPowerKwMax">
        <el-select v-model="queryParams.unitPowerKwMax" placeholder="请选择机组功率(kw)" clearable size="small"
          @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in searchOption[1]" :value="item" :key="index">{{ item }}</el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="auto"  label="机组功率(kva)区间" prop="unitPowerKvaMin">
        <el-select v-model="queryParams.unitPowerKvaMin" placeholder="请选择机组功率(kva)" clearable size="small"
          @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in searchOption[2]" :value="item" :key="index">{{ item }}</el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="auto" label="到" prop="unitPowerKvaMax">
        <el-select v-model="queryParams.unitPowerKvaMax" placeholder="请选择机组功率(kva)" clearable size="small"
          @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in searchOption[2]" :value="item" :key="index">{{ item }}</el-option>
        </el-select>
      </el-form-item>
 
      <el-form-item label="频率" prop="rate">
        <el-select v-model="queryParams.rate" placeholder="请选择频率" clearable size="small"
          @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in searchOption[3]" :value="item" :key="index">{{ item }}</el-option>
        </el-select>
      </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 type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['price:info:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['price:info:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['price:info:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-top" size="mini" @click="handleExport"
          v-hasPermi="['price:info:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-upload v-hasPermi="['price:info:import']" :show-file-list="false" class="upload-demo" with-credentials
          :headers="{
            'Authorization': 'Bearer ' + token
          }" action="http://xxgl.zzxcx.net/xxgl-admin/price/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="['price:info:export']">导入</el-button>

        </el-upload>

      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table fit :row-style="{ height: '35px' }" v-loading="loading" :data="infoList"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="品牌" align="center" prop="brand" />
      <el-table-column width="180px" label="机组型号" align="center" prop="unitModel" />
      <el-table-column label="机组功率(kw)" align="center" prop="unitPowerKw" />
      <el-table-column label="机组功率(kva)" align="center" prop="unitPowerKva" />
      <el-table-column label="频率(Hz)" align="center" prop="rate" />
      <el-table-column width="180px" label="柴油机型号" align="center" prop="dieselEngineModel" />
      <el-table-column label="转速" align="center" prop="speed" />
      <el-table-column label="动力价格" align="center" prop="powerPrice" />
      <el-table-column width="180px" label="发电机型号" align="center" prop="generatorModel" />
      <el-table-column label="发电机价格" align="center" prop="generatorPrice" />
      <el-table-column label="静音机壳价格" align="center" prop="mutePrice" />
      <el-table-column label="开架价格" align="center" prop="openPrice" />
      <el-table-column label="ATS型号" align="center" prop="atsModel" />
      <el-table-column label="ATS价格" align="center" prop="atsPrice" />
      <el-table-column label="电瓶型号" align="center" prop="batteryModel" />
      <el-table-column label="电瓶价格" align="center" prop="batteryPrice" />
      <el-table-column label="控制器铭贝" align="center" prop="controllerMinbei" />
      <el-table-column label="控制器价格" align="center" prop="controllerPrice" />
      <el-table-column label="合计含税成本(静音)" align="center" prop="totalCostMute" />
      <el-table-column label="合计含税成本(开架)" align="center" prop="totalCostOpen" />
      <el-table-column label="静音尺寸" align="center" prop="muteLong" />
      <el-table-column label="静音尺寸" align="center" prop="muteWidth" />
      <el-table-column label="静音尺寸" align="center" prop="muteHigh" />
      <el-table-column label="开架尺寸" align="center" prop="openLong" />
      <el-table-column label="开架尺寸" align="center" prop="openWidth" />
      <el-table-column label="开架尺寸" align="center" prop="openHigh" />
      <el-table-column label="CKD尺寸" align="center" prop="ckdLong" />
      <el-table-column label="CKD尺寸" align="center" prop="ckdWidth" />
      <el-table-column label="CKD尺寸" align="center" prop="ckdHigh" />
      <el-table-column fixed="right" width="180px" 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="['price:info:edit']">修改</el-button>

          <el-button @click="() => {
            $router.push('/gallery?id=' + scope.row.id)
          
          }" size="mini" type="text" icon="el-icon-picture-outline">图片</el-button>




          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['price:info: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="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="机组型号" prop="unitModel">
          <el-input v-model="form.unitModel" placeholder="请输入机组型号" />
        </el-form-item>
        <el-form-item label="机组功率(kw)" prop="unitPowerKw">
          <el-input v-model="form.unitPowerKw" placeholder="请输入机组功率(kw)" />
        </el-form-item>
        <el-form-item label="机组功率(kva)" prop="unitPowerKva">
          <el-input v-model="form.unitPowerKva" placeholder="请输入机组功率(kva)" />
        </el-form-item>
        <el-form-item label="频率(Hz)" prop="rate">
          <el-input v-model="form.rate" placeholder="请输入频率(Hz)" />
        </el-form-item>
        <el-form-item label="柴油机型号" prop="dieselEngineModel">
          <el-input v-model="form.dieselEngineModel" placeholder="请输入柴油机型号" />
        </el-form-item>
        <el-form-item label="转速" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入转速" />
        </el-form-item>
        <el-form-item label="动力价格" prop="powerPrice">
          <el-input v-model="form.powerPrice" placeholder="请输入动力价格" />
        </el-form-item>
        <el-form-item label="发电机型号" prop="generatorModel">
          <el-input v-model="form.generatorModel" placeholder="请输入发电机型号" />
        </el-form-item>
        <el-form-item label="发电机价格" prop="generatorPrice">
          <el-input v-model="form.generatorPrice" placeholder="请输入发电机价格" />
        </el-form-item>
        <el-form-item label="静音机壳价格" prop="mutePrice">
          <el-input v-model="form.mutePrice" placeholder="请输入静音机壳价格" />
        </el-form-item>
        <el-form-item label="开架价格" prop="openPrice">
          <el-input v-model="form.openPrice" placeholder="请输入开架价格" />
        </el-form-item>
        <el-form-item label="ATS型号" prop="atsModel">
          <el-input v-model="form.atsModel" placeholder="请输入ATS型号" />
        </el-form-item>
        <el-form-item label="ATS价格" prop="atsPrice">
          <el-input v-model="form.atsPrice" placeholder="请输入ATS价格" />
        </el-form-item>
        <el-form-item label="电瓶型号" prop="batteryModel">
          <el-input v-model="form.batteryModel" placeholder="请输入电瓶型号" />
        </el-form-item>
        <el-form-item label="电瓶价格" prop="batteryPrice">
          <el-input v-model="form.batteryPrice" placeholder="请输入电瓶价格" />
        </el-form-item>
        <el-form-item label="控制器铭贝" prop="controllerMinbei">
          <el-input v-model="form.controllerMinbei" placeholder="请输入控制器铭贝" />
        </el-form-item>
        <el-form-item label="控制器价格" prop="controllerPrice">
          <el-input v-model="form.controllerPrice" placeholder="请输入控制器价格" />
        </el-form-item>
        <el-form-item label="合计含税成本(静音)" prop="totalCostMute">
          <el-input v-model="form.totalCostMute" placeholder="请输入合计含税成本(静音)" />
        </el-form-item>
        <el-form-item label="合计含税成本(开架)" prop="totalCostOpen">
          <el-input v-model="form.totalCostOpen" placeholder="请输入合计含税成本(开架)" />
        </el-form-item>
        <el-form-item label="静音尺寸" prop="muteLong">
          <el-input v-model="form.muteLong" placeholder="请输入静音尺寸" />
        </el-form-item>
        <el-form-item label="静音尺寸" prop="muteWidth">
          <el-input v-model="form.muteWidth" placeholder="请输入静音尺寸" />
        </el-form-item>
        <el-form-item label="静音尺寸" prop="muteHigh">
          <el-input v-model="form.muteHigh" placeholder="请输入静音尺寸" />
        </el-form-item>
        <el-form-item label="开架尺寸" prop="openLong">
          <el-input v-model="form.openLong" placeholder="请输入开架尺寸" />
        </el-form-item>
        <el-form-item label="开架尺寸" prop="openWidth">
          <el-input v-model="form.openWidth" placeholder="请输入开架尺寸" />
        </el-form-item>
        <el-form-item label="开架尺寸" prop="openHigh">
          <el-input v-model="form.openHigh" placeholder="请输入开架尺寸" />
        </el-form-item>
        <el-form-item label="CKD尺寸" prop="ckdLong">
          <el-input v-model="form.ckdLong" placeholder="请输入CKD尺寸" />
        </el-form-item>
        <el-form-item label="CKD尺寸" prop="ckdWidth">
          <el-input v-model="form.ckdWidth" placeholder="请输入CKD尺寸" />
        </el-form-item>
        <el-form-item label="CKD尺寸" prop="ckdHigh">
          <el-input v-model="form.ckdHigh" placeholder="请输入CKD尺寸" />
        </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/manage";
import { getToken } from '@/utils/auth'
export default {
  name: "Info",
  data() {
    return {
      token: getToken(),
      fileList: [],
      //搜索下拉选项
      searchOption: [[], [], [], []],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报价表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brand: null,
        unitModel: null,
        unitPowerKwMax: null,
        unitPowerKwMin: null,


        unitPowerKvaMax: null,
        unitPowerKvaMin: null,

        rate: null,
        dieselEngineModel: null,
        speed: null,
        powerPrice: null,
        generatorModel: null,
        generatorPrice: null,
        mutePrice: null,
        openPrice: null,
        atsModel: null,
        atsPrice: null,
        batteryModel: null,
        batteryPrice: null,
        controllerMinbei: null,
        controllerPrice: null,
        totalCostMute: null,
        totalCostOpen: null,
        muteLong: null,
        muteWidth: null,
        muteHigh: null,
        openLong: null,
        openWidth: null,
        openHigh: null,
        ckdLong: null,
        ckdWidth: null,
        ckdHigh: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getSearchOption()
  },
  methods: {
    handleSuccess() {
      this.msgSuccess("上传成功");
      this.getList()
    },
    push(url) {
      this.router.push(url)
    },
    getSearchOption() {
      getFieldName('brand').then(response => {
        this.$set(this.searchOption, 0, response.data);

      })
      getFieldName('unit_power_kw').then(response => {
        this.$set(this.searchOption, 1, response.data);

      })
      getFieldName('unit_power_kva').then(response => {
        this.$set(this.searchOption, 2, response.data);

      })
      getFieldName('rate').then(response => {
        this.$set(this.searchOption, 3, response.data);

      })

    },
    /** 查询报价列表 */
    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,
        unitModel: null,
        unitPowerKw: null,
        unitPowerKva: null,
        rate: null,
        dieselEngineModel: null,
        speed: null,
        powerPrice: null,
        generatorModel: null,
        generatorPrice: null,
        mutePrice: null,
        openPrice: null,
        atsModel: null,
        atsPrice: null,
        batteryModel: null,
        batteryPrice: null,
        controllerMinbei: null,
        controllerPrice: null,
        totalCostMute: null,
        totalCostOpen: null,
        muteLong: null,
        muteWidth: null,
        muteHigh: null,
        openLong: null,
        openWidth: null,
        openHigh: null,
        ckdLong: null,
        ckdWidth: null,
        ckdHigh: 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('是否确认删除这' + this.ids.length + '数据项?', "警告", {
        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>