index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // pages/index/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. icon: { name: 'tag', isShow: true },
  9. cardCur: 0,
  10. swiperList: [{
  11. id: 0,
  12. type: 'image',
  13. url: 'https://cdn.pixabay.com/photo/2018/09/24/15/04/board-3700116__340.jpg'
  14. }, {
  15. id: 1,
  16. type: 'image',
  17. url: 'https://cdn.pixabay.com/photo/2015/09/02/12/26/desk-918425__340.jpg',
  18. }, {
  19. id: 2,
  20. type: 'image',
  21. url: 'https://cdn.pixabay.com/photo/2015/07/31/14/59/creative-869200__340.jpg'
  22. }, {
  23. id: 3,
  24. type: 'image',
  25. url: 'https://cdn.pixabay.com/photo/2019/03/12/20/27/kanban-4051777__340.jpg'
  26. }],
  27. jobList:[
  28. {
  29. tittle:"测试数据的标题",
  30. reward:"180/天",
  31. place:"西乡塘",
  32. settlement:1,
  33. isBagEating:1,
  34. encase:1,
  35. isTrafficSubsidy:1,
  36. royalty:1
  37. },
  38. {
  39. tittle: "测试数据的标题",
  40. reward: "90/天",
  41. place: "西乡塘",
  42. settlement: 1,
  43. isBagEating: 0,
  44. encase: 1,
  45. isTrafficSubsidy: 1,
  46. royalty: 0
  47. },
  48. {
  49. tittle: "测试数据的标题",
  50. reward: "50/天",
  51. place: "西乡塘",
  52. settlement: 1,
  53. isBagEating: 1,
  54. encase: 0,
  55. isTrafficSubsidy: 0,
  56. royalty: 1
  57. },
  58. {
  59. tittle: "测试数据的标题",
  60. reward: "80/天",
  61. place: "西乡塘",
  62. settlement: 3,
  63. isBagEating: 1,
  64. encase: 1,
  65. isTrafficSubsidy: 1,
  66. royalty: 1
  67. },
  68. {
  69. tittle: "测试数据的标题",
  70. reward: "80/天",
  71. place: "西乡塘",
  72. settlement: 2,
  73. isBagEating: 1,
  74. encase: 1,
  75. isTrafficSubsidy: 0,
  76. royalty: 1
  77. }
  78. ],
  79. page:1,
  80. page_size:6,
  81. isover:1,
  82. value:"123"
  83. },
  84. //点击搜索按钮
  85. search: function (event) {
  86. try {
  87. var value = wx.getStorageSync('uid')
  88. if (!value) {
  89. wx.showToast({
  90. title: '请到个人中心登录',
  91. icon: 'none'
  92. })
  93. }
  94. if (value) {
  95. wx.navigateTo({
  96. url: 'search/search',
  97. })
  98. }
  99. } catch (e) {
  100. console.log(e)
  101. }
  102. },
  103. // 跳转至商品详情
  104. job: function (e){
  105. try {
  106. var value = wx.getStorageSync('uid')
  107. if (!value) {
  108. wx.showToast({
  109. title: '请到个人中心登录',
  110. icon: 'none'
  111. })
  112. }
  113. if(value){
  114. wx.navigateTo({
  115. url: '../commodity-detail/commodity-detail?id=' + e.currentTarget.dataset.id,
  116. })
  117. }
  118. } catch (e) {
  119. console.log(e)
  120. }
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function () {
  126. var _this = this
  127. wx.request({
  128. url: app.globalData.baseURL + '/job/jobs',
  129. method: 'GET',
  130. success(res) {
  131. _this.setData({
  132. jobList: res.data.data
  133. });
  134. console.log(res.data.data)
  135. }
  136. })
  137. },
  138. /**
  139. * 生命周期函数--监听页面加载
  140. */
  141. onLoad: function (options) {
  142. // var _this = this
  143. // wx.request({
  144. // url: app.globalData.baseURL + '/jobs/',
  145. // method: 'GET',
  146. // data: {
  147. // "page": 1,
  148. // "page_size": 6,
  149. // },
  150. // success(res) {
  151. // _this.setData({
  152. // jobList: res.data ,
  153. // page: 2
  154. // });
  155. // console.log(_this.data.jobList)
  156. // }
  157. // })
  158. this.towerSwiper('swiperList');
  159. },
  160. DotStyle(e) {
  161. this.setData({
  162. DotStyle: e.detail.value
  163. })
  164. },
  165. // cardSwiper
  166. cardSwiper(e) {
  167. this.setData({
  168. cardCur: e.detail.current
  169. })
  170. },
  171. // towerSwiper
  172. // 初始化towerSwiper
  173. towerSwiper(name) {
  174. let list = this.data[name];
  175. for (let i = 0; i < list.length; i++) {
  176. list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
  177. list[i].mLeft = i - parseInt(list.length / 2)
  178. }
  179. this.setData({
  180. swiperList: list
  181. })
  182. },
  183. // towerSwiper触摸开始
  184. towerStart(e) {
  185. this.setData({
  186. towerStart: e.touches[0].pageX
  187. })
  188. },
  189. // towerSwiper计算方向
  190. towerMove(e) {
  191. this.setData({
  192. direction: e.touches[0].pageX - this.data.towerStart > 0 ? 'right' : 'left'
  193. })
  194. },
  195. // towerSwiper计算滚动
  196. towerEnd(e) {
  197. let direction = this.data.direction;
  198. let list = this.data.swiperList;
  199. if (direction == 'right') {
  200. let mLeft = list[0].mLeft;
  201. let zIndex = list[0].zIndex;
  202. for (let i = 1; i < list.length; i++) {
  203. list[i - 1].mLeft = list[i].mLeft
  204. list[i - 1].zIndex = list[i].zIndex
  205. }
  206. list[list.length - 1].mLeft = mLeft;
  207. list[list.length - 1].zIndex = zIndex;
  208. this.setData({
  209. swiperList: list
  210. })
  211. } else {
  212. let mLeft = list[list.length - 1].mLeft;
  213. let zIndex = list[list.length - 1].zIndex;
  214. for (let i = list.length - 1; i > 0; i--) {
  215. list[i].mLeft = list[i - 1].mLeft
  216. list[i].zIndex = list[i - 1].zIndex
  217. }
  218. list[0].mLeft = mLeft;
  219. list[0].zIndex = zIndex;
  220. this.setData({
  221. swiperList: list
  222. })
  223. }
  224. },
  225. /**
  226. * 页面相关事件处理函数--监听用户下拉动作
  227. */
  228. onPullDownRefresh: function () {
  229. console.log("下拉刷新")
  230. function randomSort(a, b) { return Math.random() > 0.5 ? -1 : 1; }
  231. this.setData({
  232. jobList: this.data.jobList.sort(randomSort)
  233. })
  234. wx.stopPullDownRefresh();
  235. // wx.startPullDownRefresh();
  236. },
  237. /**
  238. * 页面上拉触底事件的处理函数
  239. */
  240. onReachBottom: function () {
  241. // var _this = this
  242. // if (_this.data.isover==0){
  243. // wx.request({
  244. // url: app.globalData.baseURL + '/jobs/',
  245. // method: 'GET',
  246. // data: {
  247. // "page": _this.data.page,
  248. // "page_size": 6,
  249. // },
  250. // success(res) {
  251. // if (res.statusCode == 200) {
  252. // _this.setData({
  253. // jobList: _this.data.jobList.concat(res.data),
  254. // page: _this.data.page + 1
  255. // });
  256. // console.log(res)
  257. // } else {
  258. // console.log('没有更多了哦')
  259. // _this.setData({
  260. // isover: 1,
  261. // });
  262. // }
  263. // }
  264. // })
  265. // }
  266. },
  267. })