Newer
Older
smartKitchenFront / src / views / distributor / distributorList.vue
liyaguang on 4 Dec 2022 6 KB fix: 修改word新提bug
<!--经销商列表-->
<template>
  <div class="product_container">
    <div class="productFun">
      <div class="productInput">
        经销商编号
        <div class="inputBox" style="width: 200px">
          <el-input v-model="selectInfo.distributorCode" placeholder="请输入编号" clearable class="product-input" />
        </div>
        经销商名称
        <div class="inputBox" style="width: 200px">
          <el-input v-model="selectInfo.distributorName" placeholder="请输入名称" clearable class="product-input" />
        </div>
      </div>
      <div class="productBtn">
        <el-button type="primary" icon="el-icon-search" class="btnItem" @click="search(10, 1)">查询</el-button>
        <el-button type="primary" icon="el-icon-refresh-right" class="btnItem" @click="reset">重置</el-button>
        <el-button type="primary" icon="el-icon-folder-opened" class="btnItem" @click="exportToExcel">导出</el-button>
      </div>
    </div>
    <el-table ref="multipleTable" :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 prop="index" width="100px" label="序号" /> -->
      <el-table-column type="index" label="序号">
        <template slot-scope="scope">
          {{ (offset - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="distributorCode" width="200px" label="经销商编号" />
      <el-table-column prop="distributorName" width="400px" label="经销商名称" />
      <el-table-column prop="companyNatureName" width="150px" label="单位性质" />
      <el-table-column prop="companyTypeName" width="200px" label="企业类型" />
      <el-table-column prop="companyProvince, companyCity, companyArea, companyAddress" label="详细地址">
        <template slot-scope="scope">
          {{ (scope.row.companyProvince === scope.row.companyCity ?
              scope.row.companyCity +'/'+ scope.row.companyArea +'/'+ scope.row.companyAddress :
              scope.row.companyProvince +'/'+ scope.row.companyCity +'/'+ scope.row.companyArea+'/'+ scope.row.companyAddress)
          }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="detail(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" />
    <distributor-detail ref="distributorDetail" />
  </div>
</template>

<script>
// 组件
import GroupPage from '@/components/mycomponent/groupPage'
import DistributorDetail from '@/views/distributor/distributorDetail'
// 逻辑
import { tableRowClassName } from '@/utils/myUtils/changeTableTr'
import { listMixin, elDataDialog } from '@/utils/myUtils/mixins/listPage'
import { listPage } from '@/api/distributor/distributor'
import { outToExcel } from '@/utils/myUtils/exportToExcel'
export default { // 加入分页逻辑
  components: {
    DistributorDetail,
    GroupPage
  },
  mixins: [listMixin, elDataDialog],
  data() {
    return {
      selectInfo: { // 搜索框中的数据的数据
        distributorCode: '',
        distributorName: ''
      }
    }
  },
  mounted() {
    this.getListPage()
  },
  methods: {
    tableRowClassName: tableRowClassName,
    // 获取指定页面
    getListPage(limit = 10, offset = 1) {
      listPage(`limit=${limit}&offset=${offset}`, this.selectInfo).then(res => {
        // 得到相关数据
        res.rows.forEach((item, index) => {
          item.index = (index + 1) + ((offset - 1) * limit)
        })
        this.tableData = res
      })
    },
    search(limit, offset) {
      listPage(`limit=${limit}&offset=${offset}`, this.selectInfo).then(res => {
        // 得到相关数据
        res.rows.forEach((item, index) => {
          item.index = (index + 1) + ((offset - 1) * limit)
        })
        this.tableData = res
      })
    },
    reset() {
      this.selectInfo = {
        distributorCode: '',
        distributorName: ''
      }
      this.search(10, 1)
    },
    detail(row) {
      this.$refs.distributorDetail.initDialog('detail', row)
    },
    exportToExcel() {
      console.log('导出')
      // 全屏加载动画;
      const loading = this.$loading({
        lock: true,
        text: "数据处理中,请稍后...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      listPage(`limit=100000000&offset=1`, {})
        .then((res) => {
          res.rows = res.rows.map((item, index) => {
            return {
              序号: index + 1,
              经销商编号: item.distributorCode,
              经销商名称: item.distributorName,
              单位性质: item.companyNatureName,
              企业类型: item.companyTypeName,
              详细地址: item.companyProvince === item.companyCity ? (item.companyProvince + item.companyCity + item.companyArea+ item.companyAddress) : (item.companyCity + item.companyArea+item.companyAddress)
            }

          })
          outToExcel(res.rows, '经销商列表');
          loading.close(); // 关闭加载动画
          this.$message({
            message: "导出成功",
            type: "success",
          });
        })
        .catch((error) => {
          loading.close(); // 关闭加载动画
          this.$message({
            message: error.message,
            type: "error",
          });
        });
    },
  }
}
</script>

<style lang="scss" scoped>
.product_container {
  position: relative;
  width: 100%;
  min-height: 700px;
  overflow: auto;

  .productData {
    width: 100%;
    display: flex;
    justify-content: center;

    .middle {
      margin: 0 30px;
    }
  }

  .productFun {
    margin: 10px 20px;
    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>