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.

340 lines
8.2 KiB

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