C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

424 linhas
10 KiB

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