傅行帆 6 lat temu
rodzic
commit
031e3b8b7b
4 zmienionych plików z 138 dodań i 58 usunięć
  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 Wyświetl plik

@@ -138,7 +138,15 @@ const apis = {
138 138
     },
139 139
     add: {
140 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 152
   newsType: {

+ 9
- 9
src/store/modules/goods.js Wyświetl plik

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

+ 89
- 41
src/views/goods/edit.vue Wyświetl plik

@@ -2,16 +2,24 @@
2 2
   <div>
3 3
     <div class="form-wrapper">
4 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 15
         <el-form-item label="商品图片:">
6 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 23
           </el-upload>
16 24
         </el-form-item>
17 25
         <el-form-item label="商品名称:">
@@ -26,22 +34,21 @@
26 34
         <el-form-item label="剩余数量:">
27 35
           <el-input v-model="detail.inventory"></el-input>
28 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 37
         <el-form-item label="商品详情:">
35 38
             <div id="websiteEditorElem" style="height: 400px"></div>
36 39
         </el-form-item>
37 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 49
         </el-form-item>
43 50
         <el-form-item label="领取地址:">
44
-          <el-input v-model="detail.tel"></el-input>
51
+          <el-input v-model="detail.address"></el-input>
45 52
         </el-form-item>
46 53
         <el-form-item>
47 54
           <el-button type="primary" @click="submitForm">保存</el-button>
@@ -67,7 +74,25 @@ export default {
67 74
   data() {
68 75
     return {
69 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 98
   created() {
@@ -76,15 +101,30 @@ export default {
76 101
   computed: {
77 102
     ...mapBuildingState({
78 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 112
   methods: {
82 113
     ...mapBuildingActions(["getBuildings"]),
83
-    ...mapGoodsActions(["getGoodsDetail", "editConsultant"]),
114
+    ...mapGoodsActions(["getGoodsDetail", "editGoods", "addGoods"]),
84 115
     init() {
85
-      if (this.$route.params.id) {
116
+      this.detail.goodsId = this.$route.params.id
117
+      if (this.detail.goodsId !== undefined) {
86 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,21 +138,33 @@ export default {
98 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 147
     submitForm() {
107 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 164
         .then(res => {
110
-          if (res.personId) {
111
-            this.detail = res;
112
-          }
113
-
114 165
           this.hideLoadding();
115 166
           this.$notify.info("保存成功");
167
+           this.$router.go(-1)
116 168
         })
117 169
         .catch(err => {
118 170
           this.hideLoadding();
@@ -162,16 +214,12 @@ export default {
162 214
     ];
163 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 225
 </script>

+ 31
- 7
src/views/goods/list.vue Wyświetl plik

@@ -3,7 +3,7 @@
3 3
         <div class="system-table-search">
4 4
       <div class="flex-h">
5 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 7
         </div>
8 8
         <ul>
9 9
           <li>
@@ -59,7 +59,7 @@
59 59
       fixed="right"
60 60
       label="操作">
61 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 63
         <el-button type="text" @click="toDetail(scope.row)" size="small">编辑</el-button>
64 64
       </template>
65 65
     </el-table-column>
@@ -71,7 +71,7 @@
71 71
     :current-page.sync="pageNavi.current"
72 72
     :pageSize="pageNavi.size"
73 73
     :total="pageNavi.total || 0"
74
-    @current-change="getConsultants"
74
+    @current-change="getList"
75 75
   >
76 76
   </el-pagination>
77 77
 </div>
@@ -99,7 +99,7 @@ export default {
99 99
   },
100 100
   computed: {},
101 101
   methods: {
102
-    ...mapGoodsActions(["getGoods"]),
102
+    ...mapGoodsActions(["getGoods", "changeGoodsStatus"]),
103 103
     getList() {
104 104
       const pageNumber = this.pageNavi.current || 1;
105 105
       const pageSize = this.pageNavi.size;
@@ -119,8 +119,8 @@ export default {
119 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 125
     toDetail(row) {
126 126
       this.$router.push({
@@ -128,12 +128,36 @@ export default {
128 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 155
     search() {
132 156
       this.pageNavi.current = 1;
133 157
       this.getList();
134 158
     },
135 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 163
   created() {