/**
* 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";

  //获取下拉框
  let dataSelect;
  getSelectGJ([
    { "objectcode": "PRICE_TYPE" },
    { "objectcode": "COMPANY_TYPE", "groupcode2": "1" }
  ], function (data) {
    dataSelect = data.data;
    dataSelect.PRICE_TYPE.unshift({ "text": "", "value": "" });
    dataSelect.COMPANY_TYPE.unshift({ "text": "", "value": "" });
  });
  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" }
    ],
    toolbar: [
      { type: "settings", labelWidth: 60, labelAlign: "right" },
      {
        type: "row",
        list: [
          { type: "input", name: "companycode", label: "单位编码:", className: "layui-col-md6" },
          { type: "input", name: "companyname", label: "单位名称:", className: "layui-col-md6" },
          { type: "combo", name: "companytype", label: "单位类型:", className: "layui-col-md6", options: dataSelect.COMPANY_TYPE, readonly: true },
          {
            type: "block", className: "layui-col-md6 form_btn_left",
            list: [
              { type: "button", name: "querycarr", className: "btn-normal", value: "查询" },
              { type: "newcolumn" },
              { type: "button", name: "car_Reset", value: "重置" }
            ]
          }
        ]
      }
    ],
    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
  };

  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: "statusName", name: "状态", type: "ro" },
      { id: "memo", name: "备注", type: "ro" }
    ],
    multiselect: true,
    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: 600,
            tableHeight: 500,
            fieldText: "companyname",
            fieldValue: "companyid",
            name: "receivableId",
            label: "应收方:",
            listener: function (Grid) {
              setMethod(Grid, userTable, function () {
              });
            }
          },
          {
            className: "layui-col-md3",
            type: "selectTable",
            placeholder: "请选择应付方",
            readonly: false,
            table: userTable,
            tableWidth: 600,
            tableHeight: 500,
            fieldText: "companyname",
            fieldValue: "companyid",
            name: "payableId",
            label: "应付方:",
            listener: function (Grid) {
              setMethod(Grid, userTable, 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: "重置" }
            ]
          }
        ]
      }],

    url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bmsFeeAccountBill/bmsFeeAccountBillQuery",//数据接口
    type: "post",//数据提交方式，默认为get
    contentType: "application/json",
    params: JSON.stringify({ "flag": "query", startTime: startTime, endTime: endTime }),//查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
  var grid = new PlgGrid(opts);
  grid.renderTo("statementQuery_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 = "query";
      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 == "work_Reset") {
      grid.getToolBarForm().getDForm().setText("payableId", "");
      grid.getToolBarForm().getDForm().setText("receivableId", "");
      grid.getToolBarForm().clear();
      grid.getToolBarForm().setFormData({ startTime: startTime, endTime: endTime });
    }
  });
  //单击事件
  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: "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("statementQuery_guojzhuans2B");
};
