1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!-- 人员新增或编辑 -->
<template>
  <div>
    <el-drawer size="50%" :with-header="false" :visible.sync="visible" :before-close="handleAddClose">
      <div class="config-tabs">
        <el-menu :default-active="activeTab" mode="horizontal" class="quanxian-menu">
          <el-menu-item index="info" @click="activeTab = 'info'">{{ $t('person.user') }}</el-menu-item>
          <el-menu-item index="vourcher" @click="activeTab = 'vourcher'">{{ $t('person.voucher') }}</el-menu-item>
          <el-menu-item index="permission" @click="activeTab = 'permission'">{{ $t('person.permission') }}</el-menu-item>
        </el-menu>
        <!-- 功能页面 -->
        <el-scrollbar>
          <div style="padding: 20px;">
            <component
              :is="currentComponent"
              :key="componentKey"
              :form-data="form"
              :add-or-edit-type="addOrEditType"
              @close-drawer="handleAddClose"
              @operation-success="operationSuccess"
            />
          </div>
        </el-scrollbar>
      </div>
    </el-drawer>
  </div>
</template>
 
<script>
import Info from '@/views/person/info'
import Vourcher from '@/views/person/vourcher'
import Permission from '@/views/person/permission'
export default {
  components: { Info, Vourcher, Permission },
  data () {
    return {
      form: {
        userId: "",
        name: "",
        permissionIds: "",
        extra: ""
      },
      addOrEditType: 'add',
      visible: false,
      activeTab: 'info',
      componentKey: 0,  // 组件重新渲染的key
      deviceModel: '',
    }
  },
  computed: {
    currentComponent () {
      return this.activeTab;
    }
  },
  created () {
    this.initialForm = JSON.parse(JSON.stringify(this.form));
  },
  mounted () {
 
  },
  methods: {
    open (type, row) {
      console.log(type, row)
      this.visible = true
      this.addOrEditType = type
      this.activeTab = 'info';
      if (row) {
        let extra = row.extra ? JSON.parse(row.extra) : ""
        this.form = { ...row, extra }
      }
      // 强制重新渲染子组件
      this.componentKey += 1;
    },
 
    handleAddClose (showConfirm = true) {
      const closeAction = () => {
        this.visible = false;
        this.form = { ...this.initialForm };
        // 强制重新渲染子组件,确保下次打开是干净的
        this.componentKey += 1;
      };
      if (showConfirm) {
        this.$confirm(this.$t('common.closeTips'))
          .then(closeAction)
          .catch(() => { });
      } else {
        closeAction();
      }
    },
 
    operationSuccess (param) {
      this.form = {...param}
      this.$emit('addOrEditSuccess')
    },
  }
}
</script>
<style lang='less' scoped>
.config-tabs {
  background: transparent;
}
 
.config-tabs ::v-deep .el-tabs__header {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  margin-bottom: 20px;
  border: none;
}
 
.config-tabs ::v-deep .el-tabs__item {
  font-weight: 500;
  height: 50px;
  line-height: 50px;
}
 
.drawerHeader {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 50px 10px 30px 10px;
  font-size: 20px;
}
 
.drawerImg {
  height: 20px;
  margin-right: 20px;
}
 
// .el-drawer__wrapper {
//   z-index: 3000 !important;
// }</style>