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.

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