postageDetail.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // pages/addAddress/addAddress.js
  2. const getReq = require('../../config.js').getReq
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. topcard_id: '',
  10. card_no: '', //卡号
  11. card_type: '', //卡类型
  12. isEdit: false,
  13. },
  14. /**
  15. * 表单提交
  16. */
  17. formSubmit(e) {
  18. const { card_type, card_no, confirm_card_no } = e.detail.value
  19. if (!card_type) {
  20. app.showToast('请选择卡类型')
  21. return
  22. }
  23. if (!card_no) {
  24. app.showToast('卡号不能为空')
  25. return
  26. }
  27. else if (card_type === 'phone' && !this.checkPhone(card_no)) {
  28. app.showToast('请输入11位手机号码,暂不支持199、166、161号段充值.')
  29. return
  30. }
  31. else if (card_type === 'petrochina' && !this.checkPetrochina(card_no)) { //中国石油
  32. app.showToast('请输入以9开头的16位中石油加油卡号')
  33. return
  34. }
  35. else if (card_type === 'sinopec' && !this.checkSinopec(card_no)) { //中国石化
  36. app.showToast('请输入以1开头的19位中石化加油卡号')
  37. return
  38. }
  39. if (!confirm_card_no) {
  40. app.showToast('请再次输入卡号')
  41. return
  42. } else if (card_no !== confirm_card_no) {
  43. app.showToast('两次输入的卡号不一致')
  44. return
  45. }
  46. this.handleSubmit(e.detail.value)
  47. },
  48. handleSubmit({ card_type, card_no }) {
  49. const { topcard_id = '' } = this.data
  50. wx.showLoading({
  51. title: '加载中',
  52. })
  53. let params = {
  54. act: 'member_card',
  55. op: 'card_add',
  56. card_type,
  57. card_no
  58. }
  59. if (this.data.isEdit) {
  60. params = { topcard_id, ...params, op: 'card_edit' }
  61. }
  62. getReq(app, params, res => {
  63. wx.hideLoading()
  64. if (res.code == 200) {
  65. wx.navigateBack()
  66. }
  67. else {
  68. app.showToast(res.message)
  69. }
  70. })
  71. },
  72. radioChange(e) {
  73. // console.log('e',e)
  74. },
  75. checkPhone(phone) {
  76. if (!(/^[1]([3-9])[0-9]{9}$/.test(phone))) {
  77. return false;
  78. }
  79. let starts = ['199','166','161','191','177'];
  80. for (let i in starts) {
  81. let str = starts[i];
  82. let ret = phone.startsWith(str, 0);
  83. if (ret) {
  84. return false;
  85. }
  86. }
  87. return true
  88. },
  89. checkPetrochina(card_no) {
  90. if (!(/^[9][0-9]{15}$/.test(card_no))) {
  91. return false;
  92. }
  93. return true
  94. },
  95. checkSinopec(card_no) {
  96. if (!(/^[1][0-9]{18}$/.test(card_no))) {
  97. return false;
  98. }
  99. return true
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad: function (options) {
  105. const { card_no = '', card_type = '', topcard_id = '' } = options
  106. let title = '添加卡号'
  107. let isEdit = false
  108. if (card_no) {
  109. title = '修改卡号'
  110. isEdit = true
  111. }
  112. wx.setNavigationBarTitle({ title })
  113. console.log('postageDetail onLoad =' + card_type)
  114. console.log(card_type)
  115. this.setData({ card_no, card_type, topcard_id, isEdit })
  116. },
  117. /**
  118. * 生命周期函数--监听页面初次渲染完成
  119. */
  120. onReady: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面隐藏
  129. */
  130. onHide: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload: function () {
  136. },
  137. /**
  138. * 页面相关事件处理函数--监听用户下拉动作
  139. */
  140. onPullDownRefresh: function () {
  141. },
  142. /**
  143. * 页面上拉触底事件的处理函数
  144. */
  145. onReachBottom: function () {
  146. }
  147. })