 /**
 * guoj
 * 2020.09.21
 * 对账审核管理
    */
    import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE,UPCLOUD_RDC_TMS_BUSINESS_SERVICE,UPCLOUD_RDC_TMS_INTERFACE_SERVICE} from '@/config/serviceSettings.js';
    import { getSelectGJ, querySysPicture } from '@/utils/prolog.ajax.js';
export default () => {
    // 获取默认时间
    var startTime = Prolog.formatDate(new Date(), "%YY-%MM") + "-01 00:00:00";
    var endTime = Prolog.formatDate(new Date()) + " 23:59:59";
    var gridB;
    //应收/付方table
    var userTable = {
        columns: [
            { id: "companyid", name: "id", type: "ro", width: "130", hidden: true },
            { id: "companycode", name: "编号", type: "ro" },
            { id: "companyname", name: "名称", type: "ro" },
            { id: "companytypeName", name: "单位类型", type: "ro" }
        ],
        multiselect: false,
        pagebar: { type: "simple" },

        url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubCompany/queryCompany", //数据接口
        type: "post", //数据提交方式，默认为get
        contentType: "application/json",
        params: JSON.stringify({}), //查询提交参数，分页参数默认为pageNum,pageSize
        page: true, //是否启用分页
        totalCount: "totalCount" //总记录数字段，默认totalCount
    };

    let dataSelect;
    //获取下拉框
    getSelectGJ([{ "objectcode": "PRICE_TYPE" }], function (data) {
        dataSelect = data.data;
        dataSelect.PRICE_TYPE.unshift({ "text": "", "value": "" });
    });


    var opts = {
        //terrace显示全部，card分页显示
        skin: "card",
        //renderer:"grid",
        columns: [
            { id: "accountbillId", name: "id", type: "ro", width: "100", hidden: true },
            { id: "accountbillNo", name: "对账单号", type: "ro" },
            { id: "accountbillDate", name: "对账时间", type: "ro" },
            {
                id: "receivableCode", name: "应收方编号", type: "ro"
            },
            { id: "receivableName", name: "应收方名称", type: "ro"},
            { id: "payableCode", name: "应付方编号", type: "ro"},
            { id: "payableName", name: "应付方名称", type: "ro"},
            { id: "billnum", name: "费用单号", type: "ro"},
            { id: "feeamt", name: "总金额", type: "ro" },
            { id: "memo", name: "备注", type: "ro"}
        ],
        multiselect: false,
        toolbar: [
            { type: "settings", labelWidth: 90, labelAlign: "right" },
            {
                type: "row",
                list: [
                    { type: "calendar", name: "startTime", label: "开始时间:", className: "layui-col-md3", value: startTime},
                    { type: "calendar", name: "endTime", label: "结束时间:", className: "layui-col-md3", value: endTime},
                    {
                        className: "layui-col-md3",
                        type: "selectTable",
                        placeholder: "请选择应收方",
                        readonly: false,
                        table: userTable,
                        tableWidth: 500,
                        tableHeight: 400,
                        fieldText: "companyname",
                        fieldValue: "companyid",
                        name: "receivableId",
                        label: "应收方:",
                        listener: function () {
                        }
                    },
                    {
                        className: "layui-col-md3",
                        type: "selectTable",
                        placeholder: "请选择应付方",
                        readonly: false,
                        table: userTable,
                        tableWidth: 500,
                        tableHeight: 400,
                        fieldText: "companyname",
                        fieldValue: "companyid",
                        name: "payableId",
                        label: "应付方:",
                        listener: function () {
                        }
                    },
                    {
                        type: "block", className: "layui-col-md6 form_btn_left",
                        list: [
                            { type: "button", className: "btn-normal", name: "querywork", value: "查询" },
                            { type: "newcolumn" },
                            { type: "button", name: "work_Reset", className: "normal", value: "重置" }
                        ]
                    },
                    {
                        type: "block", className: "layui-col-md6 right",
                        list: [
                            { type: "button", className: "btn-normal", name: "addBtn", offsetLeft: 10, value: "审核" },
                            { type: "newcolumn" },
                            { type: "button", name: "boHui", className: "btn-normal", value: "驳回" }
                        ]
                    }
                ]
            }],

        url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeAccountBill/bmsFeeAccountBillAuditQuery",//数据接口
        type: "post",//数据提交方式，默认为get
        contentType: "application/json",
        params: JSON.stringify({"flag": "auditQuery",startTime: startTime, endTime: endTime}),//查询提交参数，分页参数默认为pageNum,pageSize
        page: true, //是否启用分页
        totalCount: "totalCount" //总记录数字段，默认totalCount
    };
    //分页参数 pageSize pageNum
    var grid = new PlgGrid(opts);
    grid.renderTo("reconciliationAudit_guojzhuans2A");
    grid.loadData();
    //按钮添加方法
    grid.attachToolBarEvent("onButtonClick", function (name) {
        //查询
        if (name == "querywork") {
            var fdata = grid.getToolBarForm().getFormData();
            fdata.startTime = FormatDateTime(fdata.startTime);
            fdata.endTime = Prolog.formatDate(fdata.endTime) + " 23:59:59";
          if (fdata.startTime > fdata.endTime) {
            layer.msg("开始时间不能大于结束时间");
            return false;
          }
            fdata.flag = "auditQuery";
            fdata.receivableId = fdata.receivableId == "" || fdata.receivableId == null ? "" : JSON.parse(fdata.receivableId)[0];
            fdata.payableId = fdata.payableId == "" || fdata.payableId == null ? "" : JSON.parse(fdata.payableId)[0];
            grid.setParams(JSON.stringify(fdata));
            gridB.getGrid().clearAll();
            grid.reload();
        }
        //审核
        if (name == "addBtn") {
            let data = grid.getSelectedRowId();
            if(data == "" || data == null){
                layer.msg("请选择一行");
                return;
            }
            PlgDialog.open({
              title: "审核弹出框",
              shadeClose: true, //点击遮罩关闭
              content: "<div style='padding:23px'><text style='font-size:23px'>审核意见：</text><input type='text' style='font-size:23px' id='aostInput'/></div>",
              area: ["450px", "170px"],
              type: "2",
              btn: ["确认", "关闭"], //只是为了演示
              yes: function(){
                let auditdescrible = $("#aostInput").val();
                let dataItem = {list: [data]};
                dataItem.auditdescrible = auditdescrible;
                utilAjaxGJ( UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeAccountBill/audit", "post", JSON.stringify(dataItem), ()=>{
                    layer.closeAll();
                    grid.reload();
                    gridB.getGrid().clearAll();
                    layer.msg("成功");
                }, "application/json");
              },
              btn2: function(){
                layer.closeAll();
              }
            });
        }
        //重置
        if (name == "work_Reset") {
            grid.getToolBarForm().getDForm().setText("payableId", "");
            grid.getToolBarForm().getDForm().setText("receivableId", "");
            grid.getToolBarForm().clear();
            grid.getToolBarForm().setFormData({ startTime: startTime, endTime: endTime });
        }
        //驳回
        if (name == "boHui") {
            let data = grid.getSelectedRowId();
            if(data == "" || data == null){
                layer.msg("请选择一行");
                return;
            }
            PlgDialog.open({
              title: "驳回弹出框",
              shadeClose: true, //点击遮罩关闭
              content: "<div style='padding:23px'><text style='font-size:23px'>审核意见：</text><input type='text' style='font-size:23px' id='aostInput'/></div>",
              area: ["450px", "170px"],
              type: "2",
              btn: ["确认", "关闭"], //只是为了演示
              yes: function(){
                let auditdescrible = $("#aostInput").val();
                let dataItem = {list: [data]};
                dataItem.auditdescrible = auditdescrible;
                if(auditdescrible == "" || auditdescrible == null){
                    layer.msg("审核结论必填");
                    return;
                }
                utilAjaxGJ( UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeAccountBill/reject", "post", JSON.stringify(dataItem), ()=>{
                    layer.closeAll();
                    grid.reload();
                    gridB.getGrid().clearAll();
                    layer.msg("成功");
                }, "application/json");
              },
              btn2: function(){
                layer.closeAll();
              }
            });
        }
    });
    //单击事件
    grid.on("onRowSelect", function(id) {
        gridB.getGrid().clearAll();
        gridB.setParams(JSON.stringify({ "accountbillId": id, "pageNum": "1", "pageSize": "10" }));
        gridB.reload();
    });

    var optsB = {
        //terrace显示全部，card分页显示
        skin: "card",
        //renderer:"grid",
        columns: [
            { id: "INDEX", name: "id", type: "ro", width: "100", hidden: true },
            { id: "accountbillId", name: "对账单ID", type: "ro",width: 100, hidden: true},
            { id: "accountbillNo", name: "对账单号", type: "ro",width: 100},
            { id: "feebillNo", name: "费用单号", type: "ro" ,width: 100},
            {
                id: "feebillDate", name: "费用时间", type: "ro",width: 130
            },
            { id: "receivableCode", name: "应收方编号", type: "ro" ,width: 100},
            { id: "receivableName", name: "应收方名称", type: "ro",width: 100},
            { id: "payableCode", name: "应付方编号", type: "ro",width: 100},
            { id: "payableName", name: "应付方名称", type: "ro" ,width: 100},
            { id: "feetypecode", name: "费用项目编号", type: "ro" ,width: 100},
            { id: "feetypename", name: "费用项目名称", type: "ro" ,width: 100},
            { id: "refbillno", name: "关联业务单号", type: "ro" ,width: 100},
            { id: "refbilltype", name: "关联业务类型", type: "ro" ,width: 100},
            { id: "qty", name: "计费数量", type: "ro" ,width: 100},
            { id: "price", name: "计费价格", type: "ro" ,width: 100},
            { id: "pricetype", name: "计费价格类型", type: "ro", width: 110 ,render: (v)=>{
                return getSelectValue( dataSelect.PRICE_TYPE,v);
            }},
            { id: "feeamt", name: "金额", type: "ro" ,width: 100},
            { id: "memo", name: "备注", type: "ro" ,width: 100}
        ],
        beforeLoadData: function (res) {
          res.data.forEach((item, index) => {
            item.INDEX = index + "";
          });
          return res;
        },

        url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeAccountBill/bmsFeeAccountItemQuery",//数据接口
        type: "post",//数据提交方式，默认为get
        contentType: "application/json",
        params: "{}",//查询提交参数，分页参数默认为pageNum,pageSize
        page: true, //是否启用分页
        totalCount: "totalCount" //总记录数字段，默认totalCount
    };
    //分页参数 pageSize pageNum
     gridB = new PlgGrid(optsB);
    gridB.renderTo("reconciliationAudit_guojzhuans2B");
};
