<template>
  <div class="app-container">
    <vip-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"
          >新增</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"
          >删除</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:vip:edit']"
        >修改</el-button>
        <el-button
          size="mini"
          type="text"
          icon="el-icon-delete"
          @click="handleDelete(scope.row)"
          v-hasPermi="['ss:vip:remove']"
        >删除</el-button>
      </template>
    </vip-table>

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

  </div>
</template>

<script>
import { delVip } from "@/api/ss/vip";
import UserInput from '@/components/Business/SmUser/UserInput.vue'
import StoreInput from '@/components/Business/Store/StoreInput.vue'
import VipLevelInput from '@/components/Business/VipLevel/VipLevelInput.vue'
import VipEditDialog from '@/views/ss/vip/components/VipEditDialog.vue'
import VipTable from '@/views/ss/vip/components/VipTable.vue'
import { isEmpty } from '@/utils'


export default {
  name: "MchVip",
  components: { VipTable, VipEditDialog, VipLevelInput, StoreInput, UserInput },
  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 delVip(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ss/vip/export', {
        ...this.queryParams
      }, `vip_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
