yyb
2026-05-22 552ec6b7d8ccc56c379da195fc6c9c74312b1070
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<template>
  <view class="sales-account">
    <!-- 使用通用页面头部组件 -->
    <PageHeader title="借阅管理" @back="goBack" />
 
    <!-- 搜索和筛选区域 -->
    <view class="search-section">
      <view class="search-bar">
        <view class="search-input">
          <up-input
            class="search-text"
            placeholder="请输入借阅人搜索"
            v-model="searchForm.borrower"
            @change="getList"
            clearable
          />
        </view>
        <view class="filter-button" @click="getList">
          <up-icon name="search" size="24" color="#999"></up-icon>
        </view>
      </view>
    </view>
 
    <!-- 借阅列表 -->
    <view class="ledger-list" v-if="borrowList.length > 0">
      <view v-for="(item, index) in borrowList" :key="index">
        <view class="ledger-item">
          <view class="item-header">
            <view class="item-left">
              <view class="document-icon">
                <up-icon name="file-text" size="16" color="#ffffff"></up-icon>
              </view>
              <text class="item-id">{{ item.docName || '-' }}</text>
            </view>
            <view class="item-tag" :class="getStatusClass(item.borrowStatus)">
              <text class="tag-text">{{ item.borrowStatus }}</text>
            </view>
          </view>
          <up-divider></up-divider>
          <view class="item-details">
            <view class="detail-row">
              <text class="detail-label">借阅人</text>
              <text class="detail-value">{{ item.borrower || '-' }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">借阅目的</text>
              <text class="detail-value">{{ item.borrowPurpose || '-' }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">借阅日期</text>
              <text class="detail-value">{{ item.borrowDate || '-' }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">应归还日期</text>
              <text class="detail-value">{{ item.dueReturnDate || '-' }}</text>
            </view>
            <view class="detail-row" v-if="item.remark">
              <text class="detail-label">备注</text>
              <text class="detail-value">{{ item.remark }}</text>
            </view>
          </view>
          <up-divider></up-divider>
          <view class="detail-buttons">
            <u-button
              v-if="item.borrowStatus !== '归还'"
              class="detail-button"
              size="small"
              type="primary"
              @click.stop="goEdit(item)"
            >
              编辑
            </u-button>
            <u-button
              v-if="item.borrowStatus !== '归还'"
              class="detail-button"
              size="small"
              type="error"
              plain
              @click.stop="handleDelete(item)"
            >
              删除
            </u-button>
            <u-button
              v-if="item.borrowStatus === '归还'"
              class="detail-button"
              size="small"
              type="primary"
              plain
              @click.stop="goView(item)"
            >
              查看
            </u-button>
          </view>
        </view>
      </view>
    </view>
 
    <view v-else class="no-data">
      <text>暂无借阅记录</text>
    </view>
 
    <!-- 浮动操作按钮 -->
    <view class="fab-button" @click="goAdd">
      <up-icon name="plus" size="24" color="#ffffff"></up-icon>
    </view>
  </view>
</template>
 
<script setup>
import { ref, reactive } from "vue";
import { onShow } from "@dcloudio/uni-app";
import PageHeader from "@/components/PageHeader.vue";
import { getBorrowList, deleteBorrow } from "@/api/fileManagement/borrow";
 
// 查询表单
const searchForm = reactive({
  borrower: "",
});
 
// 借阅列表数据
const borrowList = ref([]);
 
// 分页相关
const pagination = reactive({
  currentPage: 1,
  pageSize: 10,
  total: 0,
});
 
// 返回上一页
const goBack = () => {
  uni.navigateBack();
};
 
// 获取状态样式类
const getStatusClass = (status) => {
  if (status === "归还") return "tag-success";
  if (status === "借阅") return "tag-warning";
  return "tag-default";
};
 
// 加载借阅列表
const getList = async () => {
  uni.showLoading({ title: "加载中...", mask: true });
 
  const query = {
    page: -1,
    size: -1,
    borrower: searchForm.borrower || undefined,
  };
 
  try {
    const res = await getBorrowList(query);
    if (res.code === 200) {
      borrowList.value = res.data.records || [];
      pagination.total = res.data.total || 0;
    } else {
      uni.showToast({ title: res.msg || "获取借阅列表失败", icon: "none" });
      borrowList.value = [];
    }
  } catch (error) {
    uni.showToast({ title: "获取借阅列表失败", icon: "none" });
    borrowList.value = [];
  } finally {
    uni.hideLoading();
  }
};
 
// 跳转到新增页面
const goAdd = () => {
  uni.navigateTo({
    url: "/pages/fileManagement/borrow/edit",
  });
};
 
// 跳转到编辑页面
const goEdit = (item) => {
  uni.setStorageSync("borrowEditData", JSON.stringify(item));
  uni.navigateTo({
    url: `/pages/fileManagement/borrow/edit?id=${item.id}`,
  });
};
 
// 跳转到查看页面(已归还记录)
const goView = (item) => {
  uni.setStorageSync("borrowEditData", JSON.stringify(item));
  uni.navigateTo({
    url: `/pages/fileManagement/borrow/edit?id=${item.id}`,
  });
};
 
// 删除
const handleDelete = (row) => {
  uni.showModal({
    title: "删除确认",
    content: "选中的内容将被删除,是否确认删除?",
    confirmText: "确认",
    cancelText: "取消",
    success: async (res) => {
      if (res.confirm) {
        try {
          uni.showLoading({ title: "删除中...", mask: true });
          const result = await deleteBorrow([row.id]);
          if (result.code === 200) {
            uni.showToast({ title: "删除成功", icon: "success" });
            getList();
          } else {
            uni.showToast({ title: result.msg || "删除失败", icon: "none" });
          }
        } catch (error) {
          uni.showToast({ title: "删除失败", icon: "none" });
        } finally {
          uni.hideLoading();
        }
      }
    },
  });
};
 
onShow(() => {
  getList();
});
</script>
 
<style scoped lang="scss">
@import "@/styles/sales-common.scss";
 
// 标签样式
.item-tag {
  border-radius: 4px;
  padding: 2px 8px;
 
  &.tag-success {
    background: #4caf50;
  }
 
  &.tag-warning {
    background: #ff9800;
  }
 
  &.tag-default {
    background: #9e9e9e;
  }
}
 
.tag-text {
  font-size: 11px;
  color: #ffffff;
  font-weight: 500;
}
 
// 按钮样式
.detail-buttons {
  padding: 12px 0;
  display: flex;
  gap: 12px;
}
 
.detail-button {
  flex: 1;
}
</style>