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
<template>
    <div>
         <list-condition-template ref="table" :tableData="tableData" :total="total" @page-info-change="handlePageInfoChange">
             <template slot="operationSection">
                 <el-button size="mini" type="success" @click="addItem">添加属性</el-button>
             </template>
            <template slot="columns">
                <el-table-column  label="属性名称" width="200px"  prop="propName" show-overflow-tooltip>
                </el-table-column>
                <el-table-column  label="属性值单位" width="100px" prop="propUnit" show-overflow-tooltip>
                  <template slot-scope="scope">
                      {{scope.row.propUnit ? scope.row.propUnit: '-' }}
                  </template>
                </el-table-column>
                <el-table-column  label="属性值"  :formatter="getPropValue" show-overflow-tooltip>
                </el-table-column>
                <el-table-column  label="属性描述"  width="300px" prop="propDesc" show-overflow-tooltip>
                  <template slot-scope="scope">
                      {{scope.row.propDesc ? scope.row.propDesc: '-' }}
                  </template>
                </el-table-column>
                <el-table-column  label="操作" :width="`${(4 * $store.getters.colSize)+15}px`">
                    <template slot-scope="scope">
                      <wly-btn @click="propEdit(scope.row,1)">详情</wly-btn>
                      <wly-btn :type="'primary'" @click="editInfo(scope.row)">编辑</wly-btn>
                      <wly-btn :type="'warning'" @click="propEdit(scope.row,2)" >属性值管理</wly-btn>
                      <wly-btn :type="'danger'" @click="deleteItem(scope.row)" >删除</wly-btn>
                    </template>
                </el-table-column>
            </template>
         </list-condition-template>
         <product-prop-meta-info :show.sync="show"  :row="row" title="编辑属性"></product-prop-meta-info>
        <el-dialog :visible.sync="propDialogVisible" @close="closeDialog" :title="title" :close-on-click-modal="false" :modal-append-to-body="false"  v-if="propDialogVisible">
             <prop-value-components ref="propForm" :propForm="propForm"></prop-value-components>
            <div slot="footer" class="dialog-footer">
                <el-button size="mini" @click="closeDialog">关闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import productPropMetaApi from '@/api/productmanagement/productPropMeta'
import productPropMetaInfo from '@/views/productPropMeta/info.vue'
import { objectCopy } from '@/utils/objectCopyHelper'
import propValueComponents from '@/views/productPropMeta/components/propValueComponents.vue'
import productPropMetaValueApi from '@/api/productmanagement/productPropMetaValue'
export default {
  components: { productPropMetaInfo, propValueComponents },
  data () {
    return {
      tableData: [],
      show: false,
      title: null,
      row: {},
      dialogVisible: false,
      form: {},
      propDialogVisible: false,
      propForm: {},
      total: 0
    }
  },
  /*
     * 数据变化后刷新列表
   */
  activated () {
    this.queryList(this.$refs.table.getPageInfo())
  },
  methods: {
    // 删除
    deleteItem (row) {
      this.$confirm('是否删除此属性', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        try {
          const res = await productPropMetaApi.deleteItem({ propId: row.propId })
          if (res.code === '0') {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.$refs.table.changeCondition() // 查询列表
          }
        } catch (error) {
        }
      })
    },
    closeDialog () {
      this.propDialogVisible = false
      if (this.$refs.propForm.flag) {
        this.$refs.table.changeCondition()
      }
    },
    /**
     * 获取属性值
     */
    getPropValue (row) {
      let str = null
      str = row.ecProductPropMetaValueList.map(item => { return item.propValue }).join(',')
      return str
    },
    /**
       * '分页信息改变时查询列表
       */
    handlePageInfoChange (pageInfo) {
      this.queryList(pageInfo)
    },
    /**
     * 点击查询按钮
     */
    queryData () {
      this.$refs.table.changeCondition()
    },
    /**
       * 属性值编辑、详情
       */
    propEdit (row, val) {
      productPropMetaValueApi.getList({ propId: row.propId, pageSize: 0 }).then(res => {
        if (val === 1) {
          this.title = '属性详情'
          row.tag = 1
        } else {
          this.title = '属性值管理'
          row.tag = 2
        }
        this.propDialogVisible = true
        this.propForm = row
        this.propForm.list = res.data.list
      })
    },
    /**
     * 编辑
     */
    editInfo (row) {
      this.show = true
      this.row = objectCopy(row)
    },
    /**
     * 查询列表
     */
    queryList (pageInfo = { pageNum: 1, pageSize: 10 }) {
      productPropMetaApi.getList(pageInfo).then(res => {
        this.tableData = res.data.list
        this.total = res.data.total
      })
    },
    /**
       * 跳转到新增页面
       */
    addItem () {
      this.show = true
      this.title = '添加属性'
    }
  }
}
</script>