// pages/addAddress/addAddress.js const getReq = require('../../config.js').getReq const app = getApp() Page({ /** * 页面的初始数据 */ data: { topcard_id: '', card_no: '', //卡号 card_type: '', //卡类型 isEdit: false, }, /** * 表单提交 */ formSubmit(e) { const { card_type, card_no, confirm_card_no } = e.detail.value if (!card_type) { app.showToast('请选择卡类型') return } if (!card_no) { app.showToast('卡号不能为空') return } else if (card_type === 'phone' && !this.checkPhone(card_no)) { app.showToast('请输入11位手机号码,暂不支持199、166、161号段充值.') return } else if (card_type === 'petrochina' && !this.checkPetrochina(card_no)) { //中国石油 app.showToast('请输入以9开头的16位中石油加油卡号') return } else if (card_type === 'sinopec' && !this.checkSinopec(card_no)) { //中国石化 app.showToast('请输入以1开头的19位中石化加油卡号') return } if (!confirm_card_no) { app.showToast('请再次输入卡号') return } else if (card_no !== confirm_card_no) { app.showToast('两次输入的卡号不一致') return } this.handleSubmit(e.detail.value) }, handleSubmit({ card_type, card_no }) { const { topcard_id = '' } = this.data wx.showLoading({ title: '加载中', }) let params = { act: 'member_card', op: 'card_add', card_type, card_no } if (this.data.isEdit) { params = { topcard_id, ...params, op: 'card_edit' } } getReq(app, params, res => { wx.hideLoading() if (res.code == 200) { wx.navigateBack() } else { app.showToast(res.message) } }) }, radioChange(e) { // console.log('e',e) }, checkPhone(phone) { if (!(/^[1]([3-9])[0-9]{9}$/.test(phone))) { return false; } let starts = ['199','166','161','191','177']; for (let i in starts) { let str = starts[i]; let ret = phone.startsWith(str, 0); if (ret) { return false; } } return true }, checkPetrochina(card_no) { if (!(/^[9][0-9]{15}$/.test(card_no))) { return false; } return true }, checkSinopec(card_no) { if (!(/^[1][0-9]{18}$/.test(card_no))) { return false; } return true }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const { card_no = '', card_type = '', topcard_id = '' } = options let title = '添加卡号' let isEdit = false if (card_no) { title = '修改卡号' isEdit = true } wx.setNavigationBarTitle({ title }) console.log('postageDetail onLoad =' + card_type) console.log(card_type) this.setData({ card_no, card_type, topcard_id, isEdit }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { } })