123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- // pages/Components/reservation/reservation.js
- const app = getApp()
- const util = require('../../../utils/util.js')
- const base64Util = require('../../../utils/base64')
- Component({
- lifetimes: {
- attached: function () {
- // 在组件实例进入页面节点树时执行
-
-
- },
- ready:function(){
- this.setData({
- // 'posterConfig.images[0].url': '',
- // 'posterConfig.images[1].url': '',
- // 'posterConfig.texts[0].text': '',
- // 'posterConfig.texts[1].text': '',
- campusInfo: wx.getStorageSync('campusInfo'),
- imageUrl: app.globalData.imageUrl,
- 'object.name':wx.getStorageSync('campusInfo').name,
- 'object.showImg': wx.getStorageSync('shareImg'),
- // 'object.codeImg': app.globalData.imageUrl + 'excl.jpg',
- })
- this.isApple()
- },
- },
-
-
- pageLifetimes: {
- show:function() {
-
- },
- },
- properties: {
- buttonText: {
- type: String,
- value: '预约试听'
- },
- buttonURL: {
- type: String,
- value: '/pages/appointmentListen/appointmentListen'
- },
- disabled:{
- type:Boolean,
- value:false
- },
- activeShow:{
- type:Boolean,
- value:false
- },
- object:{
- type:Object,
- value:{}
- },
- isBuy:{
- type: Boolean,
- value:false
- },
- isBuyText:{
- type: String,
- value: '已购买'
- },
- isId:{
- type: String,
- value: ''
- },
- typeId:{
- type:String,
- value:''
- },
- showText:{
- type:String,
- value:''
- },
- titleText:{
- type:String,
- value:''
- },
- shareImg:{
- type:String,
- value:''
- }
- },
-
- data: {
- wechatImg:app.globalData.imageUrl + 'wechat0706.png',
- pyqImg:app.globalData.imageUrl + 'pyq0706.png',
- codeImg:app.globalData.imageUrl,
- showSaveImage:false,
- bgShow: true,
- bottomFlag: false,
- phoneList:[
- 'iPhone X' ,
- 'iPhone XR' ,
- 'iPhone XS Max',
- 'iPhone 11' ,
- 'iPhone 11 Pro' ,
- 'iPhone 11 Pro Max'
- ],
- posterConfig: {
- 'width': 590,
- 'height': 680,
- 'backgroundColor': '#fff',
- 'debug': false,
- 'preload': true,
- 'hide-loading': true,
- images: [{
- x: 24,
- y: 38,
- url: '',
- width: 542,
- height: 406
- }, {
- x: 424,
- y: 520,
- url: '',
- width: 144,
- height: 144
- }],
- texts: [
- {
- x: 24,
- y: 492,
- baseLine: 'middle',
- text: '',
- fontSize: 24,
- color: '#333333',
- }, {
- x: 24,
- y: 520,
- baseLine: 'middle',
- text: '',
- fontWeight: 'bold',
- fontSize: 28,
- color: '#333333',
- },
- {
- x: 303,
- y: 570,
- baseLine: 'middle',
- text: '长按二维码',
- fontSize: 20,
- color: '#999999',
- },
- {
- x: 303,
- y: 600,
- baseLine: 'middle',
- text: '查看',
- fontSize: 20,
- color: '#999999',
- }
- ]
- },
- },
- methods: {
- isApple:function(){
- wx.getSystemInfo({//当小程序初始化完成时 获取用户的手机机型 并写出适配ipnone手机安全区域的的适配方案
- success: (res) => {
- const phone = res.model.split(" ")
- this.data.phoneList.forEach(item => {
- if(item == phone[0]+ ' ' + phone[1]){
- this.setData({
- bottomFlag:true
- })
- return false;
- }
- });
- }
- })
- },
- jumpPage(e) {
- if (this.data.campusInfo.userId) {
- wx.navigateTo({
- url: e.currentTarget.dataset.url,
- })
- } else {
- wx.showModal({
- title: '温馨提示',
- content: '您还未选择校区,是否要去查看附近的校区?',
- confirmText: '查看校区',
- success(res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/campusDistribution/campusDistribution',
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- }
- },
- backIndexPage() {
- // wx.switchTab({
- // url: '/pages/tabBar/index/index',
- // })
- wx.redirectTo({
- url: '/pages/tabBar/index/index',
- })
- },
- advisory() {
- if (this.data.campusInfo.userId) {
- wx.makePhoneCall({
- phoneNumber: this.data.campusInfo.telephone,
- })
- return
- }
- wx.showModal({
- title: '温馨提示',
- content: '您还未选择校区,是否要去查看附近的校区?',
- confirmText: '查看校区',
- success(res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/campusDistribution/campusDistribution',
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- },
- //请求校区分布列表
- getCampusDistribution() {
- let that = this;
- wx.getStorage({
- key: 'openId',
- success: (res) => {
- util.doPost(
- 'orgSchool', {
- appId: app.globalData.appId,
- openId: res.data,
- page: 0,
- size: 10
- }
- ).then(rs => {
- if (rs.success > 0) {
- const id = wx.getStorageSync('campusInfo').id
- let list = {}
- for(var i = 0 ; i < rs.data.list.length; i++){
- if(rs.data.list[i].id == id){
- list = rs.data.list[i]
- rs.data.list.splice(i,1)
- break;
- }
- }
- rs.data.list.unshift(list)
- rs.data.list[0].userId = wx.getStorageSync('openId')
- that.setData({
- campusInfo: rs.data.list[0],
- })
- } else {
- console.log(rs.errMsg)
- }
- })
- }
- })
- },
- hideBg:function(){
- if(this.data.bgShow){
- var animation = wx.createAnimation({
- duration:200,
- timingFunction:'linear'
- }).translateY(0).step()
- this.setData({
- bgShow: false,
- })
- setTimeout(() => {
- this.setData({
- animationDataShare:animation.export(),
- })
- }, 100);
- }else{
- var animation = wx.createAnimation({
- duration:200,
- timingFunction:'linear'
- }).translateY(331).step()
- this.setData({
- animationDataShare:animation.export(),
- })
- setTimeout(() => {
- this.setData({
- bgShow:true
- })
- }, 200);
- }
- },
-
- showSaveImg:function(){
- if(!this.data.activeShow){
- this.hideBg()
- if(this.data.shareImg == ''){
- this.setData({
- shareImg: wx.getStorageSync('shareImg')
- })
- }
- if(this.data.showText == ''){
- this.setData({
- 'posterConfig.texts[0].text': '我在' + app.globalData.orgTitle,
- })
- } else {
- this.setData({
- 'posterConfig.texts[0].text': '我在' + app.globalData.orgTitle + '参加了',
- })
- }
- this.setData({
-
- 'posterConfig.texts[1].text': this.data.titleText,
- 'posterConfig.images[0].url': this.data.shareImg,
- // 'posterConfig.images[1].url': this.data.object.codeImg,
- })
- const curPage = getCurrentPages()[getCurrentPages().length - 1].route;
- if(curPage == 'pages/wcsp/wcsp' || curPage == 'pages/routine/routine'){
- this.getCode(this.data.isId,curPage,this.data.typeId)
- } else{
- this.getCode('','','')
- }
- wx.showLoading({
- title: '正在生成海报',
- mask: true
- })
-
- } else{
-
- var animation = wx.createAnimation({
- duration:200,
- timingFunction:'linear'
- }).translateY(331).step()
- this.setData({
- animationDataShare:animation.export(),
- })
- setTimeout(() => {
- this.setData({
- bgShow:true
- })
- }, 200);
- }
- this.triggerEvent('callMethod')
- },
-
- closeSaveImage() {
- this.setData({
- showSaveImage: false
- })
- this.triggerEvent('callMethod')
- },
- parentMethod:function(){
- this.triggerEvent("callMethod")
- },
- //生成图片并保存
- onPosterSuccess(e) {
- let that = this;
- let {
- detail
- } = e;
- wx.saveImageToPhotosAlbum({
- filePath: detail,
- success(res) {
- wx.showToast({
- title: '图片已保存到本地相册',
- icon:'none'
- })
- that.setData({
- showSaveImage: false
- })
- that.triggerEvent("callMethod")
- },fail(res){
- that.getSetting()
- }
- })
- },
- getSetting:function(){
- // 相册授权
- wx.getSetting({
- success(res) {
- // 进行授权检测,未授权则进行弹层授权
- if (!res.authSetting["scope.writePhotosAlbum"]) {
- wx.showModal({
- title: '提示',
- content: '您未授权相册使用权限,是否重新授权?',
- success:function(res){
- if(res.confirm){
- wx.openSetting({
- success(settingdata) {
- if (settingdata.authSetting["scope.writePhotosAlbum"]) {
- console.log("获取权限成功,再次点击图片保存到相册")
- } else {
- console.log("获取权限失败")
- }
- },fail(res){
- console.log(res)
- }
- })
- }
- }
- })
- }
- },
- fail(res) {
- console.log(res);
- }
- });
- },
- changeImg:function(shareImg,showText,titleText){
- this.setData({
- shareImg:shareImg,
- showText:showText,
- titleText:titleText
- })
- },
- getCode:function(id,curPage,typeId){
- if(typeId != ''){
- var isParam ={specialId: id,typeId:typeId}
- }else{
- var isParam ={id: id}
- }
- const codeParams={
- appId: app.globalData.appId,
- page: curPage,
- param: JSON.stringify(isParam)
- }
- if(id == ""){
- delete codeParams.param
- }
- if(curPage == ""){
- delete codeParams.page
- }
- util.doPost(
- 'getQrcode',codeParams
- ).then( res => {
- wx.hideLoading({
- success: (res) => {},
- })
- if(res != null){
- let images = res
- let timestamp = Date.parse(new Date());
- timestamp = timestamp / 1000;
- base64Util.base64src(images, timestamp, res => {
- this.setData({
- // 'posterConfig.images[0].url': this.data.imgArr[0],
- 'posterConfig.images[1].url': res,
- base64Img: res
- })
- });
- this.setData({
- showSaveImage:true,
- })
- } else {
- wx.showToast({
- title: '海报生成失败',
- })
- }
- })
- },
- onShareAppMessage:function(){
-
- },
- },
-
- })
|