contractInfo.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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" :disabled="!ifSign" @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. ifSign: false,
  45. signUrl: '',
  46. realPayAmount: '',
  47. canvasData: []
  48. }
  49. },
  50. watch: {
  51. canvasData() {
  52. context.moveTo(this.canvasData[0].x, this.canvasData[0].y)
  53. for (let i = 0; i < this.canvasData.length; i++) {
  54. context.lineTo(this.canvasData[i].x, this.canvasData[i].y)
  55. }
  56. context.stroke()
  57. context.draw(true)
  58. }
  59. },
  60. onLoad(options) {
  61. this.orderInfo = {
  62. id: options.memberCardId,
  63. couponId: options.couponId,
  64. studentId: options.studentId,
  65. }
  66. this.realPayAmount = options.realPayAmount
  67. this.getContractInfo(options.parentName, options.sex)
  68. context = uni.createCanvasContext('canvas')
  69. context.setLineWidth(3)
  70. context.setStrokeStyle("#000000")
  71. this.reset()
  72. },
  73. onShow() {},
  74. methods: {
  75. // 获取数据
  76. getContractInfo(parentName, sex) {
  77. NET.request(API.getContractInfo, {
  78. cardId: this.orderInfo.id,
  79. studentId: this.orderInfo.studentId,
  80. parentName: parentName,
  81. sex: sex,
  82. }, 'POST').then(res => {
  83. this.contractInfo = res.data
  84. }).catch(error => {
  85. this.$refs.uTips.show({
  86. title: error.message,
  87. type: 'warning',
  88. })
  89. })
  90. },
  91. reset() {
  92. this.ifSign = false
  93. context.draw()
  94. },
  95. handleTouchStart(e) {
  96. this.ifSign = true
  97. this.canvasData = []
  98. const a = e.changedTouches[0]
  99. this.canvasData.push({
  100. x: a.x,
  101. y: a.y
  102. })
  103. },
  104. handleTouchMove(e) {
  105. const a = e.changedTouches[0]
  106. this.canvasData.push({
  107. x: a.x,
  108. y: a.y
  109. })
  110. },
  111. handleTouchEnd(e) {
  112. const a = e.changedTouches[0]
  113. this.canvasData.push({
  114. x: a.x,
  115. y: a.y
  116. })
  117. },
  118. handleEnd() {
  119. context.stroke()
  120. context.draw(true)
  121. },
  122. handleConfirm() {
  123. uni.canvasToTempFilePath({
  124. canvasId: 'canvas',
  125. success: res => {
  126. this.$emit('success', res.tempFilePath)
  127. }
  128. })
  129. },
  130. // 提交签字
  131. submitContract() {
  132. let that = this
  133. uni.canvasToTempFilePath({
  134. canvasId: 'canvas',
  135. success: res => {
  136. uni.uploadFile({
  137. url: API.uploadFile,
  138. filePath: res.tempFilePath,
  139. name: 'file',
  140. header: {
  141. Authorization: uni.getStorageSync('token')
  142. },
  143. success: (uploadFileRes) => {
  144. that.signUrl = JSON.parse(uploadFileRes.data).data.id
  145. NET.request(API.submitContractForm, {
  146. contractId: that.contractInfo.id,
  147. fileId: that.signUrl,
  148. }, 'POST').then(res => {
  149. that.toPay(res.data.id)
  150. }).catch(error => {
  151. that.$refs.uTips.show({
  152. title: error.message,
  153. type: 'warning',
  154. })
  155. })
  156. }
  157. });
  158. }
  159. })
  160. },
  161. // 支付
  162. toPay(contractId) {
  163. NET.request(API.getPayParams, {
  164. ...this.orderInfo,
  165. contractId: contractId
  166. }, 'POST').then(res => {
  167. if (this.realPayAmount <= 0) {
  168. this.goToPayResult(res.data.oderNo)
  169. return false
  170. }
  171. uni.requestPayment({
  172. provider: 'wxpay',
  173. timeStamp: res.data.timeStamp,
  174. nonceStr: res.data.nonceStr,
  175. package: res.data.packageString,
  176. signType: res.data.signType,
  177. paySign: res.data.paySign,
  178. success: (payRes) => {
  179. this.goToPayResult(res.data.oderNo)
  180. },
  181. fail: (error) => {
  182. this.$refs.uTips.show({
  183. title: '支付未成功',
  184. type: 'warning',
  185. })
  186. }
  187. })
  188. }).catch(error => {
  189. this.$refs.uTips.show({
  190. title: error.message,
  191. type: 'warning',
  192. })
  193. })
  194. },
  195. // 跳转支付结果
  196. goToPayResult(oderNo) {
  197. uni.redirectTo({
  198. url: '/pagesMain/payResult?id=' + oderNo
  199. });
  200. }
  201. },
  202. }
  203. </script>
  204. <style>
  205. page {
  206. width: 100%;
  207. height: 100%;
  208. }
  209. </style>
  210. <style lang="scss" scoped>
  211. @import "@/static/css/themes.scss";
  212. .content {
  213. width: 100%;
  214. float: left;
  215. padding: 15px 15px 60px 15px;
  216. box-sizing: border-box;
  217. .web-view {
  218. height: 200px !important;
  219. }
  220. }
  221. </style>