contractInfo.vue 4.9 KB

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