certificates.vue 11 KB

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