index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. mixins: [require('../../mixin/cartMixin.js')],
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. list: [],
  10. supplyList: [],
  11. noMore: false,
  12. supply_diy_name: "供应商"
  13. },
  14. page: 1,
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. app.setShareConfig();
  20. this.getData();
  21. },
  22. /**
  23. * 授权成功回调
  24. */
  25. authSuccess: function () {
  26. let that = this;
  27. this.page = 1;
  28. this.setData({
  29. needAuth: false,
  30. noMore: false,
  31. list: [],
  32. supplyList: []
  33. }, ()=>{
  34. that.getData();
  35. })
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. let that = this;
  42. util.check_login_new().then((res) => {
  43. if (res) {
  44. this.setData({ needAuth: false });
  45. } else {
  46. this.setData({ needAuth: true, navBackUrl: `/lionfish_comshop/pages/supply/index` });
  47. }
  48. })
  49. },
  50. getData: function () {
  51. wx.showLoading();
  52. var token = wx.getStorageSync('token');
  53. var that = this;
  54. var cur_community = wx.getStorageSync('community');
  55. app.util.request({
  56. 'url': 'entry/wxapp/index',
  57. 'data': {
  58. controller: 'supply.get_list',
  59. token: token,
  60. page: that.page,
  61. head_id: cur_community.communityId
  62. },
  63. dataType: 'json',
  64. success: function (res) {
  65. wx.stopPullDownRefresh();
  66. wx.hideLoading();
  67. if (that.page==1) {
  68. let supply_diy_name = res.data.supply_diy_name || '供应商';
  69. wx.setNavigationBarTitle({
  70. title: `${supply_diy_name}列表`,
  71. })
  72. that.setData({ supply_diy_name })
  73. }
  74. if (res.data.code == 0) {
  75. let oldList = that.data.supplyList;
  76. let supplyList = oldList.concat(res.data.data);
  77. that.setData({ supplyList })
  78. } else {
  79. that.setData({ noMore: true })
  80. }
  81. }
  82. })
  83. },
  84. goDetails: function(e){
  85. let id = e.currentTarget.dataset.id || 0;
  86. id && wx.navigateTo({
  87. url: `/lionfish_comshop/pages/supply/home?id=${id}`,
  88. })
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. let that = this;
  95. this.page = 1;
  96. this.setData({
  97. noMore: false,
  98. list: [],
  99. supplyList: []
  100. }, () => {
  101. that.getData();
  102. })
  103. },
  104. openSku: function(e) {
  105. if (!this.authModal()) return;
  106. let shopidx = e.currentTarget.dataset.shopidx;
  107. let supplyList = this.data.supplyList;
  108. let rushList = supplyList[shopidx].goods_list || [];
  109. this.setData({ list: rushList })
  110. var that = this;
  111. let idx = e.currentTarget.dataset.idx;
  112. let spuItem = rushList[idx];
  113. var goods_id = spuItem.actId;
  114. var options = spuItem.skuList;
  115. that.setData({
  116. addCar_goodsid: goods_id
  117. })
  118. let list = options.list || [];
  119. let arr = [];
  120. if (list.length > 0) {
  121. for (let i = 0; i < list.length; i++) {
  122. let sku = list[i]['option_value'][0];
  123. let temp = {
  124. name: sku['name'],
  125. id: sku['option_value_id'],
  126. index: i,
  127. idx: 0
  128. };
  129. arr.push(temp);
  130. }
  131. //把单价剔除出来begin
  132. var id = '';
  133. for (let i = 0; i < arr.length; i++) {
  134. if (i == arr.length - 1) {
  135. id = id + arr[i]['id'];
  136. } else {
  137. id = id + arr[i]['id'] + "_";
  138. }
  139. }
  140. var cur_sku_arr = options.sku_mu_list[id];
  141. that.setData({
  142. sku: arr,
  143. sku_val: 1,
  144. cur_sku_arr: cur_sku_arr,
  145. skuList: spuItem.skuList,
  146. visible: true,
  147. showSku: true
  148. });
  149. } else {
  150. let goodsInfo = spuItem;
  151. that.setData({
  152. sku: [],
  153. sku_val: 1,
  154. skuList: [],
  155. cur_sku_arr: goodsInfo
  156. })
  157. let formIds = {
  158. detail: {
  159. formId: ""
  160. }
  161. };
  162. formIds.detail.formId = "the formId is a mock one";
  163. that.gocarfrom(formIds);
  164. }
  165. },
  166. /**
  167. * 页面上拉触底事件的处理函数
  168. */
  169. onReachBottom: function () {
  170. this.data.noMore || (this.page++, this.getData());
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. },
  177. onShareTimeline: function () {
  178. }
  179. })