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