certificates.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. is_over: 1,
  39. type: '', //0是个人报名,1是团体报名
  40. id: '',
  41. description: '',
  42. list: '',
  43. //个人
  44. name: '',
  45. phone: '',
  46. addr: '',
  47. work: '',
  48. //团队
  49. company: '',
  50. address: '',
  51. companyName: '',
  52. companyphone: '',
  53. num: '',
  54. people: '神农架林区红十字会',
  55. signDate: '',
  56. loading: true, //是否载入图片中
  57. size: 180,
  58. ratio: 1, //页面比例用于计算
  59. canHeight: '',
  60. canWeidth: '',
  61. url: '',
  62. img: '',
  63. showcanvas: true,
  64. uid: '',
  65. sendtime: ''
  66. };
  67. },
  68. onLoad(option) {
  69. this.type = option.type;
  70. // this.id = option.id;
  71. this.name = decodeURI(option.name)
  72. this.sendtime = option.sendtime
  73. this.IndexShare();
  74. // this.loadData();
  75. },
  76. onReady() {
  77. // detail_training({
  78. // id: this.id,
  79. // }).then(({
  80. // data
  81. // }) => {
  82. // console.log(999, data)
  83. // this.name = data.name
  84. // this.signDate = data.add_time
  85. // this.is_over = data.is_over
  86. // console.log(3, data.add_time)
  87. let obj = this;
  88. let name = obj.name
  89. let signDate = obj.sendtime
  90. function getRecTime(timestamp, fmt) {
  91. let d = new Date(timestamp * 1000)
  92. // f = fmt || 'yyyy/MM/dd',
  93. let f = fmt || 'yyyy.MM.dd'
  94. let o = {
  95. 'M+': d.getMonth() + 1, //月份
  96. 'd+': d.getDate(), //日
  97. 'h+': d.getHours(), //小时
  98. 'm+': d.getMinutes(), //分
  99. 's+': d.getSeconds(), //秒
  100. 'q+': Math.floor((d.getMonth() + 3) / 3), //季度
  101. 'S': d.getMilliseconds() //毫秒
  102. };
  103. if (/(y+)/.test(f)) {
  104. f = f.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length));
  105. }
  106. for (let k in o) {
  107. if (new RegExp('(' + k + ')').test(f)) {
  108. f = f.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr((
  109. '' + o[k]).length)));
  110. }
  111. }
  112. return f;
  113. console.log(f)
  114. }
  115. let m = getRecTime(signDate)
  116. let query = uni.createSelectorQuery();
  117. // this.loadData();
  118. // 获取页面比例
  119. query
  120. .select('.certificates')
  121. .fields({
  122. size: true
  123. },
  124. e => {
  125. console.log('获取页面比例', e)
  126. // 保存比例
  127. this.ratio = e.width / 750;
  128. }
  129. )
  130. .exec();
  131. // 获取画布宽高信息
  132. query
  133. .select('#qrShareBox')
  134. .fields({
  135. size: true
  136. },
  137. e => {
  138. console.log('获取画布宽高信息', e)
  139. obj.canHeight = e.height;
  140. obj.canWeidth = e.width;
  141. }
  142. )
  143. .exec();
  144. let ctxBg = '/static/img/graduation.png'; //画布背景
  145. let src = '/static/icon/erweima.jpg' // 二维码
  146. // let src1 = '/index/static/img/jzyz.png'
  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(m, 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. //插入印章
  207. // context.drawImage(src1, 480 * obj.ratio - codeSize/2, 810 * obj.ratio - codeSize/2, codeSize, codeSize);
  208. context.draw(false, (e) => {
  209. uni.canvasToTempFilePath({
  210. x: 0,
  211. y: 0,
  212. width: obj.canWeidth,
  213. height: obj.canHeight,
  214. destWidth: obj.canWeidth,
  215. destHeight: obj.canHeight,
  216. canvasId: 'qrShareBox',
  217. success: function(res) {
  218. console.log(res)
  219. // uni.showModal({
  220. // title:'zhi1'
  221. // })
  222. // 在H5平台下,tempFilePath 为 base64
  223. // console.log(res.tempFilePath)
  224. obj.showcanvas = false;
  225. obj.img = res.tempFilePath
  226. }
  227. })
  228. })
  229. // })
  230. },
  231. onShow() {
  232. this.uid = this.userInfo.uid;
  233. console.log('this.uid', this.uid)
  234. },
  235. computed: {
  236. ...mapState('user', ['hasLogin', 'userInfo'])
  237. },
  238. methods: {
  239. ...mapMutations('user', ['setUserInfo']),
  240. // 分享
  241. IndexShare() {
  242. let obj = this;
  243. let item = {
  244. link: obj.$store.state.baseURL + '/index/#/pages/form/certificates?name=' + encodeURI(obj.name) + '&sendtime=' + obj.sendtime,
  245. imgUrl: obj.$store.state.baseURL + '/index/static/img/002.png',
  246. desc: '结业证书',
  247. title: '江陵县红十字会',
  248. };
  249. console.log('分享加', item)
  250. weixindata(item);
  251. },
  252. getRecTime(timestamp, fmt) {
  253. let d = new Date(timestamp * 1000),
  254. // f = fmt || 'yyyy/MM/dd',
  255. f = fmt || 'yyyy.MM.dd hh:mm:ss',
  256. o = {
  257. 'M+': d.getMonth() + 1, //月份
  258. 'd+': d.getDate(), //日
  259. 'h+': d.getHours(), //小时
  260. 'm+': d.getMinutes(), //分
  261. 's+': d.getSeconds(), //秒
  262. 'q+': Math.floor((d.getMonth() + 3) / 3), //季度
  263. 'S': d.getMilliseconds() //毫秒
  264. };
  265. if (/(y+)/.test(f)) {
  266. f = f.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length));
  267. }
  268. for (let k in o) {
  269. if (new RegExp('(' + k + ')').test(f)) {
  270. f = f.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k])
  271. .length)));
  272. }
  273. }
  274. return f;
  275. console.log(f)
  276. },
  277. }
  278. };
  279. </script>
  280. <style lang="scss">
  281. page {
  282. background: #FFFFFF;
  283. width: 100%;
  284. height: 100%;
  285. .content {
  286. height: 100%;
  287. }
  288. }
  289. .box {
  290. padding: 0rpx 25rpx;
  291. width: 100%;
  292. }
  293. .top-image {
  294. width: 100%;
  295. height: 300rpx;
  296. }
  297. .top-title {
  298. width: 100%;
  299. text-align: center;
  300. padding: 25rpx 0rpx;
  301. font-size: 34rpx;
  302. border-bottom: 1rpx dashed #B5B5B5;
  303. }
  304. .canten {
  305. text-align: center !important;
  306. }
  307. .addr {
  308. color: #222222;
  309. font-size: 28rpx;
  310. padding: 25rpx 35rpx;
  311. }
  312. .text-box {
  313. padding: 25rpx 25rpx;
  314. padding-bottom: 0rpx !important;
  315. }
  316. .text {
  317. color: #222222;
  318. font-size: 28rpx;
  319. padding-bottom: 15rpx;
  320. }
  321. .weixin-icon {
  322. width: 100%;
  323. text-align: center;
  324. padding-top: 45rpx;
  325. image {
  326. width: 248rpx;
  327. height: 248rpx;
  328. }
  329. }
  330. .tip {
  331. color: #222222;
  332. font-size: 28rpx;
  333. width: 100%;
  334. text-align: center;
  335. padding-bottom: 50rpx;
  336. }
  337. .sign-tip {
  338. padding: 25rpx 0rpx;
  339. text-align: center;
  340. color: #222222;
  341. font-size: 28rpx;
  342. }
  343. .form-box {
  344. padding: 0rpx 35rpx;
  345. .label {
  346. font-size: 34rpx;
  347. padding: 25rpx 0rpx;
  348. text {
  349. color: #E62129;
  350. padding-left: 5rpx;
  351. }
  352. }
  353. input {
  354. font-size: 28rpx;
  355. color: #222222;
  356. border: 2rpx solid #979797;
  357. padding: 0rpx 15rpx;
  358. border-radius: 15rpx;
  359. height: 80rpx;
  360. }
  361. }
  362. .submit {
  363. width: 70%;
  364. margin: 0rpx auto;
  365. margin-top: 80rpx;
  366. margin-bottom: 80rpx;
  367. padding: 25rpx 0;
  368. text-align: center;
  369. background-color: #E62129;
  370. color: #FFFFFF;
  371. font-size: 32rpx;
  372. border-radius: 10rpx;
  373. }
  374. .grey {
  375. background-color: #9B9B9B !important;
  376. }
  377. .certificates {
  378. // padding: 24rpx;
  379. width: 100%;
  380. height: 100vh;
  381. }
  382. .tki-qrcode-canvas {
  383. // width: 700rpx;
  384. // height: 1245rpx;
  385. width: 750rpx;
  386. // padding: 32rpx;
  387. height: 1350rpx;
  388. margin: 0 auto;
  389. }
  390. .bgimg {
  391. width: 100%;
  392. height: 100%;
  393. image {
  394. width: 100%;
  395. height: 100%;
  396. }
  397. }
  398. .box-mian {
  399. width: 100%;
  400. height: 100%;
  401. position: absolute;
  402. padding: 380rpx 94rpx 200rpx 94rpx;
  403. color: #333;
  404. left: 0;
  405. top: 0;
  406. display: flex;
  407. flex-direction: column;
  408. justify-content: center;
  409. // align-items: center;
  410. .name {
  411. display: flex;
  412. font-size: 32rpx;
  413. .name-left {
  414. text-align: center;
  415. // padding: 0 24rpx;
  416. width: 150rpx;
  417. border-bottom: 2rpx solid #333;
  418. }
  419. }
  420. .info {
  421. margin-top: 68rpx;
  422. text-indent: 64rpx;
  423. line-height: 58rpx;
  424. }
  425. .signName {
  426. margin-top: 32rpx;
  427. display: flex;
  428. .signName-left {
  429. line-height: 34rpx;
  430. .signName-1 {}
  431. .signName-2 {
  432. font-size: 28rpx;
  433. }
  434. }
  435. .signName-right {
  436. text-align: left;
  437. // width: 100%;
  438. padding: 0 12rpx;
  439. margin-left: 12rpx;
  440. // width: 288rpx;
  441. border-bottom: 2rpx solid #333;
  442. // margin-bottom: 12rpx;
  443. .list-input {
  444. width: 100%;
  445. padding: 0 12rpx;
  446. height: 70rpx;
  447. font-size: 32rpx;
  448. text-align: left;
  449. }
  450. .signDate {
  451. display: flex;
  452. align-items: center;
  453. }
  454. }
  455. }
  456. .signDate {
  457. margin-top: 22rpx;
  458. display: flex;
  459. .signName-left {
  460. line-height: 34rpx;
  461. .signName-1 {}
  462. .signName-2 {
  463. font-size: 28rpx;
  464. }
  465. }
  466. .signName-right {
  467. text-align: left;
  468. padding-left: 12rpx;
  469. margin-left: 12rpx;
  470. width: 288rpx;
  471. border-bottom: 2rpx solid #333;
  472. .list-input {
  473. height: 70rpx;
  474. font-size: 32rpx;
  475. text-align: left;
  476. }
  477. // margin-bottom: 12rpx;
  478. }
  479. }
  480. // background-color: pink;
  481. }
  482. .imgbox {
  483. height: 1350rpx;
  484. width: 750rpx;
  485. }
  486. </style>