quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
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
<template>
  <div class="product-list">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="出售中" name="sell">
          <span slot="label">出售中 <el-tag size="mini">{{product_count.sell}}</el-tag></span>
        </el-tab-pane>
        <el-tab-pane label="仓库中" name="lower">
          <span slot="label">仓库中 <el-tag size="mini">{{product_count.lower}}</el-tag></span>
        </el-tab-pane>
        <el-tab-pane label="回收站" name="recovery">
          <span slot="label">回收站 <el-tag size="mini">{{product_count.recovery}}</el-tag></span>
        </el-tab-pane>
        <el-tab-pane label="库存紧张" name="stock">
          <span slot="label">库存紧张 <el-tag size="mini">{{product_count.stock}}</el-tag></span>
        </el-tab-pane>
        <el-tab-pane label="草稿箱" name="draft">
          <span slot="label">草稿箱 <el-tag size="mini">{{product_count.draft}}</el-tag></span>
        </el-tab-pane>
        <el-tab-pane label="待审核" name="audit">
          <span slot="label">待审核 <el-tag size="mini">{{product_count.audit}}</el-tag></span>
        </el-tab-pane>
        <el-tab-pane label="未通过" name="no_audit">
          <span slot="label">未通过 <el-tag size="mini">{{product_count.no_audit}}</el-tag></span>
        </el-tab-pane>
      </el-tabs>
      <el-form size="small" :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="商品分类">
          <el-select size="small" v-model="searchForm.category_id" placeholder="所有分类">
            <el-option label="全部" value="0"></el-option>
            <el-option v-for="(item, index) in categoryList" :key="index" :label="item.name" :value="item.category_id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品名称"><el-input size="small" v-model="searchForm.product_name" placeholder="请输入商品名称"></el-input></el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
 
    <!--添加产品-->
    <div class="common-level-rail" v-if="supplier.status==0">
      <el-button size="small" type="primary" icon="el-icon-plus" @click="addClick" v-auth="'/product/product/add'">添加产品</el-button>
      <el-button size="small" type="success" icon="el-icon-top" @click="changeStatus(false, 10)" v-auth="'/product/product/edit'">批量上架</el-button>
      <el-button size="small" type="warning" icon="el-icon-bottom" @click="changeStatus(false, 20)" v-auth="'/product/product/edit'">批量下架</el-button>
      <el-button size="small" type="danger" icon="el-icon-delete" @click="delClick(false)" v-auth="'/product/product/delete'">批量删除</el-button>
    </div>
    <div class="common-level-rail" v-if="supplier.status!=0">
      <el-button size="small" type="primary" icon="el-icon-plus" v-auth="'/product/product/add'" :disabled="true">添加产品</el-button>
      <span class="red pl16" v-if="supplier.status==10">正在退保证金</span>
      <span class="red pl16" v-if="supplier.status==20">未交纳保证金,请到移动端交纳</span>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading" @selection-change="tableCurrentChange">
           <el-table-column type="selection" width="45"></el-table-column>
          <el-table-column prop="product_name" label="产品" width="400px">
            <template slot-scope="scope">
              <div class="product-info">
                <div class="pic"><img v-img-url="scope.row.image[0].file_path" alt="" /></div>
                <div class="info">
                  <div class="name">{{ scope.row.product_name }}</div>
                  <div class="price">¥{{ scope.row.product_price }}</div>
                  <div class="price" v-if="scope.row.audit_status == 20">未通过原因:{{scope.row.audit_remark}}</div>
                  <div class="price" v-if="scope.row.audit_status == 30">强制下架:{{scope.row.audit_remark}}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="category.name" label="分类"></el-table-column>
          <el-table-column prop="sales_actual" label="实际销量"></el-table-column>
          <el-table-column prop="product_stock" label="库存"></el-table-column>
          <el-table-column prop="view_times" label="点击数"></el-table-column>
          <el-table-column prop="product_status.text" label="商品属性">
            <template slot-scope="scope">
              <span v-if="scope.row.is_virtual == 0">实物商品</span>
              <span v-if="scope.row.is_virtual == 1" class="green">虚拟商品</span>
              <span v-if="scope.row.is_virtual == 2" class="green">券商品</span>
              <span v-if="scope.row.is_virtual == 3" class="green">服务商品</span>
              <span v-if="scope.row.is_virtual == 4" class="green">团购商品</span>
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="发布时间"></el-table-column>
          <el-table-column prop="product_sort" label="排序"></el-table-column>
          <el-table-column fixed="right" label="操作" width="80">
            <template slot-scope="scope" v-if="supplier.status==0">
              <div class="table-btn-column">
                <el-button @click="editClick(scope.row)" type="text" size="small" v-auth="'/product/product/edit'">编辑商品</el-button>
                <el-button @click="delClick(scope.row)" type="text" size="small" v-auth="'/product/product/delete'">删除商品</el-button>
                <el-button v-if="activeName == 'sell'" @click="changeStatus(scope.row, 20)" type="text" size="small" v-auth="'/product/product/state'">立即下架</el-button>
                <el-button v-if="activeName == 'lower'" @click="changeStatus(scope.row, 10)" type="text" size="small" v-auth="'/product/product/state'">立即上架</el-button>
                <el-button v-if="activeName == 'recovery'" @click="changeStatus(scope.row, 20)" type="text" size="small" v-auth="'/product/product/state'">恢复</el-button>
                <el-button @click="copyClick(scope.row)" type="text" size="small" v-auth="'/product/product/copy'">一键复制</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!--分页-->
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="curPage"
        :page-size="pageSize"
        layout="total, prev, pager, next, jumper"
        :total="totalDataNumber"
      ></el-pagination>
    </div>
  </div>
