cut-one.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. // pages/cut-one/cut-one.js
  2. var app = getApp();
  3. var wxh = require('../../utils/wxh.js');
  4. var WxParse = require('../../wxParse/wxParse.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. uid: app.globalData.uid,//登录人uid
  11. bargainUid:0,//参与砍价uid
  12. bargainUserInfo:[],//参与人信息
  13. bargainId:0,//砍价产品ID
  14. status:0,// 0未参与砍价 1参与砍价 2 帮别人砍价 3 已帮别人砍价 4 砍价结束
  15. count:[],//顶部人数
  16. bargainUserHelp:[],//砍价帮人
  17. HelpCount:0,//砍价帮总人数
  18. HelpPrice:0,//剩余多少金额
  19. pricePercent:0,//进度条
  20. bargainUserHelpUserInfo:[],
  21. url: app.globalData.urlImages,
  22. hiddens: true,
  23. hiddens2:true,
  24. product:[],
  25. countDownDay:'00',
  26. countDownHour:'00',
  27. countDownMinute:'00',
  28. countDownSecond:'00',
  29. },
  30. onLoad: function (options) {
  31. app.setBarColor();
  32. app.globalData.openPages = '/pages/cut-one/cut-one?bargainUid=' + options.bargainUid + '&id=' + options.id;
  33. app.setUserInfo();
  34. if (options.id && options.bargainUid) {
  35. this.setData({
  36. bargainId: options.id,
  37. bargainUid: options.bargainUid
  38. })
  39. this.getbargain();
  40. this.getBargainCount();
  41. this.addLookBargain();
  42. } else if (options.id){
  43. this.setData({
  44. bargainId: options.id,
  45. bargainUid: app.globalData.uid
  46. })
  47. this.getbargain();
  48. this.getBargainCount();
  49. this.addLookBargain();
  50. }else {
  51. wx.showToast({
  52. title: '参数错误',
  53. icon: 'none',
  54. duration: 1000
  55. })
  56. setTimeout(function () {
  57. wx.navigateTo({
  58. url: '/pages/cut-list/cut-list'
  59. })
  60. }, 1200)
  61. }
  62. },//获取砍价产品
  63. getbargain: function () {
  64. var that = this;
  65. wx.request({
  66. url: app.globalData.url + '/routine/auth_api/get_bargain?uid=' + app.globalData.uid,
  67. data: { bargainId: that.data.bargainId },
  68. method: 'GET',
  69. success: function (res) {
  70. if (res.data.code == 200) {
  71. that.setData({
  72. product: res.data.data
  73. })
  74. that.dtime();
  75. if (that.data.bargainUid == app.globalData.uid) {
  76. that.setData({
  77. status: 1
  78. })
  79. that.setBargain();
  80. } else {
  81. that.setData({
  82. status: 2
  83. })
  84. that.getBargainUser();
  85. that.getUserInfo();
  86. that.getBargainHelpCount();
  87. }
  88. if (that.data.product.description) WxParse.wxParse('description', 'html', that.data.product.description, that, 0);
  89. if (that.data.product.rule) WxParse.wxParse('rule', 'html', that.data.product.rule, that, 0);
  90. } else {
  91. that.setData({
  92. product: []
  93. })
  94. }
  95. }
  96. })
  97. },//倒计时
  98. dtime: function () {
  99. var that = this;
  100. var timeStamp = that.data.product.stop_time;
  101. wxh.time2(timeStamp, that);
  102. },//获取顶部人数
  103. getBargainCount: function () {
  104. var that = this;
  105. wx.request({
  106. url: app.globalData.url + '/routine/auth_api/get_bargain_count?uid=' + app.globalData.uid,
  107. method: 'GET',
  108. success: function (res) {
  109. if (res.data.code == 200) {
  110. that.setData({
  111. count: res.data.data
  112. })
  113. } else {
  114. that.setData({
  115. count: []
  116. })
  117. }
  118. }
  119. })
  120. },//参与砍价
  121. setBargain: function () {
  122. var that = this;
  123. wx.request({
  124. url: app.globalData.url + '/routine/auth_api/set_bargain?uid=' + app.globalData.uid,
  125. data: { bargainId: that.data.bargainId },
  126. method: 'GET',
  127. success: function (res) {
  128. if (res.data.code == 200) {
  129. wx.showToast({
  130. title: res.data.msg,
  131. icon: 'success',
  132. duration: 2000
  133. })
  134. that.setData({
  135. status:1,
  136. bargainUid: app.globalData.uid
  137. })
  138. } else {
  139. // wx.showToast({
  140. // title: res.data.msg,
  141. // icon: 'none',
  142. // duration: 2000
  143. // })
  144. }
  145. that.setBargainHelp();
  146. that.isBargainUser();
  147. }
  148. })
  149. },//参与砍价帮砍
  150. setBargainHelp: function () {
  151. var that = this;
  152. wx.request({
  153. url: app.globalData.url + '/routine/auth_api/set_bargain_help?uid=' + app.globalData.uid,
  154. data: {
  155. bargainId: that.data.bargainId,
  156. bargainUserId: that.data.bargainUid
  157. },
  158. method: 'GET',
  159. success: function (res) {
  160. if (res.data.code == 200){
  161. wx.showToast({
  162. title: res.data.msg,
  163. icon: 'success',
  164. duration: 2000
  165. })
  166. if (that.data.bargainUid != app.globalData.uid) {
  167. that.setData({
  168. status: 3,
  169. bargainUserHelpUserInfo: res.data.data,
  170. hiddens2: false
  171. })
  172. }else{
  173. that.setData({
  174. status: 1,
  175. bargainUserHelpUserInfo: res.data.data,
  176. hiddens2: false
  177. })
  178. }
  179. that.getBargainUser();
  180. that.getUserInfo();
  181. that.getBargainHelpCount();
  182. } else {
  183. that.isBargainUserHelp();
  184. }
  185. }
  186. })
  187. },//判断当前用户是否可以砍价
  188. isBargainUserHelp:function(){
  189. var that = this;
  190. wx.request({
  191. url: app.globalData.url + '/routine/auth_api/is_bargain_user_help?uid=' + app.globalData.uid,
  192. data: {
  193. bargainId: that.data.bargainId,
  194. bargainUserId: that.data.bargainUid
  195. },
  196. method: 'GET',
  197. success: function (res) {
  198. if (res.data.code == 200) {
  199. wx.showToast({
  200. title: res.data.msg,
  201. icon: 'none',
  202. duration: 2000
  203. })
  204. } else {
  205. if (that.data.bargainUid != app.globalData.uid) {
  206. wx.showToast({
  207. title: '您不能在帮' + that.data.bargainUserInfo.nickname + '砍价了',
  208. icon: 'none',
  209. duration: 2000
  210. })
  211. that.setData({
  212. status: 3
  213. })
  214. } else {
  215. that.setData({
  216. status: 1,
  217. })
  218. }
  219. }
  220. }
  221. })
  222. },
  223. //判断当前登录人是否参与砍价
  224. isBargainUser: function () {
  225. var that = this;
  226. wx.request({
  227. url: app.globalData.url + '/routine/auth_api/is_bargain_user?uid=' + app.globalData.uid,
  228. data: { bargainId: that.data.bargainId },
  229. method: 'GET',
  230. success: function (res) {
  231. if (res.data.code == 200) {
  232. that.setData({
  233. bargainUid: app.globalData.uid,
  234. status: 1
  235. })
  236. that.getBargainUser();
  237. that.getUserInfo();
  238. that.getBargainHelpCount();
  239. } else {
  240. that.setData({
  241. bargainUid: 0,
  242. status:0
  243. })
  244. }
  245. }
  246. })
  247. },//获取砍价帮
  248. getBargainUser: function () {
  249. var that = this;
  250. wx.request({
  251. url: app.globalData.url + '/routine/auth_api/get_bargain_user?uid=' + app.globalData.uid,
  252. data: {
  253. bargainId: that.data.bargainId,
  254. bargainUid: that.data.bargainUid
  255. },
  256. method: 'GET',
  257. success: function (res) {
  258. if (res.data.code == 200) {
  259. that.setData({
  260. bargainUserHelp: res.data.data
  261. })
  262. } else {
  263. that.setData({
  264. bargainUserHelp: []
  265. })
  266. }
  267. }
  268. })
  269. },//获取当前参与砍价人的信息
  270. getUserInfo:function(){
  271. var that = this;
  272. wx.request({
  273. url: app.globalData.url + '/routine/auth_api/get_user_info_uid?uid=' + app.globalData.uid,
  274. data: {
  275. userId: that.data.bargainUid
  276. },
  277. method: 'GET',
  278. success: function (res) {
  279. if (res.data.code == 200) {
  280. that.setData({
  281. bargainUserInfo: res.data.data
  282. })
  283. } else {
  284. wx.showToast({
  285. title: res.data.msg,
  286. icon: 'none',
  287. duration: 2000
  288. })
  289. that.setData({
  290. bargainUserInfo: []
  291. })
  292. }
  293. }
  294. })
  295. },//获取砍价帮总人数
  296. getBargainHelpCount:function(){
  297. var that = this;
  298. wx.request({
  299. url: app.globalData.url + '/routine/auth_api/get_bargain_help_count?uid=' + app.globalData.uid,
  300. data: {
  301. bargainId: that.data.bargainId,
  302. bargainUserId: that.data.bargainUid
  303. },
  304. method: 'GET',
  305. success: function (res) {
  306. if (res.data.code == 200) {
  307. if (res.data.data.price <= 0 && app.globalData.uid == that.data.bargainUid){
  308. that.setData({
  309. status:4
  310. })
  311. }
  312. that.setData({
  313. HelpCount: res.data.data.count,
  314. HelpPrice: res.data.data.price,
  315. pricePercent: res.data.data.pricePercent
  316. })
  317. } else {
  318. wx.showToast({
  319. title: res.data.msg,
  320. icon: 'none',
  321. duration: 2000
  322. })
  323. that.setData({
  324. HelpCount: 0,
  325. HelpPrice:0,
  326. pricePercent:0
  327. })
  328. }
  329. }
  330. })
  331. },
  332. getCutList:function(){
  333. wx.navigateTo({
  334. url: '/pages/cut-list/cut-list'
  335. })
  336. },//砍价成功后支付订单
  337. goOrderPay:function(){
  338. var that = this;
  339. if (that.data.bargainUid != app.globalData.uid){
  340. wx.showToast({
  341. title: '参数错误',
  342. icon: 'none',
  343. duration: 2000
  344. })
  345. }else{
  346. wx.request({
  347. url: app.globalData.url + '/routine/auth_api/now_buy?uid=' + app.globalData.uid,
  348. method: 'GET',
  349. data: {
  350. productId: that.data.product.product_id,
  351. cartNum: that.data.product.num,
  352. bargainId: that.data.product.id,
  353. },
  354. success: function (res) {
  355. if (res.data.code == 200) {
  356. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  357. url: '/pages/order-confirm/order-confirm?id=' + res.data.data.cartId
  358. })
  359. } else {
  360. wx.showToast({
  361. title: res.data.msg,
  362. icon: 'none',
  363. duration: 2000
  364. })
  365. }
  366. }
  367. })
  368. }
  369. },
  370. /**
  371. * 生命周期函数--监听页面初次渲染完成
  372. */
  373. onReady: function () {
  374. },
  375. rules:function(e){
  376. this.setData({
  377. hiddens:false
  378. })
  379. },
  380. butguan:function(e){
  381. this.setData({
  382. hiddens: true
  383. })
  384. },
  385. butguan2:function(e){
  386. this.setData({
  387. hiddens2: true
  388. })
  389. },
  390. /**
  391. * 生命周期函数--监听页面隐藏
  392. */
  393. onHide: function () {
  394. },
  395. /**
  396. * 生命周期函数--监听页面卸载
  397. */
  398. onUnload: function () {
  399. },
  400. /**
  401. * 页面相关事件处理函数--监听用户下拉动作
  402. */
  403. onPullDownRefresh: function () {
  404. },
  405. /**
  406. * 页面上拉触底事件的处理函数
  407. */
  408. onReachBottom: function () {
  409. },
  410. addLookBargain: function () {
  411. var that = this;
  412. wx.request({
  413. url: app.globalData.url + '/routine/auth_api/add_look_bargain?uid=' + app.globalData.uid,
  414. method: 'GET',
  415. data: {
  416. bargainId: that.data.bargainId,
  417. },
  418. success: function (res) {
  419. that.getBargainCount();
  420. }
  421. })
  422. },
  423. addShareBargain:function(){
  424. var that = this;
  425. wx.request({
  426. url: app.globalData.url + '/routine/auth_api/add_share_bargain?uid=' + app.globalData.uid,
  427. method: 'GET',
  428. data: {
  429. bargainId: that.data.bargainId,
  430. },
  431. success: function (res) {
  432. that.getBargainCount();
  433. }
  434. })
  435. },
  436. /**
  437. * 用户点击右上角分享
  438. */
  439. onShareAppMessage: function () {
  440. var that = this;
  441. return {
  442. title: that.data.bargainUserInfo.nickname+'邀请您帮砍价',
  443. path: '/pages/cut-one/cut-one?bargainUid=' + that.data.bargainUid + '&id=' + that.data.bargainId,
  444. imageUrl: that.data.url + that.data.product.image,
  445. success:function(){
  446. that.addShareBargain();
  447. wx.showToast({
  448. title: '分享成功',
  449. icon: 'success',
  450. duration: 2000
  451. })
  452. }
  453. }
  454. }
  455. })