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.

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