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.

428 lines
10 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. noCoupon: imgurl.noCoupon.url,
  11. bannerUrl: imgurl.banner.url,
  12. loadingUrl: imgurl.loading.url,
  13. nodata: imgurl.nodata.url,
  14. wmhome: imgurl.wmhome.url,
  15. spellList: true,
  16. myspellList: false,
  17. list: [],
  18. lists: [],
  19. myLists:[],
  20. page: 1, // 设置加载的第几次,默认是第一次
  21. pageSize: 10, //返回数据的个数
  22. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  23. allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成
  24. myorder: false,
  25. actUrl: imgurl.act.url,
  26. loading:true,
  27. content:'数据正在加载中',
  28. flag: 'spellList',
  29. reloadIf:false
  30. },
  31. goback: function () {
  32. wx.switchTab({
  33. url: '/pages/main/index',
  34. })
  35. },
  36. onLoad: function (options) {
  37. let that = this;
  38. that.getBannerlist();
  39. var todayDate = new Date().getTime();
  40. that.setData({
  41. optionsData: options,
  42. todayDate: todayDate
  43. })
  44. if(options&&options.from=='myhtml'){
  45. that.getmyList();
  46. }else{
  47. // 去支付
  48. if (options && options.from == 'myspellList'){
  49. that.getList(1, "myspellList");
  50. that.setData({
  51. flag: "myspellList",
  52. spellList: false,
  53. myspellList: true,
  54. lists: null
  55. })
  56. wx.setNavigationBarTitle({
  57. title: '我的拼团'
  58. })
  59. }else{
  60. that.getList(1, "spellList");
  61. that.setData({
  62. flag: "spellList",
  63. spellList: true,
  64. myspellList: false,
  65. lists: null
  66. })
  67. wx.setNavigationBarTitle({
  68. title: '拼团专场'
  69. })
  70. }
  71. }
  72. that.getUserInfo();
  73. },
  74. onShow(){
  75. let that=this;
  76. if (this.data.reloadIf){
  77. wx.setNavigationBarTitle({
  78. title: '拼团专场'
  79. })
  80. that.getList(1, "spellList");
  81. that.setData({
  82. flag: "spellList",
  83. spellList: true,
  84. myspellList: false,
  85. lists: null
  86. })
  87. }
  88. },
  89. //切换拼团列表
  90. getSpellList(){
  91. this.setData({
  92. flag: "spellList",
  93. page:1,
  94. allow_load:true
  95. })
  96. wx.setNavigationBarTitle({
  97. title: '拼团专场'
  98. })
  99. this.getList(1, "spellList")
  100. },
  101. //去使用
  102. gotoUse(e){
  103. console.log(e)
  104. wx.navigateTo({
  105. url: '/pages/couponorder/index/index',
  106. })
  107. },
  108. //重新拼团
  109. gotoAgain(e){
  110. let data = e.currentTarget.dataset.data
  111. wx.navigateTo({
  112. url: `/pages/spellGroup/mySpellGroup/index?couponId=${data.couponId}&couponChannelId=${data.couponChannelId}`,
  113. })
  114. },
  115. //跳转到我的拼团详情
  116. gotoStatusDetail(e){
  117. console.log(e,333)
  118. let data = e.currentTarget.dataset.data
  119. wx.navigateTo({
  120. url: `/pages/spellDetail/index?orderId=${data.orderId}&couponId=${data.couponId}&orderGroupId=${data.orderGroupId}&couponChannelId=${data.couponChannelId}`,
  121. })
  122. },
  123. //切换我的拼团
  124. getmyList(){
  125. this.setData({
  126. flag: "myspellList",
  127. page: 1,
  128. allow_load: true,
  129. lists:null
  130. })
  131. wx.setNavigationBarTitle({
  132. title: '我的拼团'
  133. })
  134. this.getList(1, "myspellList")
  135. },
  136. /**
  137. * banner
  138. */
  139. getBannerlist: function () {
  140. let that = this;
  141. Http.get({
  142. url: config.api.bannerlist,
  143. data: {
  144. pageNum: 1,
  145. pageSize: 7
  146. }
  147. }).then(res => {
  148. that.setData({
  149. list: res.data.list
  150. });
  151. });
  152. },
  153. changeStatus(status){
  154. return spellStatus02.filter(item=>status==item.value)[0].name
  155. },
  156. changeStatus02(status) {
  157. console.log(status)
  158. return spellStatus.filter(item => status == item.value)[0].name
  159. },
  160. gotoPay(e){
  161. this.setData({
  162. reloadIf:true
  163. })
  164. let data = e.currentTarget.dataset.data
  165. wx.navigateTo({
  166. url: `/pages/spellGroup/paySpellGroup/index?orderId=${data.orderId}&couponId=${data.couponId}&orderGroupId=${data.orderGroupId}&couponChannelId=${data.couponChannelId}`,
  167. })
  168. },
  169. gotoEdit(e){
  170. console.log(e.currentTarget.dataset.status)
  171. let status = e.currentTarget.dataset.status
  172. if (status==10){
  173. }
  174. },
  175. getUserInfo: function () {
  176. let that = this;
  177. // 获取用户信息
  178. Http.get({
  179. url: config.api.getScore,
  180. data: {}
  181. })
  182. .then(res => {
  183. console.log(res)
  184. that.setData({
  185. nickName: res.data.nickName,
  186. avatarUrl: res.data.avatarUrl
  187. })
  188. })
  189. },
  190. getList(pageNum, flag) {
  191. var that = this;
  192. console.log(pageNum)
  193. if (that.data.allow_load) {
  194. /**
  195. * myspellList: 我的砍价
  196. * spellList: 砍价商品
  197. */
  198. that.setData({
  199. loading: true,
  200. content: '小主,我在玩命加载中...'
  201. })
  202. var param = {};
  203. if (flag == 'myspellList') {
  204. console.log(22222222)
  205. that.setData({
  206. flag: "myspellList"
  207. })
  208. var param = {
  209. pageNum: pageNum,
  210. pageSize: 10
  211. };
  212. var url = config.api.getMySepllList;
  213. } else if (flag == 'spellList') {
  214. console.log(111111)
  215. that.setData({
  216. flag: "spellList"
  217. })
  218. var param = {
  219. pageNum: pageNum,
  220. pageSize: 10,
  221. targetAd: 7
  222. };
  223. var url = config.api.couponChannelList;
  224. }
  225. // 请求接口
  226. Http.get({
  227. url: url,
  228. data: param
  229. }).then(res => {
  230. console.log(res)
  231. /**
  232. * 加载完成
  233. */
  234. if (pageNum >= res.data.pages) {
  235. if (res.data.pages == 0 || res.data.pages == 1) {
  236. that.setData({
  237. allow_load: true,
  238. loading: false,
  239. content: ""
  240. });
  241. } else {
  242. that.setData({
  243. allow_load: false,
  244. loading: true,
  245. content: "——— 再拉裤子就掉了啦 ———",
  246. });
  247. }
  248. }
  249. if (pageNum == 1) {
  250. that.setData({
  251. lists: [],
  252. })
  253. }
  254. if (flag == 'spellList') {
  255. var tmpArr = that.data.lists;
  256. tmpArr.push.apply(tmpArr, res.data.list);
  257. that.setData({
  258. lists: tmpArr
  259. })
  260. } else if (flag == 'myspellList') {
  261. console.log(res.data.list)
  262. var tmpArr = that.data.lists;
  263. res.data.list.map((item,index)=>{
  264. item.statusText = that.changeStatus(item.orderStatus);
  265. item.statusText02 = that.changeStatus02(item.orderStatus)
  266. })
  267. tmpArr.push.apply(tmpArr, res.data.list);
  268. console.log(tmpArr)
  269. let lists = [];
  270. tmpArr.map(file => {
  271. lists.push(file);
  272. })
  273. that.setData({
  274. lists: lists
  275. })
  276. }
  277. wx.stopPullDownRefresh();
  278. })
  279. .catch(err => {
  280. wx.stopPullDownRefresh();
  281. wx.showToast({
  282. title: err.message,
  283. icon: 'none',
  284. duration: 2000,
  285. mask: false
  286. });
  287. })
  288. setTimeout(function () {
  289. that.setData({
  290. loading: false,
  291. })
  292. }, 1400);
  293. } else {
  294. that.setData({
  295. loading: true,
  296. content: "——— 再拉裤子就掉了啦 ———"
  297. })
  298. setTimeout(function () {
  299. that.setData({
  300. loading: false,
  301. })
  302. }, 1400)
  303. }
  304. },
  305. /**
  306. * 如果是重新砍价,需要重新下单
  307. */
  308. orderSave: function (couponId, couponChannelId) {
  309. Http.post({
  310. url: config.api.orderSave,
  311. data: {
  312. couponId: "" + couponId,
  313. couponChannelId: "" + couponChannelId,
  314. press: true
  315. }
  316. })
  317. .then(res => {
  318. console.log(res)
  319. wx.navigateTo({
  320. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.orderNumber}`
  321. })
  322. })
  323. .catch(err => {
  324. wx.showToast({
  325. title: err.message,
  326. icon: "none"
  327. })
  328. })
  329. },
  330. inviteFriend: function (e) {
  331. /**
  332. * 添加标识
  333. */
  334. wx.navigateTo({
  335. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  336. })
  337. },
  338. // barginAgain: function (e) {
  339. // let that = this;
  340. // console.log(e)
  341. // let couponId = e.currentTarget.dataset.couponid;
  342. // let couponChannelId = e.currentTarget.dataset.couponchannelid;
  343. // // let orderId = e.currentTarget.dataset.id;
  344. // that.orderSave(couponId, couponChannelId)
  345. // },
  346. // myspellList: function () {
  347. // let that = this;
  348. // that.setData({
  349. // spellList: false,
  350. // myspellList: true,
  351. // flag: "myspellList",
  352. // allow_load: true,
  353. // loading: false,
  354. // content: "",
  355. // page: 1
  356. // })
  357. // that.getList(1, 'myspellList');
  358. // wx.setNavigationBarTitle({
  359. // title: '我的砍价'
  360. // })
  361. // },
  362. spellList: function () {
  363. let that = this;
  364. that.setData({
  365. spellList: true,
  366. myspellList: false,
  367. flag: "spellList",
  368. allow_load: true,
  369. loading: false,
  370. page: 1,
  371. content: ""
  372. })
  373. that.getList(1, 'spellList');
  374. wx.setNavigationBarTitle({
  375. title: '砍价专场'
  376. })
  377. },
  378. /**
  379. *
  380. * @param goto拼团券详情
  381. */
  382. invite: function (e) {
  383. let couponChannelId = e.currentTarget.dataset.id;
  384. let couponId = e.currentTarget.dataset.couponid;
  385. if (couponChannelId && couponId) {
  386. wx.navigateTo({
  387. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  388. })
  389. }
  390. },
  391. //加载更多
  392. onReachBottom: function () {
  393. let that = this;
  394. that.data.page++;
  395. that.setData({
  396. page: that.data.page
  397. });
  398. that.getList(that.data.page, that.data.flag);
  399. },
  400. /**
  401. * 刷新
  402. */
  403. onPullDownRefresh: function (e) {
  404. let that = this;
  405. if (that.data.flag == 'spellList') {
  406. that.getBannerlist();
  407. var todayDate = new Date().getTime();
  408. that.setData({
  409. todayDate: todayDate
  410. })
  411. that.getList(1, "spellList");
  412. that.setData({
  413. flag: "spellList",
  414. spellList: true,
  415. myspellList: false
  416. })
  417. } else if (that.data.flag == 'myspellList') {
  418. that.getList(1, "myspellList");
  419. that.setData({
  420. flag: "myspellList",
  421. spellList: false,
  422. myspellList: true
  423. })
  424. }
  425. },
  426. })