certificates.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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 = '/index/static/img/graduation.png'; //画布背景
  135. let src = '/index/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.fillText(name, 110 * obj.ratio, 574 * obj.ratio)
  162. context.fillText('先生/女士', 260 * obj.ratio, 580 * obj.ratio)
  163. context.setFontSize(31 * obj.ratio)
  164. context.fillText('您已完鄂州市红十字会普及培训', 105 * obj.ratio, 670 * obj.ratio)
  165. context.fillText('的全部课程,特发此证。', 105 * obj.ratio, 720 * obj.ratio)
  166. context.setFontSize(22 * obj.ratio)
  167. context.fillText('签发人:', 100 * obj.ratio, 800 * obj.ratio)
  168. context.fillText('Siger:', 100 * obj.ratio, 830 * obj.ratio)
  169. // 画横线
  170. context.moveTo(180 * obj.ratio, 830 * obj.ratio)
  171. context.lineTo(460 * obj.ratio, 830 * obj.ratio)
  172. context.stroke()
  173. context.fillText('签发日期:', 100 * obj.ratio, 880 * obj.ratio)
  174. context.fillText('Issuer Date:', 100 * obj.ratio, 910 * obj.ratio)
  175. context.setFontSize(26 * obj.ratio)
  176. context.fillText(m, 275 * obj.ratio, 908 * obj.ratio)
  177. context.fillText('鄂州市红十字会', 200 * obj.ratio, 820 * obj.ratio)
  178. // 画横线
  179. context.moveTo(230 * obj.ratio, 915 * obj.ratio)
  180. context.lineTo(460 * obj.ratio, 915 * obj.ratio)
  181. context.stroke()
  182. context.setFontSize(fontSize);
  183. context.fillText(fontText, fontLeft, fontTop);
  184. // 插入边框
  185. context.beginPath();
  186. context.setLineJoin('round'); //边框类型
  187. context.setLineWidth(codeBoxWidht * obj.ratio);
  188. context.setStrokeStyle(codeBoxColor); //设置包裹框颜色
  189. context.strokeRect(codeBoxX, codeBoxY, codeBoxEnd, codeBoxEnd);
  190. context.stroke();
  191. // 插入二维码
  192. context.drawImage(src, codeX, codeY, codeSize, codeSize);
  193. context.draw(false,(e) => {
  194. uni.canvasToTempFilePath({
  195. x: 0,
  196. y: 0,
  197. width: obj.canWeidth,
  198. height: obj.canHeight,
  199. destWidth: obj.canWeidth,
  200. destHeight: obj.canHeight,
  201. canvasId: 'qrShareBox',
  202. success: function(res) {
  203. console.log(res)
  204. // uni.showModal({
  205. // title:'zhi1'
  206. // })
  207. // 在H5平台下,tempFilePath 为 base64
  208. // console.log(res.tempFilePath)
  209. obj.showcanvas = false;
  210. obj.img = res.tempFilePath
  211. }
  212. })
  213. })
  214. })
  215. },
  216. onShow() {
  217. this.uid = this.userInfo.uid;
  218. console.log('this.uid',this.uid)
  219. },
  220. computed: {
  221. ...mapState('user', ['hasLogin', 'userInfo'])
  222. },
  223. methods: {
  224. ...mapMutations('user', ['setUserInfo']),
  225. // 分享
  226. IndexShare() {
  227. let obj = this;
  228. let item = {
  229. link: 'http://ez.igxys.com/index/#/pages/train/sign?type=' + obj.type + '&id=' + obj.id + '&uid=' + obj.userInfo.uid,// 分享链接
  230. imgUrl: 'http://ez.igxys.com/index/static/img/002.png',
  231. desc: '结业证书',
  232. title: '鄂州市红十字会',
  233. };
  234. console.log('分享加',item)
  235. weixindata(item);
  236. },
  237. async loadData() {
  238. let obj = this;
  239. console.log('当前is_over',obj.is_over)
  240. if( obj.is_over == 1 ) {
  241. let uid = obj.userInfo.uid
  242. console.log(9090,uid)
  243. }
  244. get_training({
  245. id:obj.id,
  246. // uid:uid
  247. }).then(({ data }) => {
  248. obj.list = data;
  249. console.log(9988,data)
  250. if(obj.list.content != null){
  251. obj.description = obj.list.content.replace(/<img/g,"<img style='max-width:100%;height:auto;'");
  252. }
  253. });
  254. },
  255. submit(){
  256. let obj = this;
  257. let data = {};
  258. if(obj.type==0){
  259. if(!obj.name){
  260. obj.$api.msg('请填写姓名!');
  261. return;
  262. }
  263. if(!obj.phone){
  264. obj.$api.msg('请输入联系方式!');
  265. return;
  266. }
  267. if(!obj.addr){
  268. obj.$api.msg('请输入联系方式!');
  269. return;
  270. }
  271. data={
  272. name:obj.name,
  273. work:obj.addr,
  274. phone:obj.phone,
  275. tid:obj.id,
  276. type:0
  277. }
  278. }
  279. if(obj.type==1){
  280. if(!obj.company){
  281. obj.$api.msg('请填写企业名称!');
  282. return;
  283. }
  284. if(!obj.address){
  285. obj.$api.msg('请填写企业地址!');
  286. return;
  287. }
  288. if(!obj.companyName){
  289. obj.$api.msg('请填写负责人姓名!');
  290. return;
  291. }
  292. if(!obj.companyphone){
  293. obj.$api.msg('请输入联系方式!');
  294. return;
  295. }
  296. if(!obj.num){
  297. obj.$api.msg('请输入参加培训人数!');
  298. return;
  299. }
  300. data={
  301. company:obj.company,
  302. address:obj.address,
  303. name:obj.companyName,
  304. phone:obj.companyphone,
  305. num:obj.num,
  306. tid:obj.id,
  307. type:1
  308. }
  309. }
  310. sign_training(data).then(function(e) {
  311. console.log(data.type)
  312. let type = data.type
  313. uni.setStorageSync('type', type)
  314. obj.$api.msg(e.msg);
  315. setTimeout(function(){
  316. uni.navigateTo({
  317. url:'/pages/train/index'
  318. })
  319. }, 1000);
  320. }).catch(e => {
  321. obj.$api.msg(e.message);
  322. setTimeout(function(){
  323. uni.navigateTo({
  324. url:'/pages/train/index'
  325. })
  326. }, 1000);
  327. });;
  328. },
  329. getRecTime(timestamp, fmt) {
  330. let d = new Date(timestamp * 1000),
  331. // f = fmt || 'yyyy/MM/dd',
  332. f = fmt || 'yyyy.MM.dd hh:mm:ss',
  333. o = {
  334. 'M+': d.getMonth() + 1, //月份
  335. 'd+': d.getDate(), //日
  336. 'h+': d.getHours(), //小时
  337. 'm+': d.getMinutes(), //分
  338. 's+': d.getSeconds(), //秒
  339. 'q+': Math.floor((d.getMonth() + 3) / 3), //季度
  340. 'S': d.getMilliseconds() //毫秒
  341. };
  342. if (/(y+)/.test(f)) {
  343. f = f.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length));
  344. }
  345. for (let k in o) {
  346. if (new RegExp('(' + k + ')').test(f)) {
  347. f = f.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
  348. }
  349. }
  350. return f;
  351. console.log(f)
  352. },
  353. }
  354. };
  355. </script>
  356. <style lang="scss">
  357. page {
  358. background: #FFFFFF;
  359. width: 100%;
  360. height: 100%;
  361. .content {
  362. height: 100%;
  363. }
  364. }
  365. .box{
  366. padding: 0rpx 25rpx;
  367. width: 100%;
  368. }
  369. .top-image{
  370. width: 100%;
  371. height: 300rpx;
  372. }
  373. .top-title{
  374. width: 100%;
  375. text-align: center;
  376. padding: 25rpx 0rpx;
  377. font-size: 34rpx;
  378. border-bottom:1rpx dashed #B5B5B5;
  379. }
  380. .canten{
  381. text-align: center !important;
  382. }
  383. .addr{
  384. color: #222222;
  385. font-size: 28rpx;
  386. padding: 25rpx 35rpx;
  387. }
  388. .text-box{
  389. padding: 25rpx 25rpx;
  390. padding-bottom: 0rpx !important;
  391. }
  392. .text{
  393. color: #222222;
  394. font-size: 28rpx;
  395. padding-bottom: 15rpx;
  396. }
  397. .weixin-icon{
  398. width: 100%;
  399. text-align: center;
  400. padding-top: 45rpx;
  401. image{
  402. width: 248rpx;
  403. height: 248rpx;
  404. }
  405. }
  406. .tip{
  407. color: #222222;
  408. font-size: 28rpx;
  409. width: 100%;
  410. text-align: center;
  411. padding-bottom: 50rpx;
  412. }
  413. .sign-tip{
  414. padding: 25rpx 0rpx;
  415. text-align: center;
  416. color: #222222;
  417. font-size: 28rpx;
  418. }
  419. .form-box{
  420. padding: 0rpx 35rpx;
  421. .label{
  422. font-size: 34rpx;
  423. padding: 25rpx 0rpx;
  424. text{
  425. color: #E62129;
  426. padding-left: 5rpx;
  427. }
  428. }
  429. input{
  430. font-size: 28rpx;
  431. color: #222222;
  432. border: 2rpx solid #979797;
  433. padding: 0rpx 15rpx;
  434. border-radius: 15rpx;
  435. height: 80rpx;
  436. }
  437. }
  438. .submit{
  439. width: 70%;
  440. margin: 0rpx auto;
  441. margin-top: 80rpx;
  442. margin-bottom: 80rpx;
  443. padding: 25rpx 0;
  444. text-align: center;
  445. background-color: #E62129;
  446. color: #FFFFFF;
  447. font-size: 32rpx;
  448. border-radius: 10rpx;
  449. }
  450. .grey{
  451. background-color: #9B9B9B !important;
  452. }
  453. .certificates{
  454. // padding: 24rpx;
  455. width: 100%;
  456. height: 100vh;
  457. }
  458. .tki-qrcode-canvas {
  459. // width: 700rpx;
  460. // height: 1245rpx;
  461. width: 750rpx;
  462. // padding: 32rpx;
  463. height: 1350rpx;
  464. margin: 0 auto;
  465. }
  466. .bgimg{
  467. width: 100%;
  468. height: 100%;
  469. image{
  470. width: 100%;
  471. height: 100%;
  472. }
  473. }
  474. .box-mian{
  475. width: 100%;
  476. height: 100%;
  477. position: absolute;
  478. padding:380rpx 94rpx 200rpx 94rpx;
  479. color: #333;
  480. left: 0;
  481. top: 0;
  482. display: flex;
  483. flex-direction: column;
  484. justify-content: center;
  485. // align-items: center;
  486. .name{
  487. display: flex;
  488. font-size: 32rpx;
  489. .name-left{
  490. text-align: center;
  491. // padding: 0 24rpx;
  492. width: 150rpx;
  493. border-bottom: 2rpx solid #333;
  494. }
  495. }
  496. .info{
  497. margin-top: 68rpx;
  498. text-indent: 64rpx;
  499. line-height: 58rpx;
  500. }
  501. .signName{
  502. margin-top: 32rpx;
  503. display: flex;
  504. .signName-left{
  505. line-height: 34rpx;
  506. .signName-1{
  507. }
  508. .signName-2{
  509. font-size: 28rpx;
  510. }
  511. }
  512. .signName-right{
  513. text-align: left;
  514. // width: 100%;
  515. padding: 0 12rpx;
  516. margin-left: 12rpx;
  517. // width: 288rpx;
  518. border-bottom: 2rpx solid #333;
  519. // margin-bottom: 12rpx;
  520. .list-input {
  521. width: 100%;
  522. padding: 0 12rpx;
  523. height: 70rpx;
  524. font-size: 32rpx;
  525. text-align: left;
  526. }
  527. .signDate{
  528. display: flex;
  529. align-items: center;
  530. }
  531. }
  532. }
  533. .signDate{
  534. margin-top: 22rpx;
  535. display: flex;
  536. .signName-left{
  537. line-height: 34rpx;
  538. .signName-1{
  539. }
  540. .signName-2{
  541. font-size: 28rpx;
  542. }
  543. }
  544. .signName-right{
  545. text-align: left;
  546. padding-left: 12rpx;
  547. margin-left: 12rpx;
  548. width: 288rpx;
  549. border-bottom: 2rpx solid #333;
  550. .list-input {
  551. height: 70rpx;
  552. font-size: 32rpx;
  553. text-align: left;
  554. }
  555. // margin-bottom: 12rpx;
  556. }
  557. }
  558. // background-color: pink;
  559. }
  560. .imgbox{
  561. height: 1350rpx;
  562. width:750rpx;
  563. }
  564. </style>