serviceDetails.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/order/serviceDetails/serviceDetails.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. goods: {},
  9. carNum: 1,
  10. carPrice: 0,
  11. title: "",
  12. address: "",
  13. worke_id: "",
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. var goods_id = options.goods_id;
  20. var title = options.title;
  21. var address = options.address;
  22. var worke_id = options.worke_id;
  23. this.setData({
  24. title: title,
  25. address: address,
  26. worke_id: worke_id,
  27. goods_id: goods_id
  28. })
  29. var that = this;
  30. app.api.useApi(app.globalData.baseAppUrl + "api/goods_info", {
  31. network_id: wx.getStorageSync('nid'),
  32. good_id: goods_id
  33. }, "get").then(function (res) {
  34. console.log(res);
  35. if (res.code != 200) {
  36. console.log(res.code);
  37. wx.showLoading({
  38. title: res.message.msg,
  39. })
  40. } else {
  41. that.setData({
  42. goods: res.message.data.good,
  43. carPrice: res.message.data.good.price.start_time!=0?res.message.data.good.price.sale_price:res.message.data.good.price.price,
  44. })
  45. }
  46. wx.hideLoading();
  47. }).catch(function (err) {
  48. console.log(222);
  49. })
  50. },
  51. minus() {
  52. if (this.data.carNum > 1) {
  53. var carnum = this.data.carNum - 1
  54. this.setData({
  55. carNum: carnum
  56. })
  57. }
  58. console.log(this.data.goods.price.start_time);
  59. if (this.data.goods.price.end_time == 0 && this.data.goods.price.start_time == 0) {
  60. var price = this.data.goods.price.price;
  61. } else {
  62. var price = this.data.goods.price.sale_price;
  63. }
  64. console.log(price);
  65. this.setData({
  66. carPrice: carnum * price
  67. })
  68. },
  69. plus() {
  70. console.log(this.data.carNum)
  71. var carnum = this.data.carNum + 1
  72. // if(this.data.carNum>=1){
  73. this.setData({
  74. carNum: carnum
  75. })
  76. // }
  77. if (this.data.goods.price.end_time == 0 && this.data.goods.price.start_time == 0) {
  78. var price = this.data.goods.price.price;
  79. } else {
  80. var price = this.data.goods.price.sale_price;
  81. }
  82. this.setData({
  83. carPrice: carnum * price
  84. })
  85. },
  86. getOrder() {
  87. var nid = this.data.worke_id;
  88. app.api.useApi(app.globalData.baseAppUrl + "api/CreateOrder", {
  89. network_id: nid,
  90. good_id: this.data.goods_id,
  91. num: this.data.carNum
  92. }, "post").then(function (res) {
  93. console.log(res);
  94. if (res.code != 200) {
  95. wx.showLoading({
  96. title: res.message.msg,
  97. })
  98. wx.setTimeout(() => {
  99. wx.hideLoading();
  100. }, 1000);
  101. } else {
  102. var order_no = res.message.data.order_no;
  103. wx.navigateTo({
  104. url: '/pages/order/confirmOreder/confirmOreder?order_no=' + order_no,
  105. })
  106. }
  107. }).catch(function (err) {
  108. console.log(222);
  109. })
  110. },
  111. })