invite.js 10 KB

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