C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

416 rader
10 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. },
  78. onShow(){
  79. let that=this;
  80. if (this.data.reloadIf){
  81. wx.setNavigationBarTitle({
  82. title: '拼团专场'
  83. })
  84. that.getList(1, "spellList");
  85. that.setData({
  86. flag: "spellList",
  87. spellList: true,
  88. myspellList: false,
  89. lists: null
  90. })
  91. }
  92. },
  93. //切换拼团列表
  94. getSpellList(){
  95. this.setData({
  96. flag: "spellList",
  97. page:1,
  98. allow_load:true
  99. })
  100. wx.setNavigationBarTitle({
  101. title: '拼团专场'
  102. })
  103. this.getList(1, "spellList")
  104. },
  105. //去使用
  106. gotoUse(e){
  107. console.log(e)
  108. wx.navigateTo({
  109. url: '/pages/couponorder/index/index',
  110. })
  111. },
  112. //重新拼团
  113. gotoAgain(e){
  114. let data = e.currentTarget.dataset.data
  115. wx.navigateTo({
  116. url: `/pages/spellGroup/mySpellGroup/index?couponId=${data.couponId}&couponChannelId=${data.couponChannelId}`,
  117. })
  118. },
  119. //跳转到我的拼团详情
  120. gotoStatusDetail(e){
  121. console.log(e,333)
  122. let data = e.currentTarget.dataset.data
  123. wx.navigateTo({
  124. url: `/pages/spellDetail/index?orderId=${data.orderId}&couponId=${data.couponId}&orderGroupId=${data.orderGroupId}&couponChannelId=${data.couponChannelId}`,
  125. })
  126. },
  127. //切换我的拼团
  128. getmyList(){
  129. this.setData({
  130. flag: "myspellList",
  131. page: 1,
  132. allow_load: true,
  133. lists:null
  134. })
  135. wx.setNavigationBarTitle({
  136. title: '我的拼团'
  137. })
  138. this.getList(1, "myspellList")
  139. },
  140. /**
  141. * banner
  142. */
  143. getBannerlist: function () {
  144. let that = this;
  145. Http.get({
  146. url: config.api.bannerlist,
  147. data: {
  148. pageNum: 1,
  149. pageSize: 7
  150. }
  151. }).then(res => {
  152. that.setData({
  153. list: res.data.list
  154. });
  155. });
  156. },
  157. changeStatus(status){
  158. return spellStatus02.filter(item=>status==item.value)[0].name
  159. },
  160. changeStatus02(status) {
  161. console.log(status)
  162. return spellStatus.filter(item => status == item.value)[0].name
  163. },
  164. gotoPay(e){
  165. this.setData({
  166. reloadIf:true
  167. })
  168. let data = e.currentTarget.dataset.data
  169. wx.navigateTo({
  170. url: `/pages/spellGroup/paySpellGroup/index?orderId=${data.orderId}&couponId=${data.couponId}&orderGroupId=${data.orderGroupId}&couponChannelId=${data.couponChannelId}`,
  171. })
  172. },
  173. gotoEdit(e){
  174. let status = e.currentTarget.dataset.status
  175. if (status==10){
  176. }
  177. },
  178. getList(pageNum, flag) {
  179. var that = this;
  180. console.log(pageNum)
  181. if (that.data.allow_load) {
  182. /**
  183. * myspellList: 我的砍价
  184. * spellList: 砍价商品
  185. */
  186. that.setData({
  187. loading: true,
  188. content: '小主,我在玩命加载中...'
  189. })
  190. var param = {};
  191. if (flag == 'myspellList') {
  192. console.log(22222222)
  193. that.setData({
  194. flag: "myspellList"
  195. })
  196. var param = {
  197. pageNum: pageNum,
  198. pageSize: 10
  199. };
  200. var url = config.api.getMySepllList;
  201. } else if (flag == 'spellList') {
  202. console.log(111111)
  203. that.setData({
  204. flag: "spellList"
  205. })
  206. var param = {
  207. pageNum: pageNum,
  208. pageSize: 10,
  209. targetAd: 7
  210. };
  211. var url = config.api.couponChannelList;
  212. }
  213. // 请求接口
  214. Http.get({
  215. url: url,
  216. data: param
  217. }).then(res => {
  218. console.log(res)
  219. /**
  220. * 加载完成
  221. */
  222. if (pageNum >= res.data.pages) {
  223. if (res.data.pages == 0 || res.data.pages == 1) {
  224. that.setData({
  225. allow_load: true,
  226. loading: false,
  227. content: ""
  228. });
  229. } else {
  230. that.setData({
  231. allow_load: false,
  232. loading: true,
  233. content: "——— 再拉裤子就掉了啦 ———",
  234. });
  235. }
  236. }
  237. if (pageNum == 1) {
  238. that.setData({
  239. lists: [],
  240. })
  241. }
  242. if (flag == 'spellList') {
  243. var tmpArr = that.data.lists;
  244. tmpArr.push.apply(tmpArr, res.data.list);
  245. that.setData({
  246. lists: tmpArr
  247. })
  248. } else if (flag == 'myspellList') {
  249. console.log(res.data.list)
  250. var tmpArr = that.data.lists;
  251. res.data.list.map((item,index)=>{
  252. item.statusText = that.changeStatus(item.orderStatus);
  253. item.statusText02 = that.changeStatus02(item.orderStatus)
  254. })
  255. tmpArr.push.apply(tmpArr, res.data.list);
  256. console.log(tmpArr)
  257. let lists = [];
  258. tmpArr.map(file => {
  259. lists.push(file);
  260. })
  261. that.setData({
  262. lists: lists
  263. })
  264. }
  265. wx.stopPullDownRefresh();
  266. })
  267. .catch(err => {
  268. wx.stopPullDownRefresh();
  269. wx.showToast({
  270. title: err.message,
  271. icon: 'none',
  272. duration: 2000,
  273. mask: false
  274. });
  275. })
  276. setTimeout(function () {
  277. that.setData({
  278. loading: false,
  279. })
  280. }, 1400);
  281. } else {
  282. that.setData({
  283. loading: true,
  284. content: "——— 再拉裤子就掉了啦 ———"
  285. })
  286. setTimeout(function () {
  287. that.setData({
  288. loading: false,
  289. })
  290. }, 1400)
  291. }
  292. },
  293. /**
  294. * 如果是重新砍价,需要重新下单
  295. */
  296. orderSave: function (couponId, couponChannelId) {
  297. Http.post({
  298. url: config.api.orderSave,
  299. data: {
  300. couponId: "" + couponId,
  301. couponChannelId: "" + couponChannelId,
  302. press: true
  303. }
  304. })
  305. .then(res => {
  306. console.log(res)
  307. wx.navigateTo({
  308. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.orderNumber}`
  309. })
  310. })
  311. .catch(err => {
  312. wx.showToast({
  313. title: err.message,
  314. icon: "none"
  315. })
  316. })
  317. },
  318. inviteFriend: function (e) {
  319. /**
  320. * 添加标识
  321. */
  322. wx.navigateTo({
  323. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  324. })
  325. },
  326. // barginAgain: function (e) {
  327. // let that = this;
  328. // console.log(e)
  329. // let couponId = e.currentTarget.dataset.couponid;
  330. // let couponChannelId = e.currentTarget.dataset.couponchannelid;
  331. // // let orderId = e.currentTarget.dataset.id;
  332. // that.orderSave(couponId, couponChannelId)
  333. // },
  334. // myspellList: function () {
  335. // let that = this;
  336. // that.setData({
  337. // spellList: false,
  338. // myspellList: true,
  339. // flag: "myspellList",
  340. // allow_load: true,
  341. // loading: false,
  342. // content: "",
  343. // page: 1
  344. // })
  345. // that.getList(1, 'myspellList');
  346. // wx.setNavigationBarTitle({
  347. // title: '我的砍价'
  348. // })
  349. // },
  350. spellList: function () {
  351. let that = this;
  352. that.setData({
  353. spellList: true,
  354. myspellList: false,
  355. flag: "spellList",
  356. allow_load: true,
  357. loading: false,
  358. page: 1,
  359. content: ""
  360. })
  361. that.getList(1, 'spellList');
  362. wx.setNavigationBarTitle({
  363. title: '砍价专场'
  364. })
  365. },
  366. /**
  367. *
  368. * @param goto拼团券详情
  369. */
  370. invite: function (e) {
  371. let couponChannelId = e.currentTarget.dataset.id;
  372. let couponId = e.currentTarget.dataset.couponid;
  373. if (couponChannelId && couponId) {
  374. wx.navigateTo({
  375. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  376. })
  377. }
  378. },
  379. //加载更多
  380. onReachBottom: function () {
  381. let that = this;
  382. that.data.page++;
  383. that.setData({
  384. page: that.data.page
  385. });
  386. that.getList(that.data.page, that.data.flag);
  387. },
  388. /**
  389. * 刷新
  390. */
  391. onPullDownRefresh: function (e) {
  392. let that = this;
  393. if (that.data.flag == 'spellList') {
  394. that.getBannerlist();
  395. var todayDate = new Date().getTime();
  396. that.setData({
  397. todayDate: todayDate
  398. })
  399. that.getList(1, "spellList");
  400. that.setData({
  401. flag: "spellList",
  402. spellList: true,
  403. myspellList: false
  404. })
  405. } else if (that.data.flag == 'myspellList') {
  406. that.getList(1, "myspellList");
  407. that.setData({
  408. flag: "myspellList",
  409. spellList: false,
  410. myspellList: true
  411. })
  412. }
  413. },
  414. })