order.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var isPaying = false;
  5. var paytype=3;//3是单买 4是套餐 5是礼品卡
  6. var buytype = 110;//110是6个月 112是12个月,111是永久
  7. var detail="";
  8. var selectedCouponID=0;
  9. Page({
  10. data: {
  11. CouponList: [],
  12. },
  13. onLoad: function (options) {
  14. var id = options.id;
  15. paytype = options.paytype;
  16. var result, price = 0;
  17. var programList = server.getProgramList();
  18. var arrProduct=wx.getStorageSync("ProductPrice");
  19. for (var j = 0; j < arrProduct.length; j++) {
  20. if (id==arrProduct[j].ProductNum){
  21. for (var k = 0; k < arrProduct[j].Period.length; k++) {
  22. if (arrProduct[j].Period[k].Select) {
  23. price = arrProduct[j].Period[k].Price;
  24. detail = arrProduct[j].Period[k].Detail;
  25. }
  26. }
  27. result = arrProduct[j];
  28. }
  29. }
  30. this.setData({
  31. Containnerheight: common.getSystemHeight(),
  32. Product: result,
  33. Price: price,
  34. IsDiscount: false,
  35. CouponName:"未选择",
  36. });
  37. },
  38. selectPeriod: function (e) {
  39. var id = e.currentTarget.dataset.id;
  40. var list = this.data.Product.Period;
  41. var price = 0;
  42. for (var i = 0; i < list.length; i++) {
  43. if (i == id) {
  44. list[i].Select = true;
  45. price = list[i].Price;
  46. if (this.data.Coupon){
  47. price=price-Number(this.data.Coupon.Price);
  48. }
  49. price = common.FormatMoney(price*100);
  50. detail = list[i].Detail;
  51. if (i==0)
  52. buytype=110;
  53. else if (i == 1)
  54. buytype = 112;
  55. else if (i == 2)
  56. buytype = 111;
  57. }
  58. else
  59. list[i].Select = false;
  60. }
  61. this.data.Product.Period = list;
  62. this.setData({
  63. Product: this.data.Product,
  64. Price: price,
  65. });
  66. },
  67. showDiscount: function () {
  68. this.GetUserCouponListByUserID();
  69. },
  70. closeDiscount: function () {
  71. this.setData({
  72. IsDiscount: false,
  73. });
  74. },
  75. GetUserCouponListByUserID: function (callback) {
  76. var that = this;
  77. that.setData({
  78. IsDiscount: true,
  79. });
  80. wx.showLoading({
  81. title: '请稍后',
  82. });
  83. server.getData('GetUserCouponListByUserID?ProductID='+app.globalData.ProgramID+'&UserID=' + app.globalData.userInfo.UserID, function (data) {
  84. if (data) {
  85. that.setData({
  86. CouponList:data,
  87. });
  88. }
  89. wx.hideLoading();
  90. });
  91. },
  92. selectCoupon:function(e){
  93. selectedCouponID=e.currentTarget.dataset.id;
  94. var list = this.data.CouponList;
  95. for(var i=0;i<list.length;i++){
  96. if (selectedCouponID==list[i].ID){
  97. var price = Number(this.data.Price) - Number(list[i].Price);
  98. if (this.data.Coupon)
  99. price+=Number(this.data.Coupon.Price);
  100. price = common.FormatMoney(price * 100);
  101. this.setData({
  102. IsDiscount: false,
  103. Coupon: list[i],
  104. Price: price,
  105. });
  106. wx.pageScrollTo({
  107. scrollTop: 2000,
  108. });
  109. break;
  110. }
  111. }
  112. },
  113. gotoFeedback: function () {
  114. server.gotoFeedback();
  115. },
  116. getPay: function (e) {
  117. if (!isPaying) {
  118. isPaying = true;
  119. var that = this;
  120. var money = that.data.Price;
  121. if (that.data.Coupon)
  122. detail += "_" + that.data.Coupon.ID+":"+Number(that.data.Coupon.Price)*100;
  123. server.payMoney(paytype, buytype, money, detail, function () {
  124. wx.redirectTo({
  125. url: './payfinish?paytype=' + paytype,
  126. });
  127. });
  128. setTimeout(function () {
  129. isPaying = false;
  130. }, 3000);
  131. }
  132. },
  133. onShareAppMessage: function () {
  134. return {
  135. title: app.globalData.ShareTitle,
  136. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  137. imageUrl: app.globalData.ShareImage,
  138. }
  139. },
  140. })