sf
jiangping
2025-04-30 dcdb0231034810232f2542f3865666ebf72daf11
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
 
<template>
  <TableLayout :permissions="['business:basegoods:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
      <el-form-item label="商品名称" prop="name">
        <el-input v-model="searchForm.name" placeholder="请输入商品名称" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="商品ID" prop="id">
        <el-input v-model="searchForm.id" placeholder="请输入商品ID" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="类别" prop="categoryId">
        <el-select v-model="searchForm.categoryId" clearable placeholder="请选择">
          <el-option v-for="item in categoryList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
        <!-- <el-input v-model="searchForm.categoryId" placeholder="请输入所属品类编码" @keypress.enter.native="search"></el-input> -->
      </el-form-item>
      <el-form-item label="品牌" prop="brandId">
        <el-select v-model="searchForm.brandId" clearable placeholder="请选择">
          <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
        <!-- <el-input v-model="searchForm.brandId" placeholder="请输入所属品牌编码" @keypress.enter.native="search"></el-input> -->
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="searchForm.status" clearable placeholder="请选择">
          <el-option v-for="item in statusList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
        <!-- <el-input v-model="searchForm.status" placeholder="请输入状态 0启用 1禁用" @keypress.enter.native="search"></el-input> -->
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar" v-permissions="['business:basegoods:create', 'business:basegoods:delete']">
        <li v-permissions="['business:basegoods:create']">
          <el-button type="primary" @click="$refs.operaGoodsWindow.open('新建商品')" icon="el-icon-plus">新建</el-button>
        </li>
        <!-- <el-button type="primary" :loading="isWorking.export"
          @click="$refs.selectProduct.open('选择平台商品')">选择平台商品</el-button> -->
        <li v-permissions="['business:basegoods:exportExcel', 'business:goods:delete']">
          <ImportButton text="导入" template-name="goods_import_modle.xlsx"
            template-path="/template/goods_import_modle.xlsx" action="/business/baseGoods/importExcel"
            @success="search" />
        </li>
        <li>
          <el-button type="primary" :loading="isWorking.export" @click="bulkOperation(0)">批量上架</el-button>
        </li>
        <li>
          <el-button type="primary" :loading="isWorking.export" @click="bulkOperation(1)">批量下架</el-button>
        </li>
        <li v-permissions="['business:goods:delete']">
          <el-button type="danger" @click="deleteByIdInBatch">批量删除</el-button>
        </li>
      </ul>
      <el-table v-loading="isWorking.search" :data="tableData.list" stripe border :header-cell-style="rowStyle"
        :cell-style="rowStyle" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" label="商品ID" min-width="100px"></el-table-column>
        <el-table-column prop="name" label="商品名称/型号" min-width="200px">
          <template slot-scope="{row}">
            <div style="display: flex; align-items: center;">
              <div style="width: 70px; height: 70px; flex-shrink: 0;">
                <el-image v-if="row.imgurl" style="width: 70px; height: 70px" :src="row.fullImgUrl"
                  :preview-src-list="[row.fullImgUrl]" fit="cover"></el-image>
              </div>
              <span style="margin-left: 15px">{{ row.name }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="brandName" label="品牌" min-width="100px"></el-table-column>
        <el-table-column prop="categoryName" label="类别" min-width="100px"></el-table-column>
        <el-table-column prop="zdPrice" label="指导价(元)" min-width="100px"></el-table-column>
        <el-table-column prop="jdPrice" label="采购价(元)" min-width="100px"></el-table-column>
        <el-table-column prop="price" label="销售价(元)" min-width="100px"></el-table-column>
        <el-table-column prop="createDate" label="创建时间" min-width="100px"></el-table-column>
        <el-table-column prop="status" v-if="containPermissions(['business:basegoods:update'])" label="状态" min-width="100px">
          <template slot-scope="{row}">
            <el-switch v-model="row.status" @change="changeStatus(row)" active-color="#13ce66" inactive-color="#ff4949"
              :active-value="0" :inactive-value="1">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column v-if="containPermissions(['business:basegoods:update', 'business:basegoods:delete'])" label="操作"
          min-width="120" fixed="right">
          <template slot-scope="{row}">
            <el-button type="text" @click="edit(row.id)" icon="el-icon-edit"
              v-permissions="['business:basegoods:update']">编辑</el-button>
            <el-button type="text" @click="deleteById(row)" icon="el-icon-delete"
              v-permissions="['business:basegoods:delete']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination @size-change="handleSizeChange" @current-change="handlePageChange" :pagination="tableData.pagination">
      </pagination>
    </template>
    <!-- 新建/修改 -->
    <OperaGoodsWindow ref="operaGoodsWindow" @success="handlePageChange" />
    <!-- 选择平台商品 -->
    <selectProduct ref="selectProduct" @success="handlePageChange" @result="search" />
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import OperaGoodsWindow from '@/components/business/OperaGoodsWindow'
import selectProduct from '@/components/business/selectProduct'
import ImportButton from '@/components/common/ImportButton'
import { brand, baseCategory } from '@/api/system/common.js'
import { updateStatus, queryById, exportDoc } from '@/api/business/goods.js'
export default {
  name: 'Goods',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaGoodsWindow, selectProduct, ImportButton },
  data() {
    return {
      // 搜索
      searchForm: {
        id: '',
        name: '',
        status: '',
        categoryId: '',
        brandId: ''
      },
      ids: '',
      idList: [],
      categoryList: [],
      brandList: [],
      statusList: [
        { name: '启用', id: 0 },
        { name: '禁用', id: 1 }
      ]
    }
  },
  provide() {
    return {
      brandList: () => this.brandList,
      categoryList: () => this.categoryList
    }
  },
  created() {
    this.config({
      module: '商品',
      api: '/business/goods',
      'field.id': 'id',
      'field.main': 'name'
    })
    this.search()
    this.getbrand()
    this.getcategory()
  },
  methods: {
    // handleSelectionChange(e) {
    //   let arr = e.map(item => item.id)
    //   this.ids = arr.join(',')
    //   this.idList = arr;
    // },
    // 批量上下架
    bulkOperation(type) {
      if (this.tableData.selectedRows.length === 0) {
        this.$tip.warning('请至少选择一条数据')
        return
      }
      let idList = this.tableData.selectedRows.map(item => item.id)
      updateStatus({
        idList,
        status: type
      }).then(res => {
        this.$tip.apiSuccess('操作成功');
        // this.$message.success({ message:res.message })
        this.handlePageChange()
      })
    },
    downloadFile() {
      exportDoc({})
        .then(response => {
          this.download(response)
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    },
    rowStyle() {
      return "text-align:center";
    },
    edit(id) {
      queryById(id)
        .then(res => {
          this.$refs.operaGoodsWindow.open('编辑商品', res)
        })
    },
    changeStatus(item) {
      updateStatus({
        idList: [item.id],
        status: item.status
      }).then(res => {
        this.$tip.apiSuccess('更新成功')
      })
        .catch (err => {
          this.$message.error(err)
        } )
      .finally(() => {
        this.handlePageChange()
      })
    },
    getbrand() {
      brand({ type: 1 })
        .then(res => {
          this.brandList = res
        })
    },
    getcategory() {
      baseCategory({})
        .then(res => {
          this.categoryList = res
        })
    }
  }
}
</script>