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.

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