payment-code.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 (e) {
  46. this.edit = true;
  47. },
  48. submit: function () {
  49. const self = this;
  50. const tmp_price = self.tmp_price ? parseFloat(parseFloat(self.tmp_price).toFixed(2)) : '';
  51. self.$showLoading({text: `生成中`});
  52. self.$request({
  53. url: self.$api.scan_code_pay.qr_code,
  54. method: 'POST',
  55. data: {
  56. price: tmp_price
  57. }
  58. }).then(info => {
  59. self.$hideLoading();
  60. if (info.code === 0) {
  61. [
  62. self.pic_url,
  63. self.price,
  64. self.tmp_price,
  65. self.edit,
  66. ] = [
  67. info.data.qr_code.file_path,
  68. tmp_price,
  69. tmp_price,
  70. false,
  71. ]
  72. } else {
  73. uni.showToast({icon: 'none', title: info.msg});
  74. }
  75. }).catch(info => {
  76. self.$hideLoading();
  77. });
  78. },
  79. //预览
  80. qrcodeClick: function (e) {
  81. uni.previewImage({
  82. urls: [this.pic_url],
  83. });
  84. },
  85. //保存
  86. saveQrcode: function () {
  87. const self = this;
  88. self.$showLoading({title: `正在保存图片`});
  89. uni.downloadFile({
  90. url: self.pic_url,
  91. success: function (e) {
  92. uni.saveImageToPhotosAlbum({
  93. filePath: e.tempFilePath,
  94. success: function () {
  95. uni.showToast({title: '保存成功'});
  96. },
  97. fail: function (err) {
  98. console.log(err.errMsg);
  99. if (err.errMsg) {
  100. uni.showModal({
  101. title: '提示',
  102. content: '您好,请先授权保存到相册权限',
  103. showCancel: false,
  104. success(res) {
  105. if (res.confirm) {
  106. uni.openSetting({
  107. success(settingdata) {
  108. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  109. uni.saveImageToPhotosAlbum({
  110. filePath: e.tempFilePath,
  111. success: function () {
  112. uni.showToast({title: '保存成功'});
  113. },
  114. })
  115. } else {
  116. uni.showModal({
  117. title: '提示',
  118. content: '授权失败,请稍后重新获取',
  119. showCancel: false,
  120. })
  121. }
  122. }
  123. })
  124. }
  125. }
  126. })
  127. }
  128. },
  129. complete: function (e) {
  130. self.$hideLoading();
  131. }
  132. });
  133. },
  134. fail: function (e) {
  135. uni.showModal({
  136. title: '图片下载失败',
  137. content: e.errMsg,
  138. showCancel: false,
  139. });
  140. },
  141. complete: function (e) {
  142. self.$hideLoading();
  143. }
  144. });
  145. },
  146. }
  147. }
  148. </script>
  149. <style scoped lang="scss">
  150. .back-o {
  151. background: #fb8a36;
  152. height: 100vh;
  153. padding-top: #{32rpx};
  154. }
  155. .back-t {
  156. width: 100%;
  157. height: 100%;
  158. padding-top: #{32rpx};
  159. }
  160. .code-box {
  161. text-align: center;
  162. background: #fff;
  163. margin: 0 auto;
  164. width: #{686rpx};
  165. border-radius: #{16rpx};
  166. }
  167. .code-box.set {
  168. padding: #{48rpx};
  169. color: #353535;
  170. }
  171. .set .receipt {
  172. font-size: #{68rpx};
  173. }
  174. .code-box .btn {
  175. color: #fff;
  176. height: #{88rpx};
  177. background: #ff4544;
  178. font-size: #{32rpx};
  179. margin-top: #{48rpx};
  180. border-radius: #{44rpx};
  181. }
  182. .code-box image {
  183. width: #{360rpx};
  184. height: #{360rpx};
  185. }
  186. .code-box .code-title {
  187. color: #353535;
  188. font-size: #{36rpx};
  189. margin-top: #{120rpx};
  190. margin-bottom: #{64rpx};
  191. }
  192. .code-box .end {
  193. color: #418bfb;
  194. font-size: #{32rpx};
  195. margin-top: #{80rpx};
  196. margin-bottom: #{100rpx};
  197. }
  198. .code-box .line {
  199. height: #{32rpx};
  200. background: #418bfb;
  201. width: 1px;
  202. margin: 0 #{60rpx};
  203. }
  204. .code-box .set-line {
  205. width: 100%;
  206. height: 1px;
  207. background: #e2e2e2;
  208. margin-top: #{40rpx};
  209. }
  210. .code-box .price {
  211. font-size: #{56rpx};
  212. color: #353535;
  213. margin-bottom: #{40rpx};
  214. }
  215. .code-input {
  216. font-size: #{68rpx};
  217. margin-top: #{40rpx};
  218. }
  219. .code-input > view {
  220. padding-right: #{22rpx};
  221. }
  222. .code-input input {
  223. height: #{100rpx};
  224. text-align: left;
  225. }
  226. </style>