sign.vue 15 KB

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