Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

175 Zeilen
4.0 KiB

  1. // pages/membersinfo/index.js
  2. const config = require('../../config/config.js')
  3. const Http = require('../../utils/HttpBasics.js')
  4. const util = require('../../utils/util.js')
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. birthdate: '',
  12. flag: 1,
  13. name:'',
  14. phone:'',
  15. sex:'',
  16. address:'',
  17. copenid:'',
  18. items: [
  19. { name: 1, value: '男', checked: false },
  20. { name: 2, value: '女', checked: false },
  21. ],
  22. subappid:'',
  23. phoneFlag:false,
  24. },
  25. bindDateChange: function (e) {
  26. this.setData({
  27. birthdate: e.detail.value,
  28. flag: 2
  29. })
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. console.log(options, 2222, util)
  36. let _this=this;
  37. this.setData({
  38. copenid: options.copenid,
  39. subappid: options.subappid
  40. })
  41. let params={
  42. userId: wx.getStorageSync('bUserId'),
  43. openid: options.copenid,
  44. appId: options.subappid
  45. }
  46. Http.post({
  47. url: config.api.findUserInfo,
  48. data: params
  49. })
  50. .then(res => {
  51. let data=res.data;
  52. if (res.data){
  53. let sexOption = _this.data.items
  54. sexOption.map((item,index)=>{
  55. if (item.name == data.sex) {
  56. item.checked=true;
  57. }
  58. })
  59. if (data.phone){
  60. this.setData({
  61. phone: data.phone,
  62. phoneFlag:true
  63. })
  64. }
  65. this.setData({
  66. birthdate: data.birthdate? util.formatDate02(data.birthdate):"请输入",
  67. name: data.name,
  68. sex: data.sex,
  69. address: data.address,
  70. items:sexOption,
  71. flag:2
  72. })
  73. }
  74. })
  75. .catch(err => {
  76. wx.showToast({
  77. title: err.message,
  78. icon: 'none',
  79. duration: 2000,
  80. mask: false
  81. });
  82. });
  83. },
  84. formSubmit(e){
  85. if (e.detail.value.name==''){
  86. wx.showToast({
  87. title: '请输入姓名',
  88. icon: 'none',
  89. duration: 2000,
  90. mask: false
  91. });
  92. return
  93. }
  94. if (this.data.phone == '' && e.detail.value.phone == '') {
  95. wx.showToast({
  96. title: '请输入会员手机号',
  97. icon: 'none',
  98. duration: 2000,
  99. mask: false
  100. });
  101. return
  102. }
  103. if (e.detail.value.address=='') {
  104. wx.showToast({
  105. title: '请输入地址',
  106. icon: 'none',
  107. duration: 2000,
  108. mask: false
  109. });
  110. return
  111. }
  112. if (!(/^1[3456789]\d{9}$/.test(e.detail.value.phone))){
  113. wx.showToast({
  114. title: '请输入正确手机号',
  115. icon: 'none',
  116. duration: 2000,
  117. mask: false
  118. });
  119. return
  120. }
  121. let params={
  122. appId: this.data.subappid,
  123. openid: this.data.copenid,
  124. name:e.detail.value.name,
  125. sex:e.detail.value.sex,
  126. address:e.detail.value.address,
  127. userId: wx.getStorageSync("bUserId") ? wx.getStorageSync("bUserId") : app.globalData.bUserId,
  128. phone: e.detail.value.phone,
  129. }
  130. if (this.data.birthdate != '' && this.data.birthdate != "请输入") {
  131. params.birthdate = this.data.birthdate + ' 00:00:00'
  132. } else {
  133. params.birthdate = ''
  134. }
  135. if (params.birthdate == '') {
  136. wx.showToast({
  137. title: '请输入生日',
  138. icon: 'none',
  139. duration: 2000,
  140. mask: false
  141. });
  142. return
  143. }
  144. wx.showLoading({
  145. title: '正在保存!',
  146. })
  147. Http.post({
  148. url: config.api.cMemberAdd,
  149. data: params
  150. })
  151. .then(res => {
  152. wx.hideLoading()
  153. wx.showToast({
  154. title: '录入成功,2秒后跳转首页',
  155. icon: 'none',
  156. duration: 2000,
  157. success:function(){
  158. wx.reLaunch({
  159. url: '../main/main',
  160. })
  161. }
  162. });
  163. })
  164. .catch(err => {
  165. wx.hideLoading()
  166. wx.showToast({
  167. title: err.message,
  168. icon: 'none',
  169. duration: 2000,
  170. mask: false
  171. });
  172. });
  173. }
  174. })