postageDetail.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. }else if(card_type ==='phone' && !this.checkPhone(card_no)){
  27. app.showToast('请输入正确的手机号码')
  28. return
  29. }
  30. if(!confirm_card_no) {
  31. app.showToast('请再次输入卡号')
  32. return
  33. }else if(card_no !== confirm_card_no) {
  34. app.showToast('两次输入的卡号不一致')
  35. return
  36. }
  37. this.handleSubmit(e.detail.value)
  38. },
  39. handleSubmit({card_type, card_no}){
  40. const { topcard_id =''} = this.data
  41. wx.showLoading({
  42. title: '加载中',
  43. })
  44. let params = {
  45. act: 'member_card',
  46. op: 'card_add',
  47. card_type,
  48. card_no
  49. }
  50. if(this.data.isEdit){
  51. params = { topcard_id, ...params, op: 'card_edit' }
  52. }
  53. getReq(app,params ,res => {
  54. wx.hideLoading()
  55. if (res.code == 200) {
  56. wx.navigateBack()
  57. }
  58. else {
  59. app.showToast(res.message)
  60. }
  61. })
  62. },
  63. radioChange(e){
  64. // console.log('e',e)
  65. },
  66. checkPhone(phone)
  67. {
  68. if(!(/^[1]([3-9])[0-9]{9}$/.test(phone))){
  69.     return false;
  70.   }
  71. return true
  72. },
  73. /**
  74. * 生命周期函数--监听页面加载
  75. */
  76. onLoad: function (options) {
  77. const { card_no = '', card_type = '', topcard_id = '' } = options
  78. let title = '添加卡号'
  79. let isEdit = false
  80. if (card_no) {
  81. title = '修改卡号'
  82. isEdit = true
  83. }
  84. wx.setNavigationBarTitle({ title })
  85. console.log('postageDetail onLoad =' + card_type)
  86. console.log(card_type)
  87. this.setData({ card_no, card_type, topcard_id,isEdit })
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom: function () {
  118. }
  119. })