certificates.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <template>
  2. <view class="content">
  3. <view class="team" v-if="!is_over">
  4. <empty></empty>
  5. </view>
  6. <view class="certificates" v-if='is_over'>
  7. <canvas v-if="showcanvas" id="qrShareBox" canvas-id="qrShareBox" class="tki-qrcode-canvas" />
  8. <image class="imgbox" v-else :src="img" mode=" aspectFill"></image>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. import { get_training, sign_training, detail_training} from '@/api/train.js';
  14. import jyfParser from "@/components/jyf-parser/jyf-parser";
  15. import {
  16. weixindata,
  17. weixinlocation
  18. } from '@/utils/wxAuthorized.js';
  19. import empty from '@/components/empty';
  20. import {
  21. userinfo
  22. } from '@/api/user.js';
  23. import {
  24. mapState,
  25. mapMutations
  26. } from 'vuex';
  27. export default {
  28. components: {
  29. empty,
  30. jyfParser
  31. },
  32. data() {
  33. return {
  34. is_over:1,
  35. type:'',//0是个人报名,1是团体报名
  36. id:'',
  37. description:'',
  38. list:'',
  39. //个人
  40. name:'',
  41. phone:'',
  42. addr:'',
  43. work:'',
  44. //团队
  45. company:'',
  46. address:'',
  47. companyName:'',
  48. companyphone:'',
  49. num:'',
  50. people:'神农架林区红十字会',
  51. signDate:'',
  52. loading: true, //是否载入图片中
  53. size: 180,
  54. ratio: 1, //页面比例用于计算
  55. canHeight: '',
  56. canWeidth: '',
  57. url:'',
  58. img:'',
  59. showcanvas:true,
  60. uid:''
  61. };
  62. },
  63. onLoad(option) {
  64. this.type = option.type;
  65. this.id = option.id;
  66. this.IndexShare();
  67. this.loadData();
  68. },
  69. onReady() {
  70. detail_training({
  71. id:this.id,
  72. }).then(({data}) => {
  73. console.log(999,data)
  74. this.name = data.name
  75. this.signDate = data.add_time
  76. this.is_over = data.is_over
  77. console.log(3,data.add_time)
  78. let obj = this;
  79. let name = obj.name
  80. let signDate = obj.signDate
  81. function getRecTime(timestamp, fmt) {
  82. let d = new Date(timestamp * 1000)
  83. // f = fmt || 'yyyy/MM/dd',
  84. let f = fmt || 'yyyy.MM.dd'
  85. let o = {
  86. 'M+': d.getMonth() + 1, //月份
  87. 'd+': d.getDate(), //日
  88. 'h+': d.getHours(), //小时
  89. 'm+': d.getMinutes(), //分
  90. 's+': d.getSeconds(), //秒
  91. 'q+': Math.floor((d.getMonth() + 3) / 3), //季度
  92. 'S': d.getMilliseconds() //毫秒
  93. };
  94. if (/(y+)/.test(f)) {
  95. f = f.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length));
  96. }
  97. for (let k in o) {
  98. if (new RegExp('(' + k + ')').test(f)) {
  99. f = f.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
  100. }
  101. }
  102. return f;
  103. console.log(f)
  104. }
  105. let m = getRecTime(signDate)
  106. let query = uni.createSelectorQuery();
  107. // this.loadData();
  108. // 获取页面比例
  109. query
  110. .select('.certificates')
  111. .fields({
  112. size: true
  113. },
  114. e => {
  115. console.log('获取页面比例',e)
  116. // 保存比例
  117. this.ratio = e.width / 750;
  118. }
  119. )
  120. .exec();
  121. // 获取画布宽高信息
  122. query
  123. .select('#qrShareBox')
  124. .fields({
  125. size: true
  126. },
  127. e => {
  128. console.log('获取画布宽高信息',e)
  129. obj.canHeight = e.height;
  130. obj.canWeidth = e.width;
  131. }
  132. )
  133. .exec();
  134. let ctxBg = '/static/img/graduation.png'; //画布背景
  135. let src = '/static/icon/erweima.jpg' // 二维码
  136. let context = uni.createCanvasContext('qrShareBox');
  137. // 插入背景图片
  138. context.drawImage(ctxBg, 0, 0, obj.canWeidth, obj.canHeight);
  139. const codeSize = obj.size * obj.ratio; //计算二维码大小
  140. const codeX = ((750 - obj.size) * obj.ratio) / 2; //二维码所在x轴位置
  141. const codeY = 999 * obj.ratio; //二维码所在y轴位置
  142. // console.log('二维码大小',codeSize)
  143. // console.log('二维码所在x轴位置',codeX)
  144. // console.log('二维码所在y轴位置',codeY)
  145. const codeBoxColor = '#FFFFFF'; //包裹框颜色
  146. const codeBoxWidht = 0; //包裹边框宽度
  147. const codeBoxSize = (codeBoxWidht / 2) * obj.ratio; //计算二维码白色包裹框大小
  148. const codeBoxX = codeX - codeBoxSize; //包裹框初始X轴
  149. const codeBoxY = codeY - codeBoxSize; //包裹框初始Y轴
  150. const codeBoxEnd = codeSize + codeBoxWidht * obj.ratio; //计算包裹框大小
  151. const fontTop = codeY + codeBoxEnd + (codeBoxWidht + 20) * obj.ratio; //文字距离上边距高度
  152. const fontSize = 24 * obj.ratio; //文字大小
  153. const fontText = ''; //文字内容
  154. const fontLeft = (codeSize - fontSize * fontText.length) / 2 + codeX; //文字左侧距离
  155. // // 插入文字
  156. context.setFontSize(32 * obj.ratio)
  157. // 画横线
  158. context.moveTo(90 * obj.ratio, 586 * obj.ratio)
  159. context.lineTo(250 * obj.ratio, 586 * obj.ratio)
  160. context.stroke();
  161. context.setTextAlign('center')
  162. context.fillText(name, 170 * obj.ratio, 574 * obj.ratio)
  163. context.setTextAlign('left')
  164. context.fillText('先生/女士', 260 * obj.ratio, 580 * obj.ratio)
  165. context.setFontSize(31 * obj.ratio)
  166. context.fillText('您已完成神农架林区红十字会普及培训', 105 * obj.ratio, 670 * obj.ratio)
  167. context.fillText('的全部课程,特发此证。', 105 * obj.ratio, 720 * obj.ratio)
  168. context.setFontSize(22 * obj.ratio)
  169. context.fillText('签发人:', 300 * obj.ratio, 800 * obj.ratio)
  170. context.fillText('Siger:', 300 * obj.ratio, 830 * obj.ratio)
  171. // 画横线
  172. context.moveTo(380 * obj.ratio, 830 * obj.ratio)
  173. context.lineTo(660 * obj.ratio, 830 * obj.ratio)
  174. context.stroke()
  175. context.fillText('签发日期:', 300 * obj.ratio, 880 * obj.ratio)
  176. context.fillText('Issuer Date:', 300 * obj.ratio, 910 * obj.ratio)
  177. context.setFontSize(26 * obj.ratio)
  178. context.fillText(m, 475 * obj.ratio, 908 * obj.ratio)
  179. context.fillText('神农架林区红十字会', 440 * obj.ratio, 820 * obj.ratio)
  180. // 画横线
  181. context.moveTo(430 * obj.ratio, 915 * obj.ratio)
  182. context.lineTo(660 * obj.ratio, 915 * obj.ratio)
  183. context.stroke()
  184. context.setFontSize(fontSize);
  185. context.fillText(fontText, fontLeft, fontTop);
  186. // 插入边框
  187. context.beginPath();
  188. context.setLineJoin('round'); //边框类型
  189. context.setLineWidth(codeBoxWidht * obj.ratio);
  190. context.setStrokeStyle(codeBoxColor); //设置包裹框颜色
  191. context.strokeRect(codeBoxX, codeBoxY, codeBoxEnd, codeBoxEnd);
  192. context.stroke();
  193. // 插入二维码
  194. context.drawImage(src, codeX, codeY, codeSize, codeSize);
  195. context.draw(false,(e) => {
  196. uni.canvasToTempFilePath({
  197. x: 0,
  198. y: 0,
  199. width: obj.canWeidth,
  200. height: obj.canHeight,
  201. destWidth: obj.canWeidth,
  202. destHeight: obj.canHeight,
  203. canvasId: 'qrShareBox',
  204. success: function(res) {
  205. console.log(res)
  206. // uni.showModal({
  207. // title:'zhi1'
  208. // })
  209. // 在H5平台下,tempFilePath 为 base64
  210. // console.log(res.tempFilePath)
  211. obj.showcanvas = false;
  212. obj.img = res.tempFilePath
  213. }
  214. })
  215. })
  216. })
  217. },
  218. onShow() {
  219. this.uid = this.userInfo.uid;
  220. console.log('this.uid',this.uid)
  221. },
  222. computed: {
  223. ...mapState('user', ['hasLogin', 'userInfo'])
  224. },
  225. methods: {
  226. ...mapMutations('user', ['setUserInfo']),
  227. // 分享
  228. IndexShare() {
  229. let obj = this;
  230. let item = {
  231. link: 'http://slj.igxys.com/index/#/pages/train/sign?type=' + obj.type + '&id=' + obj.id + '&uid=' + obj.userInfo.uid,// 分享链接
  232. imgUrl: '/index/static/img/002.png',
  233. desc: '结业证书',
  234. title: '神农架林区红十字会',
  235. };
  236. console.log('分享加',item)
  237. weixindata(item);
  238. },
  239. async loadData() {
  240. let obj = this;
  241. console.log('当前is_over',obj.is_over)
  242. if( obj.is_over == 1 ) {
  243. let uid = obj.userInfo.uid
  244. console.log(9090,uid)
  245. }
  246. get_training({
  247. id:obj.id,
  248. // uid:uid
  249. }).then(({ data }) => {
  250. obj.list = data;
  251. console.log(9988,data)
  252. if(obj.list.content != null){
  253. obj.description = obj.list.content.replace(/<img/g,"<img style='max-width:100%;height:auto;'");
  254. }
  255. });
  256. },
  257. submit(){
  258. let obj = this;
  259. let data = {};
  260. if(obj.type==0){
  261. if(!obj.name){
  262. obj.$api.msg('请填写姓名!');
  263. return;
  264. }
  265. if(!obj.phone){
  266. obj.$api.msg('请输入联系方式!');
  267. return;
  268. }
  269. if(!obj.addr){
  270. obj.$api.msg('请输入联系方式!');
  271. return;
  272. }
  273. data={
  274. name:obj.name,
  275. work:obj.addr,
  276. phone:obj.phone,
  277. tid:obj.id,
  278. type:0
  279. }
  280. }
  281. if(obj.type==1){
  282. if(!obj.company){
  283. obj.$api.msg('请填写企业名称!');
  284. return;
  285. }
  286. if(!obj.address){
  287. obj.$api.msg('请填写企业地址!');
  288. return;
  289. }
  290. if(!obj.companyName){
  291. obj.$api.msg('请填写负责人姓名!');
  292. return;
  293. }
  294. if(!obj.companyphone){
  295. obj.$api.msg('请输入联系方式!');
  296. return;
  297. }
  298. if(!obj.num){
  299. obj.$api.msg('请输入参加培训人数!');
  300. return;
  301. }
  302. data={
  303. company:obj.company,
  304. address:obj.address,
  305. name:obj.companyName,
  306. phone:obj.companyphone,
  307. num:obj.num,
  308. tid:obj.id,
  309. type:1
  310. }
  311. }
  312. sign_training(data).then(function(e) {
  313. console.log(data.type)
  314. let type = data.type
  315. uni.setStorageSync('type', type)
  316. obj.$api.msg(e.msg);
  317. setTimeout(function(){
  318. uni.navigateTo({
  319. url:'/pages/train/index'
  320. })
  321. }, 1000);
  322. }).catch(e => {
  323. obj.$api.msg(e.message);
  324. setTimeout(function(){
  325. uni.navigateTo({
  326. url:'/pages/train/index'
  327. })
  328. }, 1000);
  329. });;
  330. },
  331. getRecTime(timestamp, fmt) {
  332. let d = new Date(timestamp * 1000),
  333. // f = fmt || 'yyyy/MM/dd',
  334. f = fmt || 'yyyy.MM.dd hh:mm:ss',
  335. o = {
  336. 'M+': d.getMonth() + 1, //月份
  337. 'd+': d.getDate(), //日
  338. 'h+': d.getHours(), //小时
  339. 'm+': d.getMinutes(), //分
  340. 's+': d.getSeconds(), //秒
  341. 'q+': Math.floor((d.getMonth() + 3) / 3), //季度
  342. 'S': d.getMilliseconds() //毫秒
  343. };
  344. if (/(y+)/.test(f)) {
  345. f = f.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length));
  346. }
  347. for (let k in o) {
  348. if (new RegExp('(' + k + ')').test(f)) {
  349. f = f.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
  350. }
  351. }
  352. return f;
  353. console.log(f)
  354. },
  355. }
  356. };
  357. </script>
  358. <style lang="scss">
  359. page {
  360. background: #FFFFFF;
  361. width: 100%;
  362. height: 100%;
  363. .content {
  364. height: 100%;
  365. }
  366. }
  367. .box{
  368. padding: 0rpx 25rpx;
  369. width: 100%;
  370. }
  371. .top-image{
  372. width: 100%;
  373. height: 300rpx;
  374. }
  375. .top-title{
  376. width: 100%;
  377. text-align: center;
  378. padding: 25rpx 0rpx;
  379. font-size: 34rpx;
  380. border-bottom:1rpx dashed #B5B5B5;
  381. }
  382. .canten{
  383. text-align: center !important;
  384. }
  385. .addr{
  386. color: #222222;
  387. font-size: 28rpx;
  388. padding: 25rpx 35rpx;
  389. }
  390. .text-box{
  391. padding: 25rpx 25rpx;
  392. padding-bottom: 0rpx !important;
  393. }
  394. .text{
  395. color: #222222;
  396. font-size: 28rpx;
  397. padding-bottom: 15rpx;
  398. }
  399. .weixin-icon{
  400. width: 100%;
  401. text-align: center;
  402. padding-top: 45rpx;
  403. image{
  404. width: 248rpx;
  405. height: 248rpx;
  406. }
  407. }
  408. .tip{
  409. color: #222222;
  410. font-size: 28rpx;
  411. width: 100%;
  412. text-align: center;
  413. padding-bottom: 50rpx;
  414. }
  415. .sign-tip{
  416. padding: 25rpx 0rpx;
  417. text-align: center;
  418. color: #222222;
  419. font-size: 28rpx;
  420. }
  421. .form-box{
  422. padding: 0rpx 35rpx;
  423. .label{
  424. font-size: 34rpx;
  425. padding: 25rpx 0rpx;
  426. text{
  427. color: #E62129;
  428. padding-left: 5rpx;
  429. }
  430. }
  431. input{
  432. font-size: 28rpx;
  433. color: #222222;
  434. border: 2rpx solid #979797;
  435. padding: 0rpx 15rpx;
  436. border-radius: 15rpx;
  437. height: 80rpx;
  438. }
  439. }
  440. .submit{
  441. width: 70%;
  442. margin: 0rpx auto;
  443. margin-top: 80rpx;
  444. margin-bottom: 80rpx;
  445. padding: 25rpx 0;
  446. text-align: center;
  447. background-color: #E62129;
  448. color: #FFFFFF;
  449. font-size: 32rpx;
  450. border-radius: 10rpx;
  451. }
  452. .grey{
  453. background-color: #9B9B9B !important;
  454. }
  455. .certificates{
  456. // padding: 24rpx;
  457. width: 100%;
  458. height: 100vh;
  459. }
  460. .tki-qrcode-canvas {
  461. // width: 700rpx;
  462. // height: 1245rpx;
  463. width: 750rpx;
  464. // padding: 32rpx;
  465. height: 1350rpx;
  466. margin: 0 auto;
  467. }
  468. .bgimg{
  469. width: 100%;
  470. height: 100%;
  471. image{
  472. width: 100%;
  473. height: 100%;
  474. }
  475. }
  476. .box-mian{
  477. width: 100%;
  478. height: 100%;
  479. position: absolute;
  480. padding:380rpx 94rpx 200rpx 94rpx;
  481. color: #333;
  482. left: 0;
  483. top: 0;
  484. display: flex;
  485. flex-direction: column;
  486. justify-content: center;
  487. // align-items: center;
  488. .name{
  489. display: flex;
  490. font-size: 32rpx;
  491. .name-left{
  492. text-align: center;
  493. // padding: 0 24rpx;
  494. width: 150rpx;
  495. border-bottom: 2rpx solid #333;
  496. }
  497. }
  498. .info{
  499. margin-top: 68rpx;
  500. text-indent: 64rpx;
  501. line-height: 58rpx;
  502. }
  503. .signName{
  504. margin-top: 32rpx;
  505. display: flex;
  506. .signName-left{
  507. line-height: 34rpx;
  508. .signName-1{
  509. }
  510. .signName-2{
  511. font-size: 28rpx;
  512. }
  513. }
  514. .signName-right{
  515. text-align: left;
  516. // width: 100%;
  517. padding: 0 12rpx;
  518. margin-left: 12rpx;
  519. // width: 288rpx;
  520. border-bottom: 2rpx solid #333;
  521. // margin-bottom: 12rpx;
  522. .list-input {
  523. width: 100%;
  524. padding: 0 12rpx;
  525. height: 70rpx;
  526. font-size: 32rpx;
  527. text-align: left;
  528. }
  529. .signDate{
  530. display: flex;
  531. align-items: center;
  532. }
  533. }
  534. }
  535. .signDate{
  536. margin-top: 22rpx;
  537. display: flex;
  538. .signName-left{
  539. line-height: 34rpx;
  540. .signName-1{
  541. }
  542. .signName-2{
  543. font-size: 28rpx;
  544. }
  545. }
  546. .signName-right{
  547. text-align: left;
  548. padding-left: 12rpx;
  549. margin-left: 12rpx;
  550. width: 288rpx;
  551. border-bottom: 2rpx solid #333;
  552. .list-input {
  553. height: 70rpx;
  554. font-size: 32rpx;
  555. text-align: left;
  556. }
  557. // margin-bottom: 12rpx;
  558. }
  559. }
  560. // background-color: pink;
  561. }
  562. .imgbox{
  563. height: 1350rpx;
  564. width:750rpx;
  565. }
  566. </style>