order.js 3.8 KB

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