家政小程序
Ви не можете вибрати більше 25 тем Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const $ = global;
  2. new $.Page({
  3. data: {
  4. amount: 1,
  5. unitPrice: 599
  6. },
  7. minusAmount() {
  8. if (this.data.amount > 1) {
  9. this.setData({
  10. amount: this.data.amount - 1
  11. });
  12. }
  13. },
  14. addAmount() {
  15. this.setData({
  16. amount: this.data.amount + 1
  17. });
  18. },
  19. toPay() {
  20. const {
  21. name,
  22. phone,
  23. address,
  24. amount
  25. } = this.data;
  26. if (!name || !phone || !address || !amount) {
  27. return $.wx.showToast({
  28. title: '请把信息填写完整'
  29. });
  30. }
  31. if (!this._isPhone(phone)) {
  32. return $.wx.showToast({
  33. title: '请输入正确的手机号码'
  34. });
  35. }
  36. $.wx.showToast({
  37. title: '购买中'
  38. }, 'loading');
  39. $.request('product_order/store', 'POST', {
  40. amount,
  41. address,
  42. contact: name,
  43. phone,
  44. product_id: 1
  45. }).then((res) => {
  46. if (res.data) {
  47. this.callWXPay(res.data.id, res.data.order_type || 'product_order');
  48. }
  49. });
  50. },
  51. callWXPay(order_id, order_type) {
  52. $.request('payments/pay', 'POST', {
  53. order_id,
  54. order_type
  55. }).then((res) => {
  56. $.wx.hideToast('loading');
  57. });
  58. }
  59. });