C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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