certificates.vue 15 KB

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