This repository has been archived by the owner on Dec 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
/
loan.vue
127 lines (125 loc) · 3.14 KB
/
loan.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<style lang="less">
@import url("../../less/config");
page {
background: @bg-color;
width: 100%;
height: 100%;
}
.book {
color: #333;
margin: 26rpx 26rpx 0 26rpx;
background: @white;
border-radius: 4rpx;
box-shadow: 4rpx 4rpx 20rpx #ddd;
padding: 20rpx;
display: flex;
align-content: space-between;
flex-wrap: wrap;
>view {
width: 100%;
}
.info {
margin-top: 10rpx;
justify-content: space-between;
align-items: center;
display: flex;
color: #666;
font-size: 0.8rem;
}
.warn {
color: @base-color;
}
}
.none {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: #888;
font-size: 2rem;
text-align: center;
}
</style>
<template>
<view wx:if="{{loan_books.length!=0}}">
<block wx:for="{{loan_books}}" wx:key="{{index}}">
<view class="book">
<view class="title">{{item.title}}-{{item.author}}</view>
<view class="info">
<view>到期: {{item.due_date}}</view>
<view wx:if="{{item.arrearage>0}}" class="warn">欠费: {{item.arrearage}}</view>
<view wx:if="{{loan_type=='now'}}" class="btn warn" @tap="loan({{item.book_id}})">续借</view>
<view wx:if="{{loan_type=='history'}}">归还: {{item.return_date}}</view>
</view>
</view>
</block>
</view>
<empty wx:else msg="暂无借阅数据">
</empty>
</template>
<script>
import wepy from 'wepy'
import Empty from "../../components/empty";
import HttpMixin from "../../mixins/http";
import ToastMixin from "../../mixins/toast";
import DataMixin from "../../mixins/data";
import db from "../../util/db"
export default class Loan extends wepy.page {
config = {
navigationBarTitleText: '我的借阅',
enablePullDownRefresh: true
};
components = {
empty: Empty,
};
mixins = [HttpMixin, ToastMixin, DataMixin];
data = {
loan_books: [],
loan_now: [],
loan_history: [],
loan_type: 'now' // history
};
methods = {
async loan(bookID) {
const resp = await this.PostWithBind('/library/loan', {
book_id: bookID
})
this.get()
this.ShowToast('续借成功', 'success')
}
}
watch = {
loan_now(newVal, oldVal) {
this.loan_books = newVal
},
loan_history(newVal, oldVal) {
this.loan_books = newVal
}
}
async get() {
const t = this.loan_type === 'now' ? 0 : 1
const resp = await this.GetWithBind('/library/books?is_history=' + t)
this.loan_books = resp.data
this.$apply()
this.InitSet('loan_' + this.loan_type, resp.data)
}
async onPullDownRefresh() {
try {
await this.get()
wepy.stopPullDownRefresh()
} catch (error) {
console.log(error);
}
}
onLoad(options) {
if (options.type && options.type === 'history') {
this.loan_type = options.type
wepy.setNavigationBarTitle({
title: '历史借阅'
})
}
this.Init('loan_' + this.loan_type)
}
}
</script>