contractInfo.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <view class="content">
  3. <!-- <u-image width="100vw" height="100vh" :src="contractInfo.url"></u-image> -->
  4. <!-- <web-view :src="contractInfo.url" class="web-view"></web-view> -->
  5. <view class="canvas-container">
  6. <canvas canvas-id="canvas" id="canvas" :disable-scroll="true" style="width: 100%; height: 200px;background-color: #FFFFFF;"
  7. @touchstart="handleTouchStart($event)" @touchmove="handleTouchMove($event)" @touchend="handleTouchEnd($event)"
  8. @touchcancel="handleEnd($event)"></canvas>
  9. </view>
  10. <view class="handle-fix-box">
  11. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="toPay()">确定支付</u-button>
  12. </view>
  13. <u-top-tips ref="uTips"></u-top-tips>
  14. </view>
  15. </template>
  16. <script>
  17. var context = null
  18. import {
  19. mapGetters
  20. } from 'vuex'
  21. const NET = require('@/utils/request')
  22. const API = require('@/config/api')
  23. export default {
  24. computed: {
  25. ...mapGetters([
  26. 'mainColor',
  27. 'customStyle',
  28. ])
  29. },
  30. data() {
  31. return {
  32. orderInfo: {
  33. id: '',
  34. couponId: '',
  35. studentId: '',
  36. },
  37. contractInfo: {
  38. id: '',
  39. url: '',
  40. },
  41. canvasData: []
  42. }
  43. },
  44. watch: {
  45. canvasData() {
  46. context.moveTo(this.canvasData[0].x, this.canvasData[0].y)
  47. for (let i = 0; i < this.canvasData.length; i++) {
  48. context.lineTo(this.canvasData[i].x, this.canvasData[i].y)
  49. }
  50. context.stroke()
  51. context.draw(true)
  52. }
  53. },
  54. onLoad(options) {
  55. this.orderInfo = {
  56. id: options.memberCardId,
  57. couponId: options.couponId,
  58. studentId: options.studentId,
  59. }
  60. this.getContractInfo()
  61. context = uni.createCanvasContext('canvas')
  62. context.setLineWidth(3)
  63. context.setStrokeStyle("#000000")
  64. this.reset()
  65. },
  66. onShow() {},
  67. methods: {
  68. // 获取数据
  69. getContractInfo() {
  70. NET.request(API.getContractInfo, {
  71. cardId: this.orderInfo.id
  72. }, 'POST').then(res => {
  73. uni.downloadFile({
  74. url: res.data.url,
  75. success: (res2) => {
  76. uni.openDocument({
  77. filePath: res2.tempFilePath,
  78. });
  79. }
  80. })
  81. // this.contractInfo = res.data
  82. }).catch(error => {
  83. this.$refs.uTips.show({
  84. title: error.message,
  85. type: 'warning',
  86. })
  87. })
  88. },
  89. reset() {
  90. context.draw()
  91. },
  92. handleTouchStart(e) {
  93. this.canvasData = []
  94. const a = e.changedTouches[0]
  95. this.canvasData.push({
  96. x: a.x,
  97. y: a.y
  98. })
  99. },
  100. handleTouchMove(e) {
  101. const a = e.changedTouches[0]
  102. this.canvasData.push({
  103. x: a.x,
  104. y: a.y
  105. })
  106. },
  107. handleTouchEnd(e) {
  108. const a = e.changedTouches[0]
  109. this.canvasData.push({
  110. x: a.x,
  111. y: a.y
  112. })
  113. },
  114. handleEnd() {
  115. context.stroke()
  116. context.draw(true)
  117. },
  118. handleConfirm() {
  119. uni.canvasToTempFilePath({
  120. canvasId: 'canvas',
  121. success: res => {
  122. this.$emit('success', res.tempFilePath)
  123. }
  124. })
  125. },
  126. // 支付
  127. toPay() {
  128. NET.request(API.getPayParams, {
  129. ...this.orderInfo
  130. }, 'POST').then(res => {
  131. if (this.memberInfo.realPayAmount <= 0) {
  132. this.goToPayResult(res.data.oderNo)
  133. return false
  134. }
  135. uni.requestPayment({
  136. provider: 'wxpay',
  137. timeStamp: res.data.timeStamp,
  138. nonceStr: res.data.nonceStr,
  139. package: res.data.packageString,
  140. signType: res.data.signType,
  141. paySign: res.data.paySign,
  142. success: (payRes) => {
  143. this.goToPayResult(res.data.oderNo)
  144. },
  145. fail: (error) => {
  146. this.$refs.uTips.show({
  147. title: '支付未成功',
  148. type: 'warning',
  149. })
  150. }
  151. })
  152. }).catch(error => {
  153. this.$refs.uTips.show({
  154. title: error.message,
  155. type: 'warning',
  156. })
  157. })
  158. },
  159. // 跳转支付结果
  160. goToPayResult(oderNo) {
  161. uni.redirectTo({
  162. url: '/pagesMain/payResult?id=' + oderNo
  163. });
  164. }
  165. },
  166. }
  167. </script>
  168. <style>
  169. page {
  170. width: 100%;
  171. height: 100%;
  172. }
  173. </style>
  174. <style lang="scss" scoped>
  175. @import "@/static/css/themes.scss";
  176. .content {
  177. width: 100%;
  178. float: left;
  179. padding: 15px 15px 60px 15px;
  180. box-sizing: border-box;
  181. .web-view {
  182. height: 200px !important;
  183. }
  184. }
  185. </style>