C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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