Pages.Self = { _template: 'self.html', template: '
this is self.html
', data: function () { return { lang_choose: localStorage.getItem('lang_choose') || 'th', lang_txt: lang_self, lang_err: "", display: false, list_document: [], list_document2: [], txt_search: "", filter: { doc: "", signer: "", send: "", date: "", }, count_check: 0, selectDocument: [], mv_folder: [], selectFolder: "", list_folder:[], btn_multi_remove: false, } }, mounted: function () { window.myApp = this this.get_list_document() this.get_folder() }, filters: { date(value) { value = value || '' var date = new Date(value) var day = date.getDate() if(Number(day) <= 9) day = "0" + day var month = date.getMonth() + 1 if(Number(month) <= 9) month = "0" + month var year = date.getFullYear() value = day + "/" + month + "/" + year return value || "" }, time(value) { value = value || '' var date = new Date(value) var horus = date.getHours() if(Number(horus) <= 9) horus = "0" + horus var minutes = date.getMinutes() if(Number(minutes) <= 9) minutes = "0" + minutes var seconds = date.getSeconds() if(Number(seconds) <= 9) seconds = "0" + seconds value = horus + ":" + minutes + ":" + seconds return value || "" }, fomat_date(value) { var res = value.split("-"); var text = res[2] + '/' + res[1] + '/' + res[0] return text } }, methods: { move_list_folder:function(){ var that = this if(that.list_folder.length > 0){ for(i = 0 ; i1 ` + that.lang_txt.doc_list[that.lang_choose] + `
` + that.lang_txt.noti_trash[that.lang_choose] , icon: 'warning', showDenyButton: true, confirmButtonText: that.lang_txt.confirm[that.lang_choose], denyButtonText: that.lang_txt.cancel[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) { that.lang_err = err_s["s_" + resp.error_code][that.lang_choose] display_alert("er_alert", "block", "none", "alert-success") // that.show_all_table() setTimeout(function(){ document.location.reload() }, 3000); } else { display_alert("er_alert", "block", "none", "alert-danger") } }, error: function (error) { alert("Something went wrong!" + error); } }) } else if (result.isDenied) { console.log("cancel document to trash") } }) }, check_btn_remove: function(arr){ var that = this that.btn_multi_remove = false var list = [] var list_doc = that.list_document for(i=0;i < arr.length; i++){ var select = list_doc.find(function(s){ return arr[i] == s._id }) if (select) list.push(select) } var list_not_remove = list.filter(function(l){ return l.status != 1 && l.status != 3 }) if(list_not_remove.length == 0 ){ that.btn_multi_remove = true } }, delTrash_multi: function(){ var that = this Swal.fire({ title: that.lang_txt.want_delete[that.lang_choose] + "?", html: `` + that.selectDocument.length + " " + that.lang_txt.doc_list[that.lang_choose] + `
` + that.lang_txt.noti_trash[that.lang_choose], icon: 'warning', showDenyButton: true, confirmButtonText: that.lang_txt.confirm[that.lang_choose], denyButtonText: that.lang_txt.cancel[that.lang_choose], }).then((result) => { if (result.isConfirmed) { var data = { list_id: that.selectDocument, email: getUsername() || "N/A", } for(i=0;i < data.list_id.length;i++) { list_document_load(data.list_id[i]) } $.ajax({ type: "POST", data: JSON.stringify(data), url: api_host + 'accept_remove_document', dataType: "json", success: function (resp) { if(resp.success) { that.lang_err = err_s["s_" + resp.error_code][that.lang_choose] display_alert("er_alert", "block", "none", "alert-success") // that.show_all_table() setTimeout(function(){ document.location.reload() }, 3000); } else { display_alert("er_alert", "block", "none", "alert-danger") } }, error: function (error) { alert("Something went wrong!" + error); } }) } else if (result.isDenied) { console.log("cancel document to trash") } }) }, openBar: function () { var that = this; that.count_check = that.selectDocument.length that.check_btn_remove(that.selectDocument) }, get_list_document: function () { var that = this var data = { "company_id": "", "email": getUsername() || "N/A", "cat": 'self' }; $.ajax({ type: "POST", url: api_host + "list_document_bla", data: JSON.stringify(data), dataType: "json", success: function (resp) { if (resp.success) { if (!resp.data.length) resp.data = [] var list = resp.data if (list.length > 0) { list.sort(function (a, b) { return b.createdDtm - a.createdDtm }) for(i=0;i < list.length;i++) { list[i].diff_date = that.cal_date(list[i].createdDtm) if(list[i].exp_date ){ var c = that.cal_exp_date(list[i].exp_date) if(c <= 30){ list[i].chk_exp = true list[i].exp_date = that.$options.filters.fomat_date(list[i].exp_date) }else{ list[i].chk_exp = false } } } that.list_document = list that.list_document2 = list that.set_table() } else { that.set_table() } } }, error: function (request, status, error) { alert("|" + status + ' |' + error); } }); }, count_signer: function (signer, fields) { if (fields.length > 0) { var total = 0 for (i = 0; i < signer.length; i++) { if (signer[i].needToSign == true) { var f_owner = fields.filter(function (f) { return (signer[i].email == f.email) }) var f_sign = fields.filter(function (f) { return (signer[i].email == f.email && f.status == 1) }) if (f_sign.length == f_owner.length) { total = total + 1 } } else { total = total + 1 } } return total } else { return signer.length } }, my_status_signer: function (signer, fields, status) { if (fields && fields.length > 0 && status == 0 || !status) { var email = getUsername() || "N/A" if(!fields.length) fields = [] var my = fields.filter(function (f) { return (f.email == email && f.status == "0") }) var other = fields.filter(function (f) { return (f.email != email && f.status == "0") }) if (my.length > 0) return "0" else if (my.length == 0 && other.length > 0) return "1" else return "" } else { return "" } }, gotoDoc: function (id) { document.location.href = "#/document?id=" + id }, set_table: function () { var that = this setTimeout(function () { table = $('#table').DataTable({ paging: true, searching: false, ordering: false, info: false, lengthChange: true, responsive: true, lengthMenu: [ [20, 50, 100, -1], [20, 50, 100, "ทั้งหมด"] ], dom: '<"top"i>rt<"bottom"flp><"clear">', language: { lengthMenu: "_MENU_", }, fnDrawCallback: function( oSettings ) { var list = document.getElementsByClassName("checkfile") var list_check = [] for(i=0; i