certificates.vue 13 KB

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