contractInfo.vue 8.1 KB

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