C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

335 lignes
7.9 KiB

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