invite.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. var _request = require('../../../../utils/request.js')
  2. var wx_id = 0
  3. Page({
  4. data: {
  5. qrcode: '',
  6. info: {},
  7. all: {},
  8. all1: {},
  9. list: [],
  10. mlist: [],
  11. page: 1,
  12. per_page: 10,
  13. page1: 1,
  14. year: 0,
  15. month: 0,
  16. upmonth: 0,
  17. downmonth: 0,
  18. newy: 0,
  19. newm: 0,
  20. per_page1: 10,
  21. more: true,
  22. popup: false,
  23. sale: 0,
  24. currentTab: 0,
  25. btnshow: false,
  26. btnshow1: false,
  27. time: Date.parse(new Date()) / 1000,
  28. ashow: true,
  29. nextshow: false,
  30. prevshow: true,
  31. cinfo: '',
  32. pinfo: '',
  33. wx_user:{}
  34. },
  35. onLoad: function (options) {
  36. wx_id = getApp().globalData.wx_id
  37. // this.getinfo()
  38. this.updatemonth()
  39. this.getCode()
  40. this.getList()
  41. // this.getCount()
  42. this.getmonthlist()
  43. //this.getContributionTotal()
  44. // wx.getUserInfo({
  45. // success: res => {
  46. // this.setData({
  47. // info: res.userInfo
  48. // })
  49. // }
  50. // })
  51. //新授权
  52. wx.getUserProfile({
  53. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  54. success: (res) => {
  55. this.setData({
  56. info: res.userInfo,
  57. hasUserInfo: true
  58. })
  59. }
  60. })
  61. },
  62. getCount: function () {
  63. var that = this
  64. var url = 'v1/user/sale_rank/list'
  65. var params = {
  66. page: 1,
  67. per_page: 1
  68. }
  69. var success = function (res) {
  70. if (res.data.reward_config_list.length > 0) {
  71. that.setData({
  72. sale: res.data.self_sale
  73. })
  74. }
  75. }
  76. _request.$get(url, params, success)
  77. },
  78. getCode: function () {
  79. var that = this
  80. var url = 'v1/user/invite/qrcode'
  81. var params = {}
  82. var success = function (res) {
  83. that.setData({
  84. qrcode: res.data.qrcode_url
  85. })
  86. // that.createCtx();
  87. }
  88. _request.$get(url, params, success)
  89. },
  90. getList: function () {
  91. var that = this
  92. var url = 'v1/invite/' + wx_id + '/list'
  93. var params = {
  94. page: that.data.page,
  95. per_page: that.data.per_page
  96. }
  97. var success = function (res) {
  98. var result = that.data.list.concat(res.data.list || [])
  99. if (res.data.list_count > 10) {
  100. that.setData({
  101. btnshow: true
  102. })
  103. }
  104. if (res.data.list.length) {
  105. that.setData({
  106. list: result,
  107. page: that.data.page + 1,
  108. per_page: that.data.per_page,
  109. wx_user: res.data.wx_user
  110. })
  111. } else {
  112. that.setData({
  113. btnshow: false
  114. })
  115. }
  116. // var listMore = res.data.list_count > that.data.list.length
  117. that.setData({
  118. all: res.data,
  119. // more: listMore
  120. })
  121. }
  122. _request.$get(url, params, success)
  123. },
  124. // onReachBottom: function () {
  125. // if (this.data.more) {
  126. // var page = this.data.page + 1
  127. // this.setData({
  128. // page: page
  129. // })
  130. // this.getList()
  131. // }
  132. // },
  133. //createCtx () {
  134. // var that = this
  135. // console.log('that.data.qrcode',that.data.qrcode)
  136. // var ctx = wx.createCanvasContext('myCanvas')
  137. // ctx.drawImage(that.data.qrcode, 0, 0,200,200)
  138. // ctx.restore();
  139. // ctx.save();
  140. // ctx.beginPath(); //开始绘制
  141. // ctx.draw(true, function callback () {
  142. // that.createImage()
  143. // })
  144. //},
  145. //createImage () {
  146. // var that = this
  147. // wx.canvasToTempFilePath({
  148. // destWidth: 200,
  149. // destHeight: 200,
  150. // canvasId: 'myCanvas',
  151. // fileType: 'jpg',
  152. // success: function (res) {
  153. // console.log('createImage',res)
  154. // that.setData({
  155. // posterImage: res.tempFilePath
  156. // })
  157. // }
  158. // })
  159. //},
  160. downLoadImage () {
  161. wx.showLoading({
  162. title: '加载中',
  163. })
  164. var that = this
  165. wx.downloadFile({
  166. url: that.data.qrcode,
  167. success: function(res) {
  168. if (res.statusCode === 200) {
  169. that.saveImage(res.tempFilePath)
  170. }
  171. }
  172. })
  173. },
  174. saveImage (val) {
  175. var that = this
  176. wx.saveImageToPhotosAlbum({
  177. filePath: val,
  178. success(res) {
  179. wx.showToast({
  180. title: '已保存相册',
  181. icon: 'success',
  182. duration: 2000
  183. })
  184. },
  185. fail (res) {
  186. wx.getSetting({
  187. success (res) {
  188. if (!res.authSetting['scope.writePhotosAlbum']) {
  189. that.setData({
  190. popup: true
  191. })
  192. }
  193. }
  194. })
  195. },
  196. complete () {
  197. wx.hideLoading()
  198. }
  199. })
  200. },
  201. toDetail() {
  202. wx.navigateTo({
  203. url: '/packageUser/pages/user/invite/detail/detail'
  204. })
  205. },
  206. onShareAppMessage: function (val) {
  207. return _request.share({
  208. sc: 'xcx_invite'
  209. })
  210. },
  211. toMaterial () {
  212. wx.navigateTo({
  213. url: '/packageUser/pages/user/invite/material/material'
  214. })
  215. },
  216. setting () {
  217. this.setData({
  218. popup: false
  219. })
  220. },
  221. toRank () {
  222. wx.navigateTo({
  223. url: '/packageUser/pages/user/invite/rank/rank'
  224. })
  225. },
  226. toCotb () {
  227. wx.navigateTo({
  228. url: '/packageUser/pages/user/invite/contribution/contribution'
  229. })
  230. },
  231. changenav:function(e){
  232. var cur=e.target.dataset.current;
  233. if (this.data.currentTab == parseInt(cur)) {
  234. return false;
  235. }
  236. else {
  237. this.setData({
  238. ashow: !this.data.ashow,
  239. currentTab: cur
  240. })
  241. }
  242. },
  243. tomonth (e) {
  244. var that = this
  245. var next_id = e.currentTarget.dataset.val
  246. var count = e.currentTarget.dataset.count
  247. var year = that.data.year
  248. var month = that.data.month
  249. if ( count > 0) {
  250. wx.navigateTo({
  251. url: '/packageUser/pages/user/invite/month/month?id=' + next_id + '&year=' + year + '&month=' + month
  252. })
  253. }
  254. },
  255. tototal (e) {
  256. var next_id = e.currentTarget.dataset.val
  257. var count = e.currentTarget.dataset.count
  258. if ( count > 0) {
  259. wx.navigateTo({
  260. url: '/packageUser/pages/user/invite/total/total?id=' + next_id
  261. })
  262. }
  263. },
  264. toproxy (e) {
  265. var userid = e.currentTarget.dataset.userid
  266. wx.navigateTo({
  267. url: '/packageUser/pages/user/proxyApply/proxyApply?uid=' + userid
  268. })
  269. },
  270. updatemonth () {
  271. var that = this
  272. var date = new Date(that.data.time * 1000)
  273. var year = date.getFullYear()
  274. var month = date.getMonth() + 1
  275. // var upMonth = that.data.upmonth
  276. // var downMonth = that.data.downmonth
  277. that.setData({
  278. year: year,
  279. month: month,
  280. newy: year,
  281. newm: month,
  282. upmonth: month - 1,
  283. downmonth: month + 1
  284. })
  285. },
  286. getmonthlist () {
  287. var that = this
  288. var url = 'v1/invite/' + wx_id + '/monthly/list'
  289. var params = {
  290. page: that.data.page1,
  291. per_page: that.data.per_page1,
  292. y: that.data.year,
  293. m: that.data.month,
  294. cache: false
  295. }
  296. var success = function (res) {
  297. // wx.showLoading({
  298. // title: '加载中',
  299. // duration: 1000
  300. // })
  301. // var result = that.data.mlist.concat(res.data.list || [])
  302. if (res.data.list_count > 10) {
  303. that.setData({
  304. btnshow1: true
  305. })
  306. }
  307. if (res.data.list.length) {
  308. var result = res.data.list
  309. that.setData({
  310. mlist: result,
  311. page1: that.data.page1 + 1,
  312. per_page1: that.data.per_page1
  313. })
  314. } else {
  315. that.setData({
  316. btnshow1: false
  317. })
  318. }
  319. // var listMore = res.data.list_count > that.data.mlist.length
  320. that.setData({
  321. all1: res.data,
  322. // more: listMore
  323. })
  324. }
  325. var fail = function () {
  326. wx.hideLoading()
  327. }
  328. _request.$get(url, params, success)
  329. },
  330. getmonthlist1 () {
  331. var that = this
  332. var url = 'v1/invite/' + wx_id + '/monthly/list'
  333. var params = {
  334. page: that.data.page1,
  335. per_page: that.data.per_page1,
  336. y: that.data.year,
  337. m: that.data.month,
  338. cache: false
  339. }
  340. var success = function (res) {
  341. // wx.showLoading({
  342. // title: '加载中',
  343. // duration: 1000
  344. // })
  345. // var result = that.data.mlist.concat(res.data.list || [])
  346. if (res.data.list_count > 10) {
  347. that.setData({
  348. btnshow1: true
  349. })
  350. }
  351. if (res.data.list.length) {
  352. var result = that.data.mlist.concat(res.data.list || [])
  353. that.setData({
  354. mlist: result,
  355. page1: that.data.page1 + 1,
  356. per_page1: that.data.per_page1
  357. })
  358. } else {
  359. that.setData({
  360. btnshow1: false
  361. })
  362. }
  363. // var listMore = res.data.list_count > that.data.mlist.length
  364. that.setData({
  365. all1: res.data,
  366. // more: listMore
  367. })
  368. }
  369. var fail = function () {
  370. wx.hideLoading()
  371. }
  372. _request.$get(url, params, success)
  373. },
  374. prevmonth () {
  375. wx.showLoading({
  376. title: '加载中',
  377. duration: 1000
  378. })
  379. var that = this
  380. var m = that.data.month
  381. var y = that.data.year
  382. var ny = that.data.newy
  383. var nm = that.data.newm
  384. m = m - 1
  385. if (m < 1) {
  386. m = 12
  387. y = y - 1
  388. }
  389. that.setData({
  390. month: m,
  391. year: y,
  392. upmonth: m - 1,
  393. downmonth: m + 1,
  394. page1: 1,
  395. // mlist: []
  396. })
  397. if (y === ny && m < nm) {
  398. that.setData({
  399. nextshow: true
  400. })
  401. }
  402. if (y < ny) {
  403. that.setData({
  404. nextshow: true
  405. })
  406. }
  407. if (y === 2018 && m === 7) {
  408. that.setData({
  409. prevshow: false
  410. })
  411. }
  412. that.getmonthlist()
  413. },
  414. nextmonth () {
  415. wx.showLoading({
  416. title: '加载中',
  417. duration: 1000
  418. })
  419. var that = this
  420. var m = that.data.month
  421. var y = that.data.year
  422. var ny = that.data.newy
  423. var nm = that.data.newm
  424. m = m + 1
  425. if (m > 12) {
  426. m = 1
  427. y = y + 1
  428. }
  429. that.setData({
  430. prevshow: true,
  431. month: m,
  432. year: y,
  433. upmonth: m - 1,
  434. downmonth: m + 1,
  435. page1: 1,
  436. // mlist: []
  437. })
  438. if (y === ny && m >= nm) {
  439. that.setData({
  440. nextshow: false
  441. })
  442. }
  443. if (y < ny) {
  444. that.setData({
  445. nextshow: true
  446. })
  447. }
  448. that.getmonthlist()
  449. },
  450. getinfo () {
  451. var that = this
  452. var url = 'v1/copartner/info'
  453. var params = {
  454. }
  455. var success = function (res) {
  456. that.setData ({
  457. cinfo: res.data
  458. })
  459. }
  460. _request.$get(url, params, success)
  461. },
  462. getContributionTotal () {
  463. var that = this
  464. var url = 'v1/copartner/total'
  465. var params = {
  466. }
  467. var success = function (res) {
  468. that.setData ({
  469. pinfo: res.data
  470. })
  471. }
  472. _request.$get(url, params, success)
  473. }
  474. })