东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
5.9KB

  1. // pages/mountings/mountings.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. activityRule:false,//是否显示活动规则
  10. dataList:[],//数据列表
  11. userInfoData:false,//是否已获取用户头像昵称
  12. isAddress:false,//是否有地址
  13. addressShow:false,
  14. dateList:[],//日期列表
  15. dateChoose:'',//当前日的活动列表
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. app.globalData.nowPage = 3;
  22. if (app.globalData.openid) {
  23. this.loadFun();
  24. } else {
  25. app.globalData.openidSuccessFuc = this.loadFun;
  26. }
  27. },
  28. loadFun: function () {
  29. this.detectionUserMsg();
  30. this.getAddress();
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. this.getActivityDate();
  42. },
  43. /**
  44. * 生命周期函数--监听页面隐藏
  45. */
  46. onHide: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面卸载
  50. */
  51. onUnload: function () {
  52. },
  53. /**
  54. * 页面相关事件处理函数--监听用户下拉动作
  55. */
  56. onPullDownRefresh: function () {
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom: function () {
  62. },
  63. /**
  64. * 用户点击右上角分享
  65. */
  66. onShareAppMessage: function () {
  67. return {
  68. title: '我正在参与启辰星秒杀增配活动,一起来秒杀!',
  69. imageUrl: this.data.imgUrl+'/newImages9/13.png',
  70. path: "/pages/mountings/mountings"
  71. }
  72. },
  73. ruleShowControl(){//控制活动规则的显示与隐藏
  74. this.setData({
  75. activityRule:!this.data.activityRule
  76. })
  77. },
  78. detectionUserMsg(){//检测是否已获取用户头像昵称
  79. if(app.globalData.userInfoData && app.globalData.userInfoData.avatarUrl){
  80. this.setData({
  81. userInfoData:true
  82. })
  83. }else{
  84. app.globalData.userInfoSuccessFuc = this.detectionUserMsg;
  85. }
  86. },
  87. getAddress: function () {//获取地址
  88. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  89. if (res.code == 200) {
  90. if (res.data) {
  91. this.data.isAddress = true;
  92. }
  93. }
  94. }, this)
  95. },
  96. joinActivity(e){
  97. let state = e.target.dataset.state;
  98. let index = e.target.dataset.index;
  99. if(state==-1){//我要砍价
  100. if(this.data.isAddress){
  101. this.beginBargain(this.data.dataList[index]);
  102. }else{
  103. this.setData({
  104. addressShow: true
  105. })
  106. }
  107. }else if(state==0){//查看详情
  108. wx.navigateTo({
  109. url: '/pages/mountingsDetail/mountingsDetail?datas='+JSON.stringify(this.data.dataList[index]),
  110. })
  111. }else if(state==1){//已经成功
  112. wx.reLaunch({
  113. url: '/pages/myCenter/myCenter'
  114. })
  115. }
  116. },
  117. beginBargain(data){//发起砍价活动
  118. app.wxRequest(app.globalData.urlRoot + "bargain/beginBargain", {activity_id:data.id}, res => {
  119. if (res.code == 200) {
  120. data.activity_token = res.data.activity_token;
  121. wx.navigateTo({
  122. url: '/pages/mountingsDetail/mountingsDetail?datas='+JSON.stringify(data),
  123. })
  124. }else{
  125. wx.showToast({
  126. title: res.msg,
  127. icon: "none"
  128. })
  129. }
  130. }, this,"POST");
  131. },
  132. getUserWxMsg:function(e){//通过微信获取用户信息
  133. if (e.detail.errMsg == "getUserInfo:ok") {
  134. app.globalData.userInfoData = {};
  135. app.globalData.userInfoData.avatarUrl = e.detail.userInfo.avatarUrl;
  136. app.globalData.userInfoData.nickName = e.detail.userInfo.nickName;
  137. this.setData({
  138. userInfoData: true
  139. })
  140. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  141. if(this.data.isAddress){
  142. wx.navigateTo({
  143. url: '/pages/mountingsDetail/mountingsDetail',
  144. })
  145. }else{
  146. this.setData({
  147. addressShow: true
  148. })
  149. }
  150. }
  151. },
  152. addressControl: function () {//跳转到地址管理
  153. this.setData({
  154. addressShow: !this.data.addressShow
  155. })
  156. if(!this.data.isAddress){
  157. this.getAddress();
  158. }
  159. },
  160. getActivityDate:function(){//获取展示日期
  161. app.wxRequest(app.globalData.urlRoot + "bargain/getActivityDate", {}, res => {
  162. if (res.code == 200) {
  163. for(let i=0;i<res.data.length;i++){
  164. let date = res.data[i]['activity_date'].split('-');
  165. res.data[i]['activity_date_show'] = date[1]+'月'+date[2]+'日';
  166. }
  167. if(res.data[0]){
  168. this.setData({
  169. dateChoose:res.data[0]['activity_date']
  170. })
  171. this.getActivityList();
  172. this.setData({
  173. dateList:res.data
  174. })
  175. }
  176. }
  177. }, this);
  178. },
  179. getActivityList:function(){//获取某日的活动列表
  180. app.wxRequest(app.globalData.urlRoot + "bargain/getActivityList", {activity_date:this.data.dateChoose}, res => {
  181. if (res.code == 200) {
  182. for(let i=0;i<res.data.list.length;i++){
  183. res.data.list[i]['goods_origin_price2'] = res.data.list[i]['goods_origin_price']/100;//原价(单位:分改为元)
  184. res.data.list[i]['goods_final_price2'] = res.data.list[i]['goods_final_price']/100;//底价(单位:分改为元)
  185. res.data.list[i]['goods_surplus_num'] = res.data.list[i]['goods_total_num']-res.data.list[i]['goods_success_num'];//剩余数量
  186. res.data.list[i]['consumeNum'] = Math.ceil((1-res.data.list[i]['goods_surplus_num']/res.data.list[i]['goods_total_num'])*100);//已抢进度
  187. }
  188. this.setData({
  189. dataList:res.data.list
  190. })
  191. }
  192. }, this);
  193. },
  194. dateChange(e){//选中日期发生改变
  195. var index = e.currentTarget.dataset.index;
  196. if(this.data.dateChoose != this.data.dateList[index]['activity_date']){
  197. this.setData({
  198. dateChoose:this.data.dateList[index]['activity_date']
  199. })
  200. this.getActivityList();
  201. }
  202. }
  203. })