postageDetail.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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(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. let title = '添加卡号'
  78. if(options.card_no){
  79. title = '修改卡号'
  80. this.setData({isEdit:true})
  81. }
  82. wx.setNavigationBarTitle({ title })
  83. const { card_no = '', card_type = '', topcard_id = '' } = options
  84. this.setData({ card_no, card_type, topcard_id })
  85. },
  86. /**
  87. * 生命周期函数--监听页面初次渲染完成
  88. */
  89. onReady: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面显示
  93. */
  94. onShow: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. }
  116. })