doum
16 小时以前 1af395ecb948a9d0af14aa72d7fc8025e849e6bc
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
<template>
  <GlobalWindow
      :title="title"
      width="100%"
      :visible.sync="visible"
  >
    <TableLayout >
      <!-- 搜索表单 -->
      <el-form ref="searchForm" slot="search-form" :model="searchForm"  label-width="10px" style="display: block;" >
        <el-form-item label="" prop="name" style="display: inline-block;margin-right: 30px;width: 180px">
          <el-input v-model="searchForm.name" placeholder="商品名称" @keypress.enter.native="search"></el-input>
        </el-form-item>
        <el-form-item label="" prop="id" style="display: inline-block;margin-right: 30px;;width: 180px">
          <el-input v-model="searchForm.id" placeholder="商品ID" @keypress.enter.native="search"></el-input>
        </el-form-item>
        <el-form-item label="" prop="categoryId" style="display: inline-block;margin-right: 30px;">
          <!-- 0正常 1禁用 -->
          <el-select
              v-model="searchForm.categoryId"
              style="width: 120px"
              placeholder="所属分类"
              clearable
              @change="search"
          >
            <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" style="display: inline-block;margin-right: 30px;">
          <!-- 0正常 1禁用 -->
          <el-select
              v-model="searchForm.brandId"
              style="width: 120px"
              placeholder="所属品牌"
              clearable
              @change="search"
          >
            <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" style="display: inline-block;margin-right: 30px;">
          <!-- 0正常 1禁用 -->
          <el-select
              v-model="searchForm.status"
              style="width: 120px"
              @change="search"
              clearable
              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" >
          <li><el-button type="primary" icon="el-icon-plus" @click="setPriceBatch"  >批量定价</el-button></li>
        </ul>-->
        <div :style="'display: flex;height:'+tabelHeight+'px;'">
        <el-table
            :height="tabelHeight"
            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="120px" ></el-table-column>
          <el-table-column prop="name" label="商品名称" min-width="180px" 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="stockNum" label="剩余库存量" min-width="100px"></el-table-column>
          <el-table-column prop="status" label="上下架状态" min-width="100px"   align="center">
            <template slot-scope="{row}">
              <span  v-if="row.status ==1" class="red">已下架</span>
              <span v-else class="green">已上架</span>
            </template>
          </el-table-column>
          <el-table-column prop="price" label="展示价格" min-width="100px" align="center"></el-table-column>
          <el-table-column prop="skuPrice" label="销售价(元)"  fixed="right" min-width="100px" align="center">
            <template slot-scope="{row}">
              <span  class="orange">{{ row.skuPrice }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="shopPrice" label="供货价(元)" align="center" min-width="100px" fixed="right">
            <template slot-scope="scope">
              <el-input v-if="scope.row.isPriceSelected" v-model="scope.row.shopPrice"
                        @focus="focusEvent(scope.row,scope.$index,scope.column)"
                        @blur="blurEvent(scope.row,scope.$index,scope.column)" v-focus></el-input>
              <p :style="'cursor: pointer;'+((scope.row.skuPrice||0) <= (scope.row.shopPrice||0)?'color: red':'')+';'" class="blue" title="点击编辑" @click="cellClick(scope.row, scope.column)" v-else>
                {{scope.row.shopPrice || '未设置' }}
                <i v-if="(scope.row.skuPrice||0) <= (scope.row.shopPrice||0)" class="el-icon-warning" style="color: red"></i>
              </p>
            </template>
          </el-table-column>
<!--          <el-table-column
              label="操作"
              min-width="160"
              fixed="right"
          >
            <template slot-scope="{row}">
              <el-button type="text" v-permissions="['business:goods:update']" @click="setPrice(row)">设置价格</el-button>
            </template>
          </el-table-column>-->
        </el-table>
        <pagination
            @size-change="handleSizeChange"
            @current-change="handlePageChange"
            :pagination="tableData.pagination"
        >
        </pagination>
        </div>
      </template>
    </TableLayout>
    <template  v-slot:footer>
      <el-button @click="visible=false">返回</el-button>
    </template>
  </GlobalWindow>
</template>
 
<script>
import GlobalWindow from '@/components/common/GlobalWindow'
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import { findAll as labelList } from '@/api/business/labels'
import { setGoodsPrice } from '@/api/business/shop'
export default {
  name: 'OperaShopGoodsWindow',
  extends: BaseTable,
  components: { GlobalWindow, TableLayout, Pagination },
  data () {
    return {
      title: '',
      price: null,
      visible: false,
      tabelHeight: null,
      // 搜索
      searchForm: {
        id: '',
        name: '',
        shopId: null,
        categoryId: '',
        brandId: '',
        // 类型 0平台商城 1咖豆商城 2咖啡计划商品
        type: '0', // 平台商品
        status: 0,
        labels: ''
      },
      labels: [],
      brands: []
    }
  },
  mounted () {
    window.addEventListener('resize', this.handleResize)
  },
  beforeDestroy () {
    window.removeEventListener('resize', this.handleResize)
  },
  created: function () {
    this.config({
      module: '商品信息表',
      api: '/business/goods',
      'field.id': 'id',
      'field.main': 'id'
    })
    this.handleResize()
    labelList({
      type: 0 // 商品分类
    }).then(res => {
      this.labels = res
    })
    labelList({
      type: 1 // 商品品牌
    })
      .then(res => {
        this.brands = res
      })
  },
  directives: {
    focus: {
      inserted: function (el) {
        el.querySelector('input').focus()
      }
    }
  },
  methods: {
    setPrice (row) {
      if (row.skuPrice == null) {
        this.$tip.warning('请先设置商品销售价!')
        return
      }
      console.log(row)
    },
    setPriceBatch () {
    },
    handleResize () {
      this.tabelHeight = window.innerHeight - 400
    },
    open (title, info) {
      this.title = title
      this.visible = true
      this.searchForm.shopId = info.id
      this.search()
      this.handleResize()
    },
    handlePageChange: function (pageIndex) {
      this.__checkApi()
      this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
      this.isWorking.search = true
      this.api.fetchList({
        page: this.tableData.pagination.pageIndex,
        capacity: this.tableData.pagination.pageSize,
        model: this.searchForm,
        sorts: this.tableData.sorts
      })
        .then(data => {
          (data.records || []).forEach((item) => {
            item.isPriceSelected = false
          })
          this.tableData.list = data.records || []
          this.tableData.pagination.total = data.total
          console.log(this.tableData.list)
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking.search = false
        })
    },
    cellClick (row, column) {
      row.isPriceSelected = !row.isPriceSelected
    },
    focusEvent (row, index, column) {
      row.oldShopsPrice = row.shopPrice
    },
    blurEvent (row, curIndex, column) {
      if ( !row.skuPrice) {
        this.$tip.error('商品销售价未设置!')
        row.isPriceSelected = !row.isPriceSelected
        row.shopPrice = row.oldShopsPrice// 价格还原
        return
      }
      if (  row.skuPrice <= row.shopPrice) {
        this.$tip.error('供货价不能大于销售价')
        row.isPriceSelected = !row.isPriceSelected
        row.shopPrice = row.oldShopsPrice// 价格还原
        return
      }
      if (row.shopPrice == row.oldShopsPrice) {
        row.isPriceSelected = !row.isPriceSelected
        return
      }
      setGoodsPrice({
        id: this.searchForm.shopId,
        goodsId: row.id,
        goodsPrice: row.shopPrice
      }).then(res => {
        row.oldShopsPrice = row.shopPrice
        this.$tip.success('修改成功')
        this.$emit('success')
      }).catch(e => {
        row.shopPrice = row.oldShopsPrice// 价格还原
      }).finally(() => {
        row.isPriceSelected = !row.isPriceSelected
      })
    },
    handleClick (val) {
    }
  }
}
</script>
<style scoped>
.table-pagination{
  position: fixed !important;
  bottom: 50px;
}
</style>