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.

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