index.vue 6.35 KB
<!--  -->
<template>
  <div style="padding: 0 10px;background-color:#f7f7f7;">
    <div class="tab_show">
      <!-- 搜索 -->
      <div class="formSearch">
        <el-form :inline="true" :model="formParams" class="demo-form-inline">
          <el-form-item label="方案名称">
            <el-input v-model="formParams.logisticsName" placeholder="请输入方案名称" />
          </el-form-item>
          <el-form-item>
            <el-button style="background-color: #3F9B6A;color: #fff"  @click="add">新增物流方案</el-button>
            <el-button style="background-color: #3F9B6A;color: #fff" @click="search">查询</el-button>
            <span v-for="(item,index) in btnList" :key="index" class="promissStyle">
              <el-button type="success" plain @click="btnClick(item)">{{ item.permissionName }}</el-button>
            </span>
          </el-form-item>
        </el-form>
      </div>
      <!-- 表格 -->
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="tableData"
           :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}"
          tooltip-effect="dark"
        >
          <el-table-column label="方案名称" width="220">
            <template slot-scope="scope">{{ scope.row.logisticsName }}</template>
          </el-table-column>
          <el-table-column prop="regions" label="可配送范围" width="420" />
          <el-table-column prop="name" label="计费方式" width="220">
            <template slot-scope="scope">
              <span v-if="scope.row.chargeType == 1">按件数</span>
              <span v-if="scope.row.chargeType == 2">按重量</span>
              <span v-if="scope.row.chargeType == 3">包邮</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" show-overflow-tooltip>
            <template slot-scope="scope">
              <div class="btnList">
                <div  @click="seeMore(scope.row)" class="tableBtn greens">查看</div>
                <div  @click="edit(scope.row)" class="tableBtn greens">编辑</div>
                <div  @click="del(scope.row)" class="tableBtn greens">删除</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="fenye">
          <el-pagination
            :current-page="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="10"
            background
            small
            layout="prev, pager, next,total"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <!-- 方案组件 -->
    <grope-edit
      ref="edit"
      :dialog-visible="dialog.isVisible"
      :type="dialog.type"
      @close="editClose"
      @success="getLists"
    />
  </div>
</template>

<script>
// 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
// 例如:import 《组件名称》 from '《组件路径》';
import { getBtnList } from '@/utils/auth'
import { logisticsGetAll, logisticsDelete } from '@/api/shopSys'
import GropeEdit from './Edit'
export default {
  components: {
    GropeEdit
  },
  data() {
    // 这里存放数据
    return {
      btnList: '',
      formParams: {
        logisticsName: '',
        page: 1,
        pageSize: 10
      },
      total: 1,
      tableData: [],
      currentPage: 1,
      dialog: {
        type: 'add',
        isVisible: false
      }
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成(可以访问当前this实例)
  created() {},
  // 生命周期 - 挂载完成(可以访问DOM元素)
  mounted() {
    this.getList(this.formParams)
    this.btnList = getBtnList()
    console.log(this.btnList, 'btnList')
  },
  // 方法集合
  methods: {
    btnClick(id) {
      console.log(id)
      if (id.permissionName === '新建方案') {
        this.add()
      }
    },
    handleSizeChange(val) {
      this.formParams.pageSize = val
      this.getList(this.formParams)
    },
    handleCurrentChange(val) {
      this.formParams.page = val
      this.getList(this.formParams)
    },
    getLists() {
      console.log(111)
      this.getList(this.formParams)
    },
    // 查询
    search() {
      this.total = 1
      this.formParams.page = 1
      this.getList(this.formParams)
    },
    // 新建方案
    add() {
      this.dialog = {
        type: 'add',
        isVisible: true
      }
    },
    // 查看
    seeMore(row) {
      const { logisticsId } = row
      this.dialog = {
        type: 'check',
        isVisible: true
      }
      this.$refs.edit.setParams({
        checkId: logisticsId
      })
    },
    // 编辑
    edit(row) {
      const { logisticsId } = row
      this.dialog = {
        type: 'edit',
        isVisible: true
      }
      this.$refs.edit.setParams({
        checkId: logisticsId
      })
    },
    // 关闭弹框
    editClose() {
      this.dialog.isVisible = false
    },
    // 删除
    del(row) {
      this.$confirm('选中数据将被永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          logisticsDelete({ logisticsId: row.logisticsId }).then(res => {
            if (res.code === '') {
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
            }
            this.getList(this.formParams)
          })
        })
        .catch(() => {})
    },
    // 初始化查询所有数据
    async getList(formParams) {
      const res = await logisticsGetAll(formParams)
      this.tableData = res.data.list
      this.total = res.data.total
    }
  }
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../../styles/elDialog.scss");
.tab_show {
  padding: 0 20px 20px 20px;
  background-color:#fff;
}
.fenye {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  position: relative;
}
  ::v-deep .el-pagination__total {
    position: absolute;
    left: 10px;
  }
  .formSearch {
      display: flex;
      width: 100%;
      font-size: 14px;
      justify-content: space-between;
    }
</style>