123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- const {
- updateContractState,
- } = require("../../../config");
- const network = require('../../../network/index');
-
- // plugin/etc/pages/exbSignProtocol/exbSignProtocol.js
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- loading: false,
- orderNo: "",
- loadMsg: "请稍后...",
- isJunpSign: false,
- signType: 0, // 0 协议初始界面 1 查询协议状态界面 2 验证成功 3 签约失败,
- failMsg: "签署失败,请稍后重试",
- agreements: null,
- isAgree: false,
- path: "",
-
- isReadFile: false // 是否已经阅读过文件
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- updateContractState();
- this.configData(options);
- this.configContractQuery();
- },
- onShow() {
- if (this.data.isJunpSign) {
- this.setData({
- isJunpSign: false,
- })
- this.configContractQuery(1);
- }
- },
-
- // 配置默认参数
- configData(options) {
- const orderNo = options?.orderNo
- if (orderNo) {
- this.setData({
- orderNo: orderNo
- })
- }
- },
- /// 1.5.2.合同查询接口
- async configContractQuery(type = 0) {
- if (type == 0) {
- this.setData({
- loading: true,
- })
- } else {
- this.setData({
- signType: 1,
- })
- }
- this.configNavTitle();
- var res = await network.etc.checkProtocol({
- orderNo: this.data.orderNo,
- })
-
- if (type == 0) {
- this.setData({
- loading: false,
- })
- }
-
- const that = this;
- const {
- data,
- code,
- message,
- } = res;
-
- if (code == 0) {
- const {
- agreements,
- flag
- } = data;
- if (!flag) {
- wx.showModal({
- title: "您已签署合同",
- content: '系统查询您已签署合同,无需再次签署,请选择以下操作',
- showCancel: false,
- confirmColor: "rgba(62, 125, 245, 1)",
- confirmText: "返回",
- complete: () => {
- that.configContractState(0);
- }
- })
- } else {
- // 转换为组件可用的格式:[{key: '昱路用户协议', value: 'https://...'}]
- const agreementsData = agreements.map(obj => {
- const [key, path] = Object.entries(obj)[0];
- return {
- key,
- path
- };
- })
- this.setData({
- agreements: agreementsData,
- })
- }
- } else {
- wx.showModal({
- title: message || "签署状态查询失败,请稍后重试",
- confirmColor: "rgba(62, 125, 245, 1)",
- confirmText: "返回",
- showCancel: false,
- complete: () => {
- that.configContractState(1);
- }
- })
- }
- },
- /// 1.5.1.用户签约接口
- async configAccountSign() {
- let that = this
- var res = await network.etc.agreeProtocol({
- orderNo: this.data.orderNo,
- protocol: 1,
- loginSource: '431bfdc8b9c645e0b293b85d6ce1925b'
- })
- this.setData({
- loading: false,
- });
- const {
- code,
- message,
- } = res;
- if (code == 0) {
- that.configContractState(0);
- // wx.showModal({
- // content: message,
- // showCancel: false,
- // complete: () => {
- // that.configContractState(0);
- // }
- // })
- } else {
- wx.showToast({
- icon: "none",
- title: message || "签署参数获取失败,请稍后重试",
- });
- }
-
- },
-
- async tapSign() {
- if (this.data.isAgree) {
- this.setData({
- loading: true,
- });
- this.configAccountSign();
- } else {
- wx.showToast({
- title: '请先同意用户协议',
- icon: "none",
- })
- }
- },
-
- configContractState(state = 1) {
- console.log("合同界面:签约状态", state)
- updateContractState(state);
- wx.navigateBack();
- },
-
- tapReload() {
- this.configContractState();
- },
- configNavTitle() {
- wx.setNavigationBarTitle({
- title: this.data.signType == 0 ? "" : "签署合同",
- })
- },
- tapAgree() {
- if (this.data.isReadFile) {
- this.setData({
- isAgree: !this.data.isAgree
- })
- } else {
- let text = this.data.agreements.map(item => `《${item.key}》`).join(" ")
- wx.showModal({
- title: "签署合同",
- content: `请先点击阅读${text}`,
- showCancel: false,
- confirmColor: "rgb(72, 207, 60)",
- })
- }
- },
-
- tapProtocol(e) {
- const path = e.target.dataset.info;
- const name = e.target.dataset.name;
- this.openDocFile(path, name)
-
- },
- openDocFile(
- url,
- fileName,
- fileType = "pdf"
- ) {
- let _that = this
- let newpath = `${wx.env.USER_DATA_PATH}/${fileName}`;
- wx.showLoading({
- title: "加载中…",
- });
-
- console.log(url)
- console.log(newpath);
- wx.downloadFile({
- url: url,
- // filePath: newpath,
- success(res) {
- console.log(res);
- wx.hideLoading();
- if (res.statusCode === 200) {
- wx.openDocument({
- filePath: res.tempFilePath, // newpath,
- fileType,
- success: () => {
- _that.setData({
- isReadFile: true
- })
- },
- fail() {
- wx.showToast({
- title: "打开失败,请稍后重试",
- icon: "none",
- });
- },
- });
- } else {
- wx.showToast({
- title: "打开失败,请稍后重试",
- icon: "none",
- });
- }
- },
- fail(res) {
- wx.hideLoading()
- console.log("下载失败")
- console.log(res);
- }
- });
- }
- })
|