invite.js 9.8 KB

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