index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div class="app-container">
  3. <div style="margin-bottom:15px;">
  4. <el-input v-model="searchKey" placeholder="输入卡号或人员ID搜索" style="width:220px;margin-right:10px;" />
  5. <el-button type="primary" @click="search">搜索</el-button>
  6. <el-button type="success" @click="openAddDialog">新增卡</el-button>
  7. </div>
  8. <el-table :data="filteredList">
  9. <el-table-column prop="cardNo" label="卡号" min-width="150" />
  10. <el-table-column prop="employeeNo" label="人员ID" min-width="120" />
  11. <el-table-column prop="status" label="状态" min-width="100" />
  12. <el-table-column label="操作" min-width="200">
  13. <template #default="scope">
  14. <el-button size="mini" @click="openEditDialog(scope.row)">编辑</el-button>
  15. <el-button size="mini" type="danger" @click="deleteCard(scope.row.cardNo)">删除</el-button>
  16. </template>
  17. </el-table-column>
  18. </el-table>
  19. <div style="margin-top:10px;">卡总数:{{ cardList.length }}</div>
  20. <el-dialog :visible.sync="dialogVisible" :title="isEdit?'编辑卡':'新增卡'">
  21. <el-form :model="form" label-width="80px">
  22. <el-form-item label="卡号"><el-input v-model="form.cardNo" /></el-form-item>
  23. <el-form-item label="人员ID"><el-input v-model="form.employeeNo" /></el-form-item>
  24. <el-form-item label="状态">
  25. <el-select v-model="form.status">
  26. <el-option label="启用" value="启用" />
  27. <el-option label="禁用" value="禁用" />
  28. </el-select>
  29. </el-form-item>
  30. </el-form>
  31. <span slot="footer">
  32. <el-button @click="dialogVisible=false">取消</el-button>
  33. <el-button type="primary" @click="saveCard">保存</el-button>
  34. </span>
  35. </el-dialog>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. name: "Card",
  41. data() {
  42. return {
  43. searchKey:"",
  44. dialogVisible:false,
  45. isEdit:false,
  46. form:{},
  47. cardList:[
  48. { cardNo:"C10001", employeeNo:"1001", status:"启用" },
  49. { cardNo:"C10002", employeeNo:"1002", status:"禁用" }
  50. ]
  51. }
  52. },
  53. computed:{
  54. filteredList(){
  55. if(!this.searchKey) return this.cardList
  56. return this.cardList.filter(c=>
  57. c.cardNo.includes(this.searchKey) || c.employeeNo.includes(this.searchKey)
  58. )
  59. }
  60. },
  61. methods:{
  62. search(){ this.$message.success("搜索完成(模拟)") },
  63. openAddDialog(){ this.isEdit=false; this.form={}; this.dialogVisible=true },
  64. openEditDialog(row){ this.isEdit=true; this.form={...row}; this.dialogVisible=true },
  65. saveCard(){
  66. if(this.isEdit){
  67. let idx=this.cardList.findIndex(c=>c.cardNo===this.form.cardNo)
  68. this.cardList.splice(idx,1,this.form)
  69. } else {
  70. this.cardList.push({...this.form})
  71. }
  72. this.dialogVisible=false
  73. this.$message.success("保存成功(模拟)")
  74. },
  75. deleteCard(no){
  76. this.cardList=this.cardList.filter(c=>c.cardNo!==no)
  77. this.$message.error("已删除 卡号="+no)
  78. }
  79. }
  80. }
  81. </script>