123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- <template>
- <view class="content">
- <rich-text v-for="(item,index) in contractInfo" :key="index" :nodes="item.url" class="web-view"></rich-text>
- <u-cell-group style="width: 100%; float: left;padding:0;position: relative;">
- <u-cell-item title="乙方签字" :arrow="false" :title-style="{width: '100%'}" required>
- <view class="canvas-container" slot="label">
- <canvas canvas-id="canvas" id="canvas" :disable-scroll="true" style="width: 100%; height: 260px;background-color: #FFFFFF;border:1px solid #aaa;border-radius: 5px;"
- @touchstart="handleTouchStart($event)" @touchmove="handleTouchMove($event)" @touchend="handleTouchEnd($event)"
- @touchcancel="handleEnd($event)"></canvas>
- </view>
- </u-cell-item>
- <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>
- <view style="width:80px;height:30px;"></view>
- </u-cell-group>
- <view class="handle-fix-box" style="height:100px">
- <u-button style="margin-bottom: 10px;display: block;" type="warning" shape="circle" :ripple="true" :disabled="!ifSign" :custom-style="customStyle" @click="submitContract0()">其他方式支付</u-button>
- <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" :disabled="!ifSign" @click="submitContract()">确定支付</u-button>
- </view>
- <u-top-tips ref="uTips"></u-top-tips>
- </view>
- </template>
- <script>
- var context = null
- import {
- mapGetters
- } from 'vuex'
- const NET = require('@/utils/request')
- const API = require('@/config/api')
- export default {
- computed: {
- ...mapGetters([
- 'mainColor',
- 'customStyle',
- ])
- },
- data() {
- return {
- orderInfo: {
- cardIds: '',
- couponId: '',
- studentId: '',
- },
- contractInfo: [],
- ifSign: false,
- signUrl: '',
- realPayAmount: '',
- canvasData: []
- }
- },
- watch: {
- canvasData() {
- context.moveTo(this.canvasData[0].x, this.canvasData[0].y)
- for (let i = 0; i < this.canvasData.length; i++) {
- context.lineTo(this.canvasData[i].x, this.canvasData[i].y)
- }
- context.stroke()
- context.draw(true)
- }
- },
- onLoad(options) {
- this.orderInfo = {
- cardIds: options.memberCardId.split(','),
- couponId: options.couponId,
- studentId: options.studentId,
- }
- this.realPayAmount = options.realPayAmount
- console.log(this.realPayAmount);
- this.getContractInfo(options.parentName, options.sex)
- context = uni.createCanvasContext('canvas')
- context.setLineWidth(3)
- context.setStrokeStyle("#000000")
- this.reset()
- },
- onShow() {},
- methods: {
- // 获取数据
- getContractInfo(parentName, sex) {
- NET.request(API.getContractInfo, {
- cardIds: this.orderInfo.cardIds,
- studentId: this.orderInfo.studentId,
- parentName: parentName,
- sex: sex,
- }, 'POST').then(res => {
- this.contractInfo = res.data
- }).catch(error => {
- this.$refs.uTips.show({
- title: error.message,
- type: 'warning',
- })
- })
- },
- reset() {
- this.ifSign = false
- context.draw()
- },
- handleTouchStart(e) {
- this.ifSign = true
- this.canvasData = []
- const a = e.changedTouches[0]
- this.canvasData.push({
- x: a.x,
- y: a.y
- })
- },
- handleTouchMove(e) {
- const a = e.changedTouches[0]
- this.canvasData.push({
- x: a.x,
- y: a.y
- })
- },
- handleTouchEnd(e) {
- const a = e.changedTouches[0]
- this.canvasData.push({
- x: a.x,
- y: a.y
- })
- },
- handleEnd() {
- context.stroke()
- context.draw(true)
- },
- handleConfirm() {
- uni.canvasToTempFilePath({
- canvasId: 'canvas',
- success: res => {
- this.$emit('success', res.tempFilePath)
- }
- })
- },
- // 其他方式支付
- submitContract0() {
- let that = this
- uni.canvasToTempFilePath({
- canvasId: 'canvas',
- success: res => {
- uni.uploadFile({
- url: API.uploadFile,
- filePath: res.tempFilePath,
- name: 'file',
- header: {
- Authorization: uni.getStorageSync('token')
- },
- success: (uploadFileRes) => {
- that.signUrl = JSON.parse(uploadFileRes.data).data.id
- NET.request(API.submitContractForm, {
- contractIds: that.contractInfo.map(item => { return item.id }),
- fileId: that.signUrl,
- }, 'POST').then(res => {
- that.toPayOther(res.data.map(item => { return item.id }))
- }).catch(error => {
- that.$refs.uTips.show({
- title: error.message,
- type: 'warning',
- })
- })
- }
- });
- }
- })
- },
- // 提交签字
- submitContract() {
- let that = this
- uni.canvasToTempFilePath({
- canvasId: 'canvas',
- success: res => {
- uni.uploadFile({
- url: API.uploadFile,
- filePath: res.tempFilePath,
- name: 'file',
- header: {
- Authorization: uni.getStorageSync('token')
- },
- success: (uploadFileRes) => {
- that.signUrl = JSON.parse(uploadFileRes.data).data.id
- NET.request(API.submitContractForm, {
- contractIds: that.contractInfo.map(item => { return item.id }),
- fileId: that.signUrl,
- }, 'POST').then(res => {
- /*uni.redirectTo({
- url: '/pagesMain/payResultNo?id=' + res.data.oderNo
- });*/
- //this.goToPayResult(res.data.oderNo)
- that.toPay(res.data.map(item => { return item.id }))
- }).catch(error => {
- that.$refs.uTips.show({
- title: error.message,
- type: 'warning',
- })
- })
- }
- });
- }
- })
- },
- // 其他支付
- toPayOther(contractId) {
- NET.request(API.getPayParams0, {
- ...this.orderInfo,
- contractId: contractId
- }, 'POST').then(res => {
- uni.redirectTo({
- url: '/pagesMain/payResultNo?id=' + res.data.oderNo
- });
- })
- },
- // 支付
- toPay(contractId) {
- NET.request(API.getPayParams, {
- ...this.orderInfo,
- contractId: contractId
- }, 'POST').then(res => {
- if (this.realPayAmount <= 0) {
- this.goToPayResult(res.data.oderNo)
- return false
- }
- uni.requestPayment({
- provider: 'wxpay',
- timeStamp: res.data.timeStamp,
- nonceStr: res.data.nonceStr,
- package: res.data.packageString,
- signType: res.data.signType,
- paySign: res.data.paySign,
- success: (payRes) => {
- this.goToPayResult(res.data.oderNo)
- },
- fail: (error) => {
- NET.request(API.delete+'/'+res.data.oderId, null, 'GET').then(res => {
- this.$refs.uTips.show({
- title: '支付未成功',
- type: 'warning',
- })
- })
- }
- })
- }).catch(error => {
- this.$refs.uTips.show({
- title: error.message,
- type: 'warning',
- })
- })
- },
- // 跳转支付结果
- goToPayResult(oderNo) {
- uni.redirectTo({
- url: '/pagesMain/payResult?id=' + oderNo
- });
- }
- },
- }
- </script>
- <style>
- page {
- width: 100%;
- height: 100%;
- }
- </style>
- <style lang="scss" scoped>
- @import "@/static/css/themes.scss";
- .content {
- width: 100%;
- float: left;
- padding: 15px 15px 100px 15px;
- box-sizing: border-box;
- .web-view {
- height: 200px !important;
- }
- }
- </style>
|