Files
frontend-app/pages/contract/index.vue
T

215 lines
5.3 KiB
Vue
Raw Normal View History

2025-08-13 00:05:08 +08:00
<template>
<view class="content">
<TopSafe></TopSafe>
2025-08-13 20:41:56 +08:00
<Header title="我的合同" />
2025-08-13 00:05:08 +08:00
<view class="contract-view">
2025-08-16 00:14:55 +08:00
<ContractItem :type="type" :text="obj && obj.signatureName" :time="obj && obj.time" class="mt-24" @click="onBtn">
</ContractItem>
2025-08-13 00:05:08 +08:00
</view>
2025-08-16 00:14:55 +08:00
<u-modal :show="tipsShow" :showCancelButton="true" confirmText="去认证" @cancel="onTipsCancel" @confirm="onConfirm"
confirmColor="#7934F6" title="提示" content='签署合同需要进行实名认证,请先完成实名认证'></u-modal>
2025-08-13 23:18:06 +08:00
<DownPopup :show="downShow" @ok="onSignContract" @cancel="onCancel" />
<up-toast ref="uToastRef"></up-toast>
2025-08-13 20:41:56 +08:00
<!-- 腾讯电子签H5 → 集成到UniApp -->
<web-view v-if="signUrl" :src="signUrl" @message="handleMessage"></web-view>
2025-08-13 00:05:08 +08:00
</view>
</template>
<script>
import { getUserInfo } from '@/api/auth.js';
import Header from '@/components/common/header.vue';
import TopSafe from '@/components/common/top-safe.nvue'
import ContractItem from './components/contract-item.vue'
import DownPopup from '@/components/common/down-popup.vue';
2025-08-16 01:02:13 +08:00
import { getContractList, isSignContract, } from '@/api/contract.js'
import { getSignUrl, getMiniProgramSignUrl, signContract } from '@/api/order.js';
2025-08-13 00:05:08 +08:00
import func from '@/utils/func.js';
export default {
2025-08-13 20:41:56 +08:00
components: { Header, TopSafe, ContractItem, DownPopup },
2025-08-13 00:05:08 +08:00
data() {
return {
2025-08-13 20:41:56 +08:00
type: false,
obj: null,
flowId: null,
signUrl: null,
downShow: false,
2025-08-16 00:14:55 +08:00
tipsShow: false,
userInfo: null
2025-08-13 00:05:08 +08:00
};
},
onShow() {
2025-08-13 23:18:06 +08:00
},
2025-08-16 00:14:55 +08:00
onLoad() {
2025-08-13 00:05:08 +08:00
this.init();
2025-08-13 23:18:06 +08:00
this.userinfo();
2025-08-13 00:05:08 +08:00
},
methods: {
2025-08-13 20:41:56 +08:00
init() {
2025-08-13 23:18:06 +08:00
this.isSignContract()
2025-08-16 00:14:55 +08:00
2025-08-13 23:18:06 +08:00
},
2025-08-16 00:14:55 +08:00
userinfo() {
getUserInfo().then(res => {
if (res.bizcode == 100) {
2025-08-13 23:18:06 +08:00
this.userInfo = res.data;
}
2025-08-16 00:14:55 +08:00
console.log('res', res)
2025-08-13 23:18:06 +08:00
})
},
2025-08-16 00:14:55 +08:00
onConfirm() {
2025-08-13 23:18:06 +08:00
this.onTipsCancel();
uni.navigateTo({
2025-08-16 00:14:55 +08:00
url: '/pages/mine_package/mine_authentication/mine_authentication'
2025-08-13 23:18:06 +08:00
})
},
2025-08-16 00:14:55 +08:00
onTipsCancel() {
this.tipsShow = false;
2025-08-13 23:18:06 +08:00
},
2025-08-16 00:14:55 +08:00
onCancel() {
2025-08-13 23:18:06 +08:00
this.downShow = false;
2025-08-13 00:05:08 +08:00
},
2025-08-13 20:41:56 +08:00
isSignContract() {
2025-08-16 01:02:13 +08:00
isSignContract().then(res => {
2025-08-13 20:41:56 +08:00
if (res.bizcode == 100) {
2025-08-13 00:05:08 +08:00
this.type = res.data;
2025-08-16 00:14:55 +08:00
if (this.type) {
2025-08-13 23:18:06 +08:00
this.getSignContract()
}
2025-08-13 20:41:56 +08:00
} else {
2025-08-13 00:05:08 +08:00
this.$refs.uToastRef.show({
type: 'error',
message: res.msg,
});
}
})
},
2025-08-13 20:41:56 +08:00
getSignContract() {
getContractList().then(res => {
2025-08-13 23:18:06 +08:00
if (res.bizcode == 100 && res.data.length) {
2025-08-13 00:05:08 +08:00
this.obj = res.data[0];
2025-08-13 20:41:56 +08:00
this.obj.time = func.formatDate(new Date(res.data[0].signatureTime), 3)
} else {
2025-08-13 00:05:08 +08:00
this.$refs.uToastRef.show({
type: 'error',
message: res.msg,
});
}
})
},
2025-08-13 20:41:56 +08:00
onBtn() {
if (this.type) {
2025-08-13 00:05:08 +08:00
//查看
uni.navigateTo({
2025-08-13 20:41:56 +08:00
url: `/pages/contract/check`
2025-08-13 00:05:08 +08:00
})
2025-08-13 20:41:56 +08:00
} else {
2025-08-13 00:05:08 +08:00
//去签署
2025-08-13 20:41:56 +08:00
this.downShow = true;
2025-08-13 00:05:08 +08:00
}
2025-08-13 20:41:56 +08:00
},
// 发起合同签章
async onSignContract() {
2025-08-16 00:14:55 +08:00
if (this.userInfo.certStatus == 0) {
2025-08-13 23:18:06 +08:00
this.downShow = false;
this.tipsShow = true;
return;
2025-08-16 00:14:55 +08:00
} else if (this.userInfo.certStatus == 1) {
2025-08-13 23:18:06 +08:00
this.downShow = false;
this.$refs.uToastRef.show({
type: 'success',
message: '请耐心等待审核通过',
});
return;
}
2025-08-16 00:14:55 +08:00
const { bizcode, data } = await signContract();
2025-08-13 20:41:56 +08:00
if (bizcode === 100) {
this.flowId = data.flowId;
if (this.flowId)
// #ifdef APP-PLUS || WEB
this.onGetSignUrl(this.flowId);
// #endif
// #ifdef MP-WEIXIN
// 小程序
this.onGetMiniProgramSignUrl(this.flowId)
// #endif
}
},
// 获取H5签署链接
async onGetSignUrl(flowId) {
const params = {
// 需要的参数
flowId: flowId,
}
const { bizcode, data } = await getSignUrl(params);
if (bizcode === 100) {
this.signUrl = data.flowApproverUrlInfos[0].longUrl;
} else {
this.$refs.uToastRef.show({
type: 'error',
message: "获取签署链接失败,请稍后再试",
});
return null;
}
},
// 获取跳转至腾讯电子签小程序的签署链接
async onGetMiniProgramSignUrl(flowId) {
const params = {
flowId: flowId,
endPoint: 'HTTP_SHORT_URL'
}
const { bizcode, data } = await getMiniProgramSignUrl(params);
if (bizcode === 100) {
console.log("跳转至腾讯电子签小程序的签署链接", data);
this.openTencentESign(data.schemeUrl);
} else {
this.$refs.uToastRef.show({
type: 'error',
message: "获取签署链接失败,请稍后再试",
});
return null;
}
},
// 电子签的回调地址
handleMessage(e) {
const data = e.detail;
console.log('电子签的回调地址', e);
},
// 小程序签名
openTencentESign(signPath) {
// 这个链接需要后端调用腾讯电子签 API 获取
uni.navigateToMiniProgram({
appId: 'wxa023b292fd19d41d', // 腾讯电子签官方小程序的 appId
path: signPath, // 跳转到的页面路径 + 参数
extraData: {}, // 如果需要传额外参数
envVersion: 'release', // 小程序版本 release / trial / develop
success(res) {
console.log('跳转成功', res)
},
fail(err) {
console.error('跳转失败', err)
}
})
2025-08-13 00:05:08 +08:00
}
}
}
</script>
<style lang="scss" scoped>
2025-08-13 20:41:56 +08:00
.contract-view {
width: 100%;
height: calc(100% - 88rpx - var(--status-bar-height));
2025-08-13 00:05:08 +08:00
display: flex;
flex-direction: column;
align-items: center;
overflow-y: auto;
padding: 0 32rpx;
box-sizing: border-box;
}
</style>