123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- // 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('请输入正确的手机号码')
- return
- }
- else if(card_type ==='petrochina' && !this.checkPetrochina(card_no)){ //中国石油
- app.showToast('请输入正确的手机号码')
- return
- }
- else if(card_type ==='sinopec' && !this.checkSinopec(card_no)){ //中国石化
- app.showToast('请输入正确的手机号码')
- 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;
- }
- return true
- },
- checkPetrochina(card_no)
- {
- if(!(/^[9][0-9]{15}$/.test(card_no))){
- return false;
- }
- return true
- },
- checkSinopec(phone)
- {
- 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 () {
- }
- })
|