Newer
Older
smartKitchenFront / src / views / product / snCodeRuls.vue
liyaguang on 4 Dec 2022 7 KB fix: 修改word新提bug
<!--SN码规则列表-->
<template>
  <div class="product_container">
    <div class="productFun">
      <div class="productInput">
        SN码 (固定标识):
        <div class="inputBox" style="width: 200px">
          <el-input
            v-model="selectInfo.snCode"
            placeholder="请输入SN码固定标识"
            clearable
            class="product-input"
          />
        </div>
        个数:
        <div class="inputBox" style="width: 220px">
          <el-input
            v-model="selectInfo.snQuantity"
            placeholder="请输入SN码固定标识个数"
            clearable
            class="product-input"
          />
        </div>
      </div>
      <div class="productBtn">
        <el-button
          type="primary"
          icon="el-icon-search"
          class="btnItem"
          @click="selectData"
        >
          查询
        </el-button>
        <el-button
          type="primary"
          icon="el-icon-refresh-right"
          class="btnItem"
          @click="reset"
        >
          重置
        </el-button>
        <el-button
          type="success"
          icon="el-icon-circle-plus-outline"
          class="btnItem bggreen"
          @click="addCategory"
        >
          新增
        </el-button>
        <el-button
          type="danger"
          icon="el-icon-delete-solid"
          class="btnItem bgred"
          @click="BatchDelete"
        >
          删除
        </el-button>
        <el-button
          type="primary"
          icon="el-icon-folder-opened"
          class="btnItem"
          @click="exportToExcel"
        >
          导出
        </el-button>
      </div>
    </div>
    <el-table
      ref="multipleTable"
      v-loading="loading"
      :data="tableData.rows"
      :row-class-name="tableRowClassName"
      :header-cell-style="{
        'text-align': 'center',
        background: '  #2483b3',
        color: 'white',
      }"
      :row-style="{ 'text-align': 'center' }"
      style="width: 100%"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" label="序号" >
      <template slot-scope="scope">
          {{ (offset - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="snCode" label="SN码(固定标识)" />
      <el-table-column prop="snQuantity" label="SN码(固定标识)个数" />
      <el-table-column prop="snIllustration" label="SN码(固定标识)说明" />
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showInfo(scope.row)">
            详情
          </el-button>

          <el-button type="text" size="small" @click="Bdelete(scope.row)">
            删除
          </el-button>
          <!-- <el-button type="text" size="small">编辑</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <group-page
      v-model="isFristPage"
      :limit="limit"
      :total="total"
      :offset="offset"
      :count="tableData.total"
      @setOffset="setOffset"
      @setLimit="setLimit"
    />
    <!-- 新增弹框 -->
    <sn-code-ruls-dialog :is-show-add="isShowAdd" @close="closeAdd" />
    <sn-ruls-info-dialog
      :is-show-info="isShowInfo"
      :data-info="rowInfo"
      @close="closeInfo"
    />
  </div>
</template>

<script>
// 组件

import SnCodeRulsDialog from "../../components/mycomponent/dialog/snCodeRulsDialog.vue";
import GroupPage from "../../components/mycomponent/groupPage.vue";
import SnRulsInfoDialog from "../../components/mycomponent/dialog/snRulsInfoDialog.vue";
// 逻辑
import { tableRowClassName } from "../../utils/myUtils/changeTableTr";
import {
  S_listPage,
  S_batchDelete,
  S_delete,
} from "../../api/product/snCodeRuls";
import { listMixin, elDataDialog } from "../../utils/myUtils/mixins/listPage";
import { outToExcel } from "../../utils/myUtils/exportToExcel";
export default {
  components: {
    SnCodeRulsDialog,
    GroupPage,
    SnRulsInfoDialog,
  },
  mixins: [listMixin, elDataDialog],
  data() {
    return {
      isShowAdd: false, // 显示新增功能
      selectInfo: {
        // 搜索框中的数据的数据
        snCode: "",
        snQuantity: "",
      },
    };
  },
  methods: {
    tableRowClassName: tableRowClassName,
    closeAdd() {
      this.isShowAdd = false;
      this.refresh();
    },
    addCategory() {
      this.isShowAdd = true;
    },
    // 获取指定页面
    getListPage(limit, offset) {
      this.loading = true;
      S_listPage(`limit=${limit}&offset=${offset}`, this.queryInfo).then(
        (res) => {
          // 得到相关数据
          res.rows.forEach((item, index) => {
            item.index = index + 1 + (offset - 1) * 10;
          });
          this.tableData = res;
          this.loading = false;
        }
      );
    },
    reset() {
      this.selectInfo = {
        snCode: "",
        snQuantity: "",
      };
    },
    exportToExcel() {
      S_listPage("limit=1000000000&offset=1", {}).then((res) => {
        let list = res.rows.map(item => {
          return {
            'SN码': item.snCode,
            'SN码个数': item.snQuantity,
            'SN码说明': item.snIllustration,
            '更新时间': item.updateTime
          }
        })
        outToExcel(list,'SN码规则列表');
      });
    },
    // 批量删除
    BatchDelete() {
      if (this.$refs.multipleTable.selection.length) {
        this.$confirm(`确认删除选中的这些SN数据吗?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            //  得到选中行
            const dle_ary = this.$refs.multipleTable.selection;
            const ids = [];
            dle_ary.forEach((ele) => {
              ids.push(ele.id);
            });
            S_batchDelete({ ids: ids }).then((res) => {
              this.$message({
                message: "删除成功",
                type: "success",
              });
              this.refresh();
            });
          })
          .catch(() => {});
      } else {
        this.$message({
          message: "请先选择需要删除的SN码",
          type: "error",
        });
      }
    },
    // 删除
    Bdelete(row) {
      this.$confirm(`确认删除此数据吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          const id = row.id;
          S_delete({ id: id }).then((res) => {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.refresh();
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.product_container {
  position: relative;
  width: 100%;
  min-height: 700px;
  overflow: auto;
  height: 823px;
  .productData {
    width: 100%;
    display: flex;
    justify-content: center;
    .middle {
      margin: 0 30px;
    }
  }
  .productFun {
    margin: 0px 0px 30px;
    display: flex;
    justify-content: space-between;
    .productInput {
      display: flex;
      align-items: center;
      .inputBox {
        margin: 0 50px 0 10px;
      }
    }
    .productBtn {
      .btnItem {
        margin-right: 10px;
        border-radius: 5px;
        // height: 32px;
        // width: 84px;
        font-size: 16px;
      }
    }
  }
  .footer {
    display: flex;
    justify-content: space-between;
    color: #6666;
    margin: 30px 10px;
  }
}
</style>