sign copy.vue 16 KB

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