C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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