pay-suce.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <view class="pay_suce">
  3. <image src="../../static/logo.jpg" class="logo"></image>
  4. <!-- 显示奖学金 -->
  5. <!-- <view class="no_inte" v-if="posterShow">
  6. <image src="../../../static/imgs/shop/change_suce.png" mode=""></image>
  7. <view class="suce">支付成功</view>
  8. <view class="sub_btn" @click="skipPage(1)">查看订单详情</view>
  9. </view>
  10. <view v-else>
  11. <view class="suce_con">
  12. <image src="../../static/inte_bg.jpg" class="inte_bg"></image>
  13. <view class="inte_box flexB">
  14. <view class="inte">+{{inte}}</view>
  15. <view class="inte_intr">
  16. <view>奖</view>
  17. <view>学</view>
  18. <view>金</view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="suce_btn flexB">
  23. <view class="flexC" @click="skipPage(0)">查看奖学金详情</view>
  24. <view class="flexC" @click="skipPage(1)">查看订单详情</view>
  25. </view>
  26. </view> -->
  27. <!-- 隐藏奖学金 -->
  28. <view class="no_inte">
  29. <image src="../../../static/imgs/shop/change_suce.png" mode=""></image>
  30. <view class="suce">支付成功</view>
  31. <view class="sub_btn" @click="skipPage(1)" style="margin-top:80rpx;">查看订单详情</view>
  32. </view>
  33. <view class="poster" v-if="posterShow">
  34. <view class="poster_con flexCC">
  35. <text class="iconfont iconguanbi" @click="posterShow = false"></text>
  36. <view class="canvas" @click="preview">
  37. <canvas canvas-id="canvas" id="canvas"></canvas>
  38. <image :src="poster" class="poster_img"></image>
  39. </view>
  40. <view class="save_img">点击图片-长按-发送给朋友</view>
  41. <view class="sub_btn" @click="skipApplets()">点击进入争霸赛小程序</view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. getZbsData
  49. } from '../../../apis/shop.js'
  50. export default {
  51. data() {
  52. return {
  53. inte: 0,
  54. order_no: '',
  55. gotScore: 100,
  56. riseNumber: 10,
  57. posterShow: false,
  58. poster: '',
  59. store: '',
  60. canvasWidth: '',
  61. canvasHeight: '',
  62. scoreData: '', //分数排名信息
  63. model: '', //手机型号
  64. }
  65. },
  66. onLoad(ops) {
  67. this.store = uni.getStorageSync('store')
  68. this.order_no = ops.order_no;
  69. this.inte = ops.inte
  70. this.getData();
  71. wx.getSystemInfo({
  72. success: res => {
  73. this.model = res.model;
  74. this.canvasWidth = res.windowWidth / 375;
  75. this.canvasHeight = res.windowHeight;
  76. }
  77. });
  78. },
  79. methods: {
  80. //放大图片
  81. preview() {
  82. uni.previewImage({
  83. current: this.poster,
  84. urls: [this.poster]
  85. });
  86. },
  87. getData() {
  88. getZbsData({
  89. order_no: this.order_no,
  90. }).then(res => {
  91. if (res.code == 200) {
  92. this.scoreData = res.data;
  93. const {
  94. type
  95. } = res.data;
  96. if (type == 1) {
  97. uni.getImageInfo({
  98. src: this.store.img,
  99. success: res => {
  100. this.posterShow = true
  101. this.drawPoster(res.path)
  102. }
  103. })
  104. }
  105. }
  106. })
  107. },
  108. //进入争霸赛小程序
  109. skipApplets() {
  110. uni.navigateToMiniProgram({
  111. appId: 'wx0348d5a266f867a3',
  112. path: 'pages/index/index',
  113. extraData: {
  114. 'data1': 'test'
  115. },
  116. success(res) {
  117. console.log('打开成功')
  118. }
  119. })
  120. },
  121. //跳转页面
  122. skipPage(type) {
  123. let url = type == 0 ? '../integral-detail/integral-detail' :
  124. '../../../pages/order-info/order-info?order_no=' + this
  125. .order_no
  126. uni.redirectTo({
  127. url
  128. })
  129. },
  130. dataURLtoFile(dataurl, filename = 'file') {
  131. let arr = dataurl.split(',');
  132. let mime = arr[0].match(/:(.*?);/)[1];
  133. let suffix = mime.split('/')[1];
  134. let bstr = atob(arr[1]);
  135. let n = bstr.length;
  136. let u8arr = new Uint8Array(n);
  137. while (n--) {
  138. u8arr[n] = bstr.charCodeAt(n);
  139. }
  140. return new File([u8arr], `${filename}.${suffix}`, {
  141. type: mime
  142. });
  143. },
  144. ///绘制海报
  145. drawPoster(avatar) {
  146. let _this = this;
  147. uni.getImageInfo({
  148. src: 'https://api.jiuweiyun.cn/public/uploads/icon/poster_new.png',
  149. success: res => {
  150. uni.showLoading({
  151. title: '图片加载中...'
  152. });
  153. const {
  154. score,
  155. ranking
  156. } = _this.scoreData;
  157. console.log(this.scoreData, 'data')
  158. let ctx = uni.createCanvasContext('canvas');
  159. let rpx = _this.canvasWidth;
  160. ctx.drawImage(res.path, 0, 0, 270 * rpx, 450 * rpx);
  161. // 积分
  162. ctx.font = 'italic bold 28px Microsoft YaHei';
  163. ctx.setFillStyle('#fff');
  164. ctx.textAlign = 'center';
  165. ctx.fillText(score, uni.upx2px(250), uni.upx2px(432));
  166. //排名
  167. ctx.font = 'italic bold 18px 微软雅黑';
  168. ctx.setFillStyle('#fff');
  169. ctx.textAlign = 'center';
  170. ctx.fillText(ranking, uni.upx2px(270), uni.upx2px(467));
  171. //昵称
  172. ctx.beginPath(); //开始一个新的路径
  173. ctx.setLineWidth(2); //设置线条的宽度
  174. ctx.setStrokeStyle('#EF0A16'); //设置线条的样式
  175. ctx.setFillStyle('#EF0A16'); //设置填充的样式s
  176. ctx.font = 'noraml bold 18px 微软雅黑';
  177. ctx.textAlign = 'center';
  178. // ctx.fillText(, uni.upx2px(270), uni.upx2px(360));
  179. ctx.fillText(this.store.name, uni.upx2px(270), uni.upx2px(360));
  180. ctx.moveTo(uni.upx2px(175), uni.upx2px(375)); //设置线条的起始路径坐标
  181. ctx.lineTo(uni.upx2px(365), uni.upx2px(375)); //设置线条的终点路径坐标
  182. ctx.stroke(); //对当前路径进行描边
  183. ctx.closePath(); //关闭当前路径
  184. ctx.beginPath();
  185. ctx.arc((55 * rpx) / 2 + 110 * rpx, (55 * rpx) / 2 + 104 * rpx, (55 * rpx) / 2, 0, Math
  186. .PI * 2,
  187. false); // 画一个圆形裁剪区域
  188. ctx.clip(); // 裁剪
  189. ctx.drawImage(avatar, 110 * rpx, 104 * rpx, 55 * rpx, 55 * rpx);
  190. ctx.restore(); //恢复之前保存的绘图上下文
  191. setTimeout(res => {
  192. ctx.draw(false, () => {
  193. uni.canvasToTempFilePath({
  194. width: 270 * rpx,
  195. height: 450 * rpx,
  196. canvasId: 'canvas',
  197. success: res => {
  198. uni.hideLoading();
  199. if (this.model == 'iPhone') {
  200. this.poster = this.dataURLtoFile(res
  201. .tempFilePath).name;
  202. } else {
  203. let url = res.tempFilePath.replace(
  204. /\. +/g, '');
  205. this.poster = url.replace(/[\r\n]/g,
  206. '');
  207. }
  208. }
  209. });
  210. });
  211. uni.hideLoading();
  212. }, 1000);
  213. }
  214. })
  215. },
  216. }
  217. }
  218. </script>
  219. <style lang="scss">
  220. .pay_suce {
  221. width: 690rpx;
  222. margin: 0 auto;
  223. text-align: center;
  224. }
  225. .logo {
  226. width: 522rpx;
  227. height: 82rpx;
  228. margin: 30rpx 0;
  229. }
  230. .suce_con {
  231. position: relative;
  232. margin: 60rpx 0 110rpx;
  233. .inte_box {
  234. width: 418rpx;
  235. position: absolute;
  236. top: 26rpx;
  237. left: 137rpx;
  238. .inte {
  239. font-size: 104rpx;
  240. color: #fff;
  241. width: 300rpx;
  242. text-align: center;
  243. }
  244. .inte_intr {
  245. width: 118rpx;
  246. text-align: center;
  247. view {
  248. font-size: 44rpx;
  249. color: #fff;
  250. }
  251. }
  252. }
  253. .inte_bg {
  254. width: 418rpx;
  255. height: 222rpx;
  256. }
  257. }
  258. .suce_btn {
  259. width: 690rpx;
  260. margin: 50rpx auto 60rpx;
  261. view {
  262. width: 300rpx;
  263. height: 88rpx;
  264. border-radius: 44px;
  265. font-size: 32rpx;
  266. }
  267. view:first-child {
  268. background: #FFF4F3;
  269. color: $base-color;
  270. border: 2rpx solid #FB231F;
  271. }
  272. view:last-child {
  273. background: $base-line-bg;
  274. color: #fff;
  275. }
  276. }
  277. .poster {
  278. width: 100%;
  279. height: 100vh;
  280. position: fixed;
  281. top: 0;
  282. left: 0;
  283. background-color: rgba(0, 0, 0, 0.7);
  284. z-index: 9999;
  285. .poster_con {
  286. width: 90%;
  287. margin: 0 auto;
  288. height: 100%;
  289. display: flex;
  290. flex-direction: column;
  291. justify-content: center;
  292. align-items: center;
  293. .canvas {
  294. width: 540rpx;
  295. height: 900rpx;
  296. position: relative;
  297. #canvas {
  298. width: 540rpx;
  299. height: 900rpx;
  300. position: absolute;
  301. top: 0;
  302. left: 0;
  303. }
  304. .poster_img {
  305. -webkit-touch-callout: default;
  306. width: 100%;
  307. height: 100%;
  308. display: block;
  309. }
  310. img[src=''],
  311. img:not([src]) {
  312. opacity: 0;
  313. }
  314. }
  315. .iconfont {
  316. position: absolute;
  317. top: 2vh;
  318. right: 25rpx;
  319. color: #dedede;
  320. font-size: 60rpx;
  321. z-index: 999;
  322. }
  323. .save_img {
  324. color: #fff;
  325. width: 100%;
  326. text-align: center;
  327. font-size: 40rpx;
  328. margin: 20rpx 0;
  329. }
  330. }
  331. }
  332. .no_inte {
  333. image {
  334. width: 212rpx;
  335. height: 158rpx;
  336. margin-top: 50rpx;
  337. }
  338. .suce {
  339. font-size: 48rpx;
  340. font-weight: bold;
  341. margin: 30rpx 0 40rpx;
  342. }
  343. .hint {
  344. // margin: 40rpx 0 60rpx;
  345. margin-bottom: 20rpx;
  346. font-size: 28rpx;
  347. color: #999;
  348. }
  349. }
  350. </style>