liuxiaolong
2019-05-06 19e47fa0e48ac76a951bbfaa0a3e95211567f5a1
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<template>
  <div class="clients-wrapper" style="position: initial;">
    <div class="clients-content clients-scroll container-p-x container-p-y overflow-y">
      <!-- Header -->
      <h4 class="d-flex flex-wrap justify-content-between align-items-center font-weight-bold pt-2 mb-2">
        <div class="mb-2">数据字典管理</div>
        <div class="mb-2" style="max-width: 200px;">
          <fButton type="warning" @click.native="handleAdd" authority="sys:dict:add">
            <span class="fas fa-plus pr10"></span>
            新增字典
          </fButton>
        </div>
      </h4>
      <!-- / Header -->
 
      <!-- 设备列表 -->
      <b-card no-body>
        <!-- 检索 start -->
        <b-card-header header-tag="h4" class="media flex-wrap align-items-center py-4">
          <span style="font-size: 16px;">字典类型:</span>
          <b-form-select style="max-width: 10rem;" v-model="currentType" @change="(e)=>{currentType = e;fetchData()}" text-field="lable" :options="sys_type" class="mr10" />
          <b-input placeholder="字典名称..." autocomplete="off" style="max-width: 20rem;" class="mr10" v-model="name" @keyup.enter.native="handleSearch" />
          <b-btn variant="primary" class="mr10" @click="handleSearch">
            <span class="fs fas-search"></span>
            搜索
          </b-btn>
        </b-card-header>
        <!-- 检索 end -->
        <div class="pl20 pr20 pt10 pb30">
          <Table :data="dicList" highlight-current-row ref="leftTable">
            <TableColumn type="index" prop="index" label="序号" :index="snMethod" width="100" />
            <TableColumn label="字典类型" prop="type" :formatter="formatType" />
            <TableColumn label="字典名称" prop="lable" />
            <TableColumn label="字典值" prop="value" />
            <TableColumn label="字典附加字段" prop="revJson" />
            <TableColumn label="操作" width="280">
              <template slot-scope="scope">
                <div @click.stop>
                  <fButton type="link" style="padding:2px;" authority="sys:dict:edit" @click.native.self="$router.push({path:'/dic/add',query:{id:scope.row.id, type:'edit'}})">
                    编辑字典
                  </fButton>
                  <fButton type="link" style="padding:2px;" @click.native="handleDel(scope.row.id)" authority="sys:dict:delete">
                    删除
                  </fButton>
                </div>
              </template>
            </TableColumn>
          </Table>
          <div class="pt20 pb20">
            <b-pagination class="justify-content-center justify-content-sm-end m-0" v-if="total" v-model="currentPage" :total-rows="total" :per-page="length" />
          </div>
        </div>
      </b-card>
      <!-- / 设备列表 -->
    </div>
  </div>
</template>
 
<script>
import { Table, TableColumn } from 'element-ui'
import { getSysDicts, getGloDicts, sysDictsDel } from '../../server/dic.js'
export default {
  metaInfo: {
    title: '数字字典管理'
  },
  data: () => ({
    dicList: [],
    sys_type: [],
    length: 10,
    currentPage: 1,
    name: '',
    total: 0,
    currentType: ''
  }),
  computed: {
    userInfo() {
      return this.$store.getters.basicUserInfo
    }
  },
  async mounted() {
    await this._initGloDicts()
    await this.fetchData()
  },
  methods: {
    // * 数据获取
    async fetchData() {
      const res = await getSysDicts({
        orgId: this.userInfo.orgId,
        type: this.currentType,
        module: this.$store.state.menuName,
        start: this.length * (this.currentPage - 1),
        length: this.length,
        name: this.name
      })
      if (res) {
        this.dicList = res.data
        this.total = res.total - 0
      }
    },
    // * 序号计算
    snMethod(index) {
      return this.currentPage > 1
        ? this.length * (this.currentPage - 1) + index + 1
        : index + 1
    },
    // * 字典类型
    async fetchtGloDicts(type) {
      const res = await getGloDicts({ type })
      if (res && res.code - 0 === 0) {
        return res.data
      }
    },
    // * 初始化字典
    async _initGloDicts() {
      this.sys_type = await this.fetchtGloDicts('SYSTEM_DICT')
      this.sys_type = [{ lable: '全部', value: '' }, ...this.sys_type]
    },
    // * 格式化 type
    formatType({ type }) {
      const result = this.sys_type.find(item => item.value === type)
      if (result && result.lable) {
        return result.lable
      } else {
        return ''
      }
    },
    // * 搜索
    handleSearch() {
      this.fetchData()
    },
    // * 添加页面跳转
    handleAdd() {
      this.$router.push('dic/add')
    },
    // * 删除
    handleDel(id) {
      this.$swal(
        {
          title: '确定删除吗?',
          type: 'warning',
          showCancelButton: true,
          allowOutsideClick: true,
          confirmButtonText: '确定删除!',
          cancelButtonText: '取消删除!',
          closeOnConfirm: true
        },
        async () => {
          let res = await sysDictsDel({ id })
          if (res && res.code - 0 === 0) {
            this.$toast({
              type: 'success',
              message: '删除成功'
            })
            this.fetchData()
          } else {
            this.$toast({
              type: 'success',
              message: res.message
            })
          }
        }
      )
    }
  },
  watch: {
    currentPage(val, oldVal) {
      if (val !== oldVal) {
        this.currentPage = val
        this.fetchData()
      }
    }
  },
  components: {
    Table,
    TableColumn
  }
}
</script>