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.

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