傅行帆 6 年前
父节点
当前提交
031e3b8b7b
共有 4 个文件被更改,包括 138 次插入58 次删除
  1. 9
    1
      src/config/api.js
  2. 9
    9
      src/store/modules/goods.js
  3. 89
    41
      src/views/goods/edit.vue
  4. 31
    7
      src/views/goods/list.vue

+ 9
- 1
src/config/api.js 查看文件

138
     },
138
     },
139
     add: {
139
     add: {
140
       method: 'post',
140
       method: 'post',
141
-      url: `${commPrefix}/customer/add`
141
+      url: `${commPrefix}/taGoods/add`
142
+    },
143
+    edit: {
144
+      method: 'put',
145
+      url: `${commPrefix}/taGoods`
146
+    },
147
+    change: {
148
+      method: 'put',
149
+      url: `${commPrefix}/taGoods/change`
142
     }
150
     }
143
   },
151
   },
144
   newsType: {
152
   newsType: {

+ 9
- 9
src/store/modules/goods.js 查看文件

53
         })
53
         })
54
       })
54
       })
55
     },
55
     },
56
-    addDynamics (_, payload) {
56
+    addGoods (_, payload) {
57
       return new Promise((resolve, reject) => {
57
       return new Promise((resolve, reject) => {
58
         request({
58
         request({
59
-          ...apis.dynamic.add, 
60
-          data: payload.detail,
59
+          ...apis.goods.add, 
60
+          data: payload,
61
         }).then((data) => {
61
         }).then((data) => {
62
           resolve(data)
62
           resolve(data)
63
         }).catch((err) => {
63
         }).catch((err) => {
68
         })
68
         })
69
       })
69
       })
70
     },
70
     },
71
-    editDynamics (_, payload) {
71
+    editGoods (_, payload) {
72
       return new Promise((resolve, reject) => {
72
       return new Promise((resolve, reject) => {
73
         request({
73
         request({
74
-          ...apis.dynamic.edit,
75
-          data: payload.detail,
74
+          ...apis.goods.edit,
75
+          data: payload,
76
         }).then((data) => {
76
         }).then((data) => {
77
           resolve(data)
77
           resolve(data)
78
         }).catch((err) => {
78
         }).catch((err) => {
96
         })
96
         })
97
       })
97
       })
98
     },
98
     },
