wangfei 6 years ago
parent
commit
bd4fb1dd97

+ 20
- 2
src/components/libraryListItem/index.vue View File

@@ -12,7 +12,7 @@
12 12
         <h5 v-if="!type">{{data.BookDescription}}</h5>
13 13
         <div v-if="!type" class="flex-h" style="margin-top: .06rem;">
14 14
           <span class="flex-item">{{data.Author}} 著</span>
15
-          <span class="status active" @click="appointmentBook(data.BookId)">{{data.Status}}</span>
15
+          <span class="status active" @click="appointmentBook(data.BookId)">{{bookStatus}}</span>
16 16
         </div>
17 17
         <div v-if="!type" class="flex-h">
18 18
           <span class="flex-item">{{data.Publisher}}</span>
@@ -49,12 +49,27 @@
49 49
 
50 50
 export default {
51 51
   name: '',
52
-  props: ['data', 'type'],
52
+  props: ['data', 'type', 'status'],
53 53
   data () {
54 54
     return {
55 55
     }
56 56
   },
57 57
   computed: {
58
+    bookStatus() {
59
+      let status = '在线预约'
60
+      switch(this.status) {
61
+        case 'reserve':
62
+          status = '已预约'
63
+          break
64
+        case 'borrowed':
65
+          status = '借阅中'
66
+          break
67
+        case 'late':
68
+          status = '借阅中'
69
+          break
70
+      }
71
+      return status
72
+    }
58 73
   },
59 74
   components: {
60 75
   },
@@ -62,6 +77,9 @@ export default {
62 77
   },
63 78
   methods: {
64 79
     appointmentBook (id) {
80
+      if(this.status == 'reserve' || this.status == 'borrowed' || this.status == 'late'){
81
+        return
82
+      }
65 83
       this.$emit('appointmentBook', id)
66 84
     },
67 85
     itemClick (target) {

+ 27
- 23
src/pages/user/library/borrowedRecord/index.vue View File

@@ -7,20 +7,20 @@
7 7
       normalColor="#666"
8 8
       @slideChange="slideChange"
9 9
     >
10
-      <div class="subMain" slot="slideTabH-1">
10
+      <div class="subMain" slot="slideTabH-borrowed">
11 11
         <div>
12 12
           <ul>
13
-            <li v-for="(item, index) in borrowedRecordList" :key="index">
13
+            <li v-for="(item, index) in books.list" :key="index">
14 14
               <libraryListItem :data="item" :type="1" @itemClick="borrowedRecordClick"></libraryListItem>
15 15
             </li>
16 16
           </ul>
17 17
         </div>
18 18
       </div>
19
-      <div class="subMain" slot="slideTabH-2">
19
+      <div class="subMain" slot="slideTabH-reserve">
20 20
         <div>
21 21
           <span>请在资格保留时间内至案场借阅图书,超出预约时间将取消预约资格</span>
22 22
           <ul>
23
-            <li v-for="(item, index) in appointmentList" :key="index">
23
+            <li v-for="(item, index) in books.list" :key="index">
24 24
               <libraryListItem :data="item" :type="2"></libraryListItem>
25 25
             </li>
26 26
           </ul>
@@ -53,27 +53,24 @@
53 53
 <script>
54 54
 import slideTabH from '../../../../components/slideTabH/index'
55 55
 import libraryListItem from '../../../../components/libraryListItem/index'
56
-import { mapState, createNamespacedHelpers } from 'vuex'
57
-const { mapActions: mapAppActions } = createNamespacedHelpers('app')
58
-const { mapState: mapLibraryState, mapActions: mapLibraryAction } = createNamespacedHelpers('library')
56
+import { createNamespacedHelpers } from 'vuex'
57
+const { mapState: mapBookState, mapActions: mapBookAction } = createNamespacedHelpers('book')
59 58
 export default {
60 59
   data () {
61 60
     return {
62
-      tabList: [{ value: '借阅记录', id: '1' }, { value: '线上预约记录', id: '2' }],
63
-      showDialog: false
61
+      tabList: [{ value: '借阅记录', id: 'borrowed' }, { value: '线上预约记录', id: 'reserve' }],
62
+      showDialog: false,
63
+      status: 'borrowed',
64
+      page: 1,
65
+      pagesize: 10,
64 66
     }
65 67
   },
66 68
   created () {
69
+    this.getList()
67 70
   },
68 71
   computed: {
69
-    ...mapState({
70
-      CaseList: x => x.app.CaseList,
71
-    }),
72
-    ...mapLibraryState({
73
-      navList: x => x.navList,
74
-      bookTypeList: x => x.bookTypeList,
75
-      borrowedRecordList: x => x.borrowedRecordList,
76
-      appointmentList: x => x.appointmentList
72
+    ...mapBookState({
73
+      books: x => x.minebooks,
77 74
     })
78 75
   },
79 76
   components: {
@@ -81,19 +78,26 @@ export default {
81 78
     slideTabH
82 79
   },
83 80
   methods: {
84
-    ...mapAppActions([
85
-      'getCaseList',
81
+    ...mapBookAction([
82
+      'getMineBook',
86 83
     ]),
87
-    ...mapLibraryAction(['getBookListByType']),
88
-    navClick (item) {
89
-    },
90 84
     slideChange (e) {
91
-      if (e === 1 && !this.appointmentList.length) {
85
+      if (this.status !== this.tabList[e].id) {
86
+        this.status = this.tabList[e].id
87
+        this.page = 1
88
+        this.getList()
92 89
       }
93 90
     },
94 91
     borrowedRecordClick (e) { // 借阅记录点击事件
95 92
       this.showDialog = true
96 93
     },
94
+    getList () {
95
+      this.getMineBook({
96
+        page: this.page,
97
+        pagesize: this.pagesize,
98
+        status: this.status,
99
+      })
100
+    }
97 101
   }
98 102
 }
99 103
 </script>

+ 27
- 4
src/pages/user/mainPage/libraryIndex/index.vue View File

@@ -28,7 +28,7 @@
28 28
         <h1>精选推荐</h1>
29 29
         <ul>
30 30
           <li v-for="(item, index) in books.list" :key="index">
31
-            <libraryListItem :data="item" @appointmentBook="appointmentBook"></libraryListItem>
31
+            <libraryListItem :data="item" :status="mineBookStatus(item)" @appointmentBook="appointmentBook"></libraryListItem>
32 32
           </li>
33 33
         </ul>
34 34
       </div>
@@ -47,7 +47,7 @@
47 47
         <div class="dialogContent">
48 48
           <span class="title">确认在线预约当前图书?</span>
49 49
           <div>
50
-            <span style="color: #666;">在线预约需在2018年12月20日前前往案场借阅图书, 否则 将取消预约资格</span>
50
+            <span style="color: #666;">在线预约需在{{reserveEndDate}}前前往案场借阅图书, 否则 将取消预约资格</span>
51 51
           </div>
52 52
           <div class="btn">
53 53
             <a @click="sureAppointmentBook">确定</a>
@@ -62,6 +62,7 @@
62 62
 <script>
63 63
 import libraryListItem from '../../../../components/libraryListItem/index'
64 64
 import radio from '../../../../components/radio/index'
65
+import toolClass from '../../../../util/util'
65 66
 import { mapState, createNamespacedHelpers } from 'vuex'
66 67
 const { mapActions: mapAppActions } = createNamespacedHelpers('app')
67 68
 const { mapState: mapBookState, mapActions: mapBookActions } = createNamespacedHelpers('book')
@@ -78,6 +79,7 @@ export default {
78 79
       indexSearchKey: '',
79 80
       page: 1,
80 81
       pagesize: 10,
82
+      reserveBookId: '',
81 83
     }
82 84
   },
83 85
   computed: {
@@ -87,8 +89,12 @@ export default {
87 89
     }),
88 90
     ...mapBookState({
89 91
       navList: x => x.types.list,
90
-      books: x => x.recommends
92
+      books: x => x.recommends,
93
+      mineBooks: x => x.minebooks,
91 94
     }),
95
+    reserveEndDate() {
96
+      return toolClass.calDate(7)
97
+    }
92 98
   },
93 99
   components: {
94 100
     libraryListItem,
@@ -125,6 +131,7 @@ export default {
125 131
       'getBookType', 
126 132
       'getRecommendBook', 
127 133
       'getMineBook',
134
+      'reserveBook',
128 135
     ]),
129 136
     selectCaseId () { // 选择案场
130 137
       if (this.currentCaseId !== this.caseId) {
@@ -148,11 +155,24 @@ export default {
148 155
         page: this.page,
149 156
         pagesize: this.pagesize,
150 157
       })
158
+      this.getMineBook({
159
+        page: 1,
160
+        pagesize: 1000,
161
+      })
151 162
     },
152
-    appointmentBook () { // 预约图书
163
+    appointmentBook (id) { // 预约图书
164
+      this.reserveBookId = id
153 165
       this.showAppointmentDialog = true
154 166
     },
155 167
     sureAppointmentBook () { // 确定预约图书
168
+      this.reserveBook({
169
+        bookid: this.reserveBookId,
170
+      }).then(() => {
171
+        this.getMineBook({
172
+          page: 1,
173
+          pagesize: 1000,
174
+        })
175
+      })
156 176
       this.showAppointmentDialog = false
157 177
     },
158 178
     navClick (item) { // 点击nav
@@ -160,6 +180,9 @@ export default {
160 180
     },
161 181
     moreNav () {
162 182
       this.$router.push({ name: 'libraryNavList', query: {caseid: this.currentCaseId} })
183
+    },
184
+    mineBookStatus (item) {
185
+      return ((this.mineBooks.list || []).filter(x => x.BookId === item.BookId)[0] || {}).BorrowStatus
163 186
     }
164 187
   }
165 188
 }

+ 14
- 0
src/store/book/index.js View File

@@ -89,6 +89,20 @@ export default {
89 89
           reject(err)
90 90
         })
91 91
       })
92
+    },
93
+    reserveBook (c, { bookid }) {
94
+      return new Promise((resolve, reject) => {
95
+        Ajax({
96
+          ...api.library.reserve,
97
+          urlData: {
98
+            bookid,
99
+          },
100
+        }).then(res => {
101
+          resolve(res)
102
+        }).catch((err) => {
103
+          reject(err)
104
+        })
105
+      }) 
92 106
     }
93 107
   }
94 108
 }

+ 4
- 0
src/util/api.js View File

@@ -350,6 +350,10 @@ const $api = {
350 350
       method: 'get',
351 351
       url: `${baseUrl}${wechat}/customer/book`
352 352
     },
353
+    reserve: {
354
+      method: 'post',
355
+      url: `${baseUrl}${wechat}/book/reserve/:bookid`
356
+    },
353 357
   }
354 358
 }
355 359
 export default $api

+ 9
- 1
src/util/util.js View File

@@ -107,7 +107,15 @@ const toolClass = {
107 107
         resolve(result)
108 108
       }).catch(reject)
109 109
     })
110
-  }
110
+  },
111
+  calDate (aa) {
112
+    var date1 = new Date(),
113
+    time1=date1.getFullYear()+"-"+(date1.getMonth()+1)+"-"+date1.getDate();//time1表示当前时间
114
+    var date2 = new Date(date1);
115
+    date2.setDate(date1.getDate()+aa);       
116
+    var time2 = date2.getFullYear()+"年"+ (date2.getMonth()+1) +"月"+date2.getDate()+"日";
117
+    return time2;
118
+  },
111 119
 }
112 120
 
113 121
 export default toolClass