sign.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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"> 报名咨询电话:0716-4163849</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. console.log("---query---",query)
  143. // this.loadData();
  144. // 获取页面比例
  145. query
  146. .select('.certificates')
  147. .fields({
  148. size: true
  149. },
  150. e => {
  151. console.log('获取页面比例',e)
  152. // 保存比例
  153. this.ratio = e.width / 750;
  154. }
  155. )
  156. .exec();
  157. // 获取画布宽高信息
  158. query.select('#qrShareBox').fields(
  159. {size: true},e => {
  160. console.log('获取画布宽高信息',e)
  161. obj.canHeight = e.height;
  162. obj.canWeidth = e.width;
  163. }).exec();
  164. console.log('obj.canHeight',obj.canHeight)
  165. console.log('obj.canWeidth',obj.canWeidth)
  166. let ctxBg = 'static/img/graduation.png'; //画布背景
  167. let src = '/static/icon/erweima.jpg' // 二维码
  168. let context = uni.createCanvasContext('qrShareBox');
  169. // 插入背景图片
  170. context.drawImage(ctxBg, 0, 0, obj.canWeidth, obj.canHeight);
  171. console.log('123',obj.ratio)
  172. const codeSize = obj.size * obj.ratio; //计算二维码大小
  173. const codeX = ((750 - obj.size) * obj.ratio) / 2; //二维码所在x轴位置
  174. const codeY = 999 * obj.ratio; //二维码所在y轴位置
  175. // console.log('二维码大小',codeSize)
  176. // console.log('二维码所在x轴位置',codeX)
  177. // console.log('二维码所在y轴位置',codeY)
  178. const codeBoxColor = '#FFFFFF'; //包裹框颜色
  179. const codeBoxWidht = 0; //包裹边框宽度
  180. const codeBoxSize = (codeBoxWidht / 2) * obj.ratio; //计算二维码白色包裹框大小
  181. const codeBoxX = codeX - codeBoxSize; //包裹框初始X轴
  182. const codeBoxY = codeY - codeBoxSize; //包裹框初始Y轴
  183. const codeBoxEnd = codeSize + codeBoxWidht * obj.ratio; //计算包裹框大小
  184. const fontTop = codeY + codeBoxEnd + (codeBoxWidht + 20) * obj.ratio; //文字距离上边距高度
  185. const fontSize = 24 * obj.ratio; //文字大小
  186. const fontText = ''; //文字内容
  187. const fontLeft = (codeSize - fontSize * fontText.length) / 2 + codeX; //文字左侧距离
  188. // // 插入文字
  189. context.setFontSize(32 * obj.ratio)
  190. // 画横线
  191. context.moveTo(90 * obj.ratio, 586 * obj.ratio)
  192. context.lineTo(250 * obj.ratio, 586 * obj.ratio)
  193. context.stroke();
  194. context.setTextAlign('center')
  195. context.fillText(name, 170 * obj.ratio, 574 * obj.ratio)
  196. context.setTextAlign('left')
  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('签发人:', 300 * obj.ratio, 800 * obj.ratio)
  203. context.fillText('Siger:', 300 * obj.ratio, 830 * obj.ratio)
  204. // 画横线
  205. context.moveTo(380 * obj.ratio, 830 * obj.ratio)
  206. context.lineTo(660 * obj.ratio, 830 * obj.ratio)
  207. context.stroke()
  208. context.fillText('签发日期:', 300 * obj.ratio, 880 * obj.ratio)
  209. context.fillText('Issuer Date:', 300 * obj.ratio, 910 * obj.ratio)
  210. context.setFontSize(26 * obj.ratio)
  211. context.fillText(m, 475 * obj.ratio, 908 * obj.ratio)
  212. context.fillText('神农架林区红十字会', 440 * obj.ratio, 820 * obj.ratio)
  213. // 画横线
  214. context.moveTo(430 * obj.ratio, 915 * obj.ratio)
  215. context.lineTo(660 * 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. console.log('插入二维码src',src)
  228. context.drawImage(src, codeX, codeY, codeSize, codeSize);
  229. context.draw(false,(e) => {
  230. uni.canvasToTempFilePath({
  231. x: 0,
  232. y: 0,
  233. width: obj.canWeidth,
  234. height: obj.canHeight,
  235. destWidth: obj.canWeidth,
  236. destHeight: obj.canHeight,
  237. canvasId: 'qrShareBox',
  238. success: function(res) {
  239. // uni.showModal({
  240. // title:'zhi1'
  241. // })
  242. // 在H5平台下,tempFilePath 为 base64
  243. // console.log(res.tempFilePath)
  244. obj.showcanvas = false;
  245. obj.img = res.tempFilePath
  246. }
  247. })
  248. })
  249. })
  250. },
  251. onReady() {
  252. },
  253. computed: {
  254. ...mapState('user', ['hasLogin', 'userInfo'])
  255. },
  256. methods: {
  257. ...mapMutations('user', ['setUserInfo']),
  258. // 分享
  259. IndexShare() {
  260. let obj = this;
  261. let item = {
  262. link: 'http://slj.igxys.com/index/#/pages/train/sign?type=' + obj.type + '&id=' + obj.id + '&uid=' + obj.userInfo.uid,// 分享链接
  263. imgUrl: '/index/static/img/002.png',
  264. desc: '结业证书',
  265. title: '神农架林区红十字会',
  266. };
  267. console.log('分享加',item)
  268. weixindata(item);
  269. },
  270. async loadData() {
  271. let obj = this;
  272. console.log('当前is_over',obj.is_over)
  273. if( obj.is_over == 1 ) {
  274. let uid = obj.userInfo.uid
  275. console.log(9090,uid)
  276. }
  277. get_training({
  278. id:obj.id,
  279. // uid:uid
  280. }).then(({ data }) => {
  281. obj.list = data;
  282. console.log(9988,data)
  283. if(obj.list.content != null){
  284. obj.description = obj.list.content.replace(/<img/g,"<img style='max-width:100%;height:auto;'");
  285. }
  286. });
  287. },
  288. submit(){
  289. let obj = this;
  290. let data = {};
  291. if(obj.type==0){
  292. if(!obj.name){
  293. obj.$api.msg('请填写姓名!');
  294. return;
  295. }
  296. if(!obj.phone){
  297. obj.$api.msg('请输入联系方式!');
  298. return;
  299. }
  300. if(!obj.addr){
  301. obj.$api.msg('请输入联系方式!');
  302. return;
  303. }
  304. data={
  305. name:obj.name,
  306. work:obj.addr,
  307. phone:obj.phone,
  308. tid:obj.id,
  309. type:0
  310. }
  311. }
  312. if(obj.type==1){
  313. if(!obj.company){
  314. obj.$api.msg('请填写企业名称!');
  315. return;
  316. }
  317. if(!obj.address){
  318. obj.$api.msg('请填写企业地址!');
  319. return;
  320. }
  321. if(!obj.companyName){
  322. obj.$api.msg('请填写负责人姓名!');
  323. return;
  324. }
  325. if(!obj.companyphone){
  326. obj.$api.msg('请输入联系方式!');
  327. return;
  328. }
  329. if(!obj.num){
  330. obj.$api.msg('请输入参加培训人数!');
  331. return;
  332. }
  333. data={
  334. company:obj.company,
  335. address:obj.address,
  336. name:obj.companyName,
  337. phone:obj.companyphone,
  338. num:obj.num,
  339. tid:obj.id,
  340. type:1
  341. }
  342. }
  343. sign_training(data).then(function(e) {
  344. console.log(data.type)
  345. let type = data.type
  346. uni.setStorageSync('type', type)
  347. obj.$api.msg(e.msg);
  348. setTimeout(function(){
  349. uni.navigateTo({
  350. url:'/pages/train/index'
  351. })
  352. }, 1000);
  353. }).catch(e => {
  354. obj.$api.msg(e.message);
  355. setTimeout(function(){
  356. uni.navigateTo({
  357. url:'/pages/train/index'
  358. })
  359. }, 1000);
  360. });;
  361. },
  362. getRecTime(timestamp, fmt) {
  363. let d = new Date(timestamp * 1000),
  364. // f = fmt || 'yyyy/MM/dd',
  365. f = fmt || 'yyyy.MM.dd hh:mm:ss',
  366. o = {
  367. 'M+': d.getMonth() + 1, //月份
  368. 'd+': d.getDate(), //日
  369. 'h+': d.getHours(), //小时
  370. 'm+': d.getMinutes(), //分
  371. 's+': d.getSeconds(), //秒
  372. 'q+': Math.floor((d.getMonth() + 3) / 3), //季度
  373. 'S': d.getMilliseconds() //毫秒
  374. };
  375. if (/(y+)/.test(f)) {
  376. f = f.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length));
  377. }
  378. for (let k in o) {
  379. if (new RegExp('(' + k + ')').test(f)) {
  380. f = f.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
  381. }
  382. }
  383. return f;
  384. console.log(f)
  385. },
  386. }
  387. };
  388. </script>
  389. <style lang="scss">
  390. page {
  391. background: #FFFFFF;
  392. width: 100%;
  393. height: 100%;
  394. .content {
  395. height: 100%;
  396. }
  397. }
  398. .box{
  399. padding: 0rpx 25rpx;
  400. width: 100%;
  401. }
  402. .top-image{
  403. width: 100%;
  404. height: 300rpx;
  405. }
  406. .top-title{
  407. width: 100%;
  408. text-align: center;
  409. padding: 25rpx 0rpx;
  410. font-size: 34rpx;
  411. border-bottom:1rpx dashed #B5B5B5;
  412. }
  413. .canten{
  414. text-align: center !important;
  415. }
  416. .addr{
  417. color: #222222;
  418. font-size: 28rpx;
  419. padding: 25rpx 35rpx;
  420. }
  421. .text-box{
  422. padding: 25rpx 25rpx;
  423. padding-bottom: 0rpx !important;
  424. }
  425. .text{
  426. color: #222222;
  427. font-size: 28rpx;
  428. padding-bottom: 15rpx;
  429. }
  430. .weixin-icon{
  431. width: 100%;
  432. text-align: center;
  433. padding-top: 45rpx;
  434. image{
  435. width: 248rpx;
  436. height: 248rpx;
  437. }
  438. }
  439. .tip{
  440. color: #222222;
  441. font-size: 28rpx;
  442. width: 100%;
  443. text-align: center;
  444. padding-bottom: 50rpx;
  445. }
  446. .sign-tip{
  447. padding: 25rpx 0rpx;
  448. text-align: center;
  449. color: #222222;
  450. font-size: 28rpx;
  451. }
  452. .form-box{
  453. padding: 0rpx 35rpx;
  454. .label{
  455. font-size: 34rpx;
  456. padding: 25rpx 0rpx;
  457. text{
  458. color: #E62129;
  459. padding-left: 5rpx;
  460. }
  461. }
  462. input{
  463. font-size: 28rpx;
  464. color: #222222;
  465. border: 2rpx solid #979797;
  466. padding: 0rpx 15rpx;
  467. border-radius: 15rpx;
  468. height: 80rpx;
  469. }
  470. }
  471. .submit{
  472. width: 70%;
  473. margin: 0rpx auto;
  474. margin-top: 80rpx;
  475. margin-bottom: 80rpx;
  476. padding: 25rpx 0;
  477. text-align: center;
  478. background-color: #E62129;
  479. color: #FFFFFF;
  480. font-size: 32rpx;
  481. border-radius: 10rpx;
  482. }
  483. .grey{
  484. background-color: #9B9B9B !important;
  485. }
  486. .certificates{
  487. // padding: 24rpx;
  488. width: 100%;
  489. height: 100vh;
  490. }
  491. .tki-qrcode-canvas {
  492. // width: 700rpx;
  493. // height: 1245rpx;
  494. width: 750rpx;
  495. // padding: 32rpx;
  496. height: 1350rpx;
  497. margin: 0 auto;
  498. }
  499. .bgimg{
  500. width: 100%;
  501. height: 100%;
  502. image{
  503. width: 100%;
  504. height: 100%;
  505. }
  506. }
  507. .box-mian{
  508. width: 100%;
  509. height: 100%;
  510. position: absolute;
  511. padding:380rpx 94rpx 200rpx 94rpx;
  512. color: #333;
  513. left: 0;
  514. top: 0;
  515. display: flex;
  516. flex-direction: column;
  517. justify-content: center;
  518. // align-items: center;
  519. .name{
  520. display: flex;
  521. font-size: 32rpx;
  522. .name-left{
  523. text-align: center;
  524. // padding: 0 24rpx;
  525. width: 150rpx;
  526. border-bottom: 2rpx solid #333;
  527. }
  528. }
  529. .info{
  530. margin-top: 68rpx;
  531. text-indent: 64rpx;
  532. line-height: 58rpx;
  533. }
  534. .signName{
  535. margin-top: 32rpx;
  536. display: flex;
  537. .signName-left{
  538. line-height: 34rpx;
  539. .signName-1{
  540. }
  541. .signName-2{
  542. font-size: 28rpx;
  543. }
  544. }
  545. .signName-right{
  546. text-align: left;
  547. // width: 100%;
  548. padding: 0 12rpx;
  549. margin-left: 12rpx;
  550. // width: 288rpx;
  551. border-bottom: 2rpx solid #333;
  552. // margin-bottom: 12rpx;
  553. .list-input {
  554. width: 100%;
  555. padding: 0 12rpx;
  556. height: 70rpx;
  557. font-size: 32rpx;
  558. text-align: left;
  559. }
  560. .signDate{
  561. display: flex;
  562. align-items: center;
  563. }
  564. }
  565. }
  566. .signDate{
  567. margin-top: 22rpx;
  568. display: flex;
  569. .signName-left{
  570. line-height: 34rpx;
  571. .signName-1{
  572. }
  573. .signName-2{
  574. font-size: 28rpx;
  575. }
  576. }
  577. .signName-right{
  578. text-align: left;
  579. padding-left: 12rpx;
  580. margin-left: 12rpx;
  581. width: 288rpx;
  582. border-bottom: 2rpx solid #333;
  583. .list-input {
  584. height: 70rpx;
  585. font-size: 32rpx;
  586. text-align: left;
  587. }
  588. // margin-bottom: 12rpx;
  589. }
  590. }
  591. // background-color: pink;
  592. }
  593. .imgbox{
  594. height: 1350rpx;
  595. width:750rpx;
  596. }
  597. </style>