<template> 
 | 
    <GlobalWindow 
 | 
        :title="title" 
 | 
        width="100%" 
 | 
        :visible.sync="visible" 
 | 
        :withFooter="false" 
 | 
    > 
 | 
        <ul style="width: 100%; display: flex; align-items: center; margin-bottom: 20px;"> 
 | 
            <li style="margin-right: 10px;"><el-button type="primary" @click="$refs.operaMemberCardWindow.open('新建人员开卡', { memberId: memberId, isType: 1 })" v-permissions="['business:membercard:create']">新建</el-button></li> 
 | 
            <li style="margin-right: 10px;"><el-button type="primary" @click="batchLossReporting">挂失</el-button></li> 
 | 
            <li><el-button type="primary" @click="batchDecoupling">解挂</el-button></li> 
 | 
        </ul> 
 | 
        <el-table 
 | 
            v-loading="loading" 
 | 
            :data="list" 
 | 
            stripe 
 | 
            @selection-change="handleSelectionChange" 
 | 
        > 
 | 
            <el-table-column type="selection" width="55"></el-table-column> 
 | 
            <el-table-column prop="code" label="卡号" min-width="100px"></el-table-column> 
 | 
            <el-table-column prop="cardTypeName" label="卡类型" min-width="100px"></el-table-column> 
 | 
            <el-table-column label="状态" min-width="100px"> 
 | 
                <template slot-scope="{row}"> 
 | 
                    <span v-if="row.status === 0">禁用</span> 
 | 
                    <span v-if="row.status === 1">启用</span> 
 | 
                    <span v-if="row.status === 2">退卡</span> 
 | 
                    <span v-if="row.status === 3">挂失</span> 
 | 
                </template> 
 | 
            </el-table-column> 
 | 
            <el-table-column label="用户类型" min-width="100px"> 
 | 
                <template slot-scope="{row}"> 
 | 
                    <span v-if="row.memberType === 0">劳务访客</span> 
 | 
                    <span v-if="row.memberType === 2">内部人员</span> 
 | 
                </template> 
 | 
            </el-table-column> 
 | 
            <el-table-column prop="memberName" label="员工姓名" min-width="100px"></el-table-column> 
 | 
            <el-table-column prop="memberPhone" label="手机号" min-width="100px"></el-table-column> 
 | 
            <el-table-column prop="companyName" label="组织" min-width="100px"></el-table-column> 
 | 
            <el-table-column prop="createDate" label="开卡时间" min-width="140px"></el-table-column> 
 | 
            <el-table-column prop="editDate" label="更新时间" min-width="140px"></el-table-column> 
 | 
            <el-table-column 
 | 
                label="操作" 
 | 
                min-width="120" 
 | 
                fixed="right" 
 | 
            > 
 | 
                <template slot-scope="{row}"> 
 | 
                    <el-button type="text" v-if="row.status === 3" @click="jiegua(row.id)">解挂</el-button> 
 | 
                    <el-button type="text" v-if="row.status !== 3 && row.status !== 2" @click="tui(row.id)">退卡</el-button> 
 | 
                    <el-button type="text" v-if="row.status !== 3 && row.status !== 2" @click="guashi(row.id)">挂失</el-button> 
 | 
                </template> 
 | 
            </el-table-column> 
 | 
        </el-table> 
 | 
        <!-- 新建/修改 --> 
 | 
        <OperaMemberCardWindow ref="operaMemberCardWindow" @success="search()"/> 
 | 
    </GlobalWindow> 
 | 
</template> 
 | 
  
 | 
<script> 
 | 
  import BaseOpera from '@/components/base/BaseOpera' 
 | 
  import GlobalWindow from '@/components/common/GlobalWindow' 
 | 
  import OperaMemberCardWindow from '@/components/business/OperaMemberCardWindow' 
 | 
  import { refundCard, batchLoss, batchUnLoss, fetchList } from '@/api/business/memberCard' 
 | 
  export default { 
 | 
    name: 'cardOpeningRecord', 
 | 
    extends: BaseOpera, 
 | 
    components: { GlobalWindow, OperaMemberCardWindow }, 
 | 
    data () { 
 | 
      return { 
 | 
        memberId: null, 
 | 
        list: [], 
 | 
        tableData: { 
 | 
          selectedRows: [] 
 | 
        }, 
 | 
        loading: false 
 | 
      } 
 | 
    }, 
 | 
    created () { 
 | 
      this.config({ 
 | 
        api: '/business/memberCard', 
 | 
        'field.id': 'id' 
 | 
      }) 
 | 
    }, 
 | 
    methods: { 
 | 
      open (title, memberId) { 
 | 
        this.title = title 
 | 
        this.visible = true 
 | 
        this.list = [] 
 | 
        this.memberId = memberId 
 | 
        this.search() 
 | 
      }, 
 | 
      handleSelectionChange (e) { 
 | 
        this.tableData.selectedRows = e 
 | 
      }, 
 | 
      search() { 
 | 
        fetchList({ 
 | 
          capacity: 9999, 
 | 
          page: 1, 
 | 
          model: { 
 | 
            memberId: this.memberId 
 | 
          } 
 | 
        }).then(res => { 
 | 
          this.list = res.records 
 | 
        }) 
 | 
      }, 
 | 
      // 批量解挂 
 | 
      batchDecoupling () { 
 | 
        let arr = [] 
 | 
        this.tableData.selectedRows.forEach(item => { 
 | 
          arr.push({ id: item.id, status: 1 }) 
 | 
        }) 
 | 
        batchUnLoss(arr) 
 | 
          .then(res => { 
 | 
            this.$message.success('操作成功') 
 | 
            this.search() 
 | 
          }) 
 | 
      }, 
 | 
      // 批量挂失 
 | 
      batchLossReporting() { 
 | 
        let arr = [] 
 | 
        this.tableData.selectedRows.forEach(item => { 
 | 
          arr.push({ id: item.id, status: 3 }) 
 | 
        }) 
 | 
        batchLoss(arr) 
 | 
          .then(res => { 
 | 
            this.$message.success('操作成功') 
 | 
            this.search() 
 | 
          }) 
 | 
      }, 
 | 
      // 退卡 
 | 
      tui(id) { 
 | 
        refundCard({ id, status: 2 }) 
 | 
          .then(res => { 
 | 
            this.$message.success('操作成功') 
 | 
            this.search() 
 | 
          }) 
 | 
      }, 
 | 
      // 挂失 
 | 
      guashi(id) { 
 | 
        batchLoss([{ id, status: 3 }]) 
 | 
          .then(res => { 
 | 
            this.$message.success('操作成功') 
 | 
            this.search() 
 | 
          }) 
 | 
      }, 
 | 
      // 解挂 
 | 
      jiegua(id) { 
 | 
        batchUnLoss([{ id, status: 1 }]) 
 | 
          .then(res => { 
 | 
            this.$message.success('操作成功') 
 | 
            this.search() 
 | 
          }) 
 | 
      } 
 | 
    } 
 | 
  } 
 | 
</script> 
 |