微信

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="mainPage">
  3. <div>
  4. <loadMore :on-infinite="onInfinite" :dataList="scrollData">
  5. <div class="header flex-h">
  6. <div class="flex-item flex-h">
  7. <i class="iconfont icon-sousuo"></i>
  8. <router-link
  9. class="flex-item"
  10. :to="{name: 'booksSearch', query: {caseid: currentCaseId}}"
  11. >{{indexSearchKey}}</router-link>
  12. </div>
  13. <a @click="showDialog = true">
  14. <i class="iconfont icon-dingwei"></i>
  15. <span>{{currentCaseName}}</span>
  16. </a>
  17. </div>
  18. <nav class="nav">
  19. <a
  20. v-for="(item, index) in navList"
  21. v-if="(navList || []).length < 9 || index<7"
  22. :key="index"
  23. @click="navClick(item)"
  24. >
  25. <img :src="item.BookTypeImg" alt>
  26. <span>{{item.BookTypeName}}</span>
  27. </a>
  28. <a v-if="(navList || []).length > 8 " @click="moreNav()">
  29. <img src="https://spaceofcheng.oss-cn-beijing.aliyuncs.com/test-icon8.png" alt>
  30. <span>更多</span>
  31. </a>
  32. </nav>
  33. <div class="list">
  34. <h1>精选推荐</h1>
  35. <ul>
  36. <li v-for="(item, index) in books.list" :key="index">
  37. <libraryListItem
  38. :data="item"
  39. :status="mineBookStatus(item)"
  40. @appointmentBook="appointmentBook"
  41. ></libraryListItem>
  42. </li>
  43. </ul>
  44. </div>
  45. </loadMore>
  46. <van-dialog v-model="showDialog" :show-confirm-button="false">
  47. <div class="dialogContent">
  48. <span class="title">选择案场</span>
  49. <div>
  50. <radio :data="cases" v-model="caseId"></radio>
  51. </div>
  52. <div class="btn">
  53. <a @click="selectCaseId">确定</a>
  54. </div>
  55. </div>
  56. </van-dialog>
  57. <van-dialog v-model="showAppointmentDialog" :show-confirm-button="false">
  58. <div class="dialogContent">
  59. <span class="title">确认在线预约当前图书?</span>
  60. <div>
  61. <span style="color: #666;">在线预约需在{{reserveEndDate}}前前往案场借阅图书, 否则 将取消预约资格</span>
  62. </div>
  63. <div class="btn">
  64. <a @click="sureAppointmentBook">确定</a>
  65. <a @click="showAppointmentDialog = false">取消</a>
  66. </div>
  67. </div>
  68. </van-dialog>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. import loadMore from '@/components/vue-load-more/index'
  74. import libraryListItem from '../../../../components/libraryListItem/index'
  75. import radio from '../../../../components/radio/index'
  76. import toolClass from '../../../../util/util'
  77. import { mapState, createNamespacedHelpers } from 'vuex'
  78. const { mapActions: mapAppActions } = createNamespacedHelpers('app')
  79. const { mapState: mapBookState, mapActions: mapBookActions } = createNamespacedHelpers('book')
  80. export default {
  81. name: '',
  82. data () {
  83. return {
  84. showDialog: false,
  85. showAppointmentDialog: false,
  86. caseId: '',
  87. currentCaseId: '',
  88. currentCaseName: '',
  89. cases: [],
  90. indexSearchKey: '',
  91. page: 1,
  92. pagesize: 3,
  93. scrollData: {
  94. noFlag: false // 暂无更多数据显示
  95. },
  96. reserveBookId: '',
  97. }
  98. },
  99. computed: {
  100. ...mapState({
  101. userInfo: x => x.userCenter.userInfo,
  102. CaseList: x => x.app.CaseList
  103. }),
  104. ...mapBookState({
  105. navList: x => x.types.list,
  106. books: x => x.recommends,
  107. mineBooks: x => x.minebooks,
  108. }),
  109. reserveEndDate () {
  110. return toolClass.calDate(7)
  111. }
  112. },
  113. components: {
  114. libraryListItem,
  115. radio,
  116. loadMore
  117. },
  118. created () {
  119. if (!this.CaseList.length || this.CaseList === null) {
  120. this.getCaseList().then((res) => {
  121. (res.cases || []).map((item) => {
  122. this.cases.push({
  123. value: item.CaseName,
  124. id: item.CaseId
  125. })
  126. })
  127. this.currentCaseId = ((res.cases || [])[0] || {}).CaseId
  128. this.currentCaseName = ((res.cases || [])[0] || {}).CaseName
  129. this.init()
  130. })
  131. } else {
  132. (this.CaseList || []).map((item) => {
  133. this.cases.push({
  134. value: item.CaseName,
  135. id: item.CaseId
  136. })
  137. })
  138. this.currentCaseId = ((this.CaseList || [])[0] || {}).CaseId
  139. this.currentCaseName = ((this.CaseList || [])[0] || {}).CaseName
  140. this.init()
  141. }
  142. },
  143. methods: {
  144. ...mapAppActions(['getCaseList']),
  145. ...mapBookActions([
  146. 'getBookType',
  147. 'getRecommendBook',
  148. 'getMineBook',
  149. 'reserveBook',
  150. 'updateRecommendBookLeftNum',
  151. ]),
  152. selectCaseId () { // 选择案场
  153. if (this.currentCaseId !== this.caseId) {
  154. this.currentCaseId = this.caseId
  155. this.CaseList.map((item) => {
  156. if (item.CaseId === this.currentCaseId) this.currentCaseName = item.CaseName
  157. })
  158. this.page = 1
  159. this.init()
  160. }
  161. this.showDialog = false
  162. },
  163. init () { // 初始化
  164. this.getBookType({
  165. caseid: this.currentCaseId,
  166. page: 1,
  167. pagesize: 10,
  168. })
  169. // this.getRecommendBook({
  170. // caseid: this.currentCaseId,
  171. // page: this.page,
  172. // pagesize: this.pagesize,
  173. // })
  174. this.onInfinite()
  175. },
  176. onInfinite () {
  177. this.getMineBook({
  178. page: 1,
  179. pagesize: 1000,
  180. })
  181. let more = this.$el.querySelector('.load-more')
  182. this.getRecommendBook({
  183. caseid: this.currentCaseId,
  184. page: this.page,
  185. pagesize: this.pagesize,
  186. }).then((res) => {
  187. this.page++
  188. res.list = res.list || []
  189. if (res.list.length < res.pageSize) {
  190. more.style.display = 'none'// 隐藏加载条
  191. this.scrollData.noFlag = true
  192. } else {
  193. more.style.display = 'none'// 隐藏加载条
  194. }
  195. })
  196. },
  197. appointmentBook (id) { // 预约图书
  198. this.reserveBookId = id
  199. this.showAppointmentDialog = true
  200. },
  201. sureAppointmentBook () { // 确定预约图书
  202. this.reserveBook({
  203. bookid: this.reserveBookId,
  204. }).then(() => {
  205. this.updateRecommendBookLeftNum(this.reserveBookId)
  206. this.getMineBook({
  207. page: 1,
  208. pagesize: 1000,
  209. })
  210. })
  211. this.showAppointmentDialog = false
  212. },
  213. navClick (item) { // 点击nav
  214. this.$router.push({ name: 'booksList', query: { type: item.BookTypeId, caseid: this.currentCaseId } })
  215. },
  216. moreNav () {
  217. this.$router.push({ name: 'libraryNavList', query: { caseid: this.currentCaseId } })
  218. },
  219. mineBookStatus (item) {
  220. return ((this.mineBooks.list || []).filter(x => x.BookId === item.BookId && (x.BorrowStatus == '4' || x.BorrowStatus == '1' || x.BorrowStatus == '0'))[0] || {}).BorrowStatus
  221. }
  222. }
  223. }
  224. </script>
  225. <!-- Add "scoped" attribute to limit CSS to this component only -->
  226. <style lang="scss" scoped>
  227. @import 'page.scss';
  228. </style>