reservation.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. // pages/Components/reservation/reservation.js
  2. const app = getApp()
  3. const util = require('../../../utils/util.js')
  4. const base64Util = require('../../../utils/base64')
  5. Component({
  6. lifetimes: {
  7. attached: function () {
  8. // 在组件实例进入页面节点树时执行
  9. },
  10. ready:function(){
  11. this.setData({
  12. // 'posterConfig.images[0].url': '',
  13. // 'posterConfig.images[1].url': '',
  14. // 'posterConfig.texts[0].text': '',
  15. // 'posterConfig.texts[1].text': '',
  16. campusInfo: wx.getStorageSync('campusInfo'),
  17. imageUrl: app.globalData.imageUrl,
  18. 'object.name':wx.getStorageSync('campusInfo').name,
  19. 'object.showImg': wx.getStorageSync('shareImg'),
  20. // 'object.codeImg': app.globalData.imageUrl + 'excl.jpg',
  21. })
  22. this.isApple()
  23. },
  24. },
  25. pageLifetimes: {
  26. show:function() {
  27. },
  28. },
  29. properties: {
  30. buttonText: {
  31. type: String,
  32. value: '预约试听'
  33. },
  34. buttonURL: {
  35. type: String,
  36. value: '/pages/appointmentListen/appointmentListen'
  37. },
  38. disabled:{
  39. type:Boolean,
  40. value:false
  41. },
  42. activeShow:{
  43. type:Boolean,
  44. value:false
  45. },
  46. object:{
  47. type:Object,
  48. value:{}
  49. },
  50. isBuy:{
  51. type: Boolean,
  52. value:false
  53. },
  54. isBuyText:{
  55. type: String,
  56. value: '已购买'
  57. },
  58. isId:{
  59. type: String,
  60. value: ''
  61. },
  62. typeId:{
  63. type:String,
  64. value:''
  65. },
  66. showText:{
  67. type:String,
  68. value:''
  69. },
  70. titleText:{
  71. type:String,
  72. value:''
  73. },
  74. shareImg:{
  75. type:String,
  76. value:''
  77. }
  78. },
  79. data: {
  80. wechatImg:app.globalData.imageUrl + 'wechat0706.png',
  81. pyqImg:app.globalData.imageUrl + 'pyq0706.png',
  82. codeImg:app.globalData.imageUrl,
  83. showSaveImage:false,
  84. bgShow: true,
  85. bottomFlag: false,
  86. phoneList:[
  87. 'iPhone X' ,
  88. 'iPhone XR' ,
  89. 'iPhone XS Max',
  90. 'iPhone 11' ,
  91. 'iPhone 11 Pro' ,
  92. 'iPhone 11 Pro Max'
  93. ],
  94. posterConfig: {
  95. 'width': 590,
  96. 'height': 680,
  97. 'backgroundColor': '#fff',
  98. 'debug': false,
  99. 'preload': true,
  100. 'hide-loading': true,
  101. images: [{
  102. x: 24,
  103. y: 38,
  104. url: '',
  105. width: 542,
  106. height: 406
  107. }, {
  108. x: 424,
  109. y: 520,
  110. url: '',
  111. width: 144,
  112. height: 144
  113. }],
  114. texts: [
  115. {
  116. x: 24,
  117. y: 492,
  118. baseLine: 'middle',
  119. text: '',
  120. fontSize: 24,
  121. color: '#333333',
  122. }, {
  123. x: 24,
  124. y: 520,
  125. baseLine: 'middle',
  126. text: '',
  127. fontWeight: 'bold',
  128. fontSize: 28,
  129. color: '#333333',
  130. },
  131. {
  132. x: 303,
  133. y: 570,
  134. baseLine: 'middle',
  135. text: '长按二维码',
  136. fontSize: 20,
  137. color: '#999999',
  138. },
  139. {
  140. x: 303,
  141. y: 600,
  142. baseLine: 'middle',
  143. text: '查看',
  144. fontSize: 20,
  145. color: '#999999',
  146. }
  147. ]
  148. },
  149. },
  150. methods: {
  151. isApple:function(){
  152. wx.getSystemInfo({//当小程序初始化完成时 获取用户的手机机型 并写出适配ipnone手机安全区域的的适配方案
  153. success: (res) => {
  154. const phone = res.model.split(" ")
  155. this.data.phoneList.forEach(item => {
  156. if(item == phone[0]+ ' ' + phone[1]){
  157. this.setData({
  158. bottomFlag:true
  159. })
  160. return false;
  161. }
  162. });
  163. }
  164. })
  165. },
  166. jumpPage(e) {
  167. if (this.data.campusInfo.userId) {
  168. wx.navigateTo({
  169. url: e.currentTarget.dataset.url,
  170. })
  171. } else {
  172. wx.showModal({
  173. title: '温馨提示',
  174. content: '您还未选择校区,是否要去查看附近的校区?',
  175. confirmText: '查看校区',
  176. success(res) {
  177. if (res.confirm) {
  178. wx.navigateTo({
  179. url: '/pages/campusDistribution/campusDistribution',
  180. })
  181. } else if (res.cancel) {
  182. console.log('用户点击取消')
  183. }
  184. }
  185. })
  186. }
  187. },
  188. backIndexPage() {
  189. // wx.switchTab({
  190. // url: '/pages/tabBar/index/index',
  191. // })
  192. wx.redirectTo({
  193. url: '/pages/tabBar/index/index',
  194. })
  195. },
  196. advisory() {
  197. if (this.data.campusInfo.userId) {
  198. wx.makePhoneCall({
  199. phoneNumber: this.data.campusInfo.telephone,
  200. })
  201. return
  202. }
  203. wx.showModal({
  204. title: '温馨提示',
  205. content: '您还未选择校区,是否要去查看附近的校区?',
  206. confirmText: '查看校区',
  207. success(res) {
  208. if (res.confirm) {
  209. wx.navigateTo({
  210. url: '/pages/campusDistribution/campusDistribution',
  211. })
  212. } else if (res.cancel) {
  213. console.log('用户点击取消')
  214. }
  215. }
  216. })
  217. },
  218. //请求校区分布列表
  219. getCampusDistribution() {
  220. let that = this;
  221. wx.getStorage({
  222. key: 'openId',
  223. success: (res) => {
  224. util.doPost(
  225. 'orgSchool', {
  226. appId: app.globalData.appId,
  227. openId: res.data,
  228. page: 0,
  229. size: 10
  230. }
  231. ).then(rs => {
  232. if (rs.success > 0) {
  233. const id = wx.getStorageSync('campusInfo').id
  234. let list = {}
  235. for(var i = 0 ; i < rs.data.list.length; i++){
  236. if(rs.data.list[i].id == id){
  237. list = rs.data.list[i]
  238. rs.data.list.splice(i,1)
  239. break;
  240. }
  241. }
  242. rs.data.list.unshift(list)
  243. rs.data.list[0].userId = wx.getStorageSync('openId')
  244. that.setData({
  245. campusInfo: rs.data.list[0],
  246. })
  247. } else {
  248. console.log(rs.errMsg)
  249. }
  250. })
  251. }
  252. })
  253. },
  254. hideBg:function(){
  255. if(this.data.bgShow){
  256. var animation = wx.createAnimation({
  257. duration:200,
  258. timingFunction:'linear'
  259. }).translateY(0).step()
  260. this.setData({
  261. bgShow: false,
  262. })
  263. setTimeout(() => {
  264. this.setData({
  265. animationDataShare:animation.export(),
  266. })
  267. }, 100);
  268. }else{
  269. var animation = wx.createAnimation({
  270. duration:200,
  271. timingFunction:'linear'
  272. }).translateY(331).step()
  273. this.setData({
  274. animationDataShare:animation.export(),
  275. })
  276. setTimeout(() => {
  277. this.setData({
  278. bgShow:true
  279. })
  280. }, 200);
  281. }
  282. },
  283. showSaveImg:function(){
  284. if(!this.data.activeShow){
  285. this.hideBg()
  286. if(this.data.shareImg == ''){
  287. this.setData({
  288. shareImg: wx.getStorageSync('shareImg')
  289. })
  290. }
  291. if(this.data.showText == ''){
  292. this.setData({
  293. 'posterConfig.texts[0].text': '我在' + app.globalData.orgTitle,
  294. })
  295. } else {
  296. this.setData({
  297. 'posterConfig.texts[0].text': '我在' + app.globalData.orgTitle + '参加了',
  298. })
  299. }
  300. this.setData({
  301. 'posterConfig.texts[1].text': this.data.titleText,
  302. 'posterConfig.images[0].url': this.data.shareImg,
  303. // 'posterConfig.images[1].url': this.data.object.codeImg,
  304. })
  305. const curPage = getCurrentPages()[getCurrentPages().length - 1].route;
  306. if(curPage == 'pages/wcsp/wcsp' || curPage == 'pages/routine/routine'){
  307. this.getCode(this.data.isId,curPage,this.data.typeId)
  308. } else{
  309. this.getCode('','','')
  310. }
  311. wx.showLoading({
  312. title: '正在生成海报',
  313. mask: true
  314. })
  315. } else{
  316. var animation = wx.createAnimation({
  317. duration:200,
  318. timingFunction:'linear'
  319. }).translateY(331).step()
  320. this.setData({
  321. animationDataShare:animation.export(),
  322. })
  323. setTimeout(() => {
  324. this.setData({
  325. bgShow:true
  326. })
  327. }, 200);
  328. }
  329. this.triggerEvent('callMethod')
  330. },
  331. closeSaveImage() {
  332. this.setData({
  333. showSaveImage: false
  334. })
  335. this.triggerEvent('callMethod')
  336. },
  337. parentMethod:function(){
  338. this.triggerEvent("callMethod")
  339. },
  340. //生成图片并保存
  341. onPosterSuccess(e) {
  342. let that = this;
  343. let {
  344. detail
  345. } = e;
  346. wx.saveImageToPhotosAlbum({
  347. filePath: detail,
  348. success(res) {
  349. wx.showToast({
  350. title: '图片已保存到本地相册',
  351. icon:'none'
  352. })
  353. that.setData({
  354. showSaveImage: false
  355. })
  356. that.triggerEvent("callMethod")
  357. },fail(res){
  358. that.getSetting()
  359. }
  360. })
  361. },
  362. getSetting:function(){
  363. // 相册授权
  364. wx.getSetting({
  365. success(res) {
  366. // 进行授权检测,未授权则进行弹层授权
  367. if (!res.authSetting["scope.writePhotosAlbum"]) {
  368. wx.showModal({
  369. title: '提示',
  370. content: '您未授权相册使用权限,是否重新授权?',
  371. success:function(res){
  372. if(res.confirm){
  373. wx.openSetting({
  374. success(settingdata) {
  375. if (settingdata.authSetting["scope.writePhotosAlbum"]) {
  376. console.log("获取权限成功,再次点击图片保存到相册")
  377. } else {
  378. console.log("获取权限失败")
  379. }
  380. },fail(res){
  381. console.log(res)
  382. }
  383. })
  384. }
  385. }
  386. })
  387. }
  388. },
  389. fail(res) {
  390. console.log(res);
  391. }
  392. });
  393. },
  394. changeImg:function(shareImg,showText,titleText){
  395. this.setData({
  396. shareImg:shareImg,
  397. showText:showText,
  398. titleText:titleText
  399. })
  400. },
  401. getCode:function(id,curPage,typeId){
  402. if(typeId != ''){
  403. var isParam ={specialId: id,typeId:typeId}
  404. }else{
  405. var isParam ={id: id}
  406. }
  407. const codeParams={
  408. appId: app.globalData.appId,
  409. page: curPage,
  410. param: JSON.stringify(isParam)
  411. }
  412. if(id == ""){
  413. delete codeParams.param
  414. }
  415. if(curPage == ""){
  416. delete codeParams.page
  417. }
  418. util.doPost(
  419. 'getQrcode',codeParams
  420. ).then( res => {
  421. wx.hideLoading({
  422. success: (res) => {},
  423. })
  424. if(res != null){
  425. let images = res
  426. let timestamp = Date.parse(new Date());
  427. timestamp = timestamp / 1000;
  428. base64Util.base64src(images, timestamp, res => {
  429. this.setData({
  430. // 'posterConfig.images[0].url': this.data.imgArr[0],
  431. 'posterConfig.images[1].url': res,
  432. base64Img: res
  433. })
  434. });
  435. this.setData({
  436. showSaveImage:true,
  437. })
  438. } else {
  439. wx.showToast({
  440. title: '海报生成失败',
  441. })
  442. }
  443. })
  444. },
  445. onShareAppMessage:function(){
  446. },
  447. },
  448. })