<template>
  <div class="app-container">
    <el-form :rules="queryRules" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
      label-width="68px">
      <el-row>

        <el-col :span="24">
          <el-form-item label-width="auto" label="机组功率(kw)区间" prop="unitPowerKwMin">
            <el-input v-model.number="queryParams.unitPowerKwMin" placeholder="请选择机组功率(kw)" clearable size="small"
              @keyup.enter.native="handleQuery">

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

            </el-input>
          </el-form-item>
          <el-form-item label-width="auto" label="机组功率(kva)区间" prop="unitPowerKvaMin">
            <el-input v-model.number="queryParams.unitPowerKvaMin" placeholder="请选择机组功率(kva)" clearable size="small"
              @keyup.enter.native="handleQuery">

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

            </el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
        </el-col> -->
        <el-col :span="24">

          <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="频率" 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 label="控制器" prop="controllerPrice">
            <el-select @clear="() => {
              controllerPrice = 0
            }" v-model="queryParams.controllerPrice" placeholder="请选择控制器" clearable size="small">
              <el-option v-for="(item, index) in controllerList" @click.native="() => {
                queryParams.controllerModel = item.controllerModel
              }" :label="item.controllerModel" :value="item.controllerPrice" :key="index"></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-col>
      </el-row>








    </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-download" size="mini" @click="handleExport"
          v-hasPermi="['price:info:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

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

      <el-table-column  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 label="品牌"  align="center" prop="brand" />
      <el-table-column  label="柴油机型号" align="center" prop="dieselEngineModel" />
      <el-table-column label="转速" align="center" prop="speed" />
      <!-- <el-table-column label="动力价格" align="center" prop="powerPrice" /> -->

      <el-table-column  label="发电机型号(仿斯坦福)" align="center" prop="generatorModelFstf" />
      <!-- <el-table-column  label="发电机价格(仿斯坦福)" align="center" prop="generatorPriceFstf" /> -->
      <el-table-column  label="发电机型号(利来森马)" align="center" prop="generatorModelLlsm" />
      <!-- <el-table-column  label="发电机价格(利来森马)" align="center" prop="generatorPriceLlsm" /> -->
      <el-table-column  label="发电机型号(美迪奥)" align="center" prop="generatorModelMda" />
      <!-- <el-table-column  label="发电机价格(美迪奥)" align="center" prop="generatorPriceMda" /> -->
      <el-table-column  label="发电机型号(马拉松)" align="center" prop="generatorModelMls" />
      <!-- <el-table-column  label="发电机价格(马拉松)" align="center" prop="generatorPriceMls" /> -->
      <el-table-column  label="发电机型号(斯坦福)" align="center" prop="generatorModelStf" />
      <!-- <el-table-column  label="发电机价格(斯坦福)" align="center" prop="generatorPriceStf" /> -->






      <!-- <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="controllerModel">
        <template>
          {{ controllerModel }}

        </template>
      </el-table-column>



      <el-table-column label="合计含税成本(静音配仿斯坦福)" align="center" prop="totalCostMuteFstf">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(静音配利来森马)" align="center" prop="totalCostMuteLlsm">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(静音配美迪奥)" align="center" prop="totalCostMuteMda">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(静音配马拉松)" align="center" prop="totalCostMuteMls">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(静音配斯坦福)" align="center" prop="totalCostMuteStf">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>

      <el-table-column label="合计含税成本(开架配仿斯坦福)" align="center" prop="totalCostOpenFstf">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(开架配利来森马)" align="center" prop="totalCostOpenLlsm">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(开架配美迪奥)" align="center" prop="totalCostOpenMda">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(开架配马拉松)" align="center" prop="totalCostOpenMls">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(开架配斯坦福)" align="center" prop="totalCostOpenStf">
        <template slot-scope="scope">
          {{ scope.row.totalCostMuteFstf + controllerPrice }}
        </template>
      </el-table-column>

      <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="['price:info:edit']">修改</el-button> -->
            <div style="display:flex;justify-content: center;">
              <el-button @click="() => {
            $router.push('/gallery?id=' + scope.row.id + '&type=1')
          
          }" size="mini" type="text" icon="el-icon-picture-outline">图片</el-button>
            </div>
   


          <!-- 

          <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 { listInfo as controllerListInfo } from "@/api/price/controller";
export default {
  name: "Info",
  data() {
    return {
      controllerModel: '',
      controllerPrice: 0,
      //搜索下拉选项
      searchOption: [[], [], [], []],
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报价表格数据
      infoList: [],
      // 控制器列表
      controllerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //查询参数规则
      queryRules: {
        controllerPrice: [{ required: true, message: '请选择控制器', trigger: 'change', type: 'number' }],
        unitPowerKwMin: [
          { required: false, message: '请输入数字', trigger: 'change', type: 'number' }
        ],
        unitPowerKwMax: [
          { required: false, message: '请输入数字', trigger: 'change', type: 'number' }
        ],
        unitPowerKvaMax: [
          { required: false, message: '请输入数字', trigger: 'change', type: 'number' }
        ],
        unitPowerKvaMin: [
          { required: false, message: '请输入数字', trigger: 'change', type: 'number' }
        ],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brand: null,
        unitModel: null,
        unitPowerKwMax: null,
        unitPowerKwMin: null,
        controllerModel: '',
        controllerPrice: 0,

        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.getControllerList()

    this.getSearchOption()
  },
  methods: {
    getControllerList() {
      controllerListInfo().then(response => {
        this.controllerList = response.rows;

      })

    },
    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.controllerPrice = 0
      this.controllerModel = ''
      this.queryParams.pageNum = 1;
      this.$refs['queryForm'].validate((valid) => {
        if (valid) {
          this.controllerModel = this.queryParams.controllerModel || ''
          this.controllerPrice = this.queryParams.controllerPrice || 0
          this.queryParams.pageNum = 1;
          this.getList();
        } else {

          return false;
        }
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.controllerPrice = 0
      this.controllerModel = ''
      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>