99
-    publicDynamic (_, payload) {
99
+    changeGoodsStatus (_, payload) {
100
       return new Promise((resolve, reject) => {
100
       return new Promise((resolve, reject) => {
101
         request({
101
         request({
102
-          ...apis.dynamic.public,
103
-          urlData: payload,
102
+          ...apis.goods.change,
103
+          data: payload,
104
         }).then((data) => {
104
         }).then((data) => {
105
           resolve(data)
105
           resolve(data)
106
         }).catch((err) => {
106
         }).catch((err) => {

+ 89
- 41
src/views/goods/edit.vue 查看文件

2
   <div>
2
   <div>
3
     <div class="form-wrapper">
3
     <div class="form-wrapper">
4
       <el-form label-width="100px" :model="detail">
4
       <el-form label-width="100px" :model="detail">
5
+        <el-form-item label="项目">
6
+          <el-select v-model="detail.buildingId" placeholder="请选择">
7
+            <el-option
8
+                    v-for="item in buildingList"
9
+                    :key="item.buildingId"
10
+                    :label="item.buildingName"
11
+                    :value="item.buildingId">
12
+            </el-option>
13
+          </el-select>
14
+        </el-form-item>
5
         <el-form-item label="商品图片:">
15
         <el-form-item label="商品图片:">
6
           <el-upload
16
           <el-upload
7
-            class="avatar-uploader"
8
-            :action="upFileUrl"
9
-            name='file'
10
-            :show-file-list="false"
11
-            :before-upload="beforeImgUpload"
12
-            :on-success="handleAvatarSuccess">
13
-            <img v-if="detail.imgUrl" :src="detail.imgUrl" class="avatar">
14
-            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
17
+                  :headers="uploadHeaders"
18
+                  :action="upFileUrl"
19
+                  :show-file-list="false"
20
+                  :on-success="handleAvatarSuccess">
21
+              <img v-if="detail.imgUrl" :src="detail.imgUrl" class="avatar">
22
+              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
15
           </el-upload>
23
           </el-upload>
16
         </el-form-item>
24
         </el-form-item>
17
         <el-form-item label="商品名称:">
25
         <el-form-item label="商品名称:">
26
         <el-form-item label="剩余数量:">
34
         <el-form-item label="剩余数量:">
27
           <el-input v-model="detail.inventory"></el-input>
35
           <el-input v-model="detail.inventory"></el-input>
28
         </el-form-item>
36
         </el-form-item>
29
-        <el-form-item label="授权项目:">
30
-          <el-select v-model="detail.buildings" placeholder="请选择">
31
-            <el-option v-for="(build,i) in buildings.list || []" :key="i" :label="build.buildingName" :value="build.buildingId"></el-option>
32
-          </el-select>
33
-        </el-form-item>
34
         <el-form-item label="商品详情:">
37
         <el-form-item label="商品详情:">
35
             <div id="websiteEditorElem" style="height: 400px"></div>
38
             <div id="websiteEditorElem" style="height: 400px"></div>
36
         </el-form-item>
39
         </el-form-item>
37
         <el-form-item label="状态:">
40
         <el-form-item label="状态:">
38
-          <el-radio-group v-model="detail.status">
39
-            <el-radio-button :label="0">禁用</el-radio-button>
40
-            <el-radio-button :label="1">启用</el-radio-button>
41
-          </el-radio-group>
41
+          <el-select v-model="detail.status" clearable placeholder="请选择">
42
+            <el-option
43
+              v-for="item in options"
44
+              :key="item.value"
45
+              :label="item.label"
46
+              :value="item.value">
47
+            </el-option>
48
+          </el-select>
42
         </el-form-item>
49
         </el-form-item>
43
         <el-form-item label="领取地址:">
50
         <el-form-item label="领取地址:">
44
-          <el-input v-model="detail.tel"></el-input>
51
+          <el-input v-model="detail.address"></el-input>
45
         </el-form-item>
52
         </el-form-item>
46
         <el-form-item>
53
         <el-form-item>
47
           <el-button type="primary" @click="submitForm">保存</el-button>
54
           <el-button type="primary" @click="submitForm">保存</el-button>
67
   data() {
74
   data() {
68
     return {
75
     return {
69
       upFileUrl: apis.file.upload.url,
76
       upFileUrl: apis.file.upload.url,
70
-      detail: {}
77
+      detail: {
78
+        buildingId: '',
79
+        imgUrl: '',
80
+        goodsName: '',
81
+        pointPrice: '',
82
+        totalNum: '',
83
+        inventory: '',
84
+        status: '',
85
+        address: '',
86
+        goodsId: '',
87
+      },
88
+      options: [{
89
+          value: '1',
90
+          label: '已上架'
91
+        }, {
92
+          value: '0',
93
+          label: '已下架'
94
+        }],
95
+      buildingList: [],
71
     };
96
     };
72
   },
97
   },
73
   created() {
98
   created() {
76
   computed: {
101
   computed: {
77
     ...mapBuildingState({
102
     ...mapBuildingState({
78
       buildings: x => x.buildings
103
       buildings: x => x.buildings
79
-    })
104
+    }),
105
+    uploadHeaders () {
106
+        const token = localStorage.getItem('x-token') || ''
107
+        return {
108
+            Authorization: `Bearer ${token}`
109
+        }
110
+    }
80
   },
111
   },
81
   methods: {
112
   methods: {
82
     ...mapBuildingActions(["getBuildings"]),
113
     ...mapBuildingActions(["getBuildings"]),
83
-    ...mapGoodsActions(["getGoodsDetail", "editConsultant"]),
114
+    ...mapGoodsActions(["getGoodsDetail", "editGoods", "addGoods"]),
84
     init() {
115
     init() {
85
-      if (this.$route.params.id) {
116
+      this.detail.goodsId = this.$route.params.id
117
+      if (this.detail.goodsId !== undefined) {
86
         this.getGoodsDetail({ id: this.$route.params.id }).then(data => {
118
         this.getGoodsDetail({ id: this.$route.params.id }).then(data => {
87
-          this.detail = data;
119
+          this.detail.buildingId = data.buildingId
120
+          this.detail.imgUrl = data.imgUrl
121
+          this.detail.goodsName = data.goodsName
122
+          this.detail.pointPrice = data.pointPrice
123
+          this.detail.totalNum = data.totalNum
124
+          this.detail.inventory = data.inventory
125
+          this.detail.status = data.status
126
+          this.detail.address = data.address
127
+          this.detail.goodsId = data.goodsId
88
         });
128
         });
89
       }
129
       }
90
     },
130
     },
98
       return true;
138
       return true;
99
     },
139
     },
100
 
140
 
101
-    handleAvatarSuccess(res) {
102
-      this.detail.photo = res.data;
103
-      this.hideLoadding();
141
+    handleAvatarSuccess(res, file) {
142
+        this.imageUrl = URL.createObjectURL(file.raw);
143
+        // console.log(res)
144
+        this.detail.imgUrl = res.data
104
     },
145
     },
105
 
146
 
106
     submitForm() {
147
     submitForm() {
107
       this.showLoadding("保存中...");
148
       this.showLoadding("保存中...");
108
-      this.editConsultant(this.detail)
149
+      if (this.detail.goodsId === '' || this.detail.goodsId === undefined) {
150
+        console.log('添加')
151
+        this.addGoods(this.detail)
152
+        .then(res => {
153
+          this.hideLoadding();
154
+          this.$notify.info("保存成功");
155
+           this.$router.go(-1)
156
+        })
157
+        .catch(err => {
158
+          this.hideLoadding();
159
+          this.$notify.error(err.message);
160
+        });
161
+        return;
162
+      }
163
+      this.editGoods(this.detail)
109
         .then(res => {
164
         .then(res => {
110
-          if (res.personId) {
111
-            this.detail = res;
112
-          }
113
-
114
           this.hideLoadding();
165
           this.hideLoadding();
115
           this.$notify.info("保存成功");
166
           this.$notify.info("保存成功");
167
+           this.$router.go(-1)
116
         })
168
         })
117
         .catch(err => {
169
         .catch(err => {
118
           this.hideLoadding();
170
           this.hideLoadding();
162
     ];
214
     ];
163
     phoneEditor.create()
215
     phoneEditor.create()
164
 
216
 
165
-    // this.getBuildings({
166
-    //   pageNum: 1,
167
-    //   pageSize: 100
168
-    // }).then(() => {
169
-    //   if ((this.$route.query.id || "") !== "") {
170
-    //     this.getDetail({ id: this.$route.query.id }).then(data => {
171
-    //       phoneEditor.txt.html(data.url);
172
-    //     });
173
-    //   }
174
-    // });
217
+    this.getBuildings({
218
+      pageNum: 1,
219
+      pageSize: 100
220
+    }).then((data) => {
221
+      this.buildingList = data.records;
222
+    });
175
   }
223
   }
176
 };
224
 };
177
 </script>
225
 </script>

+ 31
- 7
src/views/goods/list.vue 查看文件

3
         <div class="system-table-search">
3
         <div class="system-table-search">
4
       <div class="flex-h">
4
       <div class="flex-h">
5
         <div class="flex-item flex-h">
5
         <div class="flex-item flex-h">
6
-          <el-button size="mini" type="success" @click='addDynamic'>新增</el-button>
6
+          <el-button size="mini" type="success" @click='addGoods'>新增</el-button>
7
         </div>
7
         </div>
8
         <ul>
8
         <ul>
9
           <li>
9
           <li>
59
       fixed="right"
59
       fixed="right"
60
       label="操作">
60
       label="操作">
61
       <template slot-scope="scope">
61
       <template slot-scope="scope">
62
-        <el-button type="text" @click="toDetail(scope.row)" size="small">{{scope.row.status == 1?'下架':'上架'}}</el-button>
62
+        <el-button type="text" @click="changeStatus(scope.row)" size="small">{{scope.row.status == 1?'下架':'上架'}}</el-button>
63
         <el-button type="text" @click="toDetail(scope.row)" size="small">编辑</el-button>
63
         <el-button type="text" @click="toDetail(scope.row)" size="small">编辑</el-button>
64
       </template>
64
       </template>
65
     </el-table-column>
65
     </el-table-column>
71
     :current-page.sync="pageNavi.current"
71
     :current-page.sync="pageNavi.current"
72
     :pageSize="pageNavi.size"
72
     :pageSize="pageNavi.size"
73
     :total="pageNavi.total || 0"
73
     :total="pageNavi.total || 0"
74
-    @current-change="getConsultants"
74
+    @current-change="getList"
75
   >
75
   >
76
   </el-pagination>
76
   </el-pagination>
77
 </div>
77
 </div>
99
   },
99
   },
100
   computed: {},
100
   computed: {},
101
   methods: {
101
   methods: {
102
-    ...mapGoodsActions(["getGoods"]),
102
+    ...mapGoodsActions(["getGoods", "changeGoodsStatus"]),
103
     getList() {
103
     getList() {
104
       const pageNumber = this.pageNavi.current || 1;
104
       const pageNumber = this.pageNavi.current || 1;
105
       const pageSize = this.pageNavi.size;
105
       const pageSize = this.pageNavi.size;
119
           this.$notify.error(err.msg || err.message);
119
           this.$notify.error(err.msg || err.message);
120
         });
120
         });
121
     },
121
     },
122
-    addDynamic() {
123
-      this.$router.push({ name: "consultant.list" });
122
+    addGoods() {
123
+      this.$router.push({ name: "goods.edit" });
124
     },
124
     },
125
     toDetail(row) {
125
     toDetail(row) {
126
       this.$router.push({
126
       this.$router.push({
128
         params: { id: row.goodsId }
128
         params: { id: row.goodsId }
129
       });
129
       });
130
     },
130
     },
131
+    changeStatus(row) {
132
+      this.showLoadding("保存中...");
133
+      this.changeGoodsStatus(row)
134
+        .then(res => {
135
+          this.hideLoadding();
136
+          this.$notify.info("保存成功");
137
+          this.search();
138
+        })
139
+        .catch(err => {
140
+          this.hideLoadding();
141
+          this.$notify.error(err.message);
142
+        });
143
+    },
144
+    showLoadding(text) {
145
+      this.loading = this.$loading({
146
+        text,
147
+        lock: true,
148
+        spinner: "el-icon-loading",
149
+        background: "rgba(255, 255, 255, 0.7)"
150
+      });
151
+    },
152
+    hideLoadding() {
153
+      if (this.loading) this.loading.close();
154
+    },
131
     search() {
155
     search() {
132
       this.pageNavi.current = 1;
156
       this.pageNavi.current = 1;
133
       this.getList();
157
       this.getList();
134
     },
158
     },
135
     newPage(page) {
159
     newPage(page) {
136
-      this.$router.replace({ name: "consultant.list", query: { page } });
160
+      this.$router.replace({ name: "goods.list", query: { page } });
137
     }
161
     }
138
   },
162
   },
139
   created() {
163
   created() {