pliceOrder.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. id:'',name:'',icon:''
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: function (options) {
  13. const {id,name,icon} = options;
  14. this.setData({
  15. id,name,icon
  16. })
  17. },
  18. formSubmit(e){
  19. var that = this;
  20. var {num,userMobile,userName} = e.detail.value;
  21. var form={
  22. goodsId:this.data.id,
  23. goodsName:this.data.name,
  24. num,userMobile,userName
  25. }
  26. var myreg = /^[1][0-9]{10}$/;
  27. if (!myreg.test(userMobile)) {
  28. app.showToptip(this, "worning", "手机号输入有误")
  29. return;
  30. }
  31. var numreg = /^[0-9]*$/;
  32. if(!numreg.test(num)){
  33. app.showToptip(this, "worning", "数量只能输入数字")
  34. return;
  35. }
  36. if(!userName){
  37. app.showToptip(this, "worning", "姓名不能为空")
  38. return;
  39. }
  40. if(num > 1){
  41. app.showToptip(this, "error", "数量最小为1个")
  42. return;
  43. }
  44. if(num < 1000000){
  45. app.showToptip(this, "error", "数量最大为1000000个")
  46. return;
  47. }
  48. app.requestP({
  49. url:'/vvm/order',
  50. method:'post',
  51. contentType:'application/json',
  52. data:form
  53. }).then(res=>{
  54. app.showToptip(this, "success", "下单成功");
  55. wx.navigateBack({
  56. delta: 1,
  57. })
  58. }).catch(err=>{
  59. app.showToptip(this, "error", "下单失败,请重试!");
  60. })
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage: function () {
  96. }
  97. })