index.vue 9.34 KB
<template>
  <div class="role-home-page">
    <div class="top_widget">
      <!-- <GLButton :size="size" fn="创建角色" icon="el-icon-plus" type="primary" @click="toCreatePage" mode="el-button">创建角色</GLButton> -->
      <el-button size="small" icon="el-icon-plus" type="primary" @click="toCreatePage">创建角色</el-button>
    </div>
    <div class="table_widget">
      <div>
        <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :searchSelectObj="searchSelectObj" :formData="searchFormData" :inline="true" @handleOk="toFindData" @handleRest="reSetFindData"></GLCombiForm>
      </div>
      <GLTable v-if="distoryTable" ref="table" :tableData="tableData" :tableTotal="tableTotal" :pageConf="pageConf" :tableParams="tableParams" @refreshTable="getTableData">
        <div slot="statusName" class="dot" slot-scope="scope">
          <span :class="roleStatus[scope.scope.statusName]"></span>
          {{ scope.scope.statusName }}
        </div>
        <template slot="auth-button" slot-scope="scope" :data="scope.scope">
          <GLTableButton :buttonList="buttonList" :buttonItem="scope.scope"></GLTableButton>
          <!-- <el-button type="text" @click="toLookPage(scope.scope)">查看</el-button>
          <el-button v-if="scope.scope.roleName != '超级管理员'" 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>
const roleStatus = {
  正常: 'normal',
  草稿: 'draft'
}
export default {
  name: '',

  data() {
    return {
      roleStatus: roleStatus,
      searchForm: {
        delFlag: '',
        roleName: '',
        merchantId: ''
      },
      searchFormData: [
        {
          label: '商户名称',
          name: 'merchantId',
          type: 'select',
          placeholder: '全部',
          optionList: [],
          optionId: 'id',
          optionLabel: 'merchantName',
          optionsName: 'merchantName',
          isHide: true
        },
        {
          label: '状态',
          name: 'delFlag',
          type: 'select',
          placeholder: '全部',
          optionList: [
            {
              optionId: '',
              optionLabel: '全部'
            },
            {
              optionId: 0,
              optionLabel: '启用'
            },
            {
              optionId: 1,
              optionLabel: '草稿'
            }
          ],
          optionId: 'optionId',
          optionLabel: 'optionLabel',
          optionsName: 'optionLabel'
        },
        {
          label: '角色名称',
          name: 'roleName',
          type: 'input'
        }
      ],
      //表格配置
      layout: 'sizes, prev, pager, next, jumper, ->, total',
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      tableParams: {
        tableOption: {
          width: '150'
        },
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        tableColumns: [
          {
            label: '角色名称',
            prop: 'roleName',
            minWidth: '250'
          },
          {
            label: '角色号',
            prop: 'roleCode',
            minWidth: '220'
          },
          {
            label: '状态',
            prop: 'statusName',
            addHtml: 'statusName'
          },
          {
            label: '创建时间',
            prop: 'createdTime',
            minWidth: '180'
          },
          {
            label: '更新时间',
            prop: 'updatedTime',
            minWidth: '180',
            formatter: val => {
              if (!val.updatedTime) {
                return '--'
              } else {
                return val.updatedTime
              }
            }
          }
        ]
      },
      buttonList: [
        {
          type: 'GLButton',
          name: row => {
            return '查看'
          },
          attrs: {
            type: 'text',
            fn: '查看'
          },
          condition: row => {
            return true
          },
          listeners: {
            click: this.toLookPage
          }
        },
        {
          type: 'GLButton',
          name: row => {
            return '编辑'
          },
          condition: row => {
            let flag = !(row.defalutRole || row.roleName == '系统默认角色')
            return flag
          },
          attrs: {
            type: 'text',
            fn: '修改'
          },
          listeners: {
            click: this.toEditPage
          }
        },
        {
          type: 'el-button',
          name: row => {
            return '删除'
          },
          condition: row => {
            return row.delFlag
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: this.todelete
          }
        }
      ],
      tableData: [],
      merchantList: [],
      tableTotal: 0,
      accountLevel: 1,
      list: [],
      distoryTable: true
    }
  },

  methods: {
    // 获取表格数据
    getTableData() {
      let { delFlag, roleName, merchantId } = this.searchForm
      let para = {}
      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
        this.tableData.length ? (this.$refs.table.tableHeightValues = '') : this.$refs.table.setTableHeightFun()
        // 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: ''
        })
        let idx = this.searchFormData.findIndex(item => item.name == 'merchantId')
        this.searchFormData[idx].optionList = this.merchantList
        // 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: '',
        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: '取消',
        customClass: 'gl-message-box',
        type: 'warning'
      }).then(() => {
        this.$apis.role.deleteRole({ id: row.id }).then(res => {
          if (res) {
            this.getTableData()
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
          }
        })
      })
    }
  },

  created() {
    const { session } = this.$globalState
    let accountLevel = session.accountLevel
    console.log(accountLevel)
    if (accountLevel != 4) {
      this.tableParams.tableColumns.splice(2, 0, { label: '所属商户名', prop: 'merchantName', width: '340', line: 1 })
      this.getMerchantName()
      let idx = this.searchFormData.findIndex(item => item.name == 'merchantId')
      this.searchFormData[idx].isHide = false
    }
    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%;
}

.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>