zjxpcyc 6 years ago
parent
commit
3f24425daf

+ 19
- 14
src/pages/system/library/books/detail.vue View File

@@ -14,13 +14,12 @@
14 14
           <el-input v-model="formData.BookBarcode" :style="{ width: '200px' }" :disabled="true"></el-input>
15 15
         </el-form-item>
16 16
         <el-form-item label="案场" prop="CaseId">
17
-          <el-select v-model="formData.CaseId" placeholder="请选择案场">
17
+          <el-select v-model="formData.CaseId" placeholder="请选择案场" @change="filterTypes">
18 18
             <el-option
19 19
               v-for="item in cases"
20 20
               :key="item.CaseId"
21 21
               :label="item.CaseName"
22 22
               :value="item.CaseId"
23
-              @change="filterTypes"
24 23
             ></el-option>
25 24
           </el-select>
26 25
         </el-form-item>
@@ -109,8 +108,8 @@ export default {
109 108
     if (id) {
110 109
       this.active = 1
111 110
 
112
-      this.getInfo({
113
-        BookId: id
111
+      this.getInfo({ id }).then((x) => {
112
+        this.filterTypes(x.CaseId)
114 113
       }).catch(err => {
115 114
         this.$message({
116 115
           showClose: true,
@@ -136,6 +135,7 @@ export default {
136 135
   watch: {
137 136
     detail: {
138 137
       handler (nv, ov) {
138
+        console.log(nv)
139 139
         if (nv.BookId === this.formData.BookId) {
140 140
           return
141 141
         }
@@ -150,12 +150,13 @@ export default {
150 150
       },
151 151
       immediate: true,
152 152
     },
153
-    formData: {
154
-      handler (nv) {
155
-        this.mergeDetail(nv)
156
-      },
157
-      deep: true,
158
-    },
153
+    // formData: {
154
+    //   handler (nv) {
155
+    //     console.log('----------', nv)
156
+    //     this.bookImg = nv.BookImg
157
+    //   },
158
+    //   deep: true,
159
+    // },
159 160
   },
160 161
   methods: {
161 162
     ...mapMutations({
@@ -189,18 +190,22 @@ export default {
189 190
     },
190 191
 
191 192
     uploadSuccess(res) {
192
-      this.formData.BookImg = res.result.url
193
+      this.$set(this.formData, 'BookImg', res.result.url)
194
+      // this.formData.BookImg = res.result.url
193 195
     },
194 196
 
195 197
     filterTypes(val) {
196
-      const CaseId = val
197
-      this.getTypeList({ page: 0, CaseId, pagesize: 10000 })
198
+      this.getTypeList({ page: 0, caseid: val, pagesize: 10000 })
198 199
     },
199 200
 
200 201
     submit() {
201 202
       this.$refs.ruleForm.validate(valid => {
202 203
         if (valid) {
203
-          this.updateDetail()
204
+          if (!this.formData.Price) {
205
+            this.formData.Price = 0
206
+          }
207
+
208
+          this.updateDetail(this.formData)
204 209
             .then(() => {
205 210
               this.$message({
206 211
                 showClose: true,

+ 54
- 6
src/pages/system/library/books/list.vue View File

@@ -25,8 +25,7 @@
25 25
     </div>
26 26
     <div>
27 27
       <el-button plain @click="editBook()" size="medium">图书录入</el-button>
28
-      <el-button plain @click="showBatchInput()" size="medium">批量导入</el-button>
29
-      <el-button type="text" size="medium">点击下载导入模板</el-button>
28
+      <el-button plain @click="showDialog = true" size="medium">批量导入</el-button>
30 29
       <div :style="{ margin: '10px 0' }">
31 30
         <el-table :data="list" border style="width: 100%">
32 31
           <el-table-column label="图片" width="128">
@@ -85,6 +84,19 @@
85 84
         ></el-pagination>
86 85
       </div>
87 86
     </div>
87
+    <el-dialog
88
+      title="批量导入"
89
+      :visible.sync="showDialog"
90
+      width="50%">
91
+      <div :style="{ margin: 'auto', width: '80%' }">
92
+        <div><el-button @click="showBatchInput" :style="{ width: '100%' }">上传文件</el-button></div>
93
+        <div><el-button type="text" size="medium" :style="{ float: 'right' }">下载导入模板</el-button></div>
94
+      </div>
95
+      <span slot="footer" class="dialog-footer">
96
+        <el-button type="primary" @click="showDialog = false">确 定</el-button>
97
+        <el-button @click="showDialog = false">取 消</el-button>
98
+      </span>
99
+    </el-dialog>
88 100
   </div>
89 101
 </template>
90 102
 
@@ -100,7 +112,8 @@ export default {
100 112
       caseId: '',
101 113
       bookBarcode: '',
102 114
       bookName: '',
103
-      inputRef: window.document.createElement('input')
115
+      inputRef: window.document.createElement('input'),
116
+      showDialog: false,
104 117
     }
105 118
   },
106 119
   computed: {
@@ -128,7 +141,8 @@ export default {
128 141
       getList: 'getBookList',
129 142
       getTypeList: 'getTypeList',
130 143
       deleteBook: 'deleteBook',
131
-      setBookRecommend: 'setBookRecommend'
144
+      setBookRecommend: 'updateBookDetail',
145
+      batchImport: 'batchImport',
132 146
     }),
133 147
 
134 148
     // 查询过滤
@@ -192,6 +206,7 @@ export default {
192 206
     // 设为/取消推荐
193 207
     setRecommend(book) {
194 208
       const tipMsg = book.IsRecommend === 1 ? '确定取消推荐?' : '确认设置为推荐?'
209
+      book.IsRecommend = Math.abs(book.IsRecommend - 1)
195 210
 
196 211
       this.$confirm(tipMsg, '提示', {
197 212
         confirmButtonText: '是',
@@ -241,6 +256,14 @@ export default {
241 256
     importBatch(e) {
242 257
       // 需要指定案场
243 258
       const caseName = this.getCaseName(this.caseId)
259
+      const file = e.target.files[0]
260
+      if (!file) {
261
+        this.$message({
262
+          showClose: true,
263
+          message: '请选择导入文件',
264
+          type: 'error'
265
+        })
266
+      }
244 267
 
245 268
       this.$confirm(`数据将被导入至【${caseName}】案场, 是否继续?`, '提示', {
246 269
         confirmButtonText: '确定',
@@ -248,8 +271,33 @@ export default {
248 271
         type: 'warning'
249 272
       })
250 273
         .then(() => {
251
-          // TODO
252
-          // const file = e.target.files[0];
274
+          const data = {
275
+            caseId: this.caseId,
276
+            excel: file,
277
+          }
278
+
279
+          this.batchImport(data).then(() => {
280
+            this.$confirm(`数据导入完成, 点击【确定】刷新页面`, '提示', {
281
+              confirmButtonText: '确定',
282
+              cancelButtonText: '取消',
283
+              type: 'warning'
284
+            }).then(() => {
285
+              window.location.reload()
286
+            })
287
+          }).catch((err) => {
288
+            this.$message({
289
+              showClose: true,
290
+              message: err,
291
+              type: 'error'
292
+            })
293
+          })
294
+
295
+          // const loading = this.$loading({
296
+          //   lock: true,
297
+          //   text: '数据导入中, 可能耗时较长, 请稍后 ...',
298
+          // })
299
+
300
+          // window.setTimeout(() => loading.close(), 2000)
253 301
         })
254 302
         .catch(x => x)
255 303
     },

+ 8
- 7
src/pages/system/library/books/types/detail.vue View File

@@ -98,12 +98,12 @@ export default {
98 98
       },
99 99
       immediate: true,
100 100
     },
101
-    formData: {
102
-      handler (nv) {
103
-        this.mergeDetail(nv)
104
-      },
105
-      deep: true,
106
-    },
101
+    // formData: {
102
+    //   handler (nv) {
103
+    //     this.mergeDetail(nv)
104
+    //   },
105
+    //   deep: true,
106
+    // },
107 107
   },
108 108
   methods: {
109 109
     ...mapMutations({
@@ -115,7 +115,8 @@ export default {
115 115
     }),
116 116
 
117 117
     uploadSuccess(res) {
118
-      this.formData.BookTypeImg = res.result.url
118
+      this.$set(this.formData, 'BookTypeImg', res.result.url)
119
+      // this.formData.BookTypeImg = res.result.url
119 120
     },
120 121
 
121 122
     submit() {

+ 52
- 30
src/store/library/index.js View File

@@ -112,7 +112,7 @@ export default {
112 112
       }
113 113
     },
114 114
     deleteTypeList (state, payload = {}) {
115
-      state.type.list = state.type.list.filter(x => x.BookTypeId === payload.BookTypeId)
115
+      state.type.list = state.type.list.filter(x => x.BookTypeId !== payload.BookTypeId)
116 116
     },
117 117
     setBookList (state, payload) {
118 118
       const { list, pagenum } = payload || {}
@@ -124,6 +124,9 @@ export default {
124 124
         state.pagenum = 0
125 125
       }
126 126
     },
127
+    deleteBookList (state, payload = {}) {
128
+      state.list = state.list.filter(x => x.BookId !== payload.BookId)
129
+    },
127 130
   },
128 131
   actions: {
129 132
     getBorrowList ({ commit }, payload) { // 获取借阅记录
@@ -166,28 +169,17 @@ export default {
166 169
     updateTypeDetail ({ commit }, payload = {}) {
167 170
       return new Promise((resolve, reject) => {
168 171
         const id = payload.BookTypeId
169
-
170 172
         payload.CreateDate = ''
171 173
 
172
-        if (!id) {
173
-          ajax({
174
-            ...api.bookType.save,
175
-            data: payload,
176
-          }).then((x) => {
177
-            commit('mergeTypeDetail', x)
178
-            resolve(x)
179
-          })
180
-            .catch(({ message }) => reject(message))
181
-        } else {
182
-          ajax({
183
-            ...api.bookType.update,
184
-            data: payload,
185
-          }).then((x) => {
186
-            commit('mergeTypeDetail', x)
187
-            resolve(x)
188
-          })
189
-            .catch(({ message }) => reject(message))
190
-        }
174
+        const apiConf = !id ? api.bookType.save : api.bookType.update
175
+        ajax({
176
+          ...apiConf,
177
+          data: payload,
178
+        }).then((x) => {
179
+          commit('mergeTypeDetail', x)
180
+          resolve(x)
181
+        })
182
+          .catch(({ message }) => reject(message))
191 183
       })
192 184
     },
193 185
     deleteType ({ commit }, payload) {
@@ -215,30 +207,60 @@ export default {
215 207
           .catch((err) => console.log(err) && reject(err.message))
216 208
       })
217 209
     },
218
-    getBookDetail ({ commit }, payload) {
210
+    getBookDetail ({ commit }, payload = {}) {
219 211
       return new Promise((resolve, reject) => {
220
-
212
+        ajax({
213
+          ...api.book.detail,
214
+          urlData: { ...payload },
215
+        }).then((x) => {
216
+          commit('mergeBookDetail', x)
217
+          resolve(x)
218
+        })
219
+          .catch(({ message }) => reject(message))
221 220
       })
222 221
     },
223
-    updateBookDetail ({ commit }, payload) {
222
+    updateBookDetail ({ commit }, payload = {}) {
224 223
       return new Promise((resolve, reject) => {
224
+        const id = payload.BookId
225 225
 
226
+        const apiConf = !id ? api.book.save : api.book.update
227
+        ajax({
228
+          ...apiConf,
229
+          data: payload,
230
+        }).then((x) => {
231
+          commit('mergeBookDetail', x)
232
+          resolve(x)
233
+        })
234
+          .catch(({ message }) => reject(message))
226 235
       })
227 236
     },
228
-    deleteBook ({ commit }, payload) {
237
+    deleteBook ({ commit }, payload = {}) {
229 238
       return new Promise((resolve, reject) => {
230
-
239
+        ajax({
240
+          ...api.book.delete,
241
+          urlData: { id: payload.BookId },
242
+        }).then((x) => {
243
+          commit('deleteBookList', payload)
244
+          resolve(x)
245
+        })
246
+          .catch(({ message }) => reject(message))
231 247
       })
232 248
     },
233
-    setBookRecommend ({ commit }, payload) {
249
+    getStockList ({ commit }, payload) {
234 250
       return new Promise((resolve, reject) => {
235 251
 
236 252
       })
237 253
     },
238
-    getStockList ({ commit }, payload) {
254
+    batchImport(_, payload) {
239 255
       return new Promise((resolve, reject) => {
240
-
256
+        ajax({
257
+          ...api.book.import,
258
+          data: payload,
259
+        }).then(() => {
260
+          resolve()
261
+        })
262
+          .catch(({ message }) => reject(message))
241 263
       })
242
-    },
264
+    }
243 265
   },
244 266
 }

+ 5
- 1
src/util/api.js View File

@@ -990,13 +990,17 @@ const $api = {
990 990
       url: `${baseUrl}${common}/book`
991 991
     },
992 992
     update: {
993
-      method: 'post',
993
+      method: 'put',
994 994
       url: `${baseUrl}${common}/book`
995 995
     },
996 996
     delete: {
997 997
       method: 'delete',
998 998
       url: `${baseUrl}${common}/book/:id`
999 999
     },
1000
+    import: {
1001
+      method: 'post',
1002
+      url: `${baseUrl}${common}/book/excel`
1003
+    },
1000 1004
   },
1001 1005
 }
1002 1006
 export default $api