C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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