Pages.Document = { _template: 'document.html', template: '
this is document.html
', data: function () { return { lang_choose: localStorage.getItem('lang_choose') || 'th', lang_txt: lang_document, upload_path: '../face/images/card/', sign_obj: {}, img1: '', img2: '', img3: '', doc_id: gup('id'), public_share: false, urlshare: '', mgs_canceldoc: '', chk_btn_cancle: false, alert: false, msg_alert: '', alert_success: '', chk_role_private: false, private_signer_mail: '', chk_download_all: false, chk_download_document: false, chk_download_cert: false, chk_download_combine: false, signer: gup('signer') || '', is_owner: false, can_see: false, tag_folder: '', approve: false, Need_Sign: false, isUseApprove: false, isStatusSign: false, approvesec:false, deletable:false, cert_expired:false } }, mounted: function () { this.cert_expired = ('true' == sessionStorage.getItem('cert_expired')) this.get_cer_info(); new ClipboardJS('#btncopy'); window.myApp = this if (this.signer != '') { this.signer = this.signer.replace("%40", "@") this.chek_link_mail() } else { this.get_edoc_detail() } }, filters: { status_doc(v) { var txt var n = parseInt(v) if (n == 1) { txt = "สำเร็จ" } else if (n == 3) { txt = 'เอกสารถูกยกเลิก' } else { txt = 'ไม่สำเร็จ' } return txt }, }, methods: { get_cer_info:function(){ var that = this var data = {} $.ajax({ type: "POST", url: api_host + "get_cer_info_BLA", data: JSON.stringify(data), dataType: "json", success: function (resp) { if(resp.success && resp.have_cert){ that.cert = resp.cert var expire_date = that.cert.expire_date var expire_day = expire_date.substring(0,2) var expire_month = expire_date.substring(3,5) var expire_year = expire_date.substring(6,10) var user_day = expire_day var user_month = expire_month var user_year = expire_year var current_day = new Date().getDate() var current_month = new Date().getMonth() var current_year = new Date().getFullYear() var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds var update_date = new Date(user_year, user_month, user_day); var current_date = new Date(current_year, current_month, current_day); var total = Math.round(Math.abs((update_date - current_date) / oneDay)); that.day_exp_cer = total var show_cert_warning = ('true' != sessionStorage.getItem('cert_expired')) window.show_cert_warning = show_cert_warning if(show_cert_warning) { window.total = total if(current_date.getTime()>update_date.getTime()) { alert('Your certificate has expired.\ncertificateของท่านหมดอายุกรุณาทำการต่ออายุ') sessionStorage.setItem('cert_expired', 'true') that.cert_expired = true } } } }, error: function (request, status, error) { alert("|" + status + ' |' + error); } }); }, open_document: function () { //if(this.cert_expired){ // alert('Your certificate has expired.\ncertificateของท่านหมดอายุกรุณาทำการต่ออายุ'); // return; //} var that = this var doc = "/bla/viewer.html?id=" + that.sign_obj.id + "&rd=" + new Date().getTime() window.open(doc) }, open_document_success: function () { var that = this var doc = "/capi/pdf?file=" + that.sign_obj.id + "&stamp=true" window.open(doc) }, get_edoc_detail: function () { var that = this $.ajax({ type: "GET", url: api_host + "get_edoc_detail?id=" + that.doc_id + '&owner=' + getUsername(), dataType: "json", success: function (data) { if (data.success) { that.sign_obj = data.data if (that.sign_obj.imageFiles[0] != undefined) { that.img1 = that.upload_path + that.sign_obj.imageFiles[0].fileName } if (that.sign_obj.imageFiles[1] != undefined) { that.img2 = that.upload_path + that.sign_obj.imageFiles[1].fileName } if (that.sign_obj.imageFiles[2] != undefined) { that.img3 = that.upload_path + that.sign_obj.imageFiles[2].fileName } that.sign_obj.status_texe = that.$options.filters.status_doc(that.sign_obj.status) that.urlshare = document.location.origin + '/bla/viewer.html?id=' + that.doc_id; if (that.sign_obj.setting_pdf && that.sign_obj.setting_pdf.length > 0) { that.tag_folder = that.sign_obj.setting_pdf[0].tag_folder } // sort signer order var use_order = that.sign_obj.use_signing_order if (use_order || use_order == "true") { that.sign_obj.signers = that.sign_obj.signers.sort(function (a, b) { return parseInt(a.order_set) - parseInt(b.order_set) }) } // points.sort(function(a, b){return a - b}); // chk btn cancle if (getUsername() == that.sign_obj.owner && that.sign_obj.status == 0) { that.chk_btn_cancle = true } if (that.sign_obj.status == 1 || that.sign_obj.status == 3) { that.deletable = true } let count_approve_fail= that.sign_obj.fields.filter(function (a) { return a.isApproved == "true" }) let count_unapprove= that.sign_obj.fields.filter(function (a) { return a.isApproved == "false" }) if(count_approve_fail.length>0){ that.approvesec = true; } if(count_unapprove.length>0){ that.approvesec = "unapprove"; } for (i = 0; i < that.sign_obj.signers.length; i++) { that.sign_obj.signers[i].status_sign_user = 0 } let count_user1 = 0 let suc = true for (i = 0; i < that.sign_obj.signers.length; i++) { let j = 0; while (j < that.sign_obj.fields.length) { if (that.sign_obj.fields[j].status == 0) { suc = false } if ((that.sign_obj.fields[j].status == 1) && (that.sign_obj.signers[i].is_group == true)) { let k = 0 while (k < that.sign_obj.signers[i].user_group.length) { if (that.sign_obj.signers[i].user_group[k].email == that.sign_obj.fields[j].email) { that.sign_obj.signers[i].status_sign_user = 1 count_user1++ break } k++ } if (that.sign_obj.signers[i].status_sign_user == 1) { break } } if ((that.sign_obj.fields[j].status == 1) && ((that.sign_obj.signers[i].email == that.sign_obj.fields[j].email) || (that.sign_obj.signers[i].delegates_mail == that.sign_obj.fields[j].email))) { that.sign_obj.signers[i].status_sign_user = 1 count_user1++ j++; break } j++ } } if (suc && (count_user1 != that.sign_obj.signers.length)) { var find_is_no_sign = that.sign_obj.fields.filter(function (a) { return a.is_no_sign == true }) var find_is_no_sign_c = that.sign_obj.fields.filter(function (a) { return a.is_no_sign == true && (a.email != "") }) if (find_is_no_sign.length != 0 && (find_is_no_sign.length == find_is_no_sign_c.length)) { for (i = 0; i < find_is_no_sign[0].person.user_group.length; i++) { for (j = 0; j < that.sign_obj.signers.length; j++) { if (find_is_no_sign[0].person.user_group[i].email == that.sign_obj.signers[j].email) { that.sign_obj.signers[j].status_sign_user = 1 } } } } } that.isUseApprove = that.sign_obj.signers[0].is_inspector that.isStatusSign = that.sign_obj.signers[0].status_sign_user var approve = that.sign_obj.signers.filter(signers => (signers.is_inspector && signers.is_inspector == true)) if (approve.length > 0) { that.sign_obj.is_have_inspector = true if(approve[0].email == getUsername()){that.approve = true;} else if(approve[0].is_group){ var approve_group = approve[0].user_group.filter(g => g.email == getUsername()) if(approve_group.length > 0){that.approve = true} } var find_status_approve = that.sign_obj.fields.filter(field => field.toolName == 'Approve') } if(find_status_approve && find_status_approve[0].status == 0){ that.sign_obj.doc_approve = false }else if (find_status_approve && find_status_approve[0].status == 1){ that.sign_obj.doc_approve = true } // var Need_Sign = that.sign_obj.signers.filter(signers => (signers.needToSign && signers.needToSign == true && signers.email == getUsername())) // if (Need_Sign.length > 0) { // that.Need_Sign = true; // } var chk = that.sign_obj.signers.filter(function (s) { if (s.needToSign && s.needToSign == true) { if (s.is_group) { var a = s.user_group.filter(function (s2) { return s2.email == getUsername() }) return a } else { return s.email == getUsername() } } else { return 0 } }) if (chk.length > 0) { that.Need_Sign = true; } // check role private mail for (i = 0; i < that.sign_obj.signers.length; i++) { if (that.sign_obj.signers[i].is_group == false) { // คนส่ง if (that.sign_obj.owner == getUsername()) { that.is_owner = true that.chk_role_private = true that.private_signer_mail = that.sign_obj.owner } else if (that.sign_obj.signers[i].email == getUsername()) { that.chk_role_private = true that.private_signer_mail = that.sign_obj.signers[i].email } } else { if (that.sign_obj.owner == getUsername()) { that.is_owner = true that.chk_role_private = true that.private_signer_mail = that.sign_obj.owner } else { for (i = 0; i < that.sign_obj.signers.length; i++) { if (that.sign_obj.signers[i].is_group) { var chk = that.sign_obj.signers[i].user_group.filter(function (a) { return a.email == getUsername() }) if (chk[0]) { that.chk_role_private = true that.private_signer_mail = chk[0].email } } } } } } } else { if (data.code == 'D00') { Swal.fire({ icon: 'error', text: that.lang_txt.Access_Denied[that.lang_choose], confirmButtonText: that.lang_txt.ok[that.lang_choose], }).then((result) => { if (result.isConfirmed) { router.push('dashboard'); // document.location.href = '/bla/web/login.html?rd=' + new Date().getTime() } }); } else if (data.code == 'D01') { Swal.fire({ icon: 'error', text: that.lang_txt.account[that.lang_choose] + getUsername() + that.lang_txt.permission[that.lang_choose], confirmButtonText: that.lang_txt.ok[that.lang_choose], }).then((result) => { if (result.isConfirmed) { document.location.href = '/bla/web/login.html?rd=' + new Date().getTime() } }); } } }, error: function (request, status, error) { console.error("|" + status + ' |' + error); } }); }, get_time_sign: function (i, e, pos) { var that = this var sign_using_position = false if (e == '' && pos && pos.length > 0) { //alert('use position') sign_using_position = true } var res = that.sign_obj.time var signer_view_only = that.sign_obj.signers.filter(function (view) { return view.email == e && view.needToSign == "false" }) if (signer_view_only.length > 0) return res // fillter time var fields = [] if (that.sign_obj.fields.length != undefined && that.sign_obj.fields.length != 0) { fields = that.sign_obj.fields.filter(function (d) { return ( (d.email == e || (sign_using_position && pos == d.position_id)) && d.toolName == 'Signature'); }); if (fields.length == 0) fields = this.sign_obj.fields.filter(function (d) { return (d.email == e || (sign_using_position && pos == d.position_id) ); }); fields.sort(function (a, b) { return b.time2 - a.time2 }); if (fields.length > 0) res = fields[0].time3 else res = '-' } return res }, set_public_share: function (n) { var that = this if (n == 1 || n == '1') { that.public_share = true that.share_doc() } else if (n == 2 || n == '2') { that.public_share = false that.urlshare = document.location.origin + '/bla/viewer.html?id=' + that.doc_id; } }, share_doc: function () { var that = this if (that.public_share) { var data = { id: that.doc_id } $.ajax({ type: "POST", url: api_host + "share_doc?id=" + that.doc_id, data: JSON.stringify(data), dataType: "json", success: function (jsonid) { if (jsonid.success) { that.urlshare = document.location.origin + '/bla/viewer.html?id=' + jsonid.data + '&stampkey=' + jsonid.x; } }, error: function (request, status, error) { console.error("|" + status + ' |' + error); } }); } else { that.urlshare = document.location.origin + '/bla/#/viewer.html?id=' + that.doc_id; } }, cancel_document: function () { var that = this; var data = { id: that.doc_id, owner: getUsername(), msg_cancel_doc: that.mgs_canceldoc } $.ajax({ type: "POST", url: api_host + "cancel_doc_bla", data: JSON.stringify(data), dataType: "json", success: function (resp) { that.alert = true if (resp.error_msg) { // that.alert_success = true // that.msg_alert = 'ยกเลิกเอกสารสำเร็จ' that.msg_alert = '' setTimeout(function () { that.alert = false; }, 1000); that.chk_btn_cancle = false that.get_edoc_detail() } else { // that.alert_success = false // that.msg_alert = 'ยกเลิกเอกสารไม่สำเร็จ' that.msg_alert = '' setTimeout(function () { that.alert = false; }, 1000); } }, error: function (request, status, error) { console.error("|" + status + ' |' + error); } }); }, copy_path: function () { var that = this that.alert = true that.alert_success = true // that.msg_alert = 'คัดลอกสำเร็จ' that.msg_alert = '' setTimeout(function () { that.alert = false; }, 1000); }, close_alert: function () { var that = this that.alert = false }, openDownload() { console.log('openDownload') $("#downloadModal").modal("show") }, submitDownload() { that = this console.log('submitDownload') if (that.chk_download_combine) { console.log('chk_download_combine') console.log(that.sign_obj) var url = "/capi/pdf?file=" + that.sign_obj.id + "&stamp=true" var name = that.sign_obj.subject + '.pdf' that.download(url, name) } else if (that.chk_download_all) { console.log('chk_download_document') that.stampPDF('all') } else if (that.chk_download_cert) { console.log('chk_download_cert') that.stampPDF('cert') } else if (that.chk_download_document) { console.log('chk_download_document') that.stampPDF('doc') } else { console.log('not check') } $("#downloadModal").modal("hide") }, download(uri, name) { var link = document.createElement("a"); link.download = name; link.href = uri; document.body.appendChild(link); link.click(); document.body.removeChild(link); delete link; }, stampPDF(download_type) { $('#loadingModal').modal('show'); console.log('stampPDF') that = this that.sign_obj.download_type = download_type const data = JSON.stringify(that.sign_obj) const url = api_host + 'download_doc_stamp' $.ajax({ url: url, type: "POST", data: data, success: function (result) { console.log('Done stampPDF') var url = "/capi/download_pdf?file=" + that.sign_obj.id + "&download_type=" + download_type + '&subject=' + that.sign_obj.subject console.log(url) var name = that.sign_obj.subject + '.pdf' if (download_type == 'cert') name = 'certificate.pdf' else if (download_type == 'all') name = that.sign_obj.subject + '.zip' that.download(url, name) $("#loadingModal").modal("hide") }, error: function (error) { console.log("Save template error: " + error) $("#loadingModal").modal("hide") } }) }, chk_download_ch(n) { that = this if (n == 0) { if (that.chk_download_all) { that.chk_download_document = true that.chk_download_cert = true } else { that.chk_download_document = false that.chk_download_cert = false } } else if (n == 1) { if (that.chk_download_document) { that.chk_download_all = false that.chk_download_cert = false } else { that.chk_download_all = false } } else if (n == 2) { if (that.chk_download_cert) { that.chk_download_all = false that.chk_download_document = false } else { that.chk_download_all = false } } else if (n == 3 && that.chk_download_combine) { that.chk_download_all = false that.chk_download_document = false that.chk_download_cert = false } }, chek_link_mail: function () { var that = this if (that.signer != getUsername()) { Swal.fire({ icon: 'error', text: that.lang_txt.account[that.lang_choose] + getUsername() + that.lang_txt.permission[that.lang_choose], confirmButtonText: that.lang_txt.ok[that.lang_choose], }).then((result) => { if (result.isConfirmed) { // document.location.href = '/bla/web/login.html?rd=' + new Date().getTime() document.location.href = '/bla/web/login.html?email=' + that.signer + '&doc_id=' + that.doc_id + '&rd=' + new Date().getTime() } }); } else { that.get_edoc_detail() } }, delTrash_single: function (id) { var that = this Swal.fire({ icon: 'warning', showDenyButton: true, text: that.lang_txt.want_delete[that.lang_choose], confirmButtonText: that.lang_txt.ok[that.lang_choose], denyButtonText: that.lang_txt.cancel_download[that.lang_choose], }).then((result) => { if (result.isConfirmed) { var data = { list_id: [], email: getUsername(), } data.list_id.push(id) list_document_load(id) $.ajax({ type: "POST", data: JSON.stringify(data), url: api_host + 'accept_remove_document', dataType: "json", success: function (resp) { if (resp.success) { Swal.fire({ icon: 'success', text: 'success', confirmButtonText: that.lang_txt.ok[that.lang_choose], }).then((result) => { if (result.isConfirmed) { router.push('dashboard'); } }); } else { Swal.fire({ icon: 'error', text: that.lang_txt.can_not_delete[that.lang_choose], confirmButtonText: that.lang_txt.ok[that.lang_choose], }) // display_alert("er_alert", "block", "none", "alert-danger") } }, error: function (error) { Swal.fire({ icon: 'error', text: that.lang_txt.can_not_delete[that.lang_choose], confirmButtonText: that.lang_txt.ok[that.lang_choose], }) //console.error("Something went wrong!" + error); } }) } else if (result.isDenied) { console.log("cancel document to trash") } }) }, } } routes.push({ path: '/document', component: Pages.Document }) var lang_document = { "doc_info": { "th": "รายละเอียดเอกสาร", "en": "Document Information" }, "doc_id": { "th": "เลขที่เอกสาร", "en": "Document ID" }, "status": { "th": "สถานะ", "en": "Status" }, "sender": { "th": "ผู้ส่ง", "en": "Sender" }, "sent_date": { "th": "ส่งเมื่อ", "en": "Sent Date" }, "exp_date": { "th": "วันหมดอายุ", "en": "Expiry Date" }, "general": { "th": "ทั่วไป", "en": "General" }, "recip_only": { "th": "เฉพาะผู้รับ", "en": "Only for the Recipient" }, "open_public": { "th": "เปิดสาธารณะ", "en": "Open for Public" }, "copy_link": { "th": "คัดลอกลิงก์", "en": "Copy link" }, "des_copy": { "th": "กรณีที่ผู้รับ ไม่ได้รับข้อความทางอีเมลสามารถคัดลอกลิงก์นี้ส่งให้ผู้รับเพื่อทำการเข้ามาเซ็นได้", "en": "If the recipient does not receive an automated email, you can copy and share this link to the recipient for a direct access to the document" }, "sign": { "th": "เซ็นเอกสาร", "en": "Sign" }, "cancel": { "th": "ยกเลิกเอกสาร", "en": "Cancel" }, "recip_info": { "th": "รายละเอียดผู้รับเอกสาร", "en": "Recipient’s Information" }, "recip": { "th": "ผู้รับ", "en": "Recipient" }, "recip_status": { "th": "สถานะของผู้รับ", "en": "Recipient’s Status" }, "sign_status": { "th": "สถานะการเซ็น", "en": "Signing Status" }, "pri_mess": { "th": "ข้อความส่วนตัว", "en": "Private Message" }, "pass_access": { "th": "รหัสการเข้าถึงเอกสาร", "en": "Security Code to access document" }, "need_sign": { "th": "ต้องเซ็น", "en": "Need to sign" }, "note": { "th": "หมายเหตุ", "en": "Note" }, "complete": { "th": "เซ็นเสร็จสมบูรณ์", "en": "Complete Signing" }, "approvecomplete": { "th": "ตรวจสอบเสร็จสมบูรณ์", "en": "Complete Approve" }, "incomplete": { "th": "ยังไม่ได้เซ็น", "en": "Incomplete Signing" }, "approveincomplete": { "th": "ยังไม่ได้ตรวจสอบ", "en": "Incomplete Approve" }, "view_only": { "th": "ดูอย่างเดียว", "en": "View Only" }, "kyc": { "th": "ต้องยืนยันตัวตน", "en": "Need e-KYC" }, "notkyc": { "th": "ไม่ต้องยืนยันตัวตน", "en": "Dispensable e-KYC" }, "close": { "th": "ปิด", "en": "Close" }, "ok": { "th": "ตกลง", "en": "Ok" }, "save": { "th": "บันทึก", "en": "Save" }, "view_document": { "th": "เปิดเอกสาร", "en": "View Document" }, "canceled": { "th": "ถูกยกเลิกเพราะ:", "en": "Canceled" }, "download": { "th": "ดาวน์โหลด", "en": "Download" }, "cancel_download": { "th": "ยกเลิก", "en": "Cancel" }, "download_detail": { "th": "เลือกไฟล์ที่คุณต้องการดาวน์โหลด", "en": "Select which files you want to download" }, "download_all": { "th": "ดาวน์โหลดทั้งหมด (แบบแยกไฟล์)", "en": "Download all (Separate file)" }, "download_document": { "th": "ดาวน์โหลดเอกสารหลักและเอกสาร Memo", "en": "Download main document and memo document" }, "download_cert": { "th": "ดาวน์โหลดใบรับรองอิเล็กทรอนิกส์", "en": "Download certificate" }, "combine": { "th": "ดาวน์โหลดทั้งหมด (แบบรวมไฟล์)", "en": "Download all (Combine file)" }, "at_least": { "th": "ต้องเซ็นอย่างน้อย", "en": "Signer at least" }, "people": { "th": "คน", "en": "people" }, "sign_order": { "th": "เซ็นตามลำดับ", "en": "Signing Order" }, "Access_Denied": { "th": "คุณไม่มีสิทธิ์ดูเอกสารนี้", "en": "Access Denied" }, "account": { "th": "บัญชี ( ", "en": " Your account (" }, "permission": { "th": ") ไม่สิทธิ์เข้าถึงเอกสารนี้", "en": ") don't have permission to access this document." }, "Document_category": { "th": "ประเภทเอกสาร", "en": "Document type" }, "Screener_Review": { "th": "การตรวจสอบเอกสาร", "en": "Screener Review" }, "Delete": { "th": "ลบเอกสาร", "en": "Delete document" }, "All_Document": { "th": "เอกสารทั้งหมด", "en": "All Document" }, "want_delete": { "th": "คุณต้องการลบเอกสาร", "en": "You want delete document" }, "can_not_delete": { "th": "ไม่สามารถลบได้เนื่องจากเอกสารยังไม่เสร็จสมบรูณ์หรือถูกยกเลิก", "en": "Can't delete, the document must be completed or cancelled." }, "Not_verified": { "th": "ไม่ผ่านการตรวจสอบ", "en": "Not verified" }, "Pass": { "th": "ผ่านการตรวจสอบ", "en": "Pass verified" }, "approve": { "th": "ตรวจสอบเอกสาร", "en": "Approve" }, "General_doc2": { "th": "เอกสารทั่วไป", "en": "General" }, "Memo_doc2": { "th": "เอกสารแบบ Memo", "en": "Memo" }, "please_sign": { "th": "กรุณาเซ็น:", "en": "Please sign:" }, }