index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { userPageList, userDelete } from "../../utils/api/api";
  2. Page({
  3. data: {
  4. isSearch: false,//是否搜索
  5. userList: [],
  6. searchData: {
  7. data: {
  8. certName: "",
  9. certNo: "",
  10. vid: ""
  11. },
  12. pageNum: 1,
  13. pageSize: 8,
  14. },
  15. total: 0,
  16. isLoading: false,
  17. },
  18. getVid(e) {
  19. this.setData({
  20. 'searchData.data.vid': e.detail.value
  21. })
  22. },
  23. getUserName(e) {
  24. this.setData({
  25. 'searchData.data.certName': e.detail.value
  26. })
  27. },
  28. getCardID(e) {
  29. this.setData({
  30. 'searchData.data.certNo': e.detail.value
  31. })
  32. },
  33. // 获取列表
  34. fetchData() {
  35. my.showLoading({
  36. content: '加载中',
  37. })
  38. this.setData({
  39. isLoading: true
  40. })
  41. userPageList(this.data.searchData).then(res => {
  42. my.hideLoading()
  43. this.setData({
  44. userList: [...this.data.userList, ...res.data.records],
  45. total: res.data.total,
  46. 'searchData.pageNum': this.data.searchData.pageNum + 1
  47. })
  48. }).catch(error => {
  49. // 请求出错时隐藏加载提示,并处理错误
  50. my.hideLoading();
  51. })
  52. .finally(() => {
  53. // 无论请求成功或失败,都需要将 isLoading 设为 false
  54. this.setData({
  55. isLoading: false
  56. });
  57. my.hideLoading();
  58. });
  59. },
  60. // 清空
  61. handleClear() {
  62. this.setData({
  63. 'searchData.data.vid': '',
  64. 'searchData.data.certName': '',
  65. 'searchData.data.certNo': '',
  66. userList: [],
  67. 'searchData.pageNum': 1,
  68. })
  69. this.fetchData()
  70. },
  71. // 搜索
  72. handleSearch() {
  73. this.setData({
  74. userList: [],
  75. 'searchData.pageNum': 1,
  76. })
  77. this.fetchData()
  78. },
  79. // 点击查询
  80. openSearch() {
  81. this.setData({
  82. isSearch: true
  83. })
  84. },
  85. // 关闭查询
  86. closeSearch() {
  87. this.setData({
  88. isSearch: false
  89. })
  90. },
  91. // 出库
  92. outStorage(e) {
  93. let vid = e.currentTarget.dataset.item
  94. let that = this
  95. my.showModal({
  96. title: "",
  97. content: "确定要出库吗?",
  98. complete: res => {
  99. if (res.confirm) {
  100. userDelete({
  101. vidList: [vid],
  102. token: 'ab051195190b4623ea62f636ae747f53',
  103. }).then(res => {
  104. my.showToast({
  105. content: "出库成功",
  106. type: "success",
  107. duration: 1000,
  108. //显示透明蒙层,防止触摸穿透
  109. mask: true,
  110. success: function () {
  111. that.setData({
  112. userList: [],
  113. 'searchData.pageNum': 1,
  114. })
  115. that.fetchData()
  116. }
  117. });
  118. });
  119. } else {
  120. my.showToast({
  121. content: "出库失败",
  122. type: "fail",
  123. duration: 1000,
  124. //显示透明蒙层,防止触摸穿透
  125. mask: true,
  126. });
  127. }
  128. }
  129. });
  130. },
  131. onShow() {
  132. this.setData({
  133. userList: [],
  134. 'searchData.pageNum': 1,
  135. })
  136. this.fetchData()
  137. },
  138. onReachBottom() {
  139. const {
  140. total,
  141. searchData: {
  142. pageNum,
  143. pageSize
  144. }
  145. } = this.data
  146. if (total <= (pageNum - 1) * pageSize) {
  147. return my.showToast({
  148. content: '没有更多了',
  149. type: 'none'
  150. })
  151. }
  152. if (this.data.isLoading) return
  153. this.fetchData()
  154. },
  155. });