invite.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. userinfo:{}
  35. },
  36. onLoad: function (options) {
  37. wx_id = getApp().globalData.wx_id
  38. // this.getinfo()
  39. this.updatemonth()
  40. this.getCode()
  41. this.getList()
  42. // this.getCount()
  43. this.getmonthlist()
  44. this.info()
  45. //this.getContributionTotal()
  46. // wx.getUserInfo({
  47. // success: res => {
  48. // this.setData({
  49. // info: res.userInfo
  50. // })
  51. // }
  52. // })
  53. //新授权
  54. wx.getUserProfile({
  55. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  56. success: (res) => {
  57. this.setData({
  58. info: res.userInfo,
  59. hasUserInfo: true
  60. })
  61. }
  62. })
  63. },
  64. info(){
  65. var that = this
  66. var url = 'v1/user/info'
  67. var params = {}
  68. var success = function (res) {
  69. that.setData({
  70. userinfo:res.data.wx_user,
  71. })
  72. }
  73. _request.$get(url, params, success)
  74. },
  75. getCount: function () {
  76. var that = this
  77. var url = 'v1/user/sale_rank/list'
  78. var params = {
  79. page: 1,
  80. per_page: 1
  81. }
  82. var success = function (res) {
  83. if (res.data.reward_config_list.length > 0) {
  84. that.setData({
  85. sale: res.data.self_sale
  86. })
  87. }
  88. }
  89. _request.$get(url, params, success)
  90. },
  91. getCode: function () {
  92. var that = this
  93. var url = 'v1/user/invite/qrcode'
  94. var params = {}
  95. var success = function (res) {
  96. that.setData({
  97. qrcode: res.data.qrcode_url
  98. })
  99. // that.createCtx();
  100. }
  101. _request.$get(url, params, success)
  102. },
  103. getList: function () {
  104. var that = this
  105. var url = 'v1/invite/' + wx_id + '/list'
  106. var params = {
  107. page: that.data.page,
  108. per_page: that.data.per_page
  109. }
  110. var success = function (res) {
  111. var result = that.data.list.concat(res.data.list || [])
  112. if (res.data.list_count > 10) {
  113. that.setData({
  114. btnshow: true
  115. })
  116. }
  117. if (res.data.list.length) {
  118. that.setData({
  119. list: result,
  120. page: that.data.page + 1,
  121. per_page: that.data.per_page,
  122. wx_user: res.data.wx_user
  123. })
  124. } else {
  125. that.setData({
  126. btnshow: false
  127. })
  128. }
  129. // var listMore = res.data.list_count > that.data.list.length
  130. that.setData({
  131. all: res.data,
  132. // more: listMore
  133. })
  134. }
  135. _request.$get(url, params, success)
  136. },
  137. // onReachBottom: function () {
  138. // if (this.data.more) {
  139. // var page = this.data.page + 1
  140. // this.setData({
  141. // page: page
  142. // })
  143. // this.getList()
  144. // }
  145. // },
  146. createCtx () {
  147. var that = this
  148. var headimg = '';
  149. var qrcodeimg = '';
  150. wx.getImageInfo({
  151. src: that.data.userinfo.head,
  152. success: function (res) {
  153. headimg = res.path;
  154. wx.getImageInfo({
  155. src: that.data.qrcode,
  156. success: function (res2) {
  157. qrcodeimg = res2.path;
  158. var ctx = wx.createCanvasContext('myCanvas')
  159. ctx.fillStyle = "#FFF"
  160. ctx.fillRect(0,0,500,400)
  161. ctx.restore();
  162. ctx.drawImage(headimg, 20, 20,60,60)
  163. ctx.drawImage(qrcodeimg, 0, 100,400,400)
  164. // ctx.restore();
  165. // ctx.save();
  166. ctx.fillStyle = "#000"
  167. ctx.font="28px Arial";
  168. ctx.fillText(that.data.userinfo.nickname, 90, 60)
  169. // ctx.beginPath(); //开始绘制
  170. ctx.draw(true, function callback () {
  171. that.createImage()
  172. })
  173. }
  174. })
  175. }
  176. })
  177. },
  178. createImage () {
  179. var that = this
  180. wx.canvasToTempFilePath({
  181. destWidth: 400,
  182. destHeight: 500,
  183. canvasId: 'myCanvas',
  184. fileType: 'jpg',
  185. success: function (res) {
  186. console.log('createImage',res)
  187. // that.setData({
  188. // posterImage: res.tempFilePath
  189. // })
  190. that.saveImage(res.tempFilePath)
  191. // wx.downloadFile({
  192. // url: res.tempFilePath,
  193. // success: function(res) {
  194. // if (res.statusCode === 200) {
  195. // that.saveImage(res.tempFilePath)
  196. // }
  197. // }
  198. // })
  199. }
  200. })
  201. },
  202. saveImage (val) {
  203. var that = this
  204. wx.saveImageToPhotosAlbum({
  205. filePath: val,
  206. success(res) {
  207. wx.showToast({
  208. title: '已保存相册',
  209. icon: 'success',
  210. duration: 2000
  211. })
  212. },
  213. fail (res) {
  214. wx.getSetting({
  215. success (res) {
  216. if (!res.authSetting['scope.writePhotosAlbum']) {
  217. that.setData({
  218. popup: true
  219. })
  220. }
  221. }
  222. })
  223. },
  224. complete () {
  225. wx.hideLoading()
  226. }
  227. })
  228. },
  229. toDetail() {
  230. wx.navigateTo({
  231. url: '/packageUser/pages/user/invite/detail/detail'
  232. })
  233. },
  234. onShareAppMessage: function (val) {
  235. return _request.share({
  236. sc: 'xcx_invite'
  237. })
  238. },
  239. toMaterial () {
  240. wx.navigateTo({
  241. url: '/packageUser/pages/user/invite/material/material'
  242. })
  243. },
  244. setting () {
  245. this.setData({
  246. popup: false
  247. })
  248. },
  249. toRank () {
  250. wx.navigateTo({
  251. url: '/packageUser/pages/user/invite/rank/rank'
  252. })
  253. },
  254. toCotb () {
  255. wx.navigateTo({
  256. url: '/packageUser/pages/user/invite/contribution/contribution'
  257. })
  258. },
  259. changenav:function(e){
  260. var cur=e.target.dataset.current;
  261. if (this.data.currentTab == parseInt(cur)) {
  262. return false;
  263. }
  264. else {
  265. this.setData({
  266. ashow: !this.data.ashow,
  267. currentTab: cur
  268. })
  269. }
  270. },
  271. tomonth (e) {
  272. var that = this
  273. var next_id = e.currentTarget.dataset.val
  274. var count = e.currentTarget.dataset.count
  275. var year = that.data.year
  276. var month = that.data.month
  277. if ( count > 0) {
  278. wx.navigateTo({
  279. url: '/packageUser/pages/user/invite/month/month?id=' + next_id + '&year=' + year + '&month=' + month
  280. })
  281. }
  282. },
  283. tototal (e) {
  284. var next_id = e.currentTarget.dataset.val
  285. var count = e.currentTarget.dataset.count
  286. if ( count > 0) {
  287. wx.navigateTo({
  288. url: '/packageUser/pages/user/invite/total/total?id=' + next_id
  289. })
  290. }
  291. },
  292. toproxy (e) {
  293. var userid = e.currentTarget.dataset.userid
  294. wx.navigateTo({
  295. url: '/packageUser/pages/user/proxyApply/proxyApply?uid=' + userid
  296. })
  297. },
  298. updatemonth () {
  299. var that = this
  300. var date = new Date(that.data.time * 1000)
  301. var year = date.getFullYear()
  302. var month = date.getMonth() + 1
  303. // var upMonth = that.data.upmonth
  304. // var downMonth = that.data.downmonth
  305. that.setData({
  306. year: year,
  307. month: month,
  308. newy: year,
  309. newm: month,
  310. upmonth: month - 1,
  311. downmonth: month + 1
  312. })
  313. },
  314. getmonthlist () {
  315. var that = this
  316. var url = 'v1/invite/' + wx_id + '/monthly/list'
  317. var params = {
  318. page: that.data.page1,
  319. per_page: that.data.per_page1,
  320. y: that.data.year,
  321. m: that.data.month,
  322. cache: false
  323. }
  324. var success = function (res) {
  325. // wx.showLoading({
  326. // title: '加载中',
  327. // duration: 1000
  328. // })
  329. // var result = that.data.mlist.concat(res.data.list || [])
  330. if (res.data.list_count > 10) {
  331. that.setData({
  332. btnshow1: true
  333. })
  334. }
  335. if (res.data.list.length) {
  336. var result = res.data.list
  337. that.setData({
  338. mlist: result,
  339. page1: that.data.page1 + 1,
  340. per_page1: that.data.per_page1
  341. })
  342. } else {
  343. that.setData({
  344. btnshow1: false
  345. })
  346. }
  347. // var listMore = res.data.list_count > that.data.mlist.length
  348. that.setData({
  349. all1: res.data,
  350. // more: listMore
  351. })
  352. }
  353. var fail = function () {
  354. wx.hideLoading()
  355. }
  356. _request.$get(url, params, success)
  357. },
  358. getmonthlist1 () {
  359. var that = this
  360. var url = 'v1/invite/' + wx_id + '/monthly/list'
  361. var params = {
  362. page: that.data.page1,
  363. per_page: that.data.per_page1,
  364. y: that.data.year,
  365. m: that.data.month,
  366. cache: false
  367. }
  368. var success = function (res) {
  369. // wx.showLoading({
  370. // title: '加载中',
  371. // duration: 1000
  372. // })
  373. // var result = that.data.mlist.concat(res.data.list || [])
  374. if (res.data.list_count > 10) {
  375. that.setData({
  376. btnshow1: true
  377. })
  378. }
  379. if (res.data.list.length) {
  380. var result = that.data.mlist.concat(res.data.list || [])
  381. that.setData({
  382. mlist: result,
  383. page1: that.data.page1 + 1,
  384. per_page1: that.data.per_page1
  385. })
  386. } else {
  387. that.setData({
  388. btnshow1: false
  389. })
  390. }
  391. // var listMore = res.data.list_count > that.data.mlist.length
  392. that.setData({
  393. all1: res.data,
  394. // more: listMore
  395. })
  396. }
  397. var fail = function () {
  398. wx.hideLoading()
  399. }
  400. _request.$get(url, params, success)
  401. },
  402. prevmonth () {
  403. wx.showLoading({
  404. title: '加载中',
  405. duration: 1000
  406. })
  407. var that = this
  408. var m = that.data.month
  409. var y = that.data.year
  410. var ny = that.data.newy
  411. var nm = that.data.newm
  412. m = m - 1
  413. if (m < 1) {
  414. m = 12
  415. y = y - 1
  416. }
  417. that.setData({
  418. month: m,
  419. year: y,
  420. upmonth: m - 1,
  421. downmonth: m + 1,
  422. page1: 1,
  423. // mlist: []
  424. })
  425. if (y === ny && m < nm) {
  426. that.setData({
  427. nextshow: true
  428. })
  429. }
  430. if (y < ny) {
  431. that.setData({
  432. nextshow: true
  433. })
  434. }
  435. if (y === 2018 && m === 7) {
  436. that.setData({
  437. prevshow: false
  438. })
  439. }
  440. that.getmonthlist()
  441. },
  442. nextmonth () {
  443. wx.showLoading({
  444. title: '加载中',
  445. duration: 1000
  446. })
  447. var that = this
  448. var m = that.data.month
  449. var y = that.data.year
  450. var ny = that.data.newy
  451. var nm = that.data.newm
  452. m = m + 1
  453. if (m > 12) {
  454. m = 1
  455. y = y + 1
  456. }
  457. that.setData({
  458. prevshow: true,
  459. month: m,
  460. year: y,
  461. upmonth: m - 1,
  462. downmonth: m + 1,
  463. page1: 1,
  464. // mlist: []
  465. })
  466. if (y === ny && m >= nm) {
  467. that.setData({
  468. nextshow: false
  469. })
  470. }
  471. if (y < ny) {
  472. that.setData({
  473. nextshow: true
  474. })
  475. }
  476. that.getmonthlist()
  477. },
  478. getinfo () {
  479. var that = this
  480. var url = 'v1/copartner/info'
  481. var params = {
  482. }
  483. var success = function (res) {
  484. that.setData ({
  485. cinfo: res.data
  486. })
  487. }
  488. _request.$get(url, params, success)
  489. },
  490. getContributionTotal () {
  491. var that = this
  492. var url = 'v1/copartner/total'
  493. var params = {
  494. }
  495. var success = function (res) {
  496. that.setData ({
  497. pinfo: res.data
  498. })
  499. }
  500. _request.$get(url, params, success)
  501. },
  502. downLoadImage () {
  503. wx.showLoading({
  504. title: '加载中',
  505. })
  506. var that = this
  507. // wx.downloadFile({
  508. // url: that.data.qrcode,
  509. // success: function(res) {
  510. // if (res.statusCode === 200) {
  511. // that.saveImage(res.tempFilePath)
  512. // }
  513. // }
  514. // })
  515. wx.getImageInfo({
  516. src: that.data.qrcode,
  517. success: function (res) {
  518. that.createCtx()
  519. }
  520. })
  521. },
  522. // createCtx () {
  523. // var that = this
  524. // console.log('createctx',that.data.qrcode);
  525. // var ctx = wx.createCanvasContext('myCanvas')
  526. // // ctx.drawImage(this.posterImage.bg.path, 0, 0, this.dpi(this.posterImage.bg.width), this.dpi(this.posterImage.bg.height))
  527. // ctx.drawImage(that.data.qrcode, 0, 0, 200, 200)
  528. // ctx.save()
  529. // ctx.translate(this.dpi(44),this.dpi(46))
  530. // ctx.save()
  531. // ctx.arc(this.dpi(60), this.dpi(59), this.dpi(40), 0, Math.PI * 2, false)
  532. // ctx.lineWidth = 1
  533. // ctx.strokeStyle = '#d4d4d4'
  534. // ctx.stroke()
  535. // ctx.clip()
  536. // ctx.drawImage(this.posterImage.head.path, this.dpi(21), this.dpi(20), this.dpi(78), this.dpi(78))
  537. // ctx.restore()
  538. // ctx.save()
  539. // ctx.textBaseline = 'middle'
  540. // ctx.font = this.dpi(24) + 'px Arial'
  541. // ctx.fillStyle = '#eab86a'
  542. // ctx.fillText('源处全球源产地的优质产品!', this.dpi(136), this.dpi(59))
  543. // ctx.restore()
  544. // ctx.drawImage(this.posterImage.project.path, this.dpi(20), this.dpi(140), this.dpi(622), this.dpi(622))
  545. // ctx.beginPath()
  546. // ctx.moveTo(this.dpi(0), this.dpi(119))
  547. // ctx.lineTo(this.dpi(662), this.dpi(119))
  548. // ctx.lineWidth = 1
  549. // ctx.strokeStyle = '#eab86a'
  550. // ctx.stroke()
  551. // ctx.closePath()
  552. // ctx.save()
  553. // ctx.restore()
  554. // ctx.restore()
  555. // ctx.draw(true, function callback (res) {
  556. // console.log('over draw',res)
  557. // that.createImage()
  558. // })
  559. // },
  560. // createImage () {
  561. // var that = this
  562. // wx.canvasToTempFilePath({
  563. // destWidth: 750,
  564. // destHeight: 1334,
  565. // canvasId: 'myCanvas',
  566. // fileType: 'jpg',
  567. // success: function (res) {
  568. // // that.setData({
  569. // // posterImage: res.tempFilePath
  570. // // })
  571. // // that.canvasLoading = true
  572. // // wx.hideLoading()
  573. // wx.downloadFile({
  574. // url: res.tempFilePath,
  575. // success: function(res) {
  576. // if (res.statusCode === 200) {
  577. // that.saveImage(res.tempFilePath)
  578. // }
  579. // }
  580. // })
  581. // }
  582. // })
  583. // },
  584. })