|
|
@@ -0,0 +1,444 @@
|
|
|
+const _Http = getApp().globalData.http;
|
|
|
+const __env = wx.getAccountInfoSync().miniProgram.envVersion;
|
|
|
+const ESIGN_APPID = __env === 'release' ? 'wxa023b292fd19d41d' : 'wx371151823f6f3edf';
|
|
|
+
|
|
|
+Page({
|
|
|
+ data: {
|
|
|
+ mxid: '',
|
|
|
+ loading: false,
|
|
|
+ submitting: false,
|
|
|
+ showAll: false,
|
|
|
+ disabled: true,
|
|
|
+ formHasEmpty: true,
|
|
|
+ licenseHasFiles: false,
|
|
|
+ idcardHasFiles: false,
|
|
|
+ licenseAttachmentids: [],
|
|
|
+ idcardAttachmentids: [],
|
|
|
+ signurl: '',
|
|
|
+ flowid: '',
|
|
|
+ form: [{
|
|
|
+ label: "营业执照名称",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入营业执照名称",
|
|
|
+ valueName: "license_name",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }, {
|
|
|
+ label: "纳税人识别号",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入纳税人识别号",
|
|
|
+ valueName: "taxno",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }, {
|
|
|
+ label: "营业执照地址",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入营业执照地址",
|
|
|
+ valueName: "license_address",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }, {
|
|
|
+ label: "签署人",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入签署人姓名",
|
|
|
+ valueName: "legal_rep",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }, {
|
|
|
+ label: "电话",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入电话",
|
|
|
+ valueName: "mobile",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }, {
|
|
|
+ label: "签署人手机号码",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "number",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入签署人手机号码",
|
|
|
+ valueName: "phonenumber",
|
|
|
+ required: true
|
|
|
+ }, {
|
|
|
+ label: "售前电话",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入售前电话",
|
|
|
+ valueName: "presalesphonenumber",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }, {
|
|
|
+ label: "售后电话",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入售后电话",
|
|
|
+ valueName: "aftersalesphonenumber",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }, {
|
|
|
+ label: "备案汇款人",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入备案汇款人(多人用逗号分隔)",
|
|
|
+ valueName: "paymans",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }, {
|
|
|
+ label: "签署人身份证号码",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入身份证号码",
|
|
|
+ valueName: "idcard",
|
|
|
+ required: true,
|
|
|
+ checking: "base"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+
|
|
|
+ onLoad(options) {
|
|
|
+ if (options.id) {
|
|
|
+ this.setData({
|
|
|
+ mxid: options.id
|
|
|
+ });
|
|
|
+ this.loadDetail(options.id);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 加载任务明细详情(系统取值) */
|
|
|
+ loadDetail(mxid) {
|
|
|
+ this.setData({
|
|
|
+ loading: true
|
|
|
+ });
|
|
|
+ _Http.basic({
|
|
|
+ id: 2026041516335302,
|
|
|
+ content: {
|
|
|
+ sa_esign_contract_taskmxid: mxid
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ this.setData({
|
|
|
+ loading: false
|
|
|
+ });
|
|
|
+ console.log("合同明细详情", res);
|
|
|
+ if (res.msg !== '成功') return wx.showToast({
|
|
|
+ title: res.msg || '加载失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ const data = res.data || {};
|
|
|
+ // 回填表单
|
|
|
+ const form = this.data.form.map(item => {
|
|
|
+ if (data[item.valueName] !== undefined && data[item.valueName] !== null) {
|
|
|
+ item.value = String(data[item.valueName]);
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ this.setData({
|
|
|
+ form
|
|
|
+ });
|
|
|
+
|
|
|
+ // 初始化附件 - 按 usetype 分类
|
|
|
+ const attinfos = data.attinfos || [];
|
|
|
+ const licenseFiles = attinfos.filter(v => v.usetype === 'bl');
|
|
|
+ const idcardFiles = attinfos.filter(v => v.usetype === 'idcard');
|
|
|
+ const licenseAttachmentids = licenseFiles.map(v => v.attachmentid);
|
|
|
+ const idcardAttachmentids = idcardFiles.map(v => v.attachmentid);
|
|
|
+ this.setData({
|
|
|
+ licenseAttachmentids,
|
|
|
+ idcardAttachmentids,
|
|
|
+ signurl: data.signurl || '',
|
|
|
+ flowid: data.flowid || ''
|
|
|
+ });
|
|
|
+
|
|
|
+ // 渲染已有附件到 Yl_Files
|
|
|
+ if (licenseFiles.length > 0) {
|
|
|
+ this.selectComponent("#Yl_license_files").handleFiles(licenseFiles, true);
|
|
|
+ }
|
|
|
+ if (idcardFiles.length > 0) {
|
|
|
+ this.selectComponent("#Yl_idcard_files").handleFiles(idcardFiles, true);
|
|
|
+ }
|
|
|
+ // 主动触发 Yl_Field 校验,更新 formComplete 状态
|
|
|
+ const formComp = this.selectComponent("#Form");
|
|
|
+ if (formComp && formComp.confirm) {
|
|
|
+ formComp.confirm();
|
|
|
+ }
|
|
|
+ this.refreshDisabled();
|
|
|
+ }).catch(() => {
|
|
|
+ this.setData({
|
|
|
+ loading: false
|
|
|
+ });
|
|
|
+ wx.showToast({
|
|
|
+ title: '加载失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 表单必填项是否完成 - detail=true 表示还有必填项未完成 */
|
|
|
+ onConfirm({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ this.setData({
|
|
|
+ formHasEmpty: detail
|
|
|
+ });
|
|
|
+ this.refreshDisabled();
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 中断 */
|
|
|
+ interrupt({
|
|
|
+ detail
|
|
|
+ }) {},
|
|
|
+
|
|
|
+ /* 切换显示 */
|
|
|
+ onChange(e) {
|
|
|
+ this.setData({
|
|
|
+ showAll: e.detail
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 刷新按钮禁用状态 */
|
|
|
+ refreshDisabled() {
|
|
|
+ // 已确认(有flowid)不禁用
|
|
|
+ if (this.data.flowid) {
|
|
|
+ this.setData({
|
|
|
+ disabled: false
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const licenseFiles = this.selectComponent("#Yl_license_files");
|
|
|
+ const idcardFiles = this.selectComponent("#Yl_idcard_files");
|
|
|
+ const licenseHasFiles = licenseFiles ? licenseFiles.getFiles().attachmentids.length > 0 : this.data.licenseAttachmentids.length > 0;
|
|
|
+ const idcardHasFiles = idcardFiles ? idcardFiles.getFiles().attachmentids.length > 0 : this.data.idcardAttachmentids.length > 0;
|
|
|
+ this.setData({
|
|
|
+ licenseHasFiles,
|
|
|
+ idcardHasFiles
|
|
|
+ });
|
|
|
+ // formHasEmpty=true 表示还有必填项未填
|
|
|
+ this.setData({
|
|
|
+ disabled: this.data.formHasEmpty || !licenseHasFiles || !idcardHasFiles
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 上传状态变化 */
|
|
|
+ changeState({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ this.setData({
|
|
|
+ loading: detail
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 查询文件详情并传给指定 Yl_Files */
|
|
|
+ fetchAndPushFiles(detail, filesId) {
|
|
|
+ Promise.all(detail.map(attachmentid => {
|
|
|
+ return _Http.basic({
|
|
|
+ "id": 2024061710590401,
|
|
|
+ "content": {
|
|
|
+ "pageSize": 1,
|
|
|
+ "pageNumber": 1,
|
|
|
+ "attachmentid": attachmentid
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })).then(res => {
|
|
|
+ this.selectComponent(filesId).handleFiles(res.map(v => v.data[0]));
|
|
|
+ this.refreshDisabled();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 营业执照上传回调 */
|
|
|
+ handleLicenseUpload({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ this.setData({
|
|
|
+ licenseAttachmentids: [...this.data.licenseAttachmentids, ...detail]
|
|
|
+ });
|
|
|
+ this.fetchAndPushFiles(detail, "#Yl_license_files");
|
|
|
+ this.createFileLink(detail, 'bl');
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 身份证上传回调 */
|
|
|
+ handleIdcardUpload({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ this.setData({
|
|
|
+ idcardAttachmentids: [...this.data.idcardAttachmentids, ...detail]
|
|
|
+ });
|
|
|
+ this.fetchAndPushFiles(detail, "#Yl_idcard_files");
|
|
|
+ this.createFileLink(detail, 'idcard');
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 文件删除回调 */
|
|
|
+ onFileDelete() {
|
|
|
+ this.refreshDisabled();
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 提交确认 */
|
|
|
+ onSubmit() {
|
|
|
+ if (this.data.disabled || this.data.submitting) return;
|
|
|
+ // 通过 Yl_Field 组件校验并获取表单数据
|
|
|
+ let formData = this.selectComponent("#Form").submit();
|
|
|
+ if (!formData) return;
|
|
|
+
|
|
|
+ // 检查附件(兼容从组件获取或从 data 获取)
|
|
|
+ const licenseFiles = this.selectComponent("#Yl_license_files");
|
|
|
+ const idcardFiles = this.selectComponent("#Yl_idcard_files");
|
|
|
+ const licenseIds = licenseFiles ? licenseFiles.getFiles().attachmentids : this.data.licenseAttachmentids;
|
|
|
+ const idcardIds = idcardFiles ? idcardFiles.getFiles().attachmentids : this.data.idcardAttachmentids;
|
|
|
+ if (licenseIds.length === 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请上传营业执照复印件',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (idcardIds.length === 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请上传身份证复印件',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 二次弹窗确认
|
|
|
+ wx.showModal({
|
|
|
+ title: '确认',
|
|
|
+ content: '合同基础信息确认后不可修改,是否开始签署?',
|
|
|
+ confirmText: '开始签署',
|
|
|
+ confirmColor: '#3874F6',
|
|
|
+ success: (res) => {
|
|
|
+ if (res.confirm) {
|
|
|
+ this.doConfirm(formData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 执行确认 - 确认任务明细后跳转电子签小程序 */
|
|
|
+ doConfirm(formData) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: '提交中...',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ this.setData({
|
|
|
+ submitting: true
|
|
|
+ });
|
|
|
+
|
|
|
+ _Http.basic({
|
|
|
+ id: 2026041315410702,
|
|
|
+ content: {
|
|
|
+ sa_esign_contract_taskmxid: this.data.mxid,
|
|
|
+ ...formData
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ wx.hideLoading();
|
|
|
+ this.setData({
|
|
|
+ submitting: false
|
|
|
+ });
|
|
|
+ console.log("确认任务明细", res);
|
|
|
+ if (res.msg !== '成功') {
|
|
|
+ return wx.showToast({
|
|
|
+ title: res.msg || '确认失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const data = res.data || {};
|
|
|
+ const signurl = data.signurl || '';
|
|
|
+ const flowid = data.flowid || '';
|
|
|
+ if (!flowid) {
|
|
|
+ return wx.showToast({
|
|
|
+ title: '签署流程未生成',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ signurl,
|
|
|
+ flowid,
|
|
|
+ disabled: false
|
|
|
+ });
|
|
|
+ // 询问用户是否跳转电子签(navigateToMiniProgram 必须由用户点击触发)
|
|
|
+ wx.showModal({
|
|
|
+ title: '确认成功',
|
|
|
+ content: '合同确认成功,是否立即前往签署?',
|
|
|
+ confirmText: '去签署',
|
|
|
+ cancelText: '返回列表',
|
|
|
+ confirmColor: '#3874F6',
|
|
|
+ success: (modalRes) => {
|
|
|
+ if (modalRes.confirm) {
|
|
|
+ this.goToSign();
|
|
|
+ } else {
|
|
|
+ wx.navigateBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }).catch(() => {
|
|
|
+ wx.hideLoading();
|
|
|
+ this.setData({
|
|
|
+ submitting: false
|
|
|
+ });
|
|
|
+ wx.showToast({
|
|
|
+ title: '确认失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 创建文件关联 */
|
|
|
+ createFileLink(attachmentids, usetype) {
|
|
|
+ return _Http.basic({
|
|
|
+ "classname": "system.attachment.Attachment",
|
|
|
+ "method": "createFileLink",
|
|
|
+ id: 10020501,
|
|
|
+ "content": {
|
|
|
+ ownertable: "sa_esign_contract_taskmx",
|
|
|
+ ownerid: this.data.mxid,
|
|
|
+ usetype,
|
|
|
+ attachmentids
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log('绑定附件', usetype, res);
|
|
|
+ }).catch(err => {
|
|
|
+ console.error('绑定附件失败', usetype, err);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 跳转腾讯电子签小程序签署 */
|
|
|
+ goToSign() {
|
|
|
+ const flowid = this.data.flowid;
|
|
|
+ if (!flowid) {
|
|
|
+ return wx.showToast({
|
|
|
+ title: '签署流程未生成',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ wx.navigateToMiniProgram({
|
|
|
+ appId: ESIGN_APPID,
|
|
|
+ path: `pages/guide?from=app&to=CONTRACT_DETAIL&id=${flowid}`,
|
|
|
+ envVersion: 'release',
|
|
|
+ complete() {
|
|
|
+ wx.navigateBack()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+});
|