zjxpcyc 6 anni fa
parent
commit
3f24425daf

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

14
           <el-input v-model="formData.BookBarcode" :style="{ width: '200px' }" :disabled="true"></el-input>
14
           <el-input v-model="formData.BookBarcode" :style="{ width: '200px' }" :disabled="true"></el-input>
15
         </el-form-item>
15
         </el-form-item>
16
         <el-form-item label="案场" prop="CaseId">
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
             <el-option
18
             <el-option
19
               v-for="item in cases"
19
               v-for="item in cases"
20
               :key="item.CaseId"
20
               :key="item.CaseId"
21
               :label="item.CaseName"
21
               :label="item.CaseName"
22
               :value="item.CaseId"
22
               :value="item.CaseId"
23
-              @change="filterTypes"
24
             ></el-option>
23
             ></el-option>
25
           </el-select>
24
           </el-select>
26
         </el-form-item>
25
         </el-form-item>
109
     if (id) {
108
     if (id) {
110
       this.active = 1
109
       this.active = 1
111
 
110
 
112
-      this.getInfo({
113
-        BookId: id
111
+      this.getInfo({ id }).then((x) => {
112
+        this.filterTypes(x.CaseId)
114
       }).catch(err => {
113
       }).catch(err => {
115
         this.$message({
114
         this.$message({
116
           showClose: true,
115
           showClose: true,
136
   watch: {
135
   watch: {
137
     detail: {
136
     detail: {
138
       handler (nv, ov) {
137
       handler (nv, ov) {
138
+        console.log(nv)
139
         if (nv.BookId === this.formData.BookId) {
139
         if (nv.BookId === this.formData.BookId) {
140
           return
140
           return
141
         }
141
         }
150
       },
150
       },
151
       immediate: true,
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
   methods: {
161
   methods: {
161
     ...mapMutations({
162
     ...mapMutations({
189
     },
190
     },
190
 
191
 
191
     uploadSuccess(res) {
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
     filterTypes(val) {
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
     submit() {
201
     submit() {
201
       this.$refs.ruleForm.validate(valid => {
202
       this.$refs.ruleForm.validate(valid => {
202
         if (valid) {
203
         if (valid) {
203
-          this.updateDetail()
204
+          if (!this.formData.Price) {
205
+            this.formData.Price = 0
206
+          }
207
+
208
+          this.updateDetail(this.formData)
204
             .then(() => {
209
             .then(() => {
205
               this.$message({
210
               this.$message({
206
                 showClose: true,
211
                 showClose: true,

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

25
     </div>
25
     </div>
26
     <div>
26
     <div>
27
       <el-button plain @click="editBook()" size="medium">图书录入</el-button>
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
       <div :style="{ margin: '10px 0' }">
29
       <div :style="{ margin: '10px 0' }">
31
         <el-table :data="list" border style="width: 100%">
30
         <el-table :data="list" border style="width: 100%">
32
           <el-table-column label="图片" width="128">
31
           <el-table-column label="图片" width="128">
85
         ></el-pagination>
84
         ></el-pagination>
86
       </div>
85
       </div>
87
     </div>
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
   </div>
100
   </div>
89
 </template>
101
 </template>
90
 
102
 
100
       caseId: '',
112
       caseId: '',
101
       bookBarcode: '',
113
       bookBarcode: '',
102
       bookName: '',
114
       bookName: '',
103
-      inputRef: window.document.createElement('input')
115
+      inputRef: window.document.createElement('input'),
116
+      showDialog: false,
104
     }
117
     }
105
   },
118
   },
106
   computed: {
119
   computed: {
128
       getList: 'getBookList',
141
       getList: 'getBookList',
129
       getTypeList: 'getTypeList',
142
       getTypeList: 'getTypeList',
130
       deleteBook: 'deleteBook',
143
       deleteBook: 'deleteBook',
131
-      setBookRecommend: 'setBookRecommend'
144
+      setBookRecommend: 'updateBookDetail',
145
+      batchImport: 'batchImport',
132
     }),
146
     }),
133
 
147
 
134
     // 查询过滤
148
     // 查询过滤
192
     // 设为/取消推荐
206
     // 设为/取消推荐
193
     setRecommend(book) {
207
     setRecommend(book) {
194
       const tipMsg = book.IsRecommend === 1 ? '确定取消推荐?' : '确认设置为推荐?'
208
       const tipMsg = book.IsRecommend === 1 ? '确定取消推荐?' : '确认设置为推荐?'
209
+      book.IsRecommend = Math.abs(book.IsRecommend - 1)
195
 
210
 
196
       this.$confirm(tipMsg, '提示', {
211
       this.$confirm(tipMsg, '提示', {
197
         confirmButtonText: '是',
212
         confirmButtonText: '是',
241
     importBatch(e) {
256
     importBatch(e) {
242
       // 需要指定案场
257
       // 需要指定案场
243
       const caseName = this.getCaseName(this.caseId)
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
       this.$confirm(`数据将被导入至【${caseName}】案场, 是否继续?`, '提示', {
268
       this.$confirm(`数据将被导入至【${caseName}】案场, 是否继续?`, '提示', {
246
         confirmButtonText: '确定',
269
         confirmButtonText: '确定',
248
         type: 'warning'
271
         type: 'warning'
249
       })
272
       })
250
         .then(() => {
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
         .catch(x => x)
302
         .catch(x => x)
255
     },
303
     },

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

98
       },
98
       },
99
       immediate: true,
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
   methods: {
108
   methods: {
109
     ...mapMutations({
109
     ...mapMutations({
115
     }),
115
     }),
116
 
116
 
117
     uploadSuccess(res) {
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
     submit() {
122
     submit() {

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

112
       }
112
       }
113
     },
113
     },
114
     deleteTypeList (state, payload = {}) {
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
     setBookList (state, payload) {
117
     setBookList (state, payload) {
118
       const { list, pagenum } = payload || {}
118
       const { list, pagenum } = payload || {}
124
         state.pagenum = 0
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
   actions: {
131
   actions: {
129
     getBorrowList ({ commit }, payload) { // 获取借阅记录
132
     getBorrowList ({ commit }, payload) { // 获取借阅记录
166
     updateTypeDetail ({ commit }, payload = {}) {
169
     updateTypeDetail ({ commit }, payload = {}) {
167
       return new Promise((resolve, reject) => {
170
       return new Promise((resolve, reject) => {
168
         const id = payload.BookTypeId
171
         const id = payload.BookTypeId
169
-
170
         payload.CreateDate = ''
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
     deleteType ({ commit }, payload) {
185
     deleteType ({ commit }, payload) {
215
           .catch((err) => console.log(err) && reject(err.message))
207
           .catch((err) => console.log(err) && reject(err.message))
216
       })
208
       })
217
     },
209
     },
218
-    getBookDetail ({ commit }, payload) {
210
+    getBookDetail ({ commit }, payload = {}) {
219
       return new Promise((resolve, reject) => {
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
       return new Promise((resolve, reject) => {
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
       return new Promise((resolve, reject) => {
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
       return new Promise((resolve, reject) => {
250
       return new Promise((resolve, reject) => {
235
 
251
 
236
       })
252
       })
237
     },
253
     },
238
-    getStockList ({ commit }, payload) {
254
+    batchImport(_, payload) {
239
       return new Promise((resolve, reject) => {
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 Vedi File

990
       url: `${baseUrl}${common}/book`
990
       url: `${baseUrl}${common}/book`
991
     },
991
     },
992
     update: {
992
     update: {
993
-      method: 'post',
993
+      method: 'put',
994
       url: `${baseUrl}${common}/book`
994
       url: `${baseUrl}${common}/book`
995
     },
995
     },
996
     delete: {
996
     delete: {
997
       method: 'delete',
997
       method: 'delete',
998
       url: `${baseUrl}${common}/book/:id`
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
 export default $api
1006
 export default $api