C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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