<template>
  <div class="app-container">
    <vip-level-table ref="table" @selection-change="handleSelectionChange" >
      <template #table-operator>
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['ss:vipLevel:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="!isEmpty(ids)"
            @click="handleDelete"
            v-hasPermi="['ss:vipLevel:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['ss:vipLevel:export']"
          >导出</el-button>
        </el-col>
      </template>
      <template v-slot:row-operator="scope">
        <el-button
          size="mini"
          type="text"
          icon="el-icon-edit"
          @click="handleUpdate(scope.row)"
          v-hasPermi="['ss:vipLevel:edit']"
        >修改</el-button>
        <el-button
          size="mini"
          type="text"
          icon="el-icon-delete"
          @click="handleDelete(scope.row)"
          v-hasPermi="['ss:vipLevel:remove']"
        >删除</el-button>
      </template>
    </vip-level-table>

    <!-- 添加或修改会员等级对话框 -->
    <vip-level-edit-dialog :show.sync="open" :id="row.id" @success="getList"/>
  </div>
</template>

<script>
import { delVipLevel } from "@/api/ss/vipLevel";
import { $showColumns } from '@/utils/mixins';
import UserLink from '@/components/Business/SmUser/UserLink.vue'
import VipLevelEditDialog from '@/views/ss/vipLevel/components/VipLevelEditDialog.vue'
import VipLevelTable from '@/views/ss/vipLevel/components/VipLevelTable.vue'
import { isEmpty } from '@/utils'


export default {
  name: "VipLevel",
  components: { VipLevelTable, VipLevelEditDialog, UserLink },
  mixins: [$showColumns],
  data() {
    return {
      row: {},
      // 是否显示弹出层
      open: false,
      // 选中数组
      ids: [],
    };
  },
  methods: {
    isEmpty,
    getList() {
      this.$refs.table.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.row = {};
      this.open = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.row = row;
      this.open = true;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除会员等级编号为"' + ids + '"的数据项？').then(function() {
        return delVipLevel(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ss/vipLevel/export', {
        ...this.queryParams
      }, `vipLevel_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
