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.

433 line
11 KiB

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