contractInfo.vue 6.6 KB

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