var _request = require('../../../../utils/request.js') var wx_id = 0 Page({ data: { qrcode: '', info: {}, all: {}, all1: {}, list: [], mlist: [], page: 1, per_page: 10, page1: 1, year: 0, month: 0, upmonth: 0, downmonth: 0, newy: 0, newm: 0, per_page1: 10, more: true, popup: false, sale: 0, currentTab: 0, btnshow: false, btnshow1: false, time: Date.parse(new Date()) / 1000, ashow: true, nextshow: false, prevshow: true, cinfo: '', pinfo: '', wx_user:{}, userinfo:{} }, onLoad: function (options) { wx_id = getApp().globalData.wx_id // this.getinfo() this.updatemonth() this.getCode() this.getList() // this.getCount() this.getmonthlist() this.info() //this.getContributionTotal() // wx.getUserInfo({ // success: res => { // this.setData({ // info: res.userInfo // }) // } // }) //新授权 wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { this.setData({ info: res.userInfo, hasUserInfo: true }) } }) }, info(){ var that = this var url = 'v1/user/info' var params = {} var success = function (res) { that.setData({ userinfo:res.data.wx_user, }) } _request.$get(url, params, success) }, getCount: function () { var that = this var url = 'v1/user/sale_rank/list' var params = { page: 1, per_page: 1 } var success = function (res) { if (res.data.reward_config_list.length > 0) { that.setData({ sale: res.data.self_sale }) } } _request.$get(url, params, success) }, getCode: function () { var that = this var url = 'v1/user/invite/qrcode' var params = {} var success = function (res) { that.setData({ qrcode: res.data.qrcode_url }) // that.createCtx(); } _request.$get(url, params, success) }, getList: function () { var that = this var url = 'v1/invite/' + wx_id + '/list' var params = { page: that.data.page, per_page: that.data.per_page } var success = function (res) { var result = that.data.list.concat(res.data.list || []) if (res.data.list_count > 10) { that.setData({ btnshow: true }) } if (res.data.list.length) { that.setData({ list: result, page: that.data.page + 1, per_page: that.data.per_page, wx_user: res.data.wx_user }) } else { that.setData({ btnshow: false }) } // var listMore = res.data.list_count > that.data.list.length that.setData({ all: res.data, // more: listMore }) } _request.$get(url, params, success) }, // onReachBottom: function () { // if (this.data.more) { // var page = this.data.page + 1 // this.setData({ // page: page // }) // this.getList() // } // }, createCtx () { var that = this var headimg = ''; var qrcodeimg = ''; wx.getImageInfo({ src: that.data.userinfo.head, success: function (res) { headimg = res.path; wx.getImageInfo({ src: that.data.qrcode, success: function (res2) { qrcodeimg = res2.path; var ctx = wx.createCanvasContext('myCanvas') ctx.fillStyle = "#FFF" ctx.fillRect(0,0,500,400) ctx.restore(); ctx.drawImage(headimg, 20, 20,60,60) ctx.drawImage(qrcodeimg, 0, 100,400,400) // ctx.restore(); // ctx.save(); ctx.fillStyle = "#000" ctx.font="28px Arial"; ctx.fillText(that.data.userinfo.nickname, 90, 60) // ctx.beginPath(); //开始绘制 ctx.draw(true, function callback () { that.createImage() }) } }) } }) }, createImage () { var that = this wx.canvasToTempFilePath({ destWidth: 400, destHeight: 500, canvasId: 'myCanvas', fileType: 'jpg', success: function (res) { console.log('createImage',res) // that.setData({ // posterImage: res.tempFilePath // }) that.saveImage(res.tempFilePath) // wx.downloadFile({ // url: res.tempFilePath, // success: function(res) { // if (res.statusCode === 200) { // that.saveImage(res.tempFilePath) // } // } // }) } }) }, saveImage (val) { var that = this wx.saveImageToPhotosAlbum({ filePath: val, success(res) { wx.showToast({ title: '已保存相册', icon: 'success', duration: 2000 }) }, fail (res) { wx.getSetting({ success (res) { if (!res.authSetting['scope.writePhotosAlbum']) { that.setData({ popup: true }) } } }) }, complete () { wx.hideLoading() } }) }, toDetail() { wx.navigateTo({ url: '/packageUser/pages/user/invite/detail/detail' }) }, onShareAppMessage: function (val) { return _request.share({ sc: 'xcx_invite' }) }, toMaterial () { wx.navigateTo({ url: '/packageUser/pages/user/invite/material/material' }) }, setting () { this.setData({ popup: false }) }, toRank () { wx.navigateTo({ url: '/packageUser/pages/user/invite/rank/rank' }) }, toCotb () { wx.navigateTo({ url: '/packageUser/pages/user/invite/contribution/contribution' }) }, changenav:function(e){ var cur=e.target.dataset.current; if (this.data.currentTab == parseInt(cur)) { return false; } else { this.setData({ ashow: !this.data.ashow, currentTab: cur }) } }, tomonth (e) { var that = this var next_id = e.currentTarget.dataset.val var count = e.currentTarget.dataset.count var year = that.data.year var month = that.data.month if ( count > 0) { wx.navigateTo({ url: '/packageUser/pages/user/invite/month/month?id=' + next_id + '&year=' + year + '&month=' + month }) } }, tototal (e) { var next_id = e.currentTarget.dataset.val var count = e.currentTarget.dataset.count if ( count > 0) { wx.navigateTo({ url: '/packageUser/pages/user/invite/total/total?id=' + next_id }) } }, toproxy (e) { var userid = e.currentTarget.dataset.userid wx.navigateTo({ url: '/packageUser/pages/user/proxyApply/proxyApply?uid=' + userid }) }, updatemonth () { var that = this var date = new Date(that.data.time * 1000) var year = date.getFullYear() var month = date.getMonth() + 1 // var upMonth = that.data.upmonth // var downMonth = that.data.downmonth that.setData({ year: year, month: month, newy: year, newm: month, upmonth: month - 1, downmonth: month + 1 }) }, getmonthlist () { var that = this var url = 'v1/invite/' + wx_id + '/monthly/list' var params = { page: that.data.page1, per_page: that.data.per_page1, y: that.data.year, m: that.data.month, cache: false } var success = function (res) { // wx.showLoading({ // title: '加载中', // duration: 1000 // }) // var result = that.data.mlist.concat(res.data.list || []) if (res.data.list_count > 10) { that.setData({ btnshow1: true }) } if (res.data.list.length) { var result = res.data.list that.setData({ mlist: result, page1: that.data.page1 + 1, per_page1: that.data.per_page1 }) } else { that.setData({ btnshow1: false }) } // var listMore = res.data.list_count > that.data.mlist.length that.setData({ all1: res.data, // more: listMore }) } var fail = function () { wx.hideLoading() } _request.$get(url, params, success) }, getmonthlist1 () { var that = this var url = 'v1/invite/' + wx_id + '/monthly/list' var params = { page: that.data.page1, per_page: that.data.per_page1, y: that.data.year, m: that.data.month, cache: false } var success = function (res) { // wx.showLoading({ // title: '加载中', // duration: 1000 // }) // var result = that.data.mlist.concat(res.data.list || []) if (res.data.list_count > 10) { that.setData({ btnshow1: true }) } if (res.data.list.length) { var result = that.data.mlist.concat(res.data.list || []) that.setData({ mlist: result, page1: that.data.page1 + 1, per_page1: that.data.per_page1 }) } else { that.setData({ btnshow1: false }) } // var listMore = res.data.list_count > that.data.mlist.length that.setData({ all1: res.data, // more: listMore }) } var fail = function () { wx.hideLoading() } _request.$get(url, params, success) }, prevmonth () { wx.showLoading({ title: '加载中', duration: 1000 }) var that = this var m = that.data.month var y = that.data.year var ny = that.data.newy var nm = that.data.newm m = m - 1 if (m < 1) { m = 12 y = y - 1 } that.setData({ month: m, year: y, upmonth: m - 1, downmonth: m + 1, page1: 1, // mlist: [] }) if (y === ny && m < nm) { that.setData({ nextshow: true }) } if (y < ny) { that.setData({ nextshow: true }) } if (y === 2018 && m === 7) { that.setData({ prevshow: false }) } that.getmonthlist() }, nextmonth () { wx.showLoading({ title: '加载中', duration: 1000 }) var that = this var m = that.data.month var y = that.data.year var ny = that.data.newy var nm = that.data.newm m = m + 1 if (m > 12) { m = 1 y = y + 1 } that.setData({ prevshow: true, month: m, year: y, upmonth: m - 1, downmonth: m + 1, page1: 1, // mlist: [] }) if (y === ny && m >= nm) { that.setData({ nextshow: false }) } if (y < ny) { that.setData({ nextshow: true }) } that.getmonthlist() }, getinfo () { var that = this var url = 'v1/copartner/info' var params = { } var success = function (res) { that.setData ({ cinfo: res.data }) } _request.$get(url, params, success) }, getContributionTotal () { var that = this var url = 'v1/copartner/total' var params = { } var success = function (res) { that.setData ({ pinfo: res.data }) } _request.$get(url, params, success) }, downLoadImage () { wx.showLoading({ title: '加载中', }) var that = this // wx.downloadFile({ // url: that.data.qrcode, // success: function(res) { // if (res.statusCode === 200) { // that.saveImage(res.tempFilePath) // } // } // }) wx.getImageInfo({ src: that.data.qrcode, success: function (res) { that.createCtx() } }) }, // createCtx () { // var that = this // console.log('createctx',that.data.qrcode); // var ctx = wx.createCanvasContext('myCanvas') // // ctx.drawImage(this.posterImage.bg.path, 0, 0, this.dpi(this.posterImage.bg.width), this.dpi(this.posterImage.bg.height)) // ctx.drawImage(that.data.qrcode, 0, 0, 200, 200) // ctx.save() // ctx.translate(this.dpi(44),this.dpi(46)) // ctx.save() // ctx.arc(this.dpi(60), this.dpi(59), this.dpi(40), 0, Math.PI * 2, false) // ctx.lineWidth = 1 // ctx.strokeStyle = '#d4d4d4' // ctx.stroke() // ctx.clip() // ctx.drawImage(this.posterImage.head.path, this.dpi(21), this.dpi(20), this.dpi(78), this.dpi(78)) // ctx.restore() // ctx.save() // ctx.textBaseline = 'middle' // ctx.font = this.dpi(24) + 'px Arial' // ctx.fillStyle = '#eab86a' // ctx.fillText('源处全球源产地的优质产品!', this.dpi(136), this.dpi(59)) // ctx.restore() // ctx.drawImage(this.posterImage.project.path, this.dpi(20), this.dpi(140), this.dpi(622), this.dpi(622)) // ctx.beginPath() // ctx.moveTo(this.dpi(0), this.dpi(119)) // ctx.lineTo(this.dpi(662), this.dpi(119)) // ctx.lineWidth = 1 // ctx.strokeStyle = '#eab86a' // ctx.stroke() // ctx.closePath() // ctx.save() // ctx.restore() // ctx.restore() // ctx.draw(true, function callback (res) { // console.log('over draw',res) // that.createImage() // }) // }, // createImage () { // var that = this // wx.canvasToTempFilePath({ // destWidth: 750, // destHeight: 1334, // canvasId: 'myCanvas', // fileType: 'jpg', // success: function (res) { // // that.setData({ // // posterImage: res.tempFilePath // // }) // // that.canvasLoading = true // // wx.hideLoading() // wx.downloadFile({ // url: res.tempFilePath, // success: function(res) { // if (res.statusCode === 200) { // that.saveImage(res.tempFilePath) // } // } // }) // } // }) // }, })