// ==UserScript==
// @name Sayyoo-CCBHome-Contract-Export-Script
// @namespace http://tampermonkey.net/
// @version SCCES-0.0.0.5
// @description try to take over the world!
// @author You
// @match https://hess.qiye.ccbhome.cn/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=hess.qiye.ccbhome.cn
// @grant GM_xmlhttpRequest
// @require https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js
// ==/UserScript==
// http://sygit.sayyoo.cn/public-group/tampermonkey-scripts/blob/master/hess_qiye_ccbhome_cn.monkey.js
'use strict';
function init() {
var actions_btn_box = document.querySelector(".actions")
var pagePathname = window.location.pathname;
if (actions_btn_box && pagePathname == '/changzu/contract/list') {
console.log("#》#》#》actions_btn_box:", actions_btn_box);
// 创建 Excel 导出页面元素
var export_excel_node = document.createElement("div");
export_excel_node.className = "btn-group pull-right";
export_excel_node.innerHTML = ''+
'';
actions_btn_box.append(export_excel_node);
$("#sayyooContractInfoExport").on('click',function(){
var recordsTotal = $('#recordsTotal').val();
$('#exportModal').modal("show");
if(recordsTotal>0){
var _html = buildExportContainer(recordsTotal)
$("#exportContainer").html(_html);
$('.export_pages').empty();
var pageDiv = '';
export_per_count = 100;
if(recordsTotal<100){
$(".export_per_count").val(recordsTotal);
var export_per_count = recordsTotal;
}else{
$(".export_per_count").val(export_per_count);
}
var pages = Math.ceil(recordsTotal/export_per_count);
for(i = 1; i <= pages; i++){
if(i == 1){
pageDiv += '';
}else{
pageDiv += '';
}
}
$('.export_pages').html(pageDiv);
$(".export_pages").on("click", "button", function () {
$(this).parent().children("button.blue").removeClass("blue");
$(this).addClass("blue");
});
//监听提交事件
var export_process_status = 0;
$("#sayyooPageExport").on("click", function() {
if(export_process_status == 1){
alert('数据导出中,请勿重复提交');
return;
}
var page = $(".export_pages button.blue").attr("data-id");
if(page){
export_process_status = 1;
$("#point").text("");
var export_per_count = $('.export_per_count').val();
if(parseInt(export_per_count)){
var per_count = parseInt(export_per_count);
if(per_count > 100){
utils.alert("每页数量不能大于100");
return;
}
export_per_count = parseInt(per_count);
}else{
utils.alert("请输入每页数量");
return;
}
page = parseInt(page);
setTimeout(()=>{
DoSayyooExport((page-1)*export_per_count, export_per_count)
export_process_status = 0;
}, 100);
}else{
$("#point").text("请先选择需要导出的页数");
}
});
}else{
var __html = '
'
+'
';
}
function fetchSetCustomerId(row_data, index){
var longRentCodeJson = sessionStorage.getItem('zeroCloud-longRentCode');
var sessionCode = JSON.parse(longRentCodeJson);
var dataRequestURL = 'https://hess.qiye.ccbhome.cn/changzu/contract/edit';
dataRequestURL = dataRequestURL+'?id='+row_data[index].id+'&code='+sessionCode.content;
console.log("#>#>#>#>#>#>#>#>fetchSetCustomerId "+dataRequestURL)
const xhr = new XMLHttpRequest();
xhr.open('GET', dataRequestURL, false);
xhr.send(null);
if(xhr.status = 200){
var domParser = new DOMParser();
var htmlDoc = domParser.parseFromString(xhr.responseText, "text/html");
var customer_id_node = htmlDoc.getElementById("hid_customer_id");
row_data[index]._customer_id = customer_id_node.value;
var salesManNameNode = htmlDoc.getElementById("salesManName");
row_data[index].sales_man_name = salesManNameNode.value;
var salesManPhoneNode = htmlDoc.getElementById("salesManPhone");
row_data[index].sales_man_phone = salesManPhoneNode.value;
var emergency_tel_node = htmlDoc.getElementById("emergency_tel");
row_data[index].emergency_tel = emergency_tel_node.value;
}
}
function fetchSetRenterInfo(row_data, index){
var longRentCodeJson = sessionStorage.getItem('zeroCloud-longRentCode');
var sessionCode = JSON.parse(longRentCodeJson);
var dataRequestURL = 'https://hess.qiye.ccbhome.cn/changzu/renter/query-renter';
dataRequestURL = dataRequestURL+'?id='+row_data[index]._customer_id+'&projectId='+row_data[index].project_id+'&code='+sessionCode.content;
console.log("#>#>#>#>#>#>#>#>fetchSetRenterInfo "+dataRequestURL)
const xhr = new XMLHttpRequest();
xhr.open('GET', dataRequestURL, false);
xhr.send(null);
if(xhr.status = 200){
var renterInfo = JSON.parse(xhr.responseText);
row_data[index].customer_phone = renterInfo.phone;
}
}
function rebuildJsonData(jsonData){
var buildJson = [];
for(let i = 0; i < jsonData.length; i++) {
var buildJsonRow = {
系统合同编号 : jsonData[i].id,
自定义合同编号 : jsonData[i].contract_no,
房源编号 : jsonData[i].room_id,
房号 : jsonData[i].room_num,
月租金 : jsonData[i].monthly_rent,
押金 : jsonData[i].hasDeposite,
押金类型 : '',
转租服务费_换房服务费 : jsonData[i].id,
签约日期 : jsonData[i].signed_time,
承租日 : jsonData[i].origin_begin_date,
到期日 : jsonData[i].origin_end_date,
实际退房日期 : jsonData[i].end_date,
付款周期 : jsonData[i].pay_period,
客户姓名 : jsonData[i].customer_name,
证件类型 : jsonData[i].card_type,
证件号码 : jsonData[i].card_num,
客户电话 : jsonData[i].customer_phone,
紧急联系人姓名 : jsonData[i].emergency_name,
紧急联系人电话 : jsonData[i].emergency_tel,
通讯地址 : '',
电子邮箱 : '',
账单交费期限 : '每月'+jsonData[i].pay_day + '号' ,
租赁面积 : jsonData[i].area,
折扣方案 : '',
对外房源编号 : '',
业务人员姓名 : jsonData[i].sales_man_name,
业务人员手机号码 : jsonData[i].sales_man_phone,
电费押金 : '',
出租类型 : '',
合同备注 : '',
上上签合同编号 : jsonData[i].fsdid,
房源获取渠道 : jsonData[i].sourceChannel
};
buildJson.push(buildJsonRow);
}
return buildJson;
}
function sheet2blob(sheet, sheetName) {
sheetName = sheetName || 'sheet1';
var workbook = {
SheetNames: [sheetName],
Sheets: {}
};
workbook.Sheets[sheetName] = sheet;
// 生成excel的配置项
var wopts = {
bookType: 'xlsx', // 要生成的文件类型
bookSST: false, // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性
type: 'binary'
};
var wbout = XLSX.write(workbook, wopts);
var blob = new Blob([s2ab(wbout)], {type:"application/octet-stream"});
// 字符串转ArrayBuffer
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
return blob;
}