granary.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. var _request = require('../../../../utils/request.js')
  2. Page({
  3. data: {
  4. page: 1,
  5. per_page: 10,
  6. productList: [],
  7. productTotal: 0,
  8. more: true,
  9. show: false,
  10. angle: 0,
  11. curIndex: 0
  12. },
  13. onLoad: function (options) {
  14. this.getIphoneX()
  15. this.getProductList()
  16. },
  17. onShow: function () {
  18. this.data.page = 1
  19. // this.getProductList()
  20. },
  21. toFarm() {
  22. wx.redirectTo({
  23. url: '/packageUser/pages/user/farm/farm'
  24. })
  25. },
  26. toSell(e) {
  27. wx.navigateTo({
  28. url: '/packageUser/pages/user/granary/use/use?tab=sell&order_id=' + e.currentTarget.dataset.id
  29. })
  30. },
  31. toBack(e) {
  32. wx.navigateTo({
  33. url: '/packageUser/pages/user/granary/use/use?tab=return&order_id=' + e.currentTarget.dataset.id
  34. })
  35. },
  36. toMine(e) {
  37. wx.navigateTo({
  38. url: '/packageUser/pages/user/granary/use/use?tab=mine&order_id=' + e.currentTarget.dataset.id
  39. })
  40. },
  41. toMine1(e) {
  42. wx.navigateTo({
  43. url: '/packageUser/pages/user/granary/use/use?tab=mine1&order_id=' + e.currentTarget.dataset.id
  44. })
  45. },
  46. review (e) {
  47. var that = this
  48. that.data.show = !that.data.show
  49. if (that.data.show) {
  50. that.data.angle = 180
  51. } else {
  52. that.data.angle = 0
  53. }
  54. that.data.curIndex = e.currentTarget.dataset.cur
  55. if (that.data.curIndex === e.currentTarget.dataset.cur) {
  56. that.setData({
  57. show: that.data.show,
  58. angle: that.data.angle,
  59. curIndex: that.data.curIndex
  60. })
  61. }
  62. },
  63. getProductList () {
  64. var that = this
  65. var url = 'v1/user/granaries'
  66. var params = {
  67. page: that.data.page,
  68. per_page: that.data.per_page,
  69. cache: false
  70. }
  71. var success = function (res) {
  72. var result = that.data.productList.concat(res.data.list || [])
  73. var listMore = res.data.list_count > that.data.productList.length
  74. that.setData({
  75. productList: result,
  76. more: listMore,
  77. productTotal: res.data.list_count
  78. })
  79. }
  80. _request.$get(url, params, success)
  81. },
  82. onReachBottom: function () {
  83. if (this.data.more) {
  84. var page = this.data.page + 1
  85. this.setData({
  86. page: page
  87. })
  88. this.getProductList()
  89. }
  90. },
  91. getIphoneX () {
  92. var that = this
  93. wx.getSystemInfo({
  94. success: function (res) {
  95. if (res.model.toLowerCase().indexOf('iphone x') > -1) {
  96. that.setData({
  97. value: 34
  98. })
  99. }
  100. }
  101. })
  102. },
  103. onShareAppMessage: function (val) {
  104. return _request.share({
  105. sc: 'xcx_user_granary'
  106. })
  107. }
  108. })