You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
5.9 KiB

  1. const config = require('../../config/config.js')
  2. const Http = require('../../utils/HttpBasics.js')
  3. const format = require('../../utils/util.js')
  4. const util = require('../../utils/util.js')
  5. const qrCodeJS = require('../../utils/qrcode.js')
  6. var app = getApp()
  7. // pages/cardPay/cardPay.js
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. pageNum: 1,
  14. phone: '',
  15. codeNum: '',
  16. inputNum: '',
  17. cardType: '',
  18. reachBottom: false
  19. },
  20. scanCode() {
  21. const that = this
  22. wx.scanCode({
  23. success: (res) => {
  24. // 清空输入框中的号码
  25. that.setData({
  26. inputNum: '',
  27. phone: ''
  28. })
  29. console.log(res.result, 'res');
  30. // 是否为电子卡
  31. const isECard = that.isJSON(res.result)
  32. // 电子卡
  33. if (isECard) {
  34. const cardInfo = JSON.parse(res.result)
  35. this.getDetail(cardInfo.ID)
  36. // 实体卡
  37. } else {
  38. const cardID = res.result
  39. this.getDetail(cardID, 1)
  40. }
  41. },
  42. fail: (res) => {
  43. wx.showToast({
  44. title: "未识别到二维码",
  45. icon: "none",
  46. mask: false
  47. })
  48. }
  49. })
  50. },
  51. getList(pageNum) {
  52. // 获取当前的时间
  53. const myDate = new Date();
  54. const startDate = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-01' + ' 00:00:00';
  55. const endDate = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + myDate.getDate() + ' 29:59:59';
  56. const that = this;
  57. let data = {
  58. ouPhone: that.data.phone,
  59. cardId: that.data.codeNum,
  60. startdate: startDate,
  61. enddate: endDate,
  62. pageNum,
  63. pageSize: 10,
  64. payType: 0,
  65. }
  66. if (that.data.cardType) {
  67. data.cardType = that.data.cardType
  68. }
  69. wx.showLoading()
  70. Http.get({
  71. url: config.api.cardPayList,
  72. data
  73. })
  74. .then(res => {
  75. console.log(res, 'res');
  76. if (res.data.list) {
  77. res.data.list.forEach(item => {
  78. item.createDate = format.formatTime(item.createDate, 'yyyy-MM-dddd hh:mm:ss')
  79. item.updateDate = format.formatTime(item.updateDate, 'yyyy-MM-dddd hh:mm:ss')
  80. item.remainingAmount = (item.remainingAmount / 100) || ''
  81. if (item.wxCardInfo && item.wxCardInfo.id) {
  82. item.cardIdHide = item.wxCardInfo.id.slice(0, 4) + `******` + item.wxCardInfo.id.slice(14)
  83. }
  84. })
  85. if (data.pageNum == 1) {
  86. that.setData({
  87. list: res.data.list,
  88. reachBottom: true // 允许下拉刷新
  89. })
  90. } else {
  91. const tempList = that.data.list
  92. res.data.list.forEach(item => {
  93. tempList.push(item)
  94. })
  95. that.setData({
  96. list: tempList
  97. })
  98. }
  99. } else {
  100. if (this.data.pageNum == 1) {
  101. that.setData({
  102. list: []
  103. })
  104. }
  105. }
  106. wx.hideLoading()
  107. })
  108. .catch(err => {
  109. console.log(err, 'err');
  110. wx.showToast({
  111. title: err.message,
  112. icon: 'none'
  113. })
  114. })
  115. },
  116. getDetail(dynamicId, cardType) {
  117. const that = this
  118. Http.get({
  119. url: config.api.cardInfoDetail + "?dynamicId=" + dynamicId,
  120. }).then(res => {
  121. that.setData({
  122. codeNum: res.data.cardId,
  123. inputNum: res.data.cardId, // 显示在输入框中的号码
  124. phone: '',// 将手机号置空
  125. cardType: cardType
  126. })
  127. this.getList(1)
  128. }).catch(err => {
  129. console.log(err, 'err');
  130. wx.showToast({
  131. title: err.message,
  132. icon: 'none'
  133. })
  134. })
  135. },
  136. goToRefund(e) {
  137. const item = e.currentTarget.dataset.item
  138. console.log(item, 'item');
  139. wx.navigateTo({
  140. url: `/pages/refundDetail/refundDetail?item=${JSON.stringify(item)}`,
  141. })
  142. },
  143. checkNum() {
  144. const phoneReg = /^(?:(?:\+|00)86)?1\d{10}$/
  145. const isPhone = phoneReg.test(this.data.phone)
  146. if (!isPhone) {
  147. wx.showToast({
  148. title: '请输入正确的手机号!',
  149. icon: 'none'
  150. })
  151. return
  152. }
  153. this.setData({
  154. pageNum: 1,
  155. });
  156. this.getList(1)
  157. console.log(this.data.pageNum, 'pageNum');
  158. },
  159. getCardNum(e) {
  160. const phoneReg = /^(?:(?:\+|00)86)?1\d{10}$/
  161. const isPhone = phoneReg.test(e.detail.value)
  162. // 当输入的值为手机号时
  163. if (isPhone) {
  164. this.setData({
  165. phone: e.detail.value,
  166. codeNum: '',
  167. })
  168. // 不为手机号时清空手机号
  169. } else {
  170. this.setData({
  171. codeNum: e.detail.value,
  172. phone: ''
  173. })
  174. }
  175. },
  176. // 检测数据是否为JSON字符串
  177. isJSON(item) {
  178. item = typeof item !== "string"
  179. ? JSON.stringify(item)
  180. : item;
  181. try {
  182. item = JSON.parse(item);
  183. } catch (e) {
  184. return false;
  185. }
  186. if (typeof item === "object" && item !== null) {
  187. return true;
  188. }
  189. return false;
  190. },
  191. /**
  192. * 生命周期函数--监听页面加载
  193. */
  194. onLoad(options) {
  195. },
  196. /**
  197. * 生命周期函数--监听页面初次渲染完成
  198. */
  199. onReady() {
  200. },
  201. /**
  202. * 生命周期函数--监听页面显示
  203. */
  204. onShow() {
  205. console.log(this.data, 'data');
  206. if (this.data.phone || this.data.codeNum) {
  207. this.setData({
  208. pageNum: 1
  209. })
  210. this.getList(1)
  211. }
  212. },
  213. /**
  214. * 生命周期函数--监听页面隐藏
  215. */
  216. onHide() {
  217. },
  218. /**
  219. * 生命周期函数--监听页面卸载
  220. */
  221. onUnload() {
  222. },
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh() {
  227. },
  228. /**
  229. * 页面上拉触底事件的处理函数
  230. */
  231. onReachBottom() {
  232. if (!this.data.reachBottom) return
  233. let pageNum = this.data.pageNum + 1
  234. this.setData({
  235. pageNum: pageNum
  236. });
  237. this.getList(this.data.pageNum);
  238. },
  239. /**
  240. * 用户点击右上角分享
  241. */
  242. onShareAppMessage() {
  243. }
  244. })