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.

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