contractInfo.vue 6.7 KB

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