zjxpcyc 6 years ago
parent
commit
04167c0de5

+ 6
- 1
src/pages/system/library/books/detail.vue View File

153
       immediate: true,
153
       immediate: true,
154
     },
154
     },
155
   },
155
   },
156
+  beforeRouteLeave (to, from, next) {
157
+    this.resetStore('detail')
158
+    next()
159
+  },
156
   methods: {
160
   methods: {
157
     ...mapMutations({
161
     ...mapMutations({
158
-      mergeDetail: 'mergeBookDetail'
162
+      mergeDetail: 'mergeBookDetail',
163
+      resetStore: 'clearData',
159
     }),
164
     }),
160
     ...mapActions({
165
     ...mapActions({
161
       getInfo: 'getBookDetail',
166
       getInfo: 'getBookDetail',

+ 18
- 3
src/pages/system/library/books/list.vue View File

52
           </el-table-column>
52
           </el-table-column>
53
           <el-table-column prop="BorrowDays" label="借阅(天)"></el-table-column>
53
           <el-table-column prop="BorrowDays" label="借阅(天)"></el-table-column>
54
           <el-table-column prop="InStock" label="总数量"></el-table-column>
54
           <el-table-column prop="InStock" label="总数量"></el-table-column>
55
-          <el-table-column prop="LeftNum" label="借出"></el-table-column>
55
+          <el-table-column prop="BorrowNum" label="借出"></el-table-column>
56
           <el-table-column label="预约">
56
           <el-table-column label="预约">
57
             <template slot-scope="scope">
57
             <template slot-scope="scope">
58
               <span>{{ getReserveNum(scope.row) }}</span>
58
               <span>{{ getReserveNum(scope.row) }}</span>
104
 import { createNamespacedHelpers, mapState } from 'vuex'
104
 import { createNamespacedHelpers, mapState } from 'vuex'
105
 import { Loading } from 'element-ui'
105
 import { Loading } from 'element-ui'
106
 
106
 
107
-const { mapState: mapLibSate, mapActions } = createNamespacedHelpers('library')
107
+const { mapState: mapLibSate, mapActions, mapMutations } = createNamespacedHelpers('library')
108
 
108
 
109
 export default {
109
 export default {
110
   name: 'bookList',
110
   name: 'bookList',
130
       types: s => s.type.list
130
       types: s => s.type.list
131
     })
131
     })
132
   },
132
   },
133
+  watch: {
134
+    defaultCase(nv) {
135
+      if (nv && !this.caseId) {
136
+        this.caseId = nv
137
+        this.filterList()
138
+      }
139
+    },
140
+  },
133
   created() {
141
   created() {
134
     this.inputRef.type = 'file'
142
     this.inputRef.type = 'file'
135
     // https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
143
     // https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
136
     this.inputRef.accept = 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
144
     this.inputRef.accept = 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
137
     this.inputRef.addEventListener('change', this.importBatch.bind(this))
145
     this.inputRef.addEventListener('change', this.importBatch.bind(this))
138
 
146
 
139
-    this.filterList()
147
+    // this.filterList()
148
+  },
149
+  beforeRouteLeave (to, from, next) {
150
+    this.resetStore('list')
151
+    next()
140
   },
152
   },
141
   methods: {
153
   methods: {
154
+    ...mapMutations({
155
+      resetStore: 'clearData',
156
+    }),
142
     ...mapActions({
157
     ...mapActions({
143
       getList: 'getBookList',
158
       getList: 'getBookList',
144
       getTypeList: 'getTypeList',
159
       getTypeList: 'getTypeList',

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

88
           return
88
           return
89
         }
89
         }
90
 
90
 
91
+        if (!this.$route.params.id) {
92
+          return
93
+        }
94
+
91
         let CaseId = nv.CaseId
95
         let CaseId = nv.CaseId
92
         if (!CaseId) {
96
         if (!CaseId) {
93
           CaseId = this.defaultCase
97
           CaseId = this.defaultCase
94
         }
98
         }
95
 
99
 
96
         this.formData = { ...nv, CaseId }
100
         this.formData = { ...nv, CaseId }
97
-        // this.mergeDetail(nv)
98
       },
101
       },
99
       immediate: true,
102
       immediate: true,
100
-    },
101
-    // formData: {
102
-    //   handler (nv) {
103
-    //     this.mergeDetail(nv)
104
-    //   },
105
-    //   deep: true,
106
-    // },
103
+    }
107
   },
104
   },
108
   methods: {
105
   methods: {
109
     ...mapMutations({
106
     ...mapMutations({
129
                 message: '更新或编辑分类成功',
126
                 message: '更新或编辑分类成功',
130
                 type: 'success'
127
                 type: 'success'
131
               })
128
               })
129
+
130
+              this.$router.push({ name: 'libraryType' })
132
             })
131
             })
133
             .catch(err => {
132
             .catch(err => {
134
               this.$message({
133
               this.$message({

+ 16
- 3
src/pages/system/library/books/types/list.vue View File

56
 
56
 
57
 const {
57
 const {
58
   mapState: mapLibSate,
58
   mapState: mapLibSate,
59
-  mapActions
59
+  mapActions,
60
+  mapMutations,
60
 } = createNamespacedHelpers('library')
61
 } = createNamespacedHelpers('library')
61
 
62
 
62
 export default {
63
 export default {
78
       pagenum: s => s.type.pagenum,
79
       pagenum: s => s.type.pagenum,
79
     })
80
     })
80
   },
81
   },
81
-  created() {
82
-    this.filterList()
82
+  watch: {
83
+    defaultCase(nv) {
84
+      if (nv && !this.caseId) {
85
+        this.caseId = nv
86
+        this.filterList()
87
+      }
88
+    },
89
+  },
90
+  beforeRouteLeave (to, from, next) {
91
+    this.resetStore('type.list')
92
+    next()
83
   },
93
   },
84
   methods: {
94
   methods: {
95
+    ...mapMutations({
96
+      resetStore: 'clearData',
97
+    }),
85
     ...mapActions({
98
     ...mapActions({
86
       getList: 'getTypeList',
99
       getList: 'getTypeList',
87
       deleteType: 'deleteType',
100
       deleteType: 'deleteType',

+ 1
- 1
src/pages/system/library/borrow/borrow.vue View File

108
   },
108
   },
109
   watch: {
109
   watch: {
110
     defaultCase(nv) {
110
     defaultCase(nv) {
111
-      if (!this.formData.caseid) {
111
+      if (nv && !this.formData.caseid) {
112
         this.formData.caseid = nv
112
         this.formData.caseid = nv
113
       }
113
       }
114
     }
114
     }

+ 22
- 0
src/store/library/index.js View File

30
     },
30
     },
31
   },
31
   },
32
   mutations: {
32
   mutations: {
33
+    clearData(state, key = '') {
34
+      if (!key) return
35
+
36
+      const ks = key.split('.')
37
+      const lastInx = ks.length - 1
38
+
39
+      ks.reduce((acc, it, inx) => {
40
+        if (inx === lastInx) {
41
+          if (it === 'list') {
42
+            acc[it] = []
43
+          } else if (it === 'detail') {
44
+            acc[it] = {}
45
+          } else if (it.indexOf('page') > -1) {
46
+            acc[it] = 1
47
+          } else {
48
+            acc[it] = undefined
49
+          }
50
+        }
51
+
52
+        return acc[it]
53
+      }, state)
54
+    },
33
     mergeTypeDetail (state, payload) {
55
     mergeTypeDetail (state, payload) {
34
       state.type.detail = payload || {}
56
       state.type.detail = payload || {}
35
 
57