contractInfo.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. this.contractInfo = res.data
  74. }).catch(error => {
  75. this.$refs.uTips.show({
  76. title: error.message,
  77. type: 'warning',
  78. })
  79. })
  80. },
  81. reset() {
  82. context.draw()
  83. },
  84. handleTouchStart(e) {
  85. this.canvasData = []
  86. const a = e.changedTouches[0]
  87. this.canvasData.push({
  88. x: a.x,
  89. y: a.y
  90. })
  91. },
  92. handleTouchMove(e) {
  93. const a = e.changedTouches[0]
  94. this.canvasData.push({
  95. x: a.x,
  96. y: a.y
  97. })
  98. },
  99. handleTouchEnd(e) {
  100. const a = e.changedTouches[0]
  101. this.canvasData.push({
  102. x: a.x,
  103. y: a.y
  104. })
  105. },
  106. handleEnd() {
  107. context.stroke()
  108. context.draw(true)
  109. },
  110. handleConfirm() {
  111. uni.canvasToTempFilePath({
  112. canvasId: 'canvas',
  113. success: res => {
  114. this.$emit('success', res.tempFilePath)
  115. }
  116. })
  117. },
  118. // 支付
  119. toPay() {
  120. NET.request(API.getPayParams, {
  121. ...this.orderInfo
  122. }, 'POST').then(res => {
  123. if (this.memberInfo.realPayAmount <= 0) {
  124. this.goToPayResult(res.data.oderNo)
  125. return false
  126. }
  127. uni.requestPayment({
  128. provider: 'wxpay',
  129. timeStamp: res.data.timeStamp,
  130. nonceStr: res.data.nonceStr,
  131. package: res.data.packageString,
  132. signType: res.data.signType,
  133. paySign: res.data.paySign,
  134. success: (payRes) => {
  135. this.goToPayResult(res.data.oderNo)
  136. },
  137. fail: (error) => {
  138. this.$refs.uTips.show({
  139. title: '支付未成功',
  140. type: 'warning',
  141. })
  142. }
  143. })
  144. }).catch(error => {
  145. this.$refs.uTips.show({
  146. title: error.message,
  147. type: 'warning',
  148. })
  149. })
  150. },
  151. // 跳转支付结果
  152. goToPayResult(oderNo) {
  153. uni.redirectTo({
  154. url: '/pagesMain/payResult?id=' + oderNo
  155. });
  156. }
  157. },
  158. }
  159. </script>
  160. <style>
  161. page {
  162. width: 100%;
  163. height: 100%;
  164. }
  165. </style>
  166. <style lang="scss" scoped>
  167. @import "@/static/css/themes.scss";
  168. .content {
  169. width: 100%;
  170. float: left;
  171. padding: 15px 15px 60px 15px;
  172. box-sizing: border-box;
  173. .web-view{
  174. height: 200px!important;
  175. }
  176. }
  177. </style>