C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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