index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/index/index.js
  2. var app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. indicatorDors: true,
  9. autoplay: true,
  10. interval:4000,
  11. duration:500,
  12. activeCategoryId:0,
  13. zw:'',
  14. imgUrls: [
  15. '../../images/ban11.jpg',
  16. '../../images/ban22.jpg'
  17. ],
  18. imgurl: app.data.resturl,
  19. utype:app.globalData.utype,
  20. keywords:''
  21. },
  22. tabClick: function(e){
  23. this.setData({
  24. activeCategoryId: e.currentTarget.id
  25. })
  26. wx.showLoading({
  27. title: '加载中',
  28. mask: true,
  29. success: ()=>{
  30. this.getGoodsList(e.currentTarget.id)
  31. }
  32. })
  33. // this.getGoodsList(e.currentTarget.id)
  34. },
  35. getGoodsList: function(){
  36. var that = this;
  37. let name = this.data.keywords;
  38. wx.request({
  39. url: app.data.resturl + '/index.action',
  40. data: {
  41. name:name
  42. },
  43. success:function(res){
  44. that.setData({
  45. goods: res.data.dlist
  46. })
  47. setTimeout(()=>{
  48. wx.hideLoading()
  49. },500)
  50. }
  51. })
  52. },
  53. tabDetails(e){
  54. let kucun = e.currentTarget.dataset.kucun;
  55. let id = e.currentTarget.dataset.id;
  56. let cid = e.currentTarget.dataset.cid;
  57. console.log(kucun + " " + id + " " + cid);
  58. if (kucun <= 0) {
  59. wx.navigateTo({
  60. url: '../../pages/tjlist/tjlist?cid=' + cid + "&id=" + id,
  61. })
  62. }else{
  63. wx.navigateTo({
  64. url: '/pages/goods-details/index?id=' + e.currentTarget.dataset.id
  65. })
  66. }
  67. },
  68. /**
  69. * 生命周期函数--监听页面加载
  70. */
  71. onLoad: function (options) {
  72. let zw = options.zw;
  73. if(zw==null){
  74. zw = '201';
  75. }
  76. app.globalData.zw = zw;
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. var that = this;
  88. that.getGoodsList();
  89. },
  90. goYuyue: function () {
  91. let uid = app.globalData.openid;
  92. if (uid == '') {
  93. wx.redirectTo({
  94. url: '../../pages/login/login'
  95. })
  96. return;
  97. }
  98. wx.navigateTo({
  99. url: '../../pages/yuyue/yuyue'
  100. })
  101. },
  102. goGonggao: function () {
  103. wx.navigateTo({
  104. url: '../../pages/gglist/gglist'
  105. })
  106. },
  107. goLiuyan: function () {
  108. let openid = app.globalData.openid;
  109. if (openid == '') {
  110. wx.redirectTo({
  111. url: '../../pages/login/login',
  112. })
  113. return;
  114. };
  115. wx.navigateTo({
  116. url: '../../pages/liuyan/liuyan'
  117. })
  118. },
  119. searchr: function () {
  120. this.getGoodsList();
  121. },
  122. keywordsInput: function (e) {
  123. let keywords = e.detail.value;
  124. this.setData({
  125. keywords: keywords
  126. });
  127. }
  128. })