liding
3 天以前 359f69135b571c8e7b6d046bc849655abfe7075d
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<template>
  <div>
    <template v-if="selectModel">
      <el-tree
        ref="tree"
        :data="treeList"
        show-checkbox
        node-key="id"
        @check="getCurrentNode"
        :default-checked-keys="selectModelKeysNew"
        :props="treeProps">
      </el-tree>
    </template>
    <template v-else>
      <div class="divBox">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <div class="container">
              <el-form inline size="small">
                <el-form-item label="状态:">
                  <el-select v-model="listPram.status" placeholder="状态" class="selWidth" @change="handlerGetList">
                    <el-option label="全部" :value="-1"></el-option>
                    <el-option label="显示" :value="1"></el-option>
                    <el-option label="不显示" :value="0"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="名称:">
                  <el-input v-model="listPram.name" placeholder="请输入名称" class="selWidth" size="small" clearable>
                    <el-button slot="append" icon="el-icon-search" @click="handlerGetList" size="small"/>
                  </el-input>
                </el-form-item>
              </el-form>
            </div>
            <el-button size="mini" type="primary" @click="handleAddMenu({id:0,name:'顶层目录'})" v-hasPermi="['admin:category:save']" >新增{{ biztype.name }}</el-button>
          </div>
          <el-table
            ref="treeList"
            :data="treeList"
            size="mini"
            class="table"
            highlight-current-row
            row-key="id"
            :tree-props="{children: 'child', hasChildren: 'hasChildren'}"
          >
            <el-table-column prop="name" label="名称" min-width="240">
              <template slot-scope="scope">
                {{ scope.row.name }} | {{ scope.row.id }}
              </template>
            </el-table-column>
            <template v-if="!selectModel">
              <el-table-column label="类型" min-width="150">
                <template slot-scope="scope">
                  <span>{{ scope.row.type | filterCategroyType | filterEmpty }}</span>
                </template>
              </el-table-column>
              <el-table-column label="分类图标" min-width="80">
                <template slot-scope="scope">
                  <div class="listPic" v-if=" biztype.value === 5 ">
                    <i :class="'el-icon-' + scope.row.extra" style="font-size: 20px;" />
                  </div>
                  <div class="demo-image__preview" v-else>
                    <el-image
                      style="width: 36px; height: 36px"
                      :src="scope.row.extra"
                      :preview-src-list="[scope.row.extra]"
                      v-if="scope.row.extra"
                    />
                    <img style="width: 36px; height: 36px" v-else :src="defaultImg" alt="">
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="Url" min-width="250" v-if="biztype.value === 5" key="2">
                <template slot-scope="scope">
                  <span>{{ scope.row.url }}</span>
                </template>
              </el-table-column>
              <el-table-column label="排序" prop="sort" min-width="150" />
              <el-table-column
                label="状态"
                min-width="150"
              >
              <!--  -->
                <template slot-scope="scope" v-if="checkPermi(['admin:category:update:status'])">
                  <el-switch
                    v-model="scope.row.status"
                    :active-value="true"
                    :inactive-value="false"
                    active-text="显示"
                    inactive-text="隐藏"
                    @change="onchangeIsShow(scope.row)"
                  />
                </template>
              </el-table-column>
             
              <el-table-column label="操作" min-width="200" fixed="right">
                <template slot-scope="scope">
                  <el-button
                    v-if="(biztype.value === 1 && scope.row.pid === 0) || biztype.value === 5"
                    type="text"
                    size="small"
                    @click="handleAddMenu(scope.row)"
                  >添加子目录</el-button>
                  <el-button type="text"  size="small" @click="handleEditMenu(scope.row)"  v-hasPermi="['admin:category:info']">编辑</el-button>
                  <el-button type="text"  size="small" @click="handleDelMenu(scope.row)"  v-hasPermi="['admin:category:delete']">删除</el-button>
                </template>
              </el-table-column>
            </template>
          </el-table>
        </el-card>
      </div>
    </template>
    <el-dialog
      :title="(editDialogConfig.isCreate===0?`创建${biztype.name}`:`编辑${biztype.name}`)"
      :visible.sync="editDialogConfig.visible"
      destroy-on-close
      :close-on-click-modal="false"
    >
      <edit
        v-if="editDialogConfig.visible"
        :prent="editDialogConfig.prent"
        :is-create="editDialogConfig.isCreate"
        :edit-data="editDialogConfig.data"
        :biztype="editDialogConfig.biztype"
        :all-tree-list="treeList"
        @hideEditDialog="hideEditDialog"
      />
    </el-dialog>
  </div>
</template>
 
