contractInfo.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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" style="height:100px">
  14. <u-button style="margin-bottom: 10px;display: block;" type="warning" shape="circle" :ripple="true" :custom-style="customStyle" :disabled="!ifSign" @click="submitContract0()">其他方式支付</u-button>
  15. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" :disabled="!ifSign" @click="submitContract()">确定支付</u-button>
  16. </view>
  17. <u-top-tips ref="uTips"></u-top-tips>
  18. </view>
  19. </template>
  20. <script>
  21. var context = null
  22. import {
  23. mapGetters
  24. } from 'vuex'
  25. const NET = require('@/utils/request')
  26. const API = require('@/config/api')
  27. export default {
  28. computed: {
  29. ...mapGetters([
  30. 'mainColor',
  31. 'customStyle',
  32. ])
  33. },
  34. data() {
  35. return {
  36. orderInfo: {
  37. id: '',
  38. couponId: '',
  39. studentId: '',
  40. },
  41. contractInfo: {
  42. id: '',
  43. url: '',
  44. },
  45. ifSign: false,
  46. signUrl: '',
  47. realPayAmount: '',
  48. canvasData: []
  49. }
  50. },
  51. watch: {
  52. canvasData() {
  53. context.moveTo(this.canvasData[0].x, this.canvasData[0].y)
  54. for (let i = 0; i < this.canvasData.length; i++) {
  55. context.lineTo(this.canvasData[i].x, this.canvasData[i].y)
  56. }
  57. context.stroke()
  58. context.draw(true)
  59. }
  60. },
  61. onLoad(options) {
  62. this.orderInfo = {
  63. id: options.memberCardId,
  64. couponId: options.couponId,
  65. studentId: options.studentId,
  66. }
  67. this.realPayAmount = options.realPayAmount
  68. this.getContractInfo(options.parentName, options.sex)
  69. context = uni.createCanvasContext('canvas')
  70. context.setLineWidth(3)
  71. context.setStrokeStyle("#000000")
  72. this.reset()
  73. },
  74. onShow() {},
  75. methods: {
  76. // 获取数据
  77. getContractInfo(parentName, sex) {
  78. NET.request(API.getContractInfo, {
  79. cardId: this.orderInfo.id,
  80. studentId: this.orderInfo.studentId,
  81. parentName: parentName,
  82. sex: sex,
  83. }, 'POST').then(res => {
  84. this.contractInfo = res.data
  85. }).catch(error => {
  86. this.$refs.uTips.show({
  87. title: error.message,
  88. type: 'warning',
  89. })
  90. })
  91. },
  92. reset() {
  93. this.ifSign = false
  94. context.draw()
  95. },
  96. handleTouchStart(e) {
  97. this.ifSign = true
  98. this.canvasData = []
  99. const a = e.changedTouches[0]
  100. this.canvasData.push({
  101. x: a.x,
  102. y: a.y
  103. })
  104. },
  105. handleTouchMove(e) {
  106. const a = e.changedTouches[0]
  107. this.canvasData.push({
  108. x: a.x,
  109. y: a.y
  110. })
  111. },
  112. handleTouchEnd(e) {
  113. const a = e.changedTouches[0]
  114. this.canvasData.push({
  115. x: a.x,
  116. y: a.y
  117. })
  118. },
  119. handleEnd() {
  120. context.stroke()
  121. context.draw(true)
  122. },
  123. handleConfirm() {
  124. uni.canvasToTempFilePath({
  125. canvasId: 'canvas',
  126. success: res => {
  127. this.$emit('success', res.tempFilePath)
  128. }
  129. })
  130. },
  131. // 其他方式支付
  132. submitContract0() {
  133. let that = this
  134. uni.canvasToTempFilePath({
  135. canvasId: 'canvas',
  136. success: res => {
  137. uni.uploadFile({
  138. url: API.uploadFile,
  139. filePath: res.tempFilePath,
  140. name: 'file',
  141. header: {
  142. Authorization: uni.getStorageSync('token')
  143. },
  144. success: (uploadFileRes) => {
  145. that.signUrl = JSON.parse(uploadFileRes.data).data.id
  146. NET.request(API.submitContractForm, {
  147. contractId: that.contractInfo.id,
  148. fileId: that.signUrl,
  149. }, 'POST').then(res => {
  150. that.toPayOther(res.data.id)
  151. }).catch(error => {
  152. that.$refs.uTips.show({
  153. title: error.message,
  154. type: 'warning',
  155. })
  156. })
  157. }
  158. });
  159. }
  160. })
  161. },
  162. // 提交签字
  163. submitContract() {
  164. let that = this
  165. uni.canvasToTempFilePath({
  166. canvasId: 'canvas',
  167. success: res => {
  168. uni.uploadFile({
  169. url: API.uploadFile,
  170. filePath: res.tempFilePath,
  171. name: 'file',
  172. header: {
  173. Authorization: uni.getStorageSync('token')
  174. },
  175. success: (uploadFileRes) => {
  176. that.signUrl = JSON.parse(uploadFileRes.data).data.id
  177. NET.request(API.submitContractForm, {
  178. contractId: that.contractInfo.id,
  179. fileId: that.signUrl,
  180. }, 'POST').then(res => {
  181. /*uni.redirectTo({
  182. url: '/pagesMain/payResultNo?id=' + res.data.oderNo
  183. });*/
  184. //this.goToPayResult(res.data.oderNo)
  185. that.toPay(res.data.id)
  186. }).catch(error => {
  187. that.$refs.uTips.show({
  188. title: error.message,
  189. type: 'warning',
  190. })
  191. })
  192. }
  193. });
  194. }
  195. })
  196. },
  197. // 其他支付
  198. toPayOther(contractId) {
  199. NET.request(API.getPayParams0, {
  200. ...this.orderInfo,
  201. contractId: contractId
  202. }, 'POST').then(res => {
  203. uni.redirectTo({
  204. url: '/pagesMain/payResultNo?id=' + res.data.oderNo
  205. });
  206. })
  207. },
  208. // 支付
  209. toPay(contractId) {
  210. NET.request(API.getPayParams, {
  211. ...this.orderInfo,
  212. contractId: contractId
  213. }, 'POST').then(res => {
  214. if (this.realPayAmount <= 0) {
  215. this.goToPayResult(res.data.oderNo)
  216. return false
  217. }
  218. uni.requestPayment({
  219. provider: 'wxpay',
  220. timeStamp: res.data.timeStamp,
  221. nonceStr: res.data.nonceStr,
  222. package: res.data.packageString,
  223. signType: res.data.signType,
  224. paySign: res.data.paySign,
  225. success: (payRes) => {
  226. this.goToPayResult(res.data.oderNo)
  227. },
  228. fail: (error) => {
  229. this.$refs.uTips.show({
  230. title: '支付未成功',
  231. type: 'warning',
  232. })
  233. }
  234. })
  235. }).catch(error => {
  236. this.$refs.uTips.show({
  237. title: error.message,
  238. type: 'warning',
  239. })
  240. })
  241. },
  242. // 跳转支付结果
  243. goToPayResult(oderNo) {
  244. uni.redirectTo({
  245. url: '/pagesMain/payResult?id=' + oderNo
  246. });
  247. }
  248. },
  249. }
  250. </script>
  251. <style>
  252. page {
  253. width: 100%;
  254. height: 100%;
  255. }
  256. </style>
  257. <style lang="scss" scoped>
  258. @import "@/static/css/themes.scss";
  259. .content {
  260. width: 100%;
  261. float: left;
  262. padding: 15px 15px 100px 15px;
  263. box-sizing: border-box;
  264. .web-view {
  265. height: 200px !important;
  266. }
  267. }
  268. </style>