index.js 11 KB

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