<script>
import * as categoryApi from '@/api/categoryApi.js'
import info from './info'
import edit from './edit'
import * as selfUtil from '@/utils/ZBKJIutil.js'
import { checkPermi, checkRole } from "@/utils/permission";
export default {
  // name: "list"
  components: { info, edit },
  props: {
    biztype: { // 类型,1 产品分类,2 附件分类,3 文章分类, 4 设置分类, 5 菜单分类
      type: Object,
      default: { value: -1 },
      validator: (obj) => {
        return obj.value > 0
      }
    },
    pid: {
      type: Number,
      default: 0,
      validator: (value) => {
        return value >= 0
      }
    },
    selectModel: { // 是否选择模式
      type: Boolean,
      default: false
    },
    selectModelKeys: {
      type: Array
    },
    rowSelect: {}
  },
  data() {
    return {
      selectModelKeysNew: this.selectModelKeys,
      loading: false,
      constants: this.$constants,
      treeProps: {
        label: 'name',
        children: 'child',
        // expandTrigger: 'hover',
        // checkStrictly: false,
        // emitPath: false
      },
      // treeCheckedKeys:[],// 选择模式下的属性结构默认选中
      multipleSelection: [],
      editDialogConfig: {
        visible: false,
        isCreate: 0, // 0=创建,1=编辑
        prent: {}, // 父级对象
        data: {},
        biztype: this.biztype // 统一主业务中的目录类型
      },
      dataList: [],
      treeList: [],
      listPram: {
        pid: this.pid,
        type: this.biztype.value,
        status: -1,
        name: '',
        page: this.$constants.page.page,
        limit: this.$constants.page.limit[0]
      },
      viewInfoConfig: {
        data: null,
        visible: false
      },
      defaultImg:require('@/assets/imgs/moren.jpg')
    }
  },
  mounted() {
   /* if(this.biztype.value === 3){
      this.listPram.pageSize = constants.page.pageSize[4]
      this.handlerGetList()
    }else{*/
    this.handlerGetTreeList()
    // }
  },
  methods: {
    checkPermi, //权限控制
    onchangeIsShow(row){
      categoryApi.categroyUpdateStatus( row.id ).then(() => {
        this.$message.success('修改成功')
        this.handlerGetTreeList()
      }).catch(()=>{
        row.status = !row.status
      })
    },
    handleEditMenu(rowData) {
      this.editDialogConfig.isCreate = 1
      this.editDialogConfig.data = rowData
      this.editDialogConfig.prent = rowData
      this.editDialogConfig.visible = true
    },
    handleAddMenu(rowData) {
      this.editDialogConfig.isCreate = 0
      this.editDialogConfig.prent = rowData
      this.editDialogConfig.data = {}
      this.editDialogConfig.biztype = this.biztype
      this.editDialogConfig.visible = true
    },
    getCurrentNode(data) {
      let node = this.$refs.tree.getNode(data);
      this.childNodes(node);
      // this.parentNodes(node);
      //是否编辑的表示
      // this.ruleForm.isEditorFlag = true;
      //编辑时候使用
      this.$emit('rulesSelect', this.$refs.tree.getCheckedKeys());
      // this.selectModelKeys = this.$refs.tree.getCheckedKeys();
      //无论编辑和新增点击了就传到后台这个值
      // this.$emit('rulesSelect', this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys()));
      // this.ruleForm.menuIdsisEditor = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys());
    },
    //具体方法可以看element官网api
    childNodes(node){
      let len = node.childNodes.length;
      for(let i = 0; i < len; i++){
        node.childNodes[i].checked = node.checked;
        this.childNodes(node.childNodes[i]);
      }
    },
    parentNodes(node){
      if(node.parent){
        for(let key in node){
          if(key == "parent"){
            node[key].checked = true;
            this.parentNodes(node[key]);
          }
        }
      }
    },
    handleDelMenu(rowData) {
      this.$confirm('确定删除当前数据?').then(() => {
        categoryApi.deleteCategroy(rowData).then(data => {
          this.handlerGetTreeList()
          this.$message.success('删除成功')
        })
      })
    },
    handlerGetList() {
      this.handlerGetTreeList();
      // categoryApi.listCategroy({status:this.listPram.status, type: 1 }).then(data => {
      //   this.treeList = data.list
      // })
    },
    handlerGetTreeList() {
      // this.biztype.value === 5 && !this.selectModel) ?  -1 : 1
      // const _pram = { type: this.biztype.value, status: !this.selectModel ? -1 : (this.biztype.value === 5 ? -1 : 1) }
      const _pram = { type: this.biztype.value, status: this.listPram.status, name: this.listPram.name  }
      this.loading = true
      this.biztype.value!==3 ? categoryApi.treeCategroy(_pram).then(data => {
        this.treeList = this.handleAddArrt(data)
        this.loading = false
      }).catch(()=>{
        this.loading = false
      }) : categoryApi.listCategroy({ type: 3, status: this.listPram.status, pid: this.listPram.pid, name: this.listPram.name}).then(data => {
        this.treeList = data.list
      })
    },
    handlerGetInfo(id) {
      this.viewInfoConfig.data = id
      this.viewInfoConfig.visible = true
    },
    handleNodeClick(data) {
      console.log('data:', data)
    },
    handleAddArrt(treeData) {
      const _result = selfUtil.addTreeListLabel(treeData)
      return _result
    },
    hideEditDialog() {
      setTimeout(() => {
        this.editDialogConfig.prent = {}
        this.editDialogConfig.type = 0
        this.editDialogConfig.visible = false
        this.handlerGetTreeList()
      }, 200)
    },
    handleSelectionChange(d1, { checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys }) {
      // this.multipleSelection =  checkedKeys.concat(halfCheckedKeys)
      this.multipleSelection = checkedKeys
      this.$emit('rulesSelect', this.multipleSelection)
    },
  }
}
</script>
 
<style scoped>
  .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }
</style>