<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="型号规格" prop="fdjModel">
        <el-input
          v-model="queryParams.fdjModel"
          placeholder="请输入型号规格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标准止口" prop="standardSeam">
        <el-input
          v-model="queryParams.standardSeam"
          placeholder="请输入标准止口"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="频率(Hz)" prop="rate">
        <el-input
          v-model="queryParams.rate"
          placeholder="请输入频率(Hz)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="功率 3-ph/50Hz/380-440V(kw)" prop="fdjPowerKw">
        <el-input
          v-model="queryParams.fdjPowerKw"
          placeholder="请输入功率 3-ph/50Hz/380-440V(kw)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="功率 3-ph/50Hz/380-440V(kva)" prop="fdjPowerKva">
        <el-input
          v-model="queryParams.fdjPowerKva"
          placeholder="请输入功率 3-ph/50Hz/380-440V(kva)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="含税出厂价" prop="singleFulcrumPrice">
        <el-input
          v-model="queryParams.singleFulcrumPrice"
          placeholder="请输入含税出厂价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="含税出厂价" prop="doubleFulcrumPrice">
        <el-input
          v-model="queryParams.doubleFulcrumPrice"
          placeholder="请输入含税出厂价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="含税出厂价" prop="packingBoxPrice">
        <el-input
          v-model="queryParams.packingBoxPrice"
          placeholder="请输入含税出厂价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="含税出厂价" prop="instrumentBoxPrice">
        <el-input
          v-model="queryParams.instrumentBoxPrice"
          placeholder="请输入含税出厂价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="含税出厂价" prop="airSwitchPrice">
        <el-input
          v-model="queryParams.airSwitchPrice"
          placeholder="请输入含税出厂价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包装尺寸
" prop="openParms">
        <el-input
          v-model="queryParams.openParms"
          placeholder="请输入包装尺寸
"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="净重/毛重" prop="weight">
        <el-input
          v-model="queryParams.weight"
          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
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['price:generator:hz50: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:generator:hz50:update']"
          >修改</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:generator:hz50:remove']"
          >删除</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="['price:generator:hz50:import']"
          :show-file-list="false"
          class="upload-demo"
          with-credentials
          :headers="{
            Authorization: 'Bearer ' + token,
          }"
          action="https://xxgl.zzxcx.net/stage-api/fdj50/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:generator:hz50:import']"
            >导入</el-button
          >
        </el-upload>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      fit
      v-loading="loading"
      size="mini"
      :data="infoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键" align="center" prop="id" /> -->
      <el-table-column label="型号规格" align="center" prop="fdjModel" />
      <el-table-column label="标准止口" align="center" prop="standardSeam" />
      <el-table-column label="频率(Hz)" align="center" prop="rate" />
      <el-table-column
        label="功率 3-ph/50Hz/380-440V(kw)"
        align="center"
        prop="fdjPowerKw"
      />
      <el-table-column
        label="功率 3-ph/50Hz/380-440V(kva)"
        align="center"
        prop="fdjPowerKva"
      />
      <el-table-column
        label="含税出厂价(单支点)"
        align="center"
        prop="singleFulcrumPrice"
      />
      <el-table-column
        label="含税出厂价(双支点)"
        align="center"
        prop="doubleFulcrumPrice"
      />
      <el-table-column
        label="含税出厂价(包装箱价格)"
        align="center"
        prop="packingBoxPrice"
      />
      <el-table-column
        label="含税出厂价(仪表箱)"
        align="center"
        prop="instrumentBoxPrice"
      />
      <el-table-column
        label="含税出厂价(空开)"
        align="center"
        prop="airSwitchPrice"
      />
      <el-table-column label="包装尺寸" align="center" prop="openParms" />
      <el-table-column label="净重/毛重" align="center" prop="weight" />

      <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:generator:hz60:update']"
              >修改</el-button
            >
            <el-button
              @click="
                () => {
                  $router.push('/gallery?id=' + scope.row.id + '&type=4');
                }
              "
              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:generator:hz60: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"
    /> -->

    <!-- 添加或修改发电机60hz报价对话框 -->
    <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="fdjModel">
          <el-input v-model="form.fdjModel" placeholder="请输入型号规格" />
        </el-form-item>
        <el-form-item label="标准止口" prop="standardSeam">
          <el-input v-model="form.standardSeam" placeholder="请输入标准止口" />
        </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="功率 3-ph/50Hz/380-440V(kw)" prop="fdjPowerKw">
          <el-input
            v-model="form.fdjPowerKw"
            placeholder="请输入功率 3-ph/50Hz/380-440V(kw)"
          />
        </el-form-item>
        <el-form-item label="功率 3-ph/50Hz/380-440V(kva)" prop="fdjPowerKva">
          <el-input
            v-model="form.fdjPowerKva"
            placeholder="请输入功率 3-ph/50Hz/380-440V(kva)"
          />
        </el-form-item>
        <el-form-item label="含税出厂价" prop="singleFulcrumPrice">
          <el-input
            v-model="form.singleFulcrumPrice"
            placeholder="请输入含税出厂价"
          />
        </el-form-item>
        <el-form-item label="含税出厂价" prop="doubleFulcrumPrice">
          <el-input
            v-model="form.doubleFulcrumPrice"
            placeholder="请输入含税出厂价"
          />
        </el-form-item>
        <el-form-item label="含税出厂价" prop="packingBoxPrice">
          <el-input
            v-model="form.packingBoxPrice"
            placeholder="请输入含税出厂价"
          />
        </el-form-item>
        <el-form-item label="含税出厂价" prop="instrumentBoxPrice">
          <el-input
            v-model="form.instrumentBoxPrice"
            placeholder="请输入含税出厂价"
          />
        </el-form-item>
        <el-form-item label="含税出厂价" prop="airSwitchPrice">
          <el-input
            v-model="form.airSwitchPrice"
            placeholder="请输入含税出厂价"
          />
        </el-form-item>
        <el-form-item
          label="包装尺寸
"
          prop="openParms"
        >
          <el-input
            v-model="form.openParms"
            placeholder="请输入包装尺寸
"
          />
        </el-form-item>
        <el-form-item label="净重/毛重" prop="weight">
          <el-input v-model="form.weight" 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,
} from "@/api/price/hz50";
import { getToken } from "@/utils/auth";
export default {
  name: "Info",
  data() {
    return {
      token: getToken(),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 发电机60hz报价表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 1000,
        fdjModel: null,
        standardSeam: null,
        rate: null,
        fdjPowerKw: null,
        fdjPowerKva: null,
        singleFulcrumPrice: null,
        doubleFulcrumPrice: null,
        packingBoxPrice: null,
        instrumentBoxPrice: null,
        airSwitchPrice: null,
        openParms: null,
        weight: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleSuccess() {
      this.msgSuccess("上传成功");
      this.getList();
      // this.getList()
    },
    /** 查询发电机60hz报价列表 */
    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,
        fdjModel: null,
        standardSeam: null,
        rate: null,
        fdjPowerKw: null,
        fdjPowerKva: null,
        singleFulcrumPrice: null,
        doubleFulcrumPrice: null,
        packingBoxPrice: null,
        instrumentBoxPrice: null,
        airSwitchPrice: null,
        openParms: null,
        weight: null,
        updateTime: null,
        createTime: 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 = "添加发电机60hz报价";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getInfo(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改发电机60hz报价";
      });
    },
    /** 提交按钮 */
    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(
        '是否确认删除发电机60hz报价编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delInfo(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有发电机60hz报价数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportInfo(queryParams);
        })
        .then((response) => {
          this.download(response.data);
        });
    },
  },
};
</script>