C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

310 行
7.6 KiB

  1. var config = require("../../config/config.js");
  2. const Http = require("../../utils/HttpBasics");
  3. const imgurl = require("../../utils/imgurl");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. orangeImg: imgurl.orange.url,
  10. blueImg: imgurl.blue.url,
  11. grayImg: imgurl.gray.url,
  12. bannerUrl: imgurl.banner.url,
  13. loadingUrl: imgurl.loading.url,
  14. bargaincancel: imgurl.bargaincancel.url,
  15. wmhome: imgurl.wmhome.url,
  16. bargainfail: imgurl.bargainfail.url,
  17. bargainsuccess: imgurl.bargainsuccess.url,
  18. bargaingoods: true,
  19. mybargain: false,
  20. list: [],
  21. lists: [],
  22. page: 1, // 设置加载的第几次,默认是第一次
  23. pageSize: 10, //返回数据的个数
  24. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  25. allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成
  26. myorder: false,
  27. actUrl: imgurl.act.url,
  28. loadingUrl: imgurl.loading.url,
  29. flag: 'bargaingoods',
  30. },
  31. goback: function () {
  32. wx.switchTab({
  33. url: '/pages/main/index',
  34. })
  35. },
  36. onLoad: function (options) {
  37. console.log(options)
  38. let that = this;
  39. // options.from =='myhtml'
  40. // 来自我的列表
  41. if (options && options.from =='myhtml'){
  42. that.mybargain();
  43. }else{
  44. that.getList(1, "bargaingoods");
  45. that.setData({
  46. flag: "bargaingoods",
  47. bargaingoods: true,
  48. mybargain: false
  49. })
  50. }
  51. that.getBannerlist();
  52. var todayDate=new Date().getTime();
  53. that.setData({
  54. todayDate:todayDate
  55. })
  56. },
  57. /**
  58. * banner
  59. */
  60. getBannerlist: function () {
  61. let that = this;
  62. Http.get({
  63. url: config.api.bannerlist,
  64. data: {
  65. pageNum: 1,
  66. pageSize: 7
  67. }
  68. }).then(res => {
  69. that.setData({
  70. list: res.data.list
  71. });
  72. });
  73. },
  74. getList(pageNum, flag) {
  75. var that = this;
  76. console.log(pageNum)
  77. if (that.data.allow_load) {
  78. /**
  79. * mybargain: 我的砍价
  80. * bargaingoods: 砍价商品
  81. */
  82. that.setData({
  83. loading: true,
  84. content: '小主,我在玩命加载中...'
  85. })
  86. var param = {};
  87. if (flag == 'mybargain') {
  88. that.setData({
  89. flag: "mybargain"
  90. })
  91. var param = {
  92. pageNum: pageNum,
  93. pageSize: 10
  94. };
  95. var url = config.api.pressOrderList;
  96. } else if (flag == 'bargaingoods') {
  97. that.setData({
  98. flag: "bargaingoods"
  99. })
  100. var param = {
  101. pageNum: pageNum,
  102. pageSize: 10,
  103. targetAd: 6
  104. };
  105. var url = config.api.couponChannelList;
  106. }
  107. // 请求接口
  108. Http.get({
  109. url: url,
  110. data: param
  111. }).then(res => {
  112. console.log(res)
  113. /**
  114. * 加载完成
  115. */
  116. if (pageNum >= res.data.pages) {
  117. if (res.data.pages == 0 || res.data.pages == 1) {
  118. that.setData({
  119. allow_load: true,
  120. loading: false,
  121. content: ""
  122. });
  123. } else {
  124. that.setData({
  125. allow_load: false,
  126. loading: true,
  127. content: "——— 再拉裤子就掉了啦 ———",
  128. });
  129. }
  130. }
  131. if (pageNum == 1) {
  132. that.setData({
  133. lists: [],
  134. })
  135. }
  136. if (flag == 'bargaingoods'){
  137. var tmpArr = that.data.lists;
  138. tmpArr.push.apply(tmpArr, res.data.list);
  139. that.setData({
  140. lists: tmpArr
  141. })
  142. } else if (flag == 'mybargain'){
  143. console.log(res.data.list)
  144. var tmpArr = that.data.lists;
  145. tmpArr.push.apply(tmpArr, res.data.list);
  146. console.log(tmpArr)
  147. let lists = [];
  148. tmpArr.map(file => {
  149. if (file.orderStatus != 1) {
  150. lists.push(file);
  151. }
  152. })
  153. that.setData({
  154. lists: lists
  155. })
  156. }
  157. wx.stopPullDownRefresh();
  158. })
  159. .catch(err => {
  160. wx.stopPullDownRefresh();
  161. wx.showToast({
  162. title: err.message,
  163. icon: 'none',
  164. duration: 2000,
  165. mask: false
  166. });
  167. })
  168. setTimeout(function () {
  169. that.setData({
  170. loading: false,
  171. })
  172. }, 1400);
  173. } else {
  174. that.setData({
  175. loading: true,
  176. content: "——— 再拉裤子就掉了啦 ———"
  177. })
  178. setTimeout(function () {
  179. that.setData({
  180. loading: false,
  181. })
  182. }, 1400)
  183. }
  184. },
  185. /**
  186. * 如果是重新砍价,需要重新下单
  187. */
  188. orderSave: function (couponId,couponChannelId,formId) {
  189. Http.post({
  190. url: config.api.orderSave,
  191. data: {
  192. couponId: "" + couponId,
  193. formId:formId,
  194. couponChannelId:""+couponChannelId,
  195. press: true
  196. }
  197. })
  198. .then(res => {
  199. console.log(res)
  200. wx.navigateTo({
  201. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.orderNumber}`
  202. })
  203. })
  204. .catch(err => {
  205. wx.showToast({
  206. title: err.message,
  207. icon: "none"
  208. })
  209. })
  210. },
  211. inviteFriend: function (e) {
  212. /**
  213. * 添加标识
  214. */
  215. wx.navigateTo({
  216. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  217. })
  218. },
  219. barginAgain: function (e) {
  220. let that = this;
  221. console.log(e)
  222. let formId = e.detail.formId;
  223. let couponId = e.currentTarget.dataset.couponid;
  224. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  225. // let orderId = e.currentTarget.dataset.id;
  226. that.orderSave(couponId,couponChannelId,formId)
  227. },
  228. mybargain: function () {
  229. let that = this;
  230. that.setData({
  231. bargaingoods: false,
  232. mybargain: true,
  233. flag: "mybargain",
  234. allow_load: true,
  235. loading: false,
  236. content: "",
  237. page:1
  238. })
  239. that.getList(1, 'mybargain');
  240. wx.setNavigationBarTitle({
  241. title: '我的砍价'
  242. })
  243. },
  244. bargaingoods: function () {
  245. let that = this;
  246. that.setData({
  247. bargaingoods: true,
  248. mybargain: false,
  249. flag: "bargaingoods",
  250. allow_load: true,
  251. loading: false,
  252. page:1,
  253. content: ""
  254. })
  255. that.getList(1, 'bargaingoods');
  256. wx.setNavigationBarTitle({
  257. title: '砍价专场'
  258. })
  259. },
  260. /**
  261. *
  262. * @param {砍价} 发起砍价
  263. */
  264. invite: function (e) {
  265. let couponChannelId = e.currentTarget.dataset.id;
  266. let couponId = e.currentTarget.dataset.couponid;
  267. if (couponChannelId && couponId) {
  268. wx.navigateTo({
  269. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  270. })
  271. }
  272. },
  273. //加载更多
  274. onReachBottom: function () {
  275. let that = this;
  276. that.data.page++;
  277. that.setData({
  278. page: that.data.page
  279. });
  280. that.getList(that.data.page, that.data.flag);
  281. },
  282. /**
  283. * 刷新
  284. */
  285. onPullDownRefresh: function (e) {
  286. let that = this;
  287. if (that.data.flag == 'bargaingoods'){
  288. that.getBannerlist();
  289. var todayDate = new Date().getTime();
  290. that.setData({
  291. todayDate: todayDate
  292. })
  293. that.getList(1, "bargaingoods");
  294. that.setData({
  295. flag: "bargaingoods",
  296. bargaingoods: true,
  297. mybargain: false
  298. })
  299. } else if (that.data.flag == 'mybargain'){
  300. that.getList(1, "mybargain");
  301. that.setData({
  302. flag: "mybargain",
  303. bargaingoods: false,
  304. mybargain: true
  305. })
  306. }
  307. },
  308. })