<template>
  <div>
    <el-form :inline="true"  v-if="visibleCopy" >
      <el-form-item class="tenant" >
        <el-input
          placeholder="根据会员类型/名称查询"
          v-model="queryParams.likeName"
          clearable
          style="width: 200px;">
        </el-input>
      </el-form-item>
      <el-form-item>
        <!-- <el-button type="" size="small" @click="getList2" v-if="$permission('/admin/memberType/check')">查询</el-button>
        <el-button type="primary" size="small" @click="handleAdd()" v-if="$permission('/admin/memberType/add')">新增</el-button> -->
        <el-button type="" size="small" @click="getList" >查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
        v-loading="loading"
        :data="tableData"
        border
        @sort-change="sortMethod"
        header-row-class-name="custom-table-header"
    >
      <el-table-column prop="tenantVipName" label="会员类型/名称" sortable align="center" width="200px">

      </el-table-column>
      <el-table-column label="功能权限" align="center" show-overflow-tooltip min-width="200px">
        <template slot-scope="scope">
          <span v-for="item in scope.row.functionIdPathNameDescriptions" :key="item.functionId">{{ item.functionName  }} &nbsp; </span>
        </template>
      </el-table-column>
      <el-table-column prop="createPersonName" v-if="!visibleCopy" label="创建人" sortable align="center" width="100px"></el-table-column>
      <el-table-column prop="createTime"  v-if="!visibleCopy" label="创建时间" sortable align="center" ></el-table-column>
      <el-table-column prop="remark"  v-if="!visibleCopy" label="备注" show-overflow-tooltip align="center" width="200px"></el-table-column>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-dropdown v-if="!visibleCopy" split-button type="primary" size="small">
            <p v-if="$permission('/admin/memberType/modify')" @click="handleEdit(scope.row)">编辑</p>
            <p v-else @click="handleEdit(scope.row)">编辑</p>
            <el-dropdown-menu slot="dropdown" class="text-align_center">
              <el-dropdown-item @click.native="handleDelete(scope.row.id)">删除</el-dropdown-item>
              <!-- <el-dropdown-item @click.native="handleAdd(scope.row.id)">新增</el-dropdown-item> -->
              <!-- <el-dropdown-item class="color-red" @click.native="handleDelete(scope.row)" divided
                v-if="$permission('/admin/memberType/delete')">删除
              </el-dropdown-item> -->
              <!-- <el-dropdown-item @click.native="distributionPersonnel(scope.row)" divided>分配人员
              </el-dropdown-item> -->
            </el-dropdown-menu>
          </el-dropdown>
          <el-tooltip  v-else  class="item" effect="dark" content="复制已有权限功能并粘贴到新增会员类别权限功能处" placement="top">
            <el-button @click="handleCopy(scope.row)" type="primary" size="small">权限复制粘贴</el-button>
          </el-tooltip>
          
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格分页 -->
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.page" :page-size="queryParams.pageSize" :total="total"
                     @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper"
      background></el-pagination>
    </div>
  </div>
</template>

<script>

export default {
  props: ['isMemberType', 'likeNames','visibleCopy'],
  data() {
    return {
      tableData: [],
      total: 0,
      loading: false,
      queryParams: {
        pageSize: 10,
        page: 1,
        likeName:'',
        orderBy: '',
        orderType: '',
      },
    };
  },
  watch: {
    isMemberType(val) {
        this.getList()
    },
    likeNames(val) {
        this.queryParams.likeName = val
        this.getList()
    },
    visibleCopy(val) {
      this.getList()
    },
  },
  mounted() {
    this.getList()
  },
  methods: {
    // 表格数据
    getList() {
      this.loading = true
      this.$api.queryTenantVipType(this.queryParams).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.list
          // this.tableDataCopy = res.data.list
          this.total = res.data.totalCount
          this.loading = false
        }
      })
    },
    handleCopy(row) {
      this.$emit('row',row)
    },
    //排序
    sortMethod({ column, prop, order }) {
      if (order == 'ascending') {
        this.queryParams.orderType = 'asc'
        this.queryParams.orderBy = prop
        this.getList()
      } else if (order == 'descending') {
        this.queryParams.orderType = 'desc'
        this.queryParams.orderBy = prop
        this.getList()
      }
    },
    // 删除
    handleDelete(id) {
      this.$confirm('此操作将删除该会员类型，不可恢复， 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
             this.$api.deleteTenantVipType({ id: id }).then(res => {
                if (res.code == 200) {
                  this.$message.success('删除成功!');
                  this.getList()
                }
              })
          }).catch(() => {
            this.$message.info('已取消删除');
          });

     
    },
    // 表格编辑
    handleEdit(row) {
      // this.title = '编辑会员类型功能权限'
      row.visible = true
      // this.isMemberType = true
      // let rows = JSON.parse(JSON.stringify(row))
      // this.ruleForm = rows
      this.$emit('tableRow', row)
    },
    // 表格分页
    handleCurrentChange(val) {
      this.queryParams.page = val;
      this.getList();
    },
  },

}
</script>

<style lang="scss" scoped>

</style>