C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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