certificates.vue 13 KB

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