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.

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