certificates.vue 13 KB

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