sign.vue 15 KB

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