payment-code.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <app-layout>
  3. <view v-if="edit" class="back-t">
  4. <view class="code-box set">
  5. <view>收款金额</view>
  6. <view class="dir-left-nowrap cross-center code-input">
  7. <view>¥</view>
  8. <input v-model="tmp_price" type="digit"/>
  9. </view>
  10. <view class="set-line"></view>
  11. <view @click="submit" class="btn main-center cross-center">确认</view>
  12. </view>
  13. </view>
  14. <view v-else class="back-o">
  15. <view class="code-box dir-top-nowrap main-center cross-center">
  16. <view class="box-grow-0 code-title">扫描二维码,向我付钱</view>
  17. <view v-if="price > 0" class="price">¥{{price}}</view>
  18. <image @click="qrcodeClick" class="box-grow-0" :src="pic_url"></image>
  19. <view class="dir-left-nowrap cross-center end">
  20. <view @click="savePrice">设置金额</view>
  21. <view class="line"></view>
  22. <view @click="saveQrcode">保存图片</view>
  23. </view>
  24. </view>
  25. </view>
  26. </app-layout>
  27. </template>
  28. <script>
  29. export default {
  30. name: "payment-code",
  31. components: {},
  32. data() {
  33. return {
  34. edit: false,
  35. pic_url: '',
  36. save_loading: false,
  37. price: '',
  38. tmp_price: ''
  39. }
  40. },
  41. onLoad: function (options) {
  42. this.submit();
  43. },
  44. methods: {
  45. savePrice: function () {
  46. this.edit = true;
  47. },
  48. submit: function () {
  49. const tmp_price = this.tmp_price ? parseFloat(parseFloat(this.tmp_price).toFixed(2)) : '';
  50. this.$showLoading({text: `生成中`});
  51. this.$request({
  52. url: this.$api.scan_code_pay.qr_code,
  53. method: 'POST',
  54. data: {
  55. price: tmp_price
  56. }
  57. }).then(info => {
  58. this.$hideLoading();
  59. if (info.code === 0) {
  60. [
  61. this.pic_url,
  62. this.price,
  63. this.tmp_price,
  64. this.edit
  65. ] = [
  66. info.data.qr_code.file_path,
  67. tmp_price,
  68. tmp_price,
  69. false
  70. ]
  71. } else {
  72. uni.showToast({icon: 'none', title: info.msg});
  73. }
  74. }).catch(() => {
  75. this.$hideLoading();
  76. });
  77. },
  78. //预览
  79. qrcodeClick: function () {
  80. uni.previewImage({
  81. urls: [this.pic_url],
  82. });
  83. },
  84. //保存
  85. saveQrcode: function () {
  86. const self = this;
  87. self.$showLoading({title: `正在保存图片`});
  88. uni.downloadFile({
  89. url: self.pic_url,
  90. success: function (e) {
  91. uni.saveImageToPhotosAlbum({
  92. filePath: e.tempFilePath,
  93. success: function () {
  94. uni.showToast({title: '保存成功'});
  95. },
  96. fail: function (err) {
  97. if (err.errMsg) {
  98. uni.showModal({
  99. title: '提示',
  100. content: '您好,请先授权保存到相册权限',
  101. showCancel: false,
  102. success(res) {
  103. if (res.confirm) {
  104. uni.openSetting({
  105. success(settingdata) {
  106. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  107. uni.saveImageToPhotosAlbum({
  108. filePath: e.tempFilePath,
  109. success: function () {
  110. uni.showToast({title: '保存成功'});
  111. }
  112. })
  113. } else {
  114. uni.showModal({
  115. title: '提示',
  116. content: '授权失败,请稍后重新获取',
  117. showCancel: false
  118. })
  119. }
  120. }
  121. })
  122. }
  123. }
  124. })
  125. }
  126. },
  127. complete: function () {
  128. self.$hideLoading();
  129. }
  130. });
  131. },
  132. fail: function (e) {
  133. uni.showModal({
  134. title: '图片下载失败',
  135. content: e.errMsg,
  136. showCancel: false
  137. });
  138. },
  139. complete: function () {
  140. self.$hideLoading();
  141. }
  142. });
  143. },
  144. }
  145. }
  146. </script>
  147. <style scoped lang="scss">
  148. .back-o {
  149. background: #fb8a36;
  150. height: 100vh;
  151. padding-top: #{32rpx};
  152. }
  153. .back-t {
  154. width: 100%;
  155. height: 100%;
  156. padding-top: #{32rpx};
  157. }
  158. .code-box {
  159. text-align: center;
  160. background: #fff;
  161. margin: 0 auto;
  162. width: #{686rpx};
  163. border-radius: #{16rpx};
  164. }
  165. .code-box.set {
  166. padding: #{48rpx};
  167. color: #353535;
  168. }
  169. .set .receipt {
  170. font-size: #{68rpx};
  171. }
  172. .code-box .btn {
  173. color: #fff;
  174. height: #{88rpx};
  175. background: #ff4544;
  176. font-size: #{32rpx};
  177. margin-top: #{48rpx};
  178. border-radius: #{44rpx};
  179. }
  180. .code-box image {
  181. width: #{360rpx};
  182. height: #{360rpx};
  183. }
  184. .code-box .code-title {
  185. color: #353535;
  186. font-size: #{36rpx};
  187. margin-top: #{120rpx};
  188. margin-bottom: #{64rpx};
  189. }
  190. .code-box .end {
  191. color: #418bfb;
  192. font-size: #{32rpx};
  193. margin-top: #{80rpx};
  194. margin-bottom: #{100rpx};
  195. }
  196. .code-box .line {
  197. height: #{32rpx};
  198. background: #418bfb;
  199. width: 1px;
  200. margin: 0 #{60rpx};
  201. }
  202. .code-box .set-line {
  203. width: 100%;
  204. height: 1px;
  205. background: #e2e2e2;
  206. margin-top: #{40rpx};
  207. }
  208. .code-box .price {
  209. font-size: #{56rpx};
  210. color: #353535;
  211. margin-bottom: #{40rpx};
  212. }
  213. .code-input {
  214. font-size: #{68rpx};
  215. margin-top: #{40rpx};
  216. }
  217. .code-input > view {
  218. padding-right: #{22rpx};
  219. }
  220. .code-input input {
  221. height: #{100rpx};
  222. text-align: left;
  223. }
  224. </style>