fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<template>
  <div>
    <el-row>
      <el-col :span="5">
        <category-tree
          ref="tree"
          @hand-show-add-category="handShowAddCategory"
          @hand-tree-item="handTreeItem"
        ></category-tree>
      </el-col>
      <el-col
        :span="19"
        class="tabs cardCurrentStyle1"
      >
        <div :style="'min-height:' + (height-233) +'px;'" class="right-con">
          <el-tabs
            type="card"
            v-model="activeName"
            @tab-click="handleClick"
          >
            <el-tab-pane
              label="分类品牌管理"
              name="first"
            >
              <addItem-prop
                ref="addItemProp1"
                :formData="listQuery"
                :catId="catId"
                :tableData="brandList"
                :total="brandListTotal"
                @hand-refresh-list="handRefreshList"
                v-loading='brandLoading'
                style="margin-top:20px;"
                :showBtn="showBtn"
              >
                <template slot="columns">
                  <el-table-column
                    label="品牌名称"
                    prop="brandName"
                    show-overflow-tooltip
                  >
                  </el-table-column>
                  <el-table-column
                    label="品牌描述"
                    prop="brandDesc"
                    show-overflow-tooltip
                  ></el-table-column>
                  <el-table-column label="操作" :width="`${$store.getters.colSize+1}px`">
                    <template slot-scope="scope">
                      <wly-btn
                        :type="'danger'"
                        @click="removeItem(scope.row,scope.$index,1)"
                      >删除</wly-btn>
                    </template>
                  </el-table-column>
                </template>
              </addItem-prop>
            </el-tab-pane>
            <el-tab-pane
              label="分类属性管理"
              name="second"
            >
              <addItem-prop
                ref="addItemProp2"
                :formData="listQuery"
                :catId="catId"
                :tableData="propList"
                :total="propListTotal"
                @hand-refresh-list="handRefreshList"
                v-loading='propLoading'
                style="margin-top:20px;"
              >
                <template slot="columns">
                  <el-table-column
                    label="属性名称"
                    prop="propName"
                    show-overflow-tooltip
                  >
                  </el-table-column>
                  <el-table-column
                    label="是否必须"
                    prop="propRequired"
                  >
                    <template slot-scope="scope">
                      <el-tag :type="scope.row.propRequired ? 'warning':'info'">{{scope.row.propRequired ? '是' : '否'}}</el-tag>
                    </template>
                  </el-table-column>
                  <!-- <el-table-column
                    label="筛选属性"
                    prop="propFilter"
                  >
                    <template slot-scope="scope">
                      <el-tag :type="scope.row.propFilter ? 'warning':'info'">{{scope.row.propFilter ? '是' : '否'}}</el-tag>
                    </template>
                  </el-table-column> -->
                  <el-table-column
                    label="单品属性"
                    prop="propSku"
                  >
                    <template slot-scope="scope">
                      <el-tag :type="scope.row.propSku ? 'warning':'info'">{{scope.row.propSku ? '是' : '否'}}</el-tag>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="展现形式"
                    prop="propShow"
                  >
                    <template slot-scope="scope">
                      {{scope.row.propShow === '0'? '文本': scope.row.propShow === '1' ? '下拉': '-'}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="操作"
                    :width="`${(2 * $store.getters.colSize)+60}px`"
                  >
                    <template slot-scope="scope">
                      <wly-btn
                        :type="'primary'"
                        @click="editItem(scope.row ,scope.$index)"
                      >编辑</wly-btn>
                      <wly-btn
                        :type="'warning'"
                        @click="propItem(scope.row,scope.$index)"
                      >属性值管理</wly-btn>
                      <!-- <wly-btn
                        :type="'danger'"
                        @click="removeItem(scope.row,scope.$index,2)"
                      >删除</wly-btn> -->
                    </template>
                  </el-table-column>
                </template>
              </addItem-prop>
            </el-tab-pane>
          </el-tabs>
        </div>
      </el-col>
    </el-row>
    <el-dialog
      :visible.sync="dialogVisible"
      title="属性值管理"
      :close-on-click-modal="false"
      :modal-append-to-body="false"
      width="40%"
      v-if="dialogVisible"
    >
      <prop-mgt
        :dialogVisible.sync="dialogVisible"
        :propForm="propForm"
      ></prop-mgt>
    </el-dialog>
    <add-category
      :show.sync='show'
      :title="title"
      :row="row"
      @hand-refresh-tree-data="handRefreshTreeData"
      :catId="catId"
    ></add-category>
    <edit-prop
      :show.sync='propShow'
      :row="editPropForm"
    ></edit-prop>
 
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import categoryTree from '@/views/productCategory/components/categoryTree.vue'
import addItemProp from '@/views/productCategory/components/addItemProp.vue'
import editProp from '@/views/productCategory/components/editProp.vue'
import addCategory from '@/views/productCategory/info.vue'
import propMgt from '@/views/productCategory/components/propMgt.vue'
import { objectCopy } from '@/utils/objectCopyHelper'
import productCategoryApi from '@/api/productmanagement/productCategory'
import productPropMetaApi from '@/api/productmanagement/productPropMeta'
 
export default {
  components: { categoryTree, addItemProp, addCategory, editProp, propMgt },
  data () {
    return {
      activeName: 'first',
      listQuery: {
        buttonText: '添加品牌',
        tag: 1
      },
      height: 300,
      show: false,
      title: null,
      row: {},
      catId: null,
      brandList: [],
      propList: [],
      brandListTotal: 0,
      propListTotal: 0,
      brandLoading: false,
      propLoading: false,
      propShow: false,
      editPropForm: {},
      dialogVisible: false,
      propForm: {},
      total: 0,
      showBtn: true
    }
  },
  computed: {
    ...mapGetters([
      'mainContainerHeight'
    ])
  },
  watch: {
    mainContainerHeight (newHeight, oldHeight) {
      this.height = newHeight
    }
  },
  created () {
    this.$nextTick(function () {
      this.height = window.innerHeight
    })
  },
  methods: {
    /**
     * 编辑属性
     */
    editItem (row, index) {
      this.propShow = true
      this.editPropForm = objectCopy(row)
    },
    /**
     * 属性值管理
     */
    propItem (row, index) {
      productPropMetaApi.getInfo({ propId: row.propId }).then(res => {
        if (res.data) {
          this.dialogVisible = true
          this.propForm.propId = res.data.propId
          this.propForm.propName = res.data.propName
          this.propForm.propValueCheckExplain = res.data.propValueCheckExplain
          this.propForm.propValueType = res.data.propValueType
          this.propForm.propShow = row.propShow
        }
      })
    },
    /**
     * 刷新列表
     */
    handRefreshList (data, tag) {
      this.listQuery.pageNum = data.pageNum
      this.listQuery.pageSize = data.pageSize
      if (tag === 1) {
        this.getCategoryBrandList()
      } else {
        this.getCategoryPropList()
      }
    },
    /**
     * 获取分类品牌列表
     */
    getCategoryBrandList () {
      this.brandLoading = true
      productCategoryApi
        .getCategoryBrandList({ categoryId: this.catId })
        .then(res => {
          if (res.data) {
            this.brandList = res.data
            this.brandListTotal = this.brandList.length
            this.brandLoading = false
          }
        })
        .catch(() => {
          this.brandLoading = false
        })
    },
    /**
     * 获取分类属性列表
     */
    getCategoryPropList () {
      this.propLoading = true
      this.listQuery.catId = this.catId
      productCategoryApi
        .getCategoryPropList(this.listQuery)
        .then(res => {
          if (res.data) {
            this.propList = res.data.list
            this.propListTotal = res.data.total
            this.propLoading = false
          }
        })
        .catch(() => {
          this.propLoading = false
        })
    },
    /**
     * 刷新列表
     */
    fn () {
      this.getCategoryBrandList()
      this.getCategoryPropList()
    },
    /**
     * 选择某个树节点触发
     */
    handTreeItem (row) {
      this.initData()
      if (row) {
        this.catId = row.catId
        this.fn()
      }
    },
    /**
     * 初始化数据
     */
    initData () {
      this.brandList = []
      this.propList = []
      this.brandListTotal = 0
      this.propListTotal = 0
      this.$refs.addItemProp1.resetTable()
      this.$refs.addItemProp2.resetTable()
    },
    /**
     *刷新分类树
     */
    handRefreshTreeData () {
      this.$refs.tree.queryList()
    },
    /**
     * 打开新增编辑弹框
     */
    handShowAddCategory (data, tag) {
      if (tag === 1) {
        if (data) {
          this.title = '新增子分类'
          this.row.parentCatId = data.catId
        } else {
          this.title = '新增分类'
          this.row = {}
        }
      } else {
        this.title = '编辑分类'
        this.row = objectCopy(data)
      }
      this.show = true
    },
    /**
     * 删除表格数据
     */
    removeItem (row, index, tag) {
      this.$confirm('确认删除这条数据吗?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          if (tag === 1) {
            this.deleteCategoryBrandItem(row) // 删除分类品牌
          } else {
            this.deleteCategoryPropItem(row) // 删除分类属性
          }
        })
        .catch(() => {})
    },
    /**
     * 删除分类品牌
     */
    deleteCategoryBrandItem (row) {
      productCategoryApi
        .deleteCategoryBrandItem({ productId: row.productId })
        .then(res => {
          if (res.data) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.$refs.addItemProp1.handleConditionChange()
          }
        })
    },
    /**
     * 删除分类属性
     */
    deleteCategoryPropItem (row) {
      productCategoryApi
        .deleteCategoryPropItem({ prodPropId: row.prodPropId })
        .then(res => {
          if (res.data) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.$refs.addItemProp2.handleConditionChange()
          }
        })
    },
    /**
     *标签页切换时修改按钮文字
     */
    handleClick (tab, event) {
      if (tab.index === '0') {
        this.listQuery.buttonText = '添加品牌'
        this.listQuery.tag = 1
        this.showBtn = true
      } else {
        this.listQuery.buttonText = '添加属性'
        this.listQuery.tag = 2
        this.showBtn = false
      }
    }
  }
}
</script>
<style  scoped>
.tabs {
  padding-left: 20px;
  border-radius: 4px;
}
.right-con{
  background: #fff;
  padding:20px;
  border-radius: 4px;
}
</style>