doum
49 分钟以前 94e23fd6ad010b560fe4cc566db38082d7619696
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
<template>
  <TableLayout :permissions="['business:goods:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
<!--      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="全部商品" name="first"></el-tab-pane>
        <el-tab-pane label="已售罄商品" name="second"></el-tab-pane>
        <el-tab-pane label="回收站商品" name="third"></el-tab-pane>
      </el-tabs>-->
      <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"
          placeholder="请选择所属分类"
        >
          <el-option
            v-for="item in labels"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属品牌" prop="brandId">
        <el-select
          v-model="searchForm.brandId"
          placeholder="请选择所属品牌"
        >
          <el-option
            v-for="item in brands"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="上架状态" prop="status">
        <el-select
          v-model="searchForm.status"
          placeholder="请选择上架状态"
        >
          <el-option :key="0" :value="0" label="上架"></el-option>
          <el-option :key="1" :value="1" label="下架"></el-option>
        </el-select>
      </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:goods:create', 'business:goods:delete']">
        <li><el-button type="primary" icon="el-icon-plus" @click="$refs.operaGoodsWindow.open('新建商品', null, 0)" v-permissions="['business:goods:create']">新建</el-button></li>
        <li><el-button type="primary"  icon="el-icon-edit"  @click="issued(0)">上架</el-button></li>
        <li><el-button type="danger"  icon="el-icon-edit"  @click="issued(1)">下架</el-button></li>
      </ul>
      <el-table
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="imgurl" label="商品信息" min-width="80px">
          <template slot-scope="{row}">
            <el-image style="width: 50px;height: 50px;" v-if="row.imgurl && row.imgurl!=''" :src="row.resourcePath+row.imgurl" :preview-src-list="[row.resourcePath+row.imgurl]"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="id" label="商品ID" min-width="150px" ></el-table-column>
        <el-table-column prop="name" label="商品名称" min-width="150px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="categoryName" label="所属分类" min-width="120px"></el-table-column>
        <el-table-column prop="brandName" label="所属品牌" min-width="120px"></el-table-column>
        <el-table-column prop="price" label="展示价格" min-width="100px"></el-table-column>
        <el-table-column prop="skuPrice" label="销售价(元)" min-width="100px"></el-table-column>
        <el-table-column prop="shopPrice" label="供货价设置" min-width="100px" align="center">
          <template slot-scope="{row}" >
            <div @click="goPriceSet(row)" style="cursor:pointer;"><span  class="red"> {{row.pricedShopNum||0}}</span> / <span class="green"> {{row.shopNum||0}}</span>  </div>
          </template>
        </el-table-column>
        <el-table-column prop="stockNum" label="剩余库存量" min-width="100px"></el-table-column>
        <el-table-column prop="salesVolume" label="实际销量" min-width="100px"></el-table-column>
        <el-table-column prop="editDate" label="最近更新时间" min-width="100px"></el-table-column>
        <el-table-column prop="status" label="上下架状态" min-width="100px" fixed="right" align="center">
          <template slot-scope="{row}">
            <el-switch
              v-model="row.status"
              :active-value="0"
              :inactive-value="1"
              active-color="#13ce66"
              inactive-color="#ff4949"
              @change="statusChange(row)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          min-width="250"
          fixed="right"
        >
          <template slot-scope="{row}">
             <el-button type="text" v-if="row.status == 1" @click="$refs.operaGoodsWindow.open('编辑商品', row, 0)" v-permissions="['business:goods:update']">编辑</el-button>
            <el-button type="text"  @click="goPriceSet(row)">供货价</el-button>
            <el-button type="text" style="color: red;" @click="deleteById(row)" v-permissions="['business:goods:delete']">删除</el-button>
            <!-- <el-button type="text" @click="$refs.operaGoodsDetailWindow.open('商品详情', row, 0)">查看详情</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"/>
    <OperaGoodsDetailWindow ref="operaGoodsDetailWindow"/>
    <OperaPlatformGoodsSkuWindow ref="operaPlatformGoodsSkuWindow"/>
    <OperaShopGoodsWindow ref="OperaShopGoodsWindow" @success="priceSuccess"/>
  </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 OperaGoodsDetailWindow from '@/components/business/OperaGoodsDetailWindow'
import OperaPlatformGoodsSkuWindow from '@/components/business/OperaPlatformGoodsSkuWindow'
import OperaShopGoodsWindow from '@/components/business/OperaShopGoodsWindow'
import { findAll as labelList } from '@/api/business/labels'
export default {
  name: 'Goods',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaGoodsWindow, OperaGoodsDetailWindow, OperaPlatformGoodsSkuWindow ,OperaShopGoodsWindow},
  data () {
    return {
      activeName: 'first',
      // 搜索
      searchForm: {
        id: '',
        creator: '',
        createDate: '',
        editor: '',
        editDate: '',
        isdeleted: '',
        remark: '',
        imgurl: '',
        name: '',
        info: '',
        categoryId: '',
        brandId: '',
        price: '',
        salenum: '',
        content: '',
        sortnum: '',
        looknum: '',
        // 类型 0平台商城 1咖豆商城 2咖啡计划商品
        type: '0', // 平台商品
        status: '',
        isrec: '',
        styleImg: '',
        labels: ''
      },
      labels: [],
      serials: [],
      brands: []
    }
  },
  provide () {
    return {
      labels: () => this.labels,
      brands: () => this.brands
    }
  },
  created () {
    this.config({
      module: '商品信息表',
      api: '/business/goods',
      'field.id': 'id',
      'field.main': 'id'
    })
    this.search()
    labelList({
      type: 0 // 商品分类
    }).then(res => {
      this.labels = res
    })
    labelList({
      type: 1 // 商品品牌
    })
      .then(res => {
        this.brands = res
      })
  },
  methods: {
    priceSuccess(){
      this.handlePageChange()
    },
    goPriceSet(row){
      if(row.skuPrice == null){
        this.$tip.warning('请先设置商品销售价!')
        return
      }
      this.$refs.OperaShopGoodsWindow.open('设置供货价 - '+row.name, row )
    },
    handleClick (val) {
 
    },
    /**
     *
     * @param {上下状态} status 0上架 1下架
     */
    issued (status) {
      if (this.tableData.selectedRows.length === 0) {
        this.$tip.warning('请至少选择一条数据')
        return
      }
      const message = `确认${status === 0 ? '上架' : '下架'}选中的商品么?`
      this.$dialog.messageWaring(message)
        .then(() => {
        })
    },
    statusChange (row) {
      this.statusChangeBiz([row])
    },
    statusChangeBiz (rows) {
      this.api.updateStatus(rows)
        .then(() => {
          this.handlePageChange()
        })
        .catch(e => {
          this.handlePageChange()
        })
    }
  }
}
</script>