index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import {
  2. getBargainDetail,
  3. postBargainStartUser,
  4. postBargainStart,
  5. postBargainHelpPrice,
  6. postBargainHelpCount,
  7. postBargainHelp,
  8. postBargainHelpList,
  9. postBargainShare
  10. } from '../../../api/activity.js';
  11. import { postCartAdd } from '../../../api/store.js';
  12. import wxh from '../../../utils/wxh.js';
  13. import WxParse from '../../../wxParse/wxParse.js';
  14. import util from '../../../utils/util.js';
  15. const app = getApp();
  16. Page({
  17. /**
  18. * 页面的初始数据
  19. */
  20. data: {
  21. countDownDay: '00',
  22. countDownHour: '00',
  23. countDownMinute: '00',
  24. countDownSecond: '00',
  25. active: false,
  26. id:0,//砍价产品编号
  27. userInfo:{},//当前用户信息
  28. bargainUid: 0,//开启砍价用户
  29. bargainUserInfo: {},//开启砍价用户信息
  30. bargainUserId: 0,//开启砍价编号
  31. bargainInfo:[],//砍价产品
  32. offset:0,
  33. limit:20,
  34. limitStatus:false,
  35. bargainUserHelpList:[],
  36. bargainUserHelpInfo:[],
  37. bargainUserBargainPrice:0,
  38. status:'', // 0 开启砍价 1 朋友帮忙砍价 2 朋友帮忙砍价成功 3 完成砍价 4 砍价失败 5已创建订单
  39. bargainCount:[],//分享人数 浏览人数 参与人数
  40. retunTop:true,
  41. bargainPartake:0,
  42. isHelp:false,
  43. interval:null,
  44. userBargainStatus:0,//判断自己是否砍价
  45. productStock:0,//判断是否售罄;
  46. quota:0,//判断是否已限量;
  47. userBargainStatusHelp:true,
  48. navH: '',
  49. statusPay:'',
  50. },
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */
  54. onLoad: function (options) {
  55. this.setData({
  56. navH: app.globalData.navHeight
  57. });
  58. var that = this;
  59. var pages = getCurrentPages();
  60. if (pages.length <= 1) that.setData({ retunTop:false});
  61. //扫码携带参数处理
  62. if (options.scene) {
  63. var value = util.getUrlParams(decodeURIComponent(options.scene));
  64. if (typeof value === 'object'){
  65. if (value.id) options.id = value.id;
  66. if (value.bargain) options.bargain = value.bargain;
  67. //记录推广人uid
  68. if (value.pid) app.globalData.spid = value.pid;
  69. }else{
  70. app.globalData.spid = value;
  71. }
  72. }
  73. if (options.hasOwnProperty('id')) {
  74. this.setData({ id: options.id, bargainUid: options.bargain || 0 });
  75. }
  76. },
  77. /**
  78. * 跳转到商品页面
  79. */
  80. goProduct:function(){
  81. return app.Tips('/pages/goods_details/index?id=' + this.data.bargainInfo.product_id);
  82. },
  83. goBack: function () {
  84. wx.navigateBack({ delta: 1 })
  85. },
  86. gobargainUserInfo:function(){//获取开启砍价用户信息
  87. var that = this;
  88. var data = { bargainId: that.data.id, bargainUserUid: that.data.bargainUid };
  89. postBargainStartUser(data).then(res=>{
  90. that.setData({ bargainUserInfo: res.data });
  91. });
  92. },
  93. goPay: function () {//立即支付
  94. var that = this;
  95. var data = {
  96. productId: that.data.bargainInfo.product_id,
  97. bargainId: that.data.id,
  98. cartNum: that.data.bargainInfo.num,
  99. uniqueId:'',
  100. combinationId:0,
  101. secKillId:0,
  102. 'new':1
  103. };
  104. postCartAdd(data).then(res=>{
  105. wx.navigateTo({ url: '/pages/order_confirm/index?cartId=' + res.data.cartId });
  106. }).catch(err=>{
  107. return app.Tips({title:err})
  108. });
  109. },
  110. getBargainDetails:function(){//获取砍价产品详情
  111. var that = this;
  112. var id = that.data.id;
  113. getBargainDetail(id).then(function(res){
  114. that.setData({
  115. bargainInfo: res.data.bargain,
  116. bargainPrice:res.data.bargain.price,
  117. userInfo: res.data.userInfo,
  118. bargainSumCount: res.data.bargainSumCount,
  119. userBargainStatus: res.data.userBargainStatus,
  120. productStock: res.data.bargain.attr.product_stock,
  121. quota: res.data.bargain.attr.quota
  122. });
  123. app.globalData.openPages = '/pages/activity/goods_bargain_details/index?id=' + that.data.id + '&bargain=' + that.data.bargainUid + '&scene=' + that.data.userInfo.uid;
  124. WxParse.wxParse('description', 'html', that.data.bargainInfo.description || '', that, 0);
  125. WxParse.wxParse('rule', 'html', that.data.bargainInfo.rule || '', that, 0);
  126. wxh.time2(that.data.bargainInfo.stop_time, that);
  127. that.getBargainHelpCount();
  128. that.setData({ bargainUserHelpList: [] });
  129. that.getBargainUser();
  130. that.gobargainUserInfo();
  131. }).catch(function(err){
  132. return app.Tips({ title: err }, { tab: 3, url: 1 });
  133. })
  134. },
  135. // 自己砍价;
  136. userBargain:function(){
  137. let that = this;
  138. if (that.data.userInfo.uid == that.data.bargainUid){
  139. that.setBargain();
  140. }
  141. },
  142. getBargainHelpCount: function () {//获取砍价帮总人数、剩余金额、进度条、已经砍掉的价格
  143. var that = this;
  144. var data = { bargainId: that.data.id, bargainUserUid:that.data.bargainUid };
  145. postBargainHelpCount(data).then(res=>{
  146. var price = util.$h.Sub(that.data.bargainPrice, res.data.alreadyPrice);
  147. that.setData({
  148. bargainUserHelpInfo: res.data,
  149. 'bargainInfo.price': parseFloat(price) <= 0 ? 0 : price,
  150. userBargainStatusHelp: res.data.userBargainStatus,
  151. statusPay: res.data.status
  152. });
  153. })
  154. },
  155. currentBargainUser:function(){//当前用户砍价
  156. this.setData({ bargainUid:this.data.userInfo.uid });
  157. this.setBargain();
  158. },
  159. setBargain:function(){//参与砍价
  160. var that = this;
  161. postBargainStart(that.data.id).then(res=>{
  162. that.setData({ bargainUserId: res.data });
  163. that.getBargainUserBargainPrice();
  164. that.setBargainHelp();
  165. that.getBargainHelpCount();
  166. that.setData({
  167. userBargainStatus:1
  168. })
  169. })
  170. },
  171. setBargainHelp: function () {//帮好友砍价
  172. var that = this;
  173. var data = { bargainId: that.data.id, bargainUserUid: that.data.bargainUid };
  174. postBargainHelp(data).then(res=>{
  175. that.setData({ bargainUserHelpList: [],isHelp:true });
  176. that.getBargainUser();
  177. that.getBargainUserBargainPrice();
  178. that.getBargainHelpCount();
  179. }).catch(err=>{
  180. that.setData({ bargainUserHelpList: [] });
  181. that.getBargainUser();
  182. })
  183. },
  184. getBargainUser: function () {//获取砍价帮
  185. var that = this;
  186. var data = {
  187. bargainId: that.data.id,
  188. bargainUserUid: that.data.bargainUid,
  189. offset: that.data.offset,
  190. limit: that.data.limit,
  191. };
  192. postBargainHelpList(data).then(res=>{
  193. var bargainUserHelpListNew = [];
  194. var bargainUserHelpList = that.data.bargainUserHelpList;
  195. var len = res.data.length;
  196. bargainUserHelpListNew = bargainUserHelpList.concat(res.data);
  197. that.setData({ bargainUserHelpList: bargainUserHelpListNew, limitStatus: data.limit > len, offest: Number(data.offset) + Number(data.limit) });
  198. });
  199. },
  200. getBargainUserBargainPricePoster:function(){
  201. var that = this;
  202. wx.navigateTo({
  203. url: '/pages/activity/poster-poster/index?type=1&id=' + that.data.id,
  204. });
  205. },
  206. getBargainUserBargainPrice: function () {//获取帮忙砍价砍掉多少金额
  207. var that = this;
  208. var data = {bargainId: that.data.id,bargainUserUid: that.data.bargainUid};
  209. postBargainHelpPrice(data).then(res=>{
  210. that.setData({ bargainUserBargainPrice: res.data, active: true });
  211. }).catch(err=>{
  212. that.setData({ active: false });
  213. });
  214. },
  215. goBargainList:function(){
  216. wx.navigateTo({
  217. url: '/pages/activity/goods_bargain/index',
  218. })
  219. },
  220. close:function(){
  221. this.setData({
  222. active: false
  223. })
  224. },
  225. /**
  226. * 生命周期函数--监听页面初次渲染完成
  227. */
  228. onReady: function () {
  229. },
  230. onLoadFun: function (e) {
  231. let uid = e.detail.uid;
  232. if(!this.data.bargainUid && uid){
  233. this.setData({bargainUid:uid});
  234. }
  235. if(!this.data.bargainUid){
  236. return app.Tips({ title:'参数错误'},{tab:3,url:1})
  237. }
  238. this.getBargainDetails();
  239. this.addShareBargain();
  240. app.globalData.openPages = '/pages/activity/goods_bargain_details/index?id=' + this.data.id + '&bargain=' + this.data.bargainUid + '&spid=' + e.detail.uid;
  241. this.setData({ bargainPartake: e.detail.uid});
  242. },
  243. /**
  244. * 生命周期函数--监听页面显示
  245. */
  246. onShow: function () {
  247. },
  248. /**
  249. * 生命周期函数--监听页面隐藏
  250. */
  251. onHide: function () {
  252. if (this.data.interval !== null) clearInterval(this.data.interval);
  253. },
  254. /**
  255. * 生命周期函数--监听页面卸载
  256. */
  257. onUnload: function () {
  258. if (this.data.interval !== null) clearInterval(this.data.interval);
  259. },
  260. /**
  261. * 页面相关事件处理函数--监听用户下拉动作
  262. */
  263. onPullDownRefresh: function () {
  264. },
  265. /**
  266. * 页面上拉触底事件的处理函数
  267. */
  268. onReachBottom: function () {
  269. },
  270. addShareBargain: function () {//添加分享次数 获取人数
  271. var that = this;
  272. postBargainShare(this.data.id).then(res=>{
  273. that.setData({ bargainCount: res.data })
  274. });
  275. },
  276. /**
  277. * 用户点击右上角分享
  278. */
  279. onShareAppMessage: function () {
  280. var that = this;
  281. that.close();
  282. that.addShareBargain();
  283. return {
  284. title: '您的好友' + that.data.userInfo.nickname + '邀请您帮他砍' + that.data.bargainInfo.title+' 快去帮忙吧!',
  285. path: app.globalData.openPages,
  286. imageUrl: that.data.bargainInfo.image,
  287. }
  288. }
  289. })