postageDetail.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/addAddress/addAddress.js
  2. const getReq = require('../../config.js').getReq
  3. const appInstance = 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. appInstance.showToast('请选择卡类型')
  21. return
  22. }
  23. if(!card_no) {
  24. appInstance.showToast('卡号不能为空')
  25. return
  26. }else if(card_type ==='phone' && !this.checkPhone(card_no)){
  27. appInstance.showToast('请输入正确的手机号码')
  28. return
  29. }
  30. if(!confirm_card_no) {
  31. appInstance.showToast('请再次输入卡号')
  32. return
  33. }else if(card_no !== confirm_card_no) {
  34. appInstance.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(params ,res => {
  54. wx.hideLoading()
  55. if (res.code == 200) {
  56. wx.navigateBack()
  57. }
  58. else {
  59. appInstance.showToast(res.message)
  60. }
  61. })
  62. },
  63. radioChange(e){
  64. // console.log('e',e)
  65. },
  66. checkPhone(phone){
  67. if(!(/^[1]([3-9])[0-9]{9}$/.test(phone))){
  68.     return false;
  69.   }
  70. return true
  71. },
  72. /**
  73. * 生命周期函数--监听页面加载
  74. */
  75. onLoad: function (options) {
  76. let title = '添加卡号'
  77. if(options.card_no){
  78. title = '修改卡号'
  79. this.setData({isEdit:true})
  80. }
  81. wx.setNavigationBarTitle({ title })
  82. const { card_no = '', card_type = '', topcard_id = '' } = options
  83. this.setData({ card_no, card_type, topcard_id })
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面隐藏
  97. */
  98. onHide: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面卸载
  102. */
  103. onUnload: function () {
  104. },
  105. /**
  106. * 页面相关事件处理函数--监听用户下拉动作
  107. */
  108. onPullDownRefresh: function () {
  109. },
  110. /**
  111. * 页面上拉触底事件的处理函数
  112. */
  113. onReachBottom: function () {
  114. }
  115. })