index.vue 7.62 KB
<template>
  <div class="role-home-page">
    <div class="top_widget">
      <el-button size="small" icon="el-icon-plus" type="primary" @click="toCreatePage">创建角色</el-button>
    </div>
    <div class="table_widget">
      <div class="search_widget">
        <div class="left_wrap">
          <div v-if="accountLevel != 4" class="top_select">
            <span class="select_label">商户名称</span>
            <el-select size="small" clearable filterable v-model="searchForm.merchantId" placeholder="请选择">
              <el-option v-for="item in merchantList" :key="item.id" :label="item.merchantName" :value="item.id"></el-option>
            </el-select>
          </div>
          <div class="top_select">
            <span class="select_label">状态</span>
            <el-select size="small" v-model="searchForm.delFlag" placeholder="请选择">
              <el-option v-for="item in optionData" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </div>
          <div class="top_select">
            <span class="select_label">角色名称</span>
            <el-input style="width: 76%" size="small" v-model="searchForm.roleName" clearable placeholder="请输入"></el-input>
          </div>
        </div>
        <div class="btn_wrapper">
          <el-button size="small" @click="reSetFindData">重置</el-button>
          <el-button type="primary" size="small" @click="toFindData">查询</el-button>
        </div>
      </div>
      <GLTable v-if="distoryTable" ref="table" :layout="layout" :tableData="tableData" :tableTotal="tableTotal" :pageConf="pageConf" :tableParams="tableParams" @refreshTable="getTableData">
        <template slot="auth-button" slot-scope="scope" :data="scope.scope">
          <el-button type="text" @click="toLookPage(scope.scope)">查看</el-button>
          <el-button type="text" @click="toEditPage(scope.scope)">修改</el-button>
          <el-button v-if="scope.scope.delFlag" type="text" @click="todelete(scope.scope)">删除</el-button>
        </template>
      </GLTable>
    </div>
  </div>
</template>

<script>
export default {
  name: '',

  data() {
    return {
      searchForm: {
        delFlag: 2,
        roleName: '',
        merchantId: ''
      },
      optionData: [
        {
          value: 2,
          label: '全部'
        },
        {
          value: 1,
          label: '草稿'
        },
        {
          value: 0,
          label: '启用'
        }
      ],
      //表格配置
      layout: 'sizes, prev, pager, next, jumper, ->, total',
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      tableParams: {
        tableOption: true,
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        tableColumns: [
          {
            label: '角色名称',
            prop: 'roleName'
          },
          {
            label: '角色号',
            prop: 'roleCode'
          },
          {
            label: '状态',
            prop: 'statusName',
            width: '100px'
          },
          {
            label: '创建时间',
            prop: 'createdTime',
            width: '160px'
          },
          {
            label: '更新时间',
            prop: 'updatedTime',
            width: '160px',
            formatter: val => {
              if (!val.updatedTime) {
                return '--'
              } else {
                return val.updatedTime
              }
            }
          }
        ]
      },
      tableData: [],
      merchantList: [],
      tableTotal: 0,
      accountLevel: 1,
      list: [],
      distoryTable: true
    }
  },

  methods: {
    // 获取表格数据
    getTableData() {
      let { delFlag, roleName, merchantId } = this.searchForm
      let para = {}
      console.log(merchantId)
      if (!this.distoryTable) {//代表重置
        para = {
          pageNum: 1,
          pageSize: 10
        }
      } else {
        para = {
          pageNum: this.$refs.table.page.pageNum,
          pageSize: this.$refs.table.page.pageSize
        }
      }
      if (delFlag < 2) {
        para.delFlag = delFlag
      }
      if (roleName) {
        para.roleName = roleName
      }
      if (merchantId) {
        para.merchantId = merchantId
      }
      this.$apis.role.roleDataList(para).then(res => {
        this.tableData = res.data
        this.tableTotal = res.count
        if (!res.data.length || !res) {
          this.$refs.table.setTableHeightFun()
        }
        // this.$nextTick(() => {
        //   this.$refs.table.setTableHeightFun()
        // })
      })
    },
    getMerchantName() {
      this.$apis.role.merchantDataList({ source: 'glsx' }).then(res => {
        this.merchantList = res || []
        this.merchantList.unshift({
          merchantName: '全部',
          id: 0
        })
        // this.filterList()
      })
    },
    // 过滤数据
    // filterList(query = '') {
    //   let arr = this.merchantList.filter(item => {
    //     return item.merchantName.includes(query)
    //   })
    //   if (arr.length > 100) {
    //     this.list = arr.slice(0, 100)
    //   } else {
    //     this.list = arr
    //   }
    // },
    // 重置
    reSetFindData() {
      this.distoryTable = false
      this.searchForm = {
        delFlag: 2,
        roleName: '',
        merchantId: ''
      }
      this.getTableData()
      this.$nextTick(() => {
        this.distoryTable = true
      })
    },
    // 查询
    toFindData() {
      this.getTableData()
    },
    // 去创建角色页面
    toCreatePage() {
      this.$router.push('/role/create')
    },
    // 去查看角色页面
    toLookPage(row) {
      this.$router.push('/role/look/' + row.id)
    },
    // 去修改角色页面
    toEditPage(row) {
      this.$router.push('/role/create/' + row.id)
    },
    // 去删除草稿
    todelete(row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$apis.role.deleteRole({ id: row.id }).then(res => {
            if (res) {
              this.getTableData()
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
            }
          })
        })
        .catch(() => {})
    }
  },

  created() {
    const { session } = this.$globalState
    let accountLevel = session.accountLevel
    if (accountLevel != 4) {
      this.tableParams.tableColumns.splice(2, 0, { label: '所属商户名', prop: 'merchantName' })
      this.getMerchantName()
    }
    this.accountLevel = accountLevel
  },

  mounted() {
    this.getTableData()
  }
}
</script>

<style lang="scss" scoped>
.role-home-page {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.top_widget {
  width: 100%;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  padding: 0 20px 20px 0;
}
.table_widget {
  width: 100%;
  // height: calc(100% - 138px);
  background: #ffffff;
  box-shadow: 0px 10px 20px 0px rgba(88, 80, 255, 0.1);
  box-sizing: border-box;
  padding: 20px;
}
.search_widget {
  padding: 0 0 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .left_wrap {
    display: flex;
    align-items: center;
    .top_select {
      display: flex;
      align-items: center;
      margin-right: 30px;
      .select_label {
        font-size: 14px;
        font-weight: 400;
        color: #333333;
        margin-right: 10px;
        white-space: nowrap;
      }
    }
  }
  .btn_wrapper {
    display: flex;
    align-items: center;
  }
}
</style>