index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <template>
  2. <view class="visit-container">
  3. <!-- 搜索栏 -->
  4. <view class="search-bar">
  5. <u-search
  6. v-model="searchKeyword"
  7. placeholder="搜索学生姓名、学号或企业"
  8. :show-action="false"
  9. @search="handleSearch"
  10. @custom="handleSearch"
  11. bg-color="#f6f6f6"
  12. height="72"
  13. shape="round"
  14. />
  15. </view>
  16. <!-- 筛选条件 -->
  17. <view class="filter-bar" v-if="showFilter">
  18. <view class="filter-item">
  19. <u-input
  20. v-model="queryParams.visitorName"
  21. placeholder="走访人姓名"
  22. border="surround"
  23. clearable
  24. />
  25. </view>
  26. <view class="filter-item">
  27. <view @click="showStatusPicker = true">
  28. <u-input
  29. v-model="statusText"
  30. placeholder="选择走访状态"
  31. readonly
  32. border="surround"
  33. suffix-icon="arrow-down"
  34. />
  35. </view>
  36. </view>
  37. <view class="filter-item">
  38. <view @click="showDatePicker = true">
  39. <u-input
  40. v-model="dateRangeText"
  41. placeholder="选择走访日期"
  42. readonly
  43. border="surround"
  44. suffix-icon="calendar"
  45. />
  46. </view>
  47. </view>
  48. <view class="filter-actions">
  49. <u-button
  50. type="primary"
  51. size="small"
  52. @click="handleFilter"
  53. :loading="loading"
  54. >
  55. 筛选
  56. </u-button>
  57. <u-button
  58. type="default"
  59. size="small"
  60. @click="resetFilter"
  61. style="margin-left: 10rpx;"
  62. >
  63. 重置
  64. </u-button>
  65. </view>
  66. </view>
  67. <!-- 筛选按钮 -->
  68. <view class="action-bar">
  69. <u-button
  70. type="default"
  71. size="small"
  72. :icon="showFilter ? 'arrow-up' : 'arrow-down'"
  73. @click="showFilter = !showFilter"
  74. >
  75. {{ showFilter ? '收起筛选' : '展开筛选' }}
  76. </u-button>
  77. <u-button
  78. type="primary"
  79. size="small"
  80. icon="plus"
  81. @click="handleAdd"
  82. >
  83. 新增走访
  84. </u-button>
  85. </view>
  86. <!-- 走访记录列表 -->
  87. <view class="list-container">
  88. <view class="list-content" v-if="visitList.length > 0">
  89. <view
  90. class="visit-card"
  91. v-for="item in visitList"
  92. :key="item.visitId"
  93. @click="handleView(item)"
  94. >
  95. <!-- 学生信息 -->
  96. <view class="card-header">
  97. <view class="student-info">
  98. <text class="student-name">{{ item.studentName }}</text>
  99. <text class="student-no">{{ item.studentNo }}</text>
  100. </view>
  101. <view class="status-badge">
  102. <u-tag
  103. :text="item.statusName || item.status"
  104. :type="getStatusType(item.status)"
  105. size="mini"
  106. />
  107. </view>
  108. </view>
  109. <!-- 企业信息 -->
  110. <view class="card-row">
  111. <u-icon name="home" size="16" color="#909399" />
  112. <text class="info-text">{{ item.companyName || '-' }}</text>
  113. </view>
  114. <!-- 走访信息 -->
  115. <view class="card-row">
  116. <u-icon name="calendar" size="16" color="#909399" />
  117. <text class="info-text">{{ item.visitDate || '-' }}</text>
  118. <u-icon name="account" size="16" color="#909399" style="margin-left: 20rpx;" />
  119. <text class="info-text">{{ item.visitorName || '-' }}</text>
  120. </view>
  121. <!-- 班级专业信息 -->
  122. <view class="card-row">
  123. <u-icon name="bookmark" size="16" color="#909399" />
  124. <text class="info-text">{{ item.className || '-' }} / {{ item.majorName || '-' }}</text>
  125. </view>
  126. <!-- 操作按钮 -->
  127. <view class="card-actions">
  128. <u-button
  129. type="default"
  130. size="mini"
  131. @click.stop="handleEdit(item)"
  132. v-if="item.status === 'planned' || item.status === '0'"
  133. >
  134. 编辑
  135. </u-button>
  136. <u-button
  137. type="error"
  138. size="mini"
  139. @click.stop="handleDelete(item)"
  140. style="margin-left: 10rpx;"
  141. v-if="item.status === 'planned' || item.status === '0'"
  142. >
  143. 删除
  144. </u-button>
  145. </view>
  146. </view>
  147. </view>
  148. <!-- 空状态 -->
  149. <view class="empty-state" v-else-if="!loading">
  150. <u-empty
  151. mode="data"
  152. text="暂无走访记录"
  153. textColor="#c8c9cc"
  154. iconColor="#c8c9cc"
  155. />
  156. </view>
  157. <!-- 加载状态 -->
  158. <view class="loading-state" v-if="loading">
  159. <u-loading-icon mode="circle" />
  160. <text style="margin-left: 10rpx; color: #909399;">加载中...</text>
  161. </view>
  162. </view>
  163. <!-- 上拉加载更多 -->
  164. <view class="load-more" v-if="hasMore && visitList.length > 0">
  165. <u-loadmore
  166. :status="loadMoreStatus"
  167. @loadmore="loadMore"
  168. load-text="加载更多"
  169. loading-text="正在加载..."
  170. no-more-text="没有更多了"
  171. />
  172. </view>
  173. <!-- 状态选择器 -->
  174. <u-picker
  175. :show="showStatusPicker"
  176. :columns="statusOptions"
  177. :default-index="[currentStatusIndex]"
  178. @confirm="handleStatusConfirm"
  179. @cancel="showStatusPicker = false"
  180. />
  181. <!-- 日期范围选择器 -->
  182. <u-calendar
  183. :show="showDatePicker"
  184. mode="range"
  185. @confirm="handleDateConfirm"
  186. @close="showDatePicker = false"
  187. />
  188. </view>
  189. </template>
  190. <script>
  191. import { listVisit, delVisit, getVisitStatusDict } from '@/api/visit.js';
  192. export default {
  193. name: 'VisitList',
  194. data() {
  195. return {
  196. // 搜索和筛选
  197. searchKeyword: '',
  198. showFilter: false,
  199. queryParams: {
  200. pageNum: 1,
  201. pageSize: 10,
  202. studentKeyword: '',
  203. companyName: '',
  204. visitorName: '',
  205. status: '',
  206. beginVisitDate: '',
  207. endVisitDate: ''
  208. },
  209. // 列表数据
  210. visitList: [],
  211. total: 0,
  212. loading: false,
  213. hasMore: true,
  214. loadMoreStatus: 'loadmore',
  215. // 状态选择
  216. showStatusPicker: false,
  217. statusOptions: [],
  218. currentStatusIndex: -1,
  219. statusText: '',
  220. statusDict: [],
  221. // 日期选择
  222. showDatePicker: false,
  223. dateRangeText: '',
  224. selectedDateRange: []
  225. };
  226. },
  227. onLoad() {
  228. this.initPage();
  229. },
  230. onPullDownRefresh() {
  231. this.refreshList();
  232. },
  233. onReachBottom() {
  234. if (this.hasMore && this.loadMoreStatus === 'loadmore') {
  235. this.loadMore();
  236. }
  237. },
  238. methods: {
  239. // 初始化页面
  240. async initPage() {
  241. await this.loadStatusDict();
  242. this.getList();
  243. },
  244. // 加载状态字典
  245. async loadStatusDict() {
  246. try {
  247. const response = await getVisitStatusDict();
  248. if (response.code === 200 && response.data) {
  249. this.statusDict = response.data;
  250. this.statusOptions = [
  251. [
  252. { text: '全部状态', value: '' },
  253. ...response.data.map(item => ({
  254. text: item.dictLabel,
  255. value: item.dictValue
  256. }))
  257. ]
  258. ];
  259. }
  260. } catch (error) {
  261. console.error('加载状态字典失败:', error);
  262. // 设置默认状态选项
  263. this.statusOptions = [[
  264. { text: '全部状态', value: '' },
  265. { text: '计划中', value: 'planned' },
  266. { text: '已完成', value: 'completed' },
  267. { text: '已取消', value: 'cancelled' }
  268. ]];
  269. }
  270. },
  271. // 获取列表数据
  272. async getList(isLoadMore = false) {
  273. if (this.loading) return;
  274. this.loading = true;
  275. if (!isLoadMore) {
  276. this.loadMoreStatus = 'loadmore';
  277. } else {
  278. this.loadMoreStatus = 'loading';
  279. }
  280. try {
  281. const response = await listVisit(this.queryParams);
  282. if (response.code === 200) {
  283. // 后端返回的是TableDataInfo格式,直接包含rows和total字段
  284. const { rows, total } = response;
  285. if (isLoadMore) {
  286. this.visitList = [...this.visitList, ...rows || []];
  287. } else {
  288. this.visitList = rows || [];
  289. }
  290. this.total = total || 0;
  291. // 判断是否还有更多数据
  292. const currentTotal = this.visitList.length;
  293. this.hasMore = currentTotal < this.total;
  294. if (!this.hasMore) {
  295. this.loadMoreStatus = 'nomore';
  296. }
  297. } else {
  298. uni.showToast({ title: response.msg || '获取数据失败', icon: 'none' });
  299. }
  300. } catch (error) {
  301. console.error('获取走访记录列表失败:', error);
  302. uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
  303. } finally {
  304. this.loading = false;
  305. if (this.queryParams.pageNum === 1) {
  306. uni.stopPullDownRefresh();
  307. }
  308. }
  309. },
  310. // 刷新列表
  311. refreshList() {
  312. this.queryParams.pageNum = 1;
  313. this.getList();
  314. },
  315. // 加载更多
  316. loadMore() {
  317. if (this.hasMore && !this.loading) {
  318. this.queryParams.pageNum++;
  319. this.getList(true);
  320. }
  321. },
  322. // 搜索
  323. handleSearch() {
  324. this.queryParams.studentKeyword = this.searchKeyword;
  325. this.refreshList();
  326. },
  327. // 筛选
  328. handleFilter() {
  329. this.refreshList();
  330. },
  331. // 重置筛选
  332. resetFilter() {
  333. this.queryParams = {
  334. ...this.queryParams,
  335. studentKeyword: this.searchKeyword,
  336. companyName: '',
  337. visitorName: '',
  338. status: '',
  339. beginVisitDate: '',
  340. endVisitDate: ''
  341. };
  342. this.statusText = '';
  343. this.dateRangeText = '';
  344. this.selectedDateRange = [];
  345. this.currentStatusIndex = -1;
  346. this.refreshList();
  347. },
  348. // 状态选择确认
  349. handleStatusConfirm(value) {
  350. const selected = value.value[0];
  351. this.queryParams.status = selected.value;
  352. this.statusText = selected.text;
  353. this.currentStatusIndex = value.index[0];
  354. this.showStatusPicker = false;
  355. },
  356. // 日期选择确认
  357. handleDateConfirm(value) {
  358. this.selectedDateRange = value;
  359. if (value && value.length === 2) {
  360. this.queryParams.beginVisitDate = value[0];
  361. this.queryParams.endVisitDate = value[1];
  362. this.dateRangeText = `${value[0]} ~ ${value[1]}`;
  363. } else {
  364. this.queryParams.beginVisitDate = '';
  365. this.queryParams.endVisitDate = '';
  366. this.dateRangeText = '';
  367. }
  368. this.showDatePicker = false;
  369. },
  370. // 获取状态类型
  371. getStatusType(status) {
  372. switch (status) {
  373. case 'planned':
  374. case '0':
  375. return 'primary';
  376. case 'completed':
  377. case '1':
  378. return 'success';
  379. case 'cancelled':
  380. case '2':
  381. return 'error';
  382. default:
  383. return 'default';
  384. }
  385. },
  386. // 查看详情
  387. handleView(item) {
  388. uni.navigateTo({
  389. url: `/pages/visit/detail?id=${item.visitId}`
  390. });
  391. },
  392. // 新增走访
  393. handleAdd() {
  394. uni.navigateTo({
  395. url: '/pages/visit/add'
  396. });
  397. },
  398. // 编辑走访
  399. handleEdit(item) {
  400. uni.navigateTo({
  401. url: `/pages/visit/edit?id=${item.visitId}`
  402. });
  403. },
  404. // 删除走访
  405. handleDelete(item) {
  406. uni.showModal({
  407. title: '确认删除',
  408. content: `确定要删除${item.studentName}的走访记录吗?`,
  409. success: async (res) => {
  410. if (res.confirm) {
  411. await this.deleteVisit(item.visitId);
  412. }
  413. }
  414. });
  415. },
  416. // 执行删除
  417. async deleteVisit(id) {
  418. try {
  419. uni.showLoading({ title: '删除中...' });
  420. const response = await delVisit(id);
  421. if (response.code === 200) {
  422. uni.showToast({ title: '删除成功', icon: 'success' });
  423. this.refreshList();
  424. } else {
  425. uni.showToast({ title: response.msg || '删除失败', icon: 'none' });
  426. }
  427. } catch (error) {
  428. console.error('删除走访记录失败:', error);
  429. uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
  430. } finally {
  431. uni.hideLoading();
  432. }
  433. }
  434. }
  435. };
  436. </script>
  437. <style lang="scss" scoped>
  438. .visit-container {
  439. min-height: 100vh;
  440. background-color: #f8f8f8;
  441. }
  442. .search-bar {
  443. padding: 20rpx;
  444. background: #ffffff;
  445. }
  446. .filter-bar {
  447. background: #ffffff;
  448. padding: 0 20rpx 20rpx;
  449. border-bottom: 1rpx solid #ebeef5;
  450. .filter-item {
  451. margin-bottom: 20rpx;
  452. }
  453. .filter-actions {
  454. display: flex;
  455. justify-content: flex-end;
  456. gap: 10rpx;
  457. }
  458. }
  459. .action-bar {
  460. display: flex;
  461. justify-content: space-between;
  462. align-items: center;
  463. padding: 20rpx;
  464. background: #ffffff;
  465. border-bottom: 1rpx solid #ebeef5;
  466. }
  467. .list-container {
  468. padding: 20rpx;
  469. }
  470. .visit-card {
  471. background: #ffffff;
  472. border-radius: 12rpx;
  473. padding: 24rpx;
  474. margin-bottom: 20rpx;
  475. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
  476. .card-header {
  477. display: flex;
  478. justify-content: space-between;
  479. align-items: center;
  480. margin-bottom: 16rpx;
  481. .student-info {
  482. .student-name {
  483. font-size: 32rpx;
  484. font-weight: 600;
  485. color: #303133;
  486. margin-right: 16rpx;
  487. }
  488. .student-no {
  489. font-size: 26rpx;
  490. color: #909399;
  491. }
  492. }
  493. }
  494. .card-row {
  495. display: flex;
  496. align-items: center;
  497. margin-bottom: 12rpx;
  498. .info-text {
  499. font-size: 28rpx;
  500. color: #606266;
  501. margin-left: 8rpx;
  502. }
  503. &:last-of-type {
  504. margin-bottom: 16rpx;
  505. }
  506. }
  507. .card-actions {
  508. display: flex;
  509. justify-content: flex-end;
  510. gap: 10rpx;
  511. padding-top: 16rpx;
  512. border-top: 1rpx solid #ebeef5;
  513. }
  514. }
  515. .empty-state {
  516. padding: 80rpx 20rpx;
  517. text-align: center;
  518. }
  519. .loading-state {
  520. display: flex;
  521. align-items: center;
  522. justify-content: center;
  523. padding: 40rpx;
  524. }
  525. .load-more {
  526. padding: 20rpx;
  527. }
  528. </style>