</template>
 
<script>
import PorductApi from '@/api/product.js';
export default {
  components: {},
  data() {
    return {
      /*切换菜单*/
      activeName: 'sell',
      /*切换选中值*/
      activeIndex: '0',
      /*是否正在加载*/
      loading: true,
      /*一页多少条*/
      pageSize: 10,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*搜索参数*/
      searchForm: {
        product_name: '',
        category_id: ''
      },
      /*列表数据*/
      tableData: [],
      /*全部分类*/
      categoryList: [],
      supplier:[],
      /*统计数据*/
      product_count: {},
      /*多选的*/
      multipleSelection: [],
    };
  },
  created() {
    /*获取列表*/
    this.getData();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.loading = true;
      self.curPage = val;
      self.getData();
    },
 
    /*每页多少条*/
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
 
    /*切换菜单*/
    handleClick(tab, event) {
      let self = this;
      self.curPage = 1;
      self.getData();
    },
 
    /*获取列表*/
    getData() {
      let self = this;
      let Params = self.searchForm;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      Params.type = self.activeName;
      self.loading = true;
      PorductApi.productList(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.categoryList = data.data.category;
          self.totalDataNumber = data.data.list.total;
          self.supplier = data.data.supplier;
          self.product_count = data.data.product_count;
        })
        .catch(error => {
          self.loading = false;
        });
    },
 
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.getData();
    },
 
    /*打开添加*/
    addClick() {
      this.$router.push('/product/product/add');
    },
 
    /*打开编辑*/
    editClick(row) {
      this.$router.push({
        path: '/product/product/edit',
        query: {
          product_id: row.product_id,
          scene: 'edit'
        }
      });
    },
 
    /*打开复制*/
    copyClick(row) {
      this.$router.push({
        path: '/product/product/edit',
        query: {
          product_id: row.product_id,
          scene: 'copy'
        }
      });
    },
 
    /*删除*/
    delClick: function(row) {
      let self = this;
      let msg = '';
      let ids='';
      if(row){
         ids=row.product_id;
      }else{
        let temp_list=[];
 
        for (let i = 0; i < self.multipleSelection.length; i++) {
          let item = self.multipleSelection[i];
          temp_list.push(item.product_id);
        }
        if(temp_list.length<=0){
          self.$message({
            message: '请先选择商品',
            type: 'error'
          });
          return;
        }
        ids=temp_list.join();
        row=self.tableData[0];
      }
 
      if(row.product_status == 30){
        msg = '删除后不可恢复,确认删除该记录吗?';
      }else{
        msg = '删除后将移动到回收站,确定删除该记录吗?';
      }
      self
        .$confirm(msg, '提示', {
          type: 'warning'
        })
        .then(() => {
          PorductApi.delProduct({
            product_id: ids,
          }).then(data => {
            self.$message({
              message: data.msg,
              type: 'success'
            });
            self.getData();
          });
        });
    },
    /*修改状态*/
    changeStatus(row,value){
      let self = this;
      let msg = '';
      let ids='';
      if(row){
         ids=row.product_id;
      }else{
        let temp_list=[];
 
        for (let i = 0; i < self.multipleSelection.length; i++) {
          let item = self.multipleSelection[i];
          temp_list.push(item.product_id);
        }
        if(temp_list.length<=0){
          self.$message({
            message: '请先选择商品',
            type: 'error'
          });
          return;
        }
        ids=temp_list.join();
        row=self.tableData[0];
      }
 
      if(value == 10){
        msg = '确认要上架该商品吗?';
      }else{
        msg = '确认要下架该商品吗?';
        if(self.activeName == 'recovery'){
          msg = '确认要移动该商品到仓库吗?';
        }
      }
      self.$confirm(msg, '提示', {
          type: 'warning'
        })
        .then(() => {
          PorductApi.changeStatus({
            product_id: ids,
            state: value
          }).then(data => {
            self.$message({
              message: '操作成功',
              type: 'success'
            });
            self.getData();
          });
        });
    },
    /*监听复选按钮选中事件*/
    tableCurrentChange(val) {
      this.multipleSelection = val;
    }
  }
};
</script>
 
<style></style>