| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- // pages/cut-one/cut-one.js
- var app = getApp();
- var wxh = require('../../utils/wxh.js');
- var WxParse = require('../../wxParse/wxParse.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- uid: app.globalData.uid,//登录人uid
- bargainUid:0,//参与砍价uid
- bargainUserInfo:[],//参与人信息
- bargainId:0,//砍价产品ID
- status:0,// 0未参与砍价 1参与砍价 2 帮别人砍价 3 已帮别人砍价 4 砍价结束
- count:[],//顶部人数
- bargainUserHelp:[],//砍价帮人
- HelpCount:0,//砍价帮总人数
- HelpPrice:0,//剩余多少金额
- pricePercent:0,//进度条
- bargainUserHelpUserInfo:[],
- url: app.globalData.urlImages,
- hiddens: true,
- hiddens2:true,
- product:[],
- countDownDay:'00',
- countDownHour:'00',
- countDownMinute:'00',
- countDownSecond:'00',
- },
- onLoad: function (options) {
- app.setBarColor();
- app.globalData.openPages = '/pages/cut-one/cut-one?bargainUid=' + options.bargainUid + '&id=' + options.id;
- app.setUserInfo();
- if (options.id && options.bargainUid) {
- this.setData({
- bargainId: options.id,
- bargainUid: options.bargainUid
- })
- this.getbargain();
- this.getBargainCount();
- this.addLookBargain();
- } else if (options.id){
- this.setData({
- bargainId: options.id,
- bargainUid: app.globalData.uid
- })
- this.getbargain();
- this.getBargainCount();
- this.addLookBargain();
- }else {
- wx.showToast({
- title: '参数错误',
- icon: 'none',
- duration: 1000
- })
- setTimeout(function () {
- wx.navigateTo({
- url: '/pages/cut-list/cut-list'
- })
- }, 1200)
- }
- },//获取砍价产品
- getbargain: function () {
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/get_bargain?uid=' + app.globalData.uid,
- data: { bargainId: that.data.bargainId },
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200) {
- that.setData({
- product: res.data.data
- })
- that.dtime();
- if (that.data.bargainUid == app.globalData.uid) {
- that.setData({
- status: 1
- })
- that.setBargain();
- } else {
- that.setData({
- status: 2
- })
- that.getBargainUser();
- that.getUserInfo();
- that.getBargainHelpCount();
- }
- if (that.data.product.description) WxParse.wxParse('description', 'html', that.data.product.description, that, 0);
- if (that.data.product.rule) WxParse.wxParse('rule', 'html', that.data.product.rule, that, 0);
- } else {
- that.setData({
- product: []
- })
- }
- }
- })
- },//倒计时
- dtime: function () {
- var that = this;
- var timeStamp = that.data.product.stop_time;
- wxh.time2(timeStamp, that);
- },//获取顶部人数
- getBargainCount: function () {
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/get_bargain_count?uid=' + app.globalData.uid,
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200) {
- that.setData({
- count: res.data.data
- })
- } else {
- that.setData({
- count: []
- })
- }
- }
- })
- },//参与砍价
- setBargain: function () {
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/set_bargain?uid=' + app.globalData.uid,
- data: { bargainId: that.data.bargainId },
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200) {
- wx.showToast({
- title: res.data.msg,
- icon: 'success',
- duration: 2000
- })
- that.setData({
- status:1,
- bargainUid: app.globalData.uid
- })
- } else {
- // wx.showToast({
- // title: res.data.msg,
- // icon: 'none',
- // duration: 2000
- // })
- }
- that.setBargainHelp();
- that.isBargainUser();
- }
- })
- },//参与砍价帮砍
- setBargainHelp: function () {
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/set_bargain_help?uid=' + app.globalData.uid,
- data: {
- bargainId: that.data.bargainId,
- bargainUserId: that.data.bargainUid
- },
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200){
- wx.showToast({
- title: res.data.msg,
- icon: 'success',
- duration: 2000
- })
- if (that.data.bargainUid != app.globalData.uid) {
- that.setData({
- status: 3,
- bargainUserHelpUserInfo: res.data.data,
- hiddens2: false
- })
- }else{
- that.setData({
- status: 1,
- bargainUserHelpUserInfo: res.data.data,
- hiddens2: false
- })
- }
- that.getBargainUser();
- that.getUserInfo();
- that.getBargainHelpCount();
- } else {
- that.isBargainUserHelp();
- }
- }
- })
- },//判断当前用户是否可以砍价
- isBargainUserHelp:function(){
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/is_bargain_user_help?uid=' + app.globalData.uid,
- data: {
- bargainId: that.data.bargainId,
- bargainUserId: that.data.bargainUid
- },
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200) {
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 2000
- })
- } else {
- if (that.data.bargainUid != app.globalData.uid) {
- wx.showToast({
- title: '您不能在帮' + that.data.bargainUserInfo.nickname + '砍价了',
- icon: 'none',
- duration: 2000
- })
- that.setData({
- status: 3
- })
- } else {
- that.setData({
- status: 1,
- })
- }
- }
- }
- })
- },
- //判断当前登录人是否参与砍价
- isBargainUser: function () {
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/is_bargain_user?uid=' + app.globalData.uid,
- data: { bargainId: that.data.bargainId },
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200) {
- that.setData({
- bargainUid: app.globalData.uid,
- status: 1
- })
- that.getBargainUser();
- that.getUserInfo();
- that.getBargainHelpCount();
- } else {
- that.setData({
- bargainUid: 0,
- status:0
- })
- }
- }
- })
- },//获取砍价帮
- getBargainUser: function () {
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/get_bargain_user?uid=' + app.globalData.uid,
- data: {
- bargainId: that.data.bargainId,
- bargainUid: that.data.bargainUid
- },
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200) {
- that.setData({
- bargainUserHelp: res.data.data
- })
- } else {
- that.setData({
- bargainUserHelp: []
- })
- }
- }
- })
- },//获取当前参与砍价人的信息
- getUserInfo:function(){
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/get_user_info_uid?uid=' + app.globalData.uid,
- data: {
- userId: that.data.bargainUid
- },
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200) {
- that.setData({
- bargainUserInfo: res.data.data
- })
- } else {
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 2000
- })
- that.setData({
- bargainUserInfo: []
- })
- }
- }
- })
- },//获取砍价帮总人数
- getBargainHelpCount:function(){
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/get_bargain_help_count?uid=' + app.globalData.uid,
- data: {
- bargainId: that.data.bargainId,
- bargainUserId: that.data.bargainUid
- },
- method: 'GET',
- success: function (res) {
- if (res.data.code == 200) {
- if (res.data.data.price <= 0 && app.globalData.uid == that.data.bargainUid){
- that.setData({
- status:4
- })
- }
- that.setData({
- HelpCount: res.data.data.count,
- HelpPrice: res.data.data.price,
- pricePercent: res.data.data.pricePercent
- })
- } else {
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 2000
- })
- that.setData({
- HelpCount: 0,
- HelpPrice:0,
- pricePercent:0
- })
- }
- }
- })
- },
- getCutList:function(){
- wx.navigateTo({
- url: '/pages/cut-list/cut-list'
- })
- },//砍价成功后支付订单
- goOrderPay:function(){
- var that = this;
- if (that.data.bargainUid != app.globalData.uid){
- wx.showToast({
- title: '参数错误',
- icon: 'none',
- duration: 2000
- })
- }else{
- wx.request({
- url: app.globalData.url + '/routine/auth_api/now_buy?uid=' + app.globalData.uid,
- method: 'GET',
- data: {
- productId: that.data.product.product_id,
- cartNum: that.data.product.num,
- bargainId: that.data.product.id,
- },
- success: function (res) {
- if (res.data.code == 200) {
- wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
- url: '/pages/order-confirm/order-confirm?id=' + res.data.data.cartId
- })
- } else {
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 2000
- })
- }
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- rules:function(e){
- this.setData({
- hiddens:false
- })
- },
- butguan:function(e){
- this.setData({
- hiddens: true
- })
- },
- butguan2:function(e){
- this.setData({
- hiddens2: true
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- addLookBargain: function () {
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/add_look_bargain?uid=' + app.globalData.uid,
- method: 'GET',
- data: {
- bargainId: that.data.bargainId,
- },
- success: function (res) {
- that.getBargainCount();
- }
- })
- },
- addShareBargain:function(){
- var that = this;
- wx.request({
- url: app.globalData.url + '/routine/auth_api/add_share_bargain?uid=' + app.globalData.uid,
- method: 'GET',
- data: {
- bargainId: that.data.bargainId,
- },
- success: function (res) {
- that.getBargainCount();
- }
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- var that = this;
- return {
- title: that.data.bargainUserInfo.nickname+'邀请您帮砍价',
- path: '/pages/cut-one/cut-one?bargainUid=' + that.data.bargainUid + '&id=' + that.data.bargainId,
- imageUrl: that.data.url + that.data.product.image,
- success:function(){
- that.addShareBargain();
- wx.showToast({
- title: '分享成功',
- icon: 'success',
- duration: 2000
- })
- }
- }
- }
- })
|