postageDetail.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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('请输入正确的手机号码')
  29. return
  30. }
  31. else if(card_type ==='petrochina' && !this.checkPetrochina(card_no)){ //中国石油
  32. app.showToast('请输入正确的手机号码')
  33. return
  34. }
  35. else if(card_type ==='sinopec' && !this.checkSinopec(card_no)){ //中国石化
  36. app.showToast('请输入正确的手机号码')
  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. {
  77. if(!(/^[1]([3-9])[0-9]{9}$/.test(phone))){
  78.     return false;
  79.   }
  80. return true
  81. },
  82. checkPetrochina(card_no)
  83. {
  84. if(!(/^[9][0-9]{15}$/.test(card_no))){
  85.     return false;
  86.   }
  87. return true
  88. },
  89. checkSinopec(phone)
  90. {
  91. if(!(/^[1][0-9]{18}$/.test(card_no))){
  92.     return false;
  93.   }
  94. return true
  95. },
  96. /**
  97. * 生命周期函数--监听页面加载
  98. */
  99. onLoad: function (options) {
  100. const { card_no = '', card_type = '', topcard_id = '' } = options
  101. let title = '添加卡号'
  102. let isEdit = false
  103. if (card_no) {
  104. title = '修改卡号'
  105. isEdit = true
  106. }
  107. wx.setNavigationBarTitle({ title })
  108. console.log('postageDetail onLoad =' + card_type)
  109. console.log(card_type)
  110. this.setData({ card_no, card_type, topcard_id,isEdit })
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload: function () {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh: function () {
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom: function () {
  141. }
  142. })