certificates.vue 12 KB

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