C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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