<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-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-width="auto" label="配件" prop="accessory">
            <el-select v-model="computedQuery.accessory">
              <el-option key="1" value="mutePrice" label="静音机壳"></el-option>
              <el-option key="2" value="openPrice" label="开架"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label-width="auto" label="AST" prop="unitPowerKvaMax">
            <el-select v-model="computedQuery.isHaveAst">
              <el-option key="1" :value="true" label="有"></el-option>
              <el-option key="2" :value="false" label="无"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="控制器" prop="controllerPrice">
            <el-select v-model="computedQuery.controllerPrice" placeholder="请选择控制器" clearable size="small">
              <el-option @click.native="() => {
                computedQuery.controllerModel = item.controllerModel
              }" v-for="(item, index) in controllerList" :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-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 size="mini" :row-style="{ height: '25px' }" v-loading="loading" :data="infoList"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column width="100px" label="机组型号" align="center" prop="unitModel" />
      <el-table-column label="机组功率(kw)" align="center" prop="unitPowerKw" />
      <el-table-column label="机组功率备用(kw)" align="center" prop="unitPowerKwSpare" />
      <el-table-column label="机组功率(kva)" align="center" prop="unitPowerKva" />
      <el-table-column label="机组功率备用(kva)" align="center" prop="unitPowerKvaSpare" />
      <el-table-column label="频率(Hz)" align="center" prop="rate" />
      <el-table-column width="100px" label="柴油机型号" align="center" prop="dieselEngineModel" />
      <el-table-column label="品牌" align="center" prop="brand" />
      <el-table-column label="转速" align="center" prop="speed" />
      <el-table-column v-hasPermi="['price:info:list:powerPrice']" v-if="checkPermissions(['price:info:list:powerPrice'])" label="动力价格" align="center" prop="powerPrice" />

      <el-table-column label="发电机型号(仿斯坦福)" align="center" prop="generatorModelFstf" />
      <el-table-column label="发电机价格(仿斯坦福)"  v-if="checkPermissions(['price:info:list:generatorPrice'])"  v-hasPermi="['price:info:list:generatorPrice']" align="center"
        prop="generatorPriceFstf" />
      <el-table-column label="发电机型号(利来森马)" align="center" prop="generatorModelLlsm" />
      <el-table-column label="发电机价格(利来森马)"  v-if="checkPermissions(['price:info:list:generatorPrice'])" v-hasPermi="['price:info:list:generatorPrice']" align="center"
        prop="generatorPriceLlsm" />
      <el-table-column label="发电机型号(美迪奥)" align="center" prop="generatorModelMda" />
      <el-table-column label="发电机价格(美迪奥)"  v-if="checkPermissions(['price:info:list:generatorPrice'])" v-hasPermi="['price:info:list:generatorPrice']" align="center"
        prop="generatorPriceMda" />
      <el-table-column label="发电机型号(马拉松)" align="center" prop="generatorModelMls" />
      <el-table-column label="发电机价格(马拉松)"  v-if="checkPermissions(['price:info:list:generatorPrice'])" v-hasPermi="['price:info:list:generatorPrice']" align="center"
        prop="generatorPriceMls" />
      <el-table-column label="发电机型号(斯坦福)" align="center" prop="generatorModelStf" />
      <el-table-column label="发电机价格(斯坦福)"  v-if="checkPermissions(['price:info:list:generatorPrice'])" v-hasPermi="['price:info:list:generatorPrice']" align="center"
        prop="generatorPriceStf" />

      <el-table-column v-if="computedQuery.accessory == 'mutePrice'&&checkPermissions(['price:info:list:mutePrice'])" label="静音机壳价格" align="center"
        v-hasPermi="['price:info:list:mutePrice']"   prop="mutePrice" />

      <el-table-column v-if="computedQuery.accessory == 'openPrice'&&checkPermissions(['price:info:list:openPrice'])" label="开架价格" align="center"
        v-hasPermi="['price:info:list:openPrice']" prop="openPrice" />

      <el-table-column v-if="computedQuery.isHaveAst" label="ATS型号" align="center" prop="atsModel" />
      <el-table-column v-if="computedQuery.isHaveAst&&checkPermissions(['price:info:list:astPrice'])"  v-hasPermi="['price:info:list:astPrice']" label="ATS价格"
        align="center" prop="atsPrice" />
      <el-table-column label="电瓶型号" align="center" prop="batteryModel" />
      <el-table-column label="电瓶价格" v-hasPermi="['price:info:list:batteryPrice']" v-if="checkPermissions(['price:info:list:batteryPrice'])" align="center" prop="batteryPrice" />
      <el-table-column label="控制器型号" align="center" prop="controllerModel">
        <template>
          {{ computedQuery.controllerModel }}

        </template>
      </el-table-column>
      <el-table-column v-hasPermi="['price:info:list:controllerPrice']" v-if="checkPermissions(['price:info:list:controllerPrice'])" label="控制器价格" align="center"
        prop="controllerPrice">
        <template>
          {{ computedQuery.controllerPrice }}

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


      <el-table-column label="合计含税成本(仿斯坦福)" align="center" prop="totalCostMuteFstf">
        <template slot-scope="scope">
          {{ computedTotalPrice(scope.row, scope.row.generatorPriceFstf) }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(利来森马)" align="center" prop="totalCostMuteLlsm">
        <template slot-scope="scope">
          {{ computedTotalPrice(scope.row, scope.row.generatorPriceLlsm) }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(美迪奥)" align="center" prop="totalCostMuteMda">
        <template slot-scope="scope">
          {{ computedTotalPrice(scope.row, scope.row.generatorPriceMda) }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(马拉松)" align="center" prop="totalCostMuteMls">
        <template slot-scope="scope">
          {{ computedTotalPrice(scope.row, scope.row.generatorPriceMls) }}
        </template>
      </el-table-column>
      <el-table-column label="合计含税成本(斯坦福)" align="center" prop="totalCostMuteStf">
        <template slot-scope="scope">
          {{ computedTotalPrice(scope.row, scope.row.generatorPriceStf) }}
        </template>
      </el-table-column>
      <el-table-column v-if="computedQuery.accessory == 'openPrice'" label="开架尺寸（长/宽/高/重量）" align="center"
        prop="openParms" />
      <el-table-column v-if="computedQuery.accessory == 'mutePrice'" label="静音尺寸（长/宽/高/重量）" align="center"
        prop="muteParms" />



      <!-- <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 width="180px" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <div style="display:inline-flex">
            <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 + '&type=1')
            
            }" 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>
          </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-select v-model="form.brand" placeholder="请选择品牌" clearable size="small" @keyup.enter.native="handleQuery">
            <el-option v-for="(item, index) in searchOption[0]" :value="item" :key="index" :label="item"></el-option>
          </el-select>

        </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="brand">
          <el-input v-model="form.brand" placeholder="请输入动力品牌" />
        </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="generatorModelFstf">
          <el-input v-model="form.generatorModelFstf" placeholder="请输入发电机型号(仿斯坦福)" />
        </el-form-item>
        <el-form-item label="发电机价格(仿斯坦福)" prop="generatorPriceFstf">
          <el-input v-model="form.generatorPriceFstf" placeholder="请输入发电机价格(仿斯坦福)" />
        </el-form-item>
        <el-form-item label="发电机型号(斯坦福)" prop="generatorModelStf">
          <el-input v-model="form.generatorModelStf" placeholder="请输入发电机型号(斯坦福)" />
        </el-form-item>
        <el-form-item label="发电机价格(斯坦福)" prop="generatorPriceStf">
          <el-input v-model="form.generatorPriceStf" placeholder="请输入发电机价格(斯坦福)" />
        </el-form-item>
        <el-form-item label="发电机型号(利来森马)" prop="generatorModelLlsm">
          <el-input v-model="form.generatorModelLlsm" placeholder="请输入发电机型号(利来森马)" />
        </el-form-item>
        <el-form-item label="发电机价格(利来森马)" prop="generatorPriceLlsm">
          <el-input v-model="form.generatorPriceLlsm" placeholder="请输入发电机价格(利来森马)" />
        </el-form-item>
        <el-form-item label="发电机型号(马拉松)" prop="generatorModelMls">
          <el-input v-model="form.generatorModelMls" placeholder="请输入发电机型号(马拉松)" />
        </el-form-item>
        <el-form-item label="发电机价格(马拉松)" prop="generatorPriceMls">
          <el-input v-model="form.generatorPriceMls" placeholder="请输入发电机价格(马拉松)" />
        </el-form-item>
        <el-form-item label="发电机型号(美迪奥)" prop="generatorModelMda">
          <el-input v-model="form.generatorModelMda" placeholder="请输入发电机型号(美迪奥)" />
        </el-form-item>
        <el-form-item label="发电机价格(美迪奥)" prop="generatorPriceMda">
          <el-input v-model="form.generatorPriceMda" 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="totalCostMuteFstf">
          <el-input v-model="form.totalCostMuteFstf" placeholder="请输入合计含税成本(静音配仿斯坦福)" />
        </el-form-item>
        <el-form-item label="合计含税成本(开架配仿斯坦福)" prop="totalCostOpenFstf">
          <el-input v-model="form.totalCostOpenFstf" placeholder="请输入合计含税成本(开架配仿斯坦福)" />
        </el-form-item>
        <el-form-item label="合计含税成本(静音配斯坦福)" prop="totalCostMuteStf">
          <el-input v-model="form.totalCostMuteStf" placeholder="请输入合计含税成本(静音配斯坦福)" />
        </el-form-item>
        <el-form-item label="合计含税成本(开架配斯坦福)" prop="totalCostOpenStf">
          <el-input v-model="form.totalCostOpenStf" placeholder="请输入合计含税成本(开架配斯坦福)" />
        </el-form-item>
        <el-form-item label="合计含税成本(静音配利来森马)" prop="totalCostMuteLlsm">
          <el-input v-model="form.totalCostMuteLlsm" placeholder="请输入合计含税成本(静音配利来森马)" />
        </el-form-item>
        <el-form-item label="合计含税成本(开架配利来森马)" prop="totalCostOpenLlsm">
          <el-input v-model="form.totalCostOpenLlsm" placeholder="请输入合计含税成本(开架配利来森马)" />
        </el-form-item>
        <el-form-item label="合计含税成本(静音配马拉松)" prop="totalCostMuteMls">
          <el-input v-model="form.totalCostMuteMls" placeholder="请输入合计含税成本(静音配马拉松)" />
        </el-form-item>
        <el-form-item label="合计含税成本(开架配马拉松)" prop="totalCostOpenMls">
          <el-input v-model="form.totalCostOpenMls" placeholder="请输入合计含税成本(开架配马拉松)" />
        </el-form-item>
        <el-form-item label="合计含税成本(静音配美迪奥)" prop="totalCostMuteMda">
          <el-input v-model="form.totalCostMuteMda" placeholder="请输入合计含税成本(静音配美迪奥)" />
        </el-form-item>
        <el-form-item label="合计含税成本(开架配美迪奥)" prop="totalCostOpenMda">
          <el-input v-model="form.totalCostOpenMda" placeholder="请输入合计含税成本(开架配美迪奥)" />
        </el-form-item>
        <el-form-item label="静音尺寸" prop="muteParms">
          <el-input v-model="form.muteParms" placeholder="请输入静音尺寸" />
        </el-form-item>
        <el-form-item label="静音尺寸" prop="openParms">
          <el-input v-model="form.openParms" 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/manage";
import { listInfo as controllerListInfo } from "@/api/price/controller";
import { getToken } from '@/utils/auth'
import { mapGetters } from 'vuex'
let computedQuery = {
  accessory: "mutePrice",
  isHaveAst: true,
  controllerPrice: null,
  controllerModel: null
}
const controllerPriceValidator = (rule, value, callBack) => {
  console.log(computedQuery.controllerPrice && computedQuery.controllerModel)
  if (computedQuery.controllerPrice && computedQuery.controllerModel) {
    callBack()
  }
  else {
    callBack(new Error('必须选择一个控制器'))
  }


}
export default {
  name: "Info",
  data() {
    return {

      controllerModel: "",
      controllerPrice: 0,
      token: getToken(),
      fileList: [],
      //搜索下拉选项
      searchOption: [[], [], [], []],
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报价表格数据
      infoList: [],
      // 控制器列表
      controllerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //查询参数规则
      queryRules: {
        controllerPrice: [{ validator: controllerPriceValidator, 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' }
        ],

      },
      //计算参数
      computedQuery: computedQuery,
      // 查询参数
      queryParams: {

        pageNum: 1,
        pageSize: 10,
        brand: null,
        unitModel: null,
        unitPowerKwMax: null,
        unitPowerKwMin: null,
        controllerPrice: 0,
        controllerModel: "",

        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: {
      }
    };
  },
  computed: {
    ...mapGetters(['permissions', 'roles'])
  },
  created() {
    this.getControllerList()

    this.getSearchOption()
  },
  methods: {
    //检查用户是否可以看
    checkPermissions(permissions) {
      let res = false
      //管理员权限完整
      if (this.roles.includes('admin')) {

        return true
      }
      else {
        if (Array.isArray(permissions)) {
          res = permissions.every(item => {
            return this.permissions.includes(item)
          })


        }
        else {
          res = this.permissions.includes(permissions)

        }
        return res




      }


    },

    computedTotalPrice(row, alternatorPrice) {

      let totalPrice = row.powerPrice + alternatorPrice + row[computedQuery.accessory] + computedQuery.controllerPrice + (computedQuery.isHaveAst ? row.atsPrice : 0) + row.batteryPrice
      return totalPrice



    },
    getControllerList() {
      controllerListInfo().then(response => {
        this.controllerList = response.rows;
        this.computedQuery.controllerModel = response.rows[0].controllerModel
        this.computedQuery.controllerPrice = response.rows[0].controllerPrice
      })

    },
    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.$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>