index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // pointExchange/index.js
  2. const app = getApp();
  3. import util from '../utils/util.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. appAssetsUrl:app.appAssetsUrl,
  10. tools:[{
  11. text:'积分任务'
  12. },{
  13. text:'积分中心'
  14. },{
  15. text:'我的兑换'
  16. }],
  17. typeList: [],
  18. typeListIndex: 0,
  19. nameListEle: [],
  20. totalScore: '--',//总积分
  21. itemData:{
  22. id:'',
  23. needScore: '--'
  24. },
  25. nodata: util.nodata(),
  26. params: {
  27. pageNum: 1,
  28. pageSize: 10,
  29. type: ''
  30. },
  31. total:{
  32. currPage: 0,
  33. totalPage: 0
  34. },
  35. noMore:false,
  36. listData:[],
  37. navScrollWidth: 0,
  38. statusBarHeight: 0,
  39. statusBarMH: 0
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. this.height();
  46. this.loadData();
  47. this.getTypeList();
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function() {
  53. //获得popup组件
  54. this.popup = this.selectComponent("#popup");
  55. this.popup2 = this.selectComponent("#popup2");
  56. this.popup3 = this.selectComponent("#popup3");
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function () {
  62. this.loadData();
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload: function () {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function () {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. },
  89. // 自定义高度处理
  90. height() {
  91. const { platform, statusBarHeight } = wx.getSystemInfoSync()
  92. let height = statusBarHeight + 4 //ios 24px
  93. let mH = statusBarHeight + 4
  94. if (platform.toLowerCase() == "android") {
  95. height += 4 //android 28px
  96. mH += 4
  97. }
  98. height = height + 38
  99. // 胶囊高度 32px 下边框6px height 状态栏高度
  100. this.setData({
  101. statusBarHeight: height + 'px',
  102. statusBarMH: mH + 'px'
  103. })
  104. },
  105. switchType(e) {
  106. let index = e.currentTarget.dataset.index;
  107. this.setData({
  108. typeListIndex: index
  109. })
  110. this.scroll(index);
  111. this.loadList(true);
  112. },
  113. back(){
  114. wx.navigateBack();
  115. },
  116. toDatail(e){
  117. wx.navigateTo({
  118. url: `/pointExchange/pages/detail/detail?id=${e.currentTarget.dataset.id}&totalScore=${this.data.totalScore}`
  119. })
  120. },
  121. goTool(e){
  122. let index = e.currentTarget.dataset.index;
  123. if(index == 0){
  124. wx.navigateTo({
  125. url:'/pointExchange/pages/task/task'
  126. })
  127. }else if(index == 1){
  128. wx.navigateTo({
  129. url:`/pointExchange/pages/center/center?totalScore=${this.data.totalScore}`
  130. })
  131. }else if(index == 2){
  132. wx.navigateTo({
  133. url:'/pointExchange/pages/my/my'
  134. })
  135. }
  136. },
  137. getTypeList(){
  138. let that = this;
  139. app._post_form('productType/list', '', null,
  140. function(res) {
  141. if (res.code == 0) {
  142. that.setData({
  143. typeList: res.data
  144. })
  145. wx.nextTick(() => {
  146. let query = wx.createSelectorQuery();
  147. query.selectAll('.nameitem').boundingClientRect().exec(function (res) {
  148. let nameListEle = [];
  149. for(let i in res[0]){
  150. nameListEle.push(res[0][i].width*1);
  151. }
  152. that.setData({
  153. nameListEle
  154. })
  155. })
  156. })
  157. that.loadList(true);
  158. }
  159. })
  160. },
  161. scroll(index){
  162. let that = this;
  163. let leftNum = 0;
  164. if(index>0){
  165. for(let i in that.data.nameListEle){
  166. if(i<index){
  167. leftNum += that.data.nameListEle[i];
  168. leftNum += (20 / 750 * wx.getSystemInfoSync().windowWidth)
  169. }
  170. }
  171. }
  172. that.setData({
  173. navScrollWidth: leftNum
  174. })
  175. },
  176. loadData() {
  177. let that = this;
  178. app._post_form('scoreStu/totalScore', '', {
  179. stuId: util.getUserId()
  180. },
  181. function(res) {
  182. if (res.code == 0) {
  183. that.setData({
  184. totalScore: res.data
  185. })
  186. }
  187. })
  188. },
  189. bindscrolltolower(){
  190. this.loadList();
  191. },
  192. loadList(isRefresh) {
  193. let that = this;
  194. if (!isRefresh && this.data.noMore) {
  195. wx.showToast({
  196. title: '没有更多了~',
  197. icon: 'none'
  198. })
  199. return false;
  200. }
  201. this.setData({
  202. listData: isRefresh ? [] : this.data.listData,
  203. noMore: isRefresh ? false : this.data.noMore,
  204. params: {
  205. ...this.data.params,
  206. pageNum: isRefresh?1:this.data.params.pageNum+1,
  207. type: this.data.typeList[this.data.typeListIndex].id
  208. }
  209. })
  210. wx.showLoading({
  211. title: '努力加载中...',
  212. })
  213. app._post_form('product/page', '', this.data.params,
  214. function(res) {
  215. if (res.code == 0) {
  216. if(res.page.list.length>0 && that.data.listData.length>0 && res.page.list[0].id == that.data.listData[0].id){
  217. return ;
  218. }
  219. let listData = that.data.listData;
  220. listData.push(...res.page.list);
  221. that.setData({
  222. listData,
  223. currPage: res.page.currPage,
  224. totalPage: res.page.totalPage,
  225. noMore: res.page.totalPage == res.page.currPage
  226. })
  227. }
  228. })
  229. },
  230. //弹窗
  231. showPopup(e) {
  232. this[e.currentTarget.dataset.name].showPopup();
  233. this.setData({
  234. itemData:{
  235. ...this.data.itemData,
  236. id: e.currentTarget.dataset.id,
  237. needScore: e.currentTarget.dataset.needscore
  238. }
  239. })
  240. },
  241. //取消事件
  242. _error(e) {
  243. this[e.currentTarget.dataset.name].hidePopup();
  244. },
  245. useCoupon(e) {
  246. this.popup.hidePopup();
  247. let that = this;
  248. wx.showLoading({
  249. title: '提交中...',
  250. })
  251. app._post_form('product/exchange', "", {
  252. pId: this.data.itemData.id,
  253. stuId: util.getUserId()
  254. }, function(res) {
  255. if (res.code === 0) {
  256. that.loadData();
  257. that.popup2.showPopup();
  258. }
  259. })
  260. },
  261. toPointExchangeByMe(){
  262. this.popup2.hidePopup();
  263. wx.navigateTo({
  264. url:'/pointExchange/pages/my/my'
  265. })
  266. }
  267. })