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. 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. if (price.toString().indexOf(".") < 0) {
  50. price = price + ".00";
  51. }
  52. detail = list[i].Detail;
  53. if (i==0)
  54. buytype=110;
  55. else if (i == 1)
  56. buytype = 112;
  57. else if (i == 2)
  58. buytype = 111;
  59. }
  60. else
  61. list[i].Select = false;
  62. }
  63. this.data.Product.Period = list;
  64. this.setData({
  65. Product: this.data.Product,
  66. Price: price,
  67. });
  68. },
  69. showDiscount: function () {
  70. this.GetUserCouponListByUserID();
  71. },
  72. closeDiscount: function () {
  73. this.setData({
  74. IsDiscount: false,
  75. });
  76. },
  77. GetUserCouponListByUserID: function (callback) {
  78. var that = this;
  79. that.setData({
  80. IsDiscount: true,
  81. });
  82. wx.showLoading({
  83. title: '请稍后',
  84. });
  85. server.getData('GetUserCouponListByUserID?ProductID='+app.globalData.ProgramID+'&UserID=' + app.globalData.userInfo.UserID, function (data) {
  86. if (data) {
  87. that.setData({
  88. CouponList:data,
  89. });
  90. }
  91. wx.hideLoading();
  92. });
  93. },
  94. selectCoupon:function(e){
  95. selectedCouponID=e.currentTarget.dataset.id;
  96. var list = this.data.CouponList;
  97. for(var i=0;i<list.length;i++){
  98. if (selectedCouponID==list[i].ID){
  99. var price = Number(this.data.Price) - Number(list[i].Price);
  100. if (this.data.Coupon)
  101. price+=Number(this.data.Coupon.Price);
  102. if (price.toString().indexOf(".")<0){
  103. price=price+".00";
  104. }
  105. this.setData({
  106. IsDiscount: false,
  107. Coupon: list[i],
  108. Price: price,
  109. });
  110. wx.pageScrollTo({
  111. scrollTop: 2000,
  112. });
  113. break;
  114. }
  115. }
  116. },
  117. gotoFeedback: function () {
  118. server.gotoFeedback();
  119. },
  120. getPay: function (e) {
  121. if (!isPaying) {
  122. isPaying = true;
  123. var that = this;
  124. var money = that.data.Price;
  125. if (that.data.Coupon)
  126. detail += "_" + that.data.Coupon.ID+":"+Number(that.data.Coupon.Price)*100;
  127. server.payMoney(paytype, buytype, money, detail, function () {
  128. wx.redirectTo({
  129. url: './payfinish?paytype=' + paytype,
  130. });
  131. });
  132. setTimeout(function () {
  133. isPaying = false;
  134. }, 3000);
  135. }
  136. },
  137. onShareAppMessage: function () {
  138. return {
  139. title: app.globalData.ShareTitle,
  140. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  141. imageUrl: app.globalData.ShareImage,
  142. }
  143. },
  144. })