addcustomer.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // pages/customermanage/addcustomer.js
  2. const app = getApp();
  3. const phoneRegExp = /^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|147)\d{8}$/,
  4. customerCodeRegExp = /^\d{1,10}$/;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. error: '',
  11. formData: {
  12. customerId: app.$util.customerId,
  13. customerCode: '',
  14. mobile: '',
  15. }
  16. },
  17. formInputChange(e) {
  18. const {
  19. field
  20. } = e.currentTarget.dataset
  21. this.setData({
  22. [`formData.${field}`]: e.detail.value
  23. })
  24. },
  25. submit() {
  26. const {
  27. customerCode,
  28. mobile
  29. } = this.data.formData;
  30. let error = '';
  31. if (!phoneRegExp.test(mobile)) {
  32. error = '您输入的手机号有误,请重新输入';
  33. }
  34. if (!mobile) {
  35. error = '请输入手机号';
  36. }
  37. if (!customerCodeRegExp.test(customerCode)) {
  38. error = '您输入的户号有误,请重新输入';
  39. }
  40. if (!customerCode) {
  41. error = '请输入户号';
  42. }
  43. if (error) {
  44. this.setData({
  45. error
  46. })
  47. return;
  48. }
  49. app.$http.get('/user/codeAndPhoneQuery', this.data.formData).then(({ status, data = {}, msg }) => {
  50. if (status === 0) {
  51. const {userNumber, username, address} = data;
  52. if (userNumber) {
  53. this.popup.setData({
  54. extClass: 'customer-popup',
  55. type: 'success',
  56. title: '您确认绑定当前户名?',
  57. content: `户名:${username || '-'}`,
  58. content1: `地址:${address || '-'}`,
  59. params: data
  60. });
  61. this.popup.show();
  62. }
  63. } else {
  64. this.popup.setData({
  65. type: 'error',
  66. title: '',
  67. content: msg || `您输入的户号与手机号不匹配,请重新输入`,
  68. content1: ''
  69. });
  70. this.popup.show();
  71. }
  72. })
  73. },
  74. cancelEvent: function () {
  75. this.popup.close();
  76. },
  77. confirmEvent: function () {
  78. if (this.popup.data.type == 'success' && this.popup.data.params) {
  79. const { customerId, userNumber } = this.popup.data.params;
  80. app.$http.postForm('/user/bindingAccount', {
  81. customerId,
  82. userNumber
  83. }).then(({ status, msg, data }) => {
  84. if (status === 0) {
  85. app.globalData = {};
  86. app.getUserInfo(app.token);
  87. this.popup.close();
  88. wx.navigateBack({
  89. delta: 1
  90. })
  91. } else {
  92. this.popup.setData({
  93. type: 'error',
  94. content: msg,
  95. });
  96. }
  97. })
  98. return;
  99. }
  100. this.popup.close();
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function () {
  106. //获得popup组件
  107. this.popup = this.selectComponent("#popup");
  108. }
  109. })