contractInfo.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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;padding:0;position: relative;">
  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: 260px;background-color: #FFFFFF;border:1px solid #aaa;border-radius: 5px;"
  8. @touchstart="handleTouchStart($event)" @touchmove="handleTouchMove($event)" @touchend="handleTouchEnd($event)"
  9. @touchcancel="handleEnd($event)"></canvas>
  10. </view>
  11. </u-cell-item>
  12. <view style="width:80px;height:30px;text-align: center;line-height: 30px;background-color: #ff6e3e;color:#fff;border-radius: 5px;position: absolute;right:0;z-index:5;" @click="reset">重新签名</view>
  13. <view style="width:80px;height:30px;"></view>
  14. </u-cell-group>
  15. <view class="handle-fix-box" style="height:100px">
  16. <u-button style="margin-bottom: 10px;display: block;" type="warning" shape="circle" :ripple="true" :disabled="!ifSign" :custom-style="customStyle" @click="submitContract0()">其他方式支付</u-button>
  17. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" :disabled="!ifSign" @click="submitContract()">确定支付</u-button>
  18. </view>
  19. <u-top-tips ref="uTips"></u-top-tips>
  20. </view>
  21. </template>
  22. <script>
  23. var context = null
  24. import {
  25. mapGetters
  26. } from 'vuex'
  27. const NET = require('@/utils/request')
  28. const API = require('@/config/api')
  29. export default {
  30. computed: {
  31. ...mapGetters([
  32. 'mainColor',
  33. 'customStyle',
  34. ])
  35. },
  36. data() {
  37. return {
  38. orderInfo: {
  39. cardIds: '',
  40. couponId: '',
  41. studentId: '',
  42. },
  43. contractInfo: [],
  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. cardIds: options.memberCardId.split(','),
  63. couponId: options.couponId,
  64. studentId: options.studentId,
  65. }
  66. this.realPayAmount = options.realPayAmount
  67. console.log(this.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. cardIds: this.orderInfo.cardIds,
  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. contractIds: that.contractInfo.map(item => { return item.id }),
  148. fileId: that.signUrl,
  149. }, 'POST').then(res => {
  150. that.toPayOther(res.data.map(item => { return item.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. contractIds: that.contractInfo.map(item => { return item.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.map(item => { return item.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. NET.request(API.delete+'/'+res.data.oderId, null, 'GET').then(res => {
  230. this.$refs.uTips.show({
  231. title: '支付未成功',
  232. type: 'warning',
  233. })
  234. })
  235. }
  236. })
  237. }).catch(error => {
  238. this.$refs.uTips.show({
  239. title: error.message,
  240. type: 'warning',
  241. })
  242. })
  243. },
  244. // 跳转支付结果
  245. goToPayResult(oderNo) {
  246. uni.redirectTo({
  247. url: '/pagesMain/payResult?id=' + oderNo
  248. });
  249. }
  250. },
  251. }
  252. </script>
  253. <style>
  254. page {
  255. width: 100%;
  256. height: 100%;
  257. }
  258. </style>
  259. <style lang="scss" scoped>
  260. @import "@/static/css/themes.scss";
  261. .content {
  262. width: 100%;
  263. float: left;
  264. padding: 15px 15px 100px 15px;
  265. box-sizing: border-box;
  266. .web-view {
  267. height: 200px !important;
  268. }
  269. }
  270. </style>