C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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