/**
 * zzx
 * 2021.06.01
 * 客户回访查询
    */
    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 carousel = layui.carousel;
  carousel.render({
    elem: "#clientReviewQuery",
    autoplay: false,
    index: 0,
    arrow: "none",
    indicator: "none",
    anim: "fade",
    width: "100%", //设置容器宽度
    height: "100%"
  });
  let dataView = ["#clientReviewQuery_main", "#clientReviewQuery_view"];
  function setViewName(name) {
    for (var i = 0; i < dataView.length; i++) {
      if (name == dataView[i]) {
        $(name).css("display", "block");
      }
      else {
        $(dataView[i]).css("display", "none");
      }
    }
  }
  // 返回
  $(document).on("click", "#clientReviewQuery_view_return", function () {
    setViewName("#clientReviewQuery_main");
  });

  // 获取默认时间
  var startTime = Prolog.formatDate(new Date(), "%YY-%MM") + "-01 00:00:00";
  var endTime = Prolog.formatDate(new Date()) + " 23:59:59";
  var dataSelete = {};
  // 获取下拉框
  getSelectGJ([
    { "objectcode": "TMS_RETURN_VISIT_TYPE" },
    { "objectcode": "AUDIT_FLOW_STATUS" },
    { "objectcode": "RETURN_VISIT_AUDIT_OPINION" }
  ], function (data) {
    data.data.TMS_RETURN_VISIT_TYPE.unshift({ "text": "", "value": "" });
    data.data.AUDIT_FLOW_STATUS.unshift({ "text": "", "value": "" });
    dataSelete = data.data;
  });

  var grid;
  // 配送中心table
  var branchTable = {
    columns: [
      { id: "companyid", name: "id", type: "ro", width: "130", hidden: true },
      { id: "companycode", name: "配送中心编号", type: "ro" },
      { id: "companyname", name: "配送中心名称", type: "ro" }
    ],
    multiselect: false,
    contentType: "application/json",

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubCompany/queryCompanyBranch", //数据接口
    type: "post", //数据提交方式，默认为get
    pagebar: { type: "simple" },
    params: JSON.stringify({ "companytype": "S" }), //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  // 回访对象table
  var huifTable = {
    columns: [
      { id: "companyid", name: "id", type: "ro", width: "130", hidden: true },
      { id: "companycode", name: "对象编号", type: "ro" },
      { id: "companyname", name: "对象名称", type: "ro" }
    ],
    multiselect: false,
    contentType: "application/json",

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

  var opts = {
    skin: "card",
    columns: [
      { id: "INDEX", name: "id", type: "ro", width: "100", hidden: true },
      { id: "branchname", name: "配送中心", type: "ro", width: 150 },
      { id: "returnVisitNo", name: "回访编号", type: "ro", width: 150 },
      { id: "returnVisitDate", name: "回访时间", type: "ro", width: 130 },
      {
        id: "returnVisitType", name: "回访类型", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelete.TMS_RETURN_VISIT_TYPE, v);
        }
      },
      { id: "returnVisitObjectName", name: "回访对象", type: "ro", width: 100 },
      { id: "returnVisitObjectPerson", name: "客户参与人", type: "ro", width: 100 },
      { id: "returnVisitPerson", name: "己方参与人", type: "ro", width: 100 },
      { id: "returnVisitContent", name: "回访内容", type: "ro", width: 100 },
      { id: "returnVisitResult", name: "回访结果", type: "ro", width: 120 },
      { id: "createperson", name: "回访登记人", type: "ro", width: 100 },
      { id: "createtime", name: "登记时间", type: "ro", width: 130 },
      { id: "memo", name: "备注", type: "ro", width: 100 },
      {
        id: "status", name: "审核状态", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelete.AUDIT_FLOW_STATUS, v);
        }
      },
      { id: "auditPerson", name: "审核人", type: "ro", width: 100 },
      { id: "auditDate", name: "审核时间", type: "ro", width: 100 },
      {
        id: "auditOpinion", name: "审核意见", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelete.RETURN_VISIT_AUDIT_OPINION, v);
        }
      },
      { id: "auditDescription", name: "审核描述", type: "ro", width: 100 },
      {
        id: "op", name: "操作", type: "button", align: "center", fixed: "right", width: 120, render: function () {
          return "查看明细^clientReviewQuery_view";
        }
      }
    ],
    multiselect: false,
    fixedLast: true, //开启固定列，固定最后一行，倒数第二列不能隐藏
    toolbar: [
      { type: "settings", labelWidth: 90, labelAlign: "right" },
      {
        type: "row",
        list: [
          { type: "calendar", name: "startTime", className: "layui-col-md3", label: "开始时间:", value: startTime },
          { type: "calendar", name: "endTime", className: "layui-col-md3", label: "结束时间:", value: endTime },
          {
            className: "layui-col-md3",
            type: "selectTable",
            placeholder: "请选择配送中心",
            readonly: false,
            table: branchTable,
            tableWidth: 500,
            tableHeight: 400,
            fieldText: "companyname",
            fieldValue: "companyid",
            name: "branchidList",
            label: "配送中心:",
            listener: function (grid) {
              setMethod(grid, branchTable, function () { });
            }
          },
          { type: "hidden", name: "branchid", label: "配送中心:" },
          { type: "combo", name: "returnVisitType", label: "回访类型:", className: "layui-col-md3", options: dataSelete.TMS_RETURN_VISIT_TYPE, readonly: true },
          {
            className: "layui-col-md3",
            type: "selectTable",
            placeholder: "请选择回访对象",
            readonly: false,
            table: huifTable,
            tableWidth: 500,
            tableHeight: 400,
            fieldText: "companyname",
            fieldValue: "companyid",
            name: "returnVisitObjectIdList",
            label: "回访对象:",
            listener: function (grid) {
              setMethod(grid, huifTable, function () { });
            }
          },
          { type: "hidden", name: "returnVisitObjectId", label: "回访对象:", className: "layui-col-md3" },
          { type: "combo", name: "status", label: "审核状态:", className: "layui-col-md3", options: dataSelete.AUDIT_FLOW_STATUS, readonly: true },
          {
            type: "block", className: "layui-col-md3 form_btn_left",
            list: [
              { type: "button", className: "btn-normal", name: "querywork", value: "查 询" },
              { type: "newcolumn" },
              { type: "button", name: "work_Reset", className: "normal", value: "重 置" }
            ]
          }
        ]
      }
    ],
    beforeLoadData: function (res) {
      res.data.list.forEach((item, index) => {
        item.INDEX = index + "";
      });
      return res;
    },

    url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/returnVisit/query",//数据接口
    type: "post",//数据提交方式，默认为get
    contentType: "application/json",
    params: JSON.stringify({ startTime: startTime, endTime: endTime }),//查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  grid = new PlgGrid(opts);
  grid.renderTo("clientReviewQuery_master");
  // $("#clientReviewQuery_master").addClass("layui-form");
  // grid.attachEvent("onDataReady", function () {
  //   setTimeout(function () {
  //     layui.form.render();
  //   }, 200);
  // });
  grid.loadData();

  // 按钮添加方法
  grid.attachToolBarEvent("onButtonClick", function (name) {
    // 查询
    if (name == "querywork") {
      var jsonData = grid.getToolBarForm().getFormData();
      jsonData.startTime = jsonData.startTime ? Prolog.formatDate(jsonData.startTime) + " 00:00:00" : "";
      jsonData.endTime = jsonData.endTime ? Prolog.formatDate(jsonData.endTime) + " 23:59:59" : "";
      if (jsonData.startTime > jsonData.endTime) {
        layer.msg("开始时间不能大于结束时间");
        return false;
      }
      jsonData.branchid = jsonData.branchidList ? JSON.parse(jsonData.branchidList)[0] : "";
      jsonData.returnVisitObjectId = jsonData.returnVisitObjectIdList ? JSON.parse(jsonData.returnVisitObjectIdList)[0] : "";
      delete jsonData.branchidList;
      delete jsonData.returnVisitObjectIdList;
      dealNullQueryCondition(jsonData);
      grid.setParams(JSON.stringify(jsonData));
      grid.reload();
    }
    // 重置
    if (name == "work_Reset") {
      grid.getToolBarForm().getDForm().setText("branchidList", "");
      grid.getToolBarForm().getDForm().setText("returnVisitObjectIdList", "");
      grid.getToolBarForm().clear();
      grid.getToolBarForm().setFormData({ startTime: startTime, endTime: endTime });
    }
  });
  // 查看明细
  window.clientReviewQuery_view = function (rid, rdata) {
    setViewName("#clientReviewQuery_view");
    new PlgPanel({
      renderer: "clientReviewQuery_view_form",
      skin: 2,
      header: {
        isShow: true,
        title: "基本信息"
      },
      defaultBody: {
        layoutCol: 3,
        valueBj: true,
        cols: [
          [
            { label: "配送中心", value: rdata.branchname },
            { label: "回访时间", value: rdata.returnVisitDate },
            { label: "回访类型", value: getSelectValue(dataSelete.TMS_RETURN_VISIT_TYPE, rdata.returnVisitType) }
          ],
          [
            { label: "客户参与人", value: rdata.returnVisitObjectPerson },
            { label: "己方参与人", value: rdata.returnVisitPerson },
            { label: "回访对象", value: rdata.returnVisitObjectName }
          ],
          [{ label: "回访内容", value: rdata.returnVisitContent, layoutCol: 12 }],
          [{ label: "回访结果", value: rdata.returnVisitResult, layoutCol: 12 }],
          [{ label: "审核描述", value: rdata.auditDescription, layoutCol: 12 }],
          [{ label: "审核状态", value: getSelectValue(dataSelete.AUDIT_FLOW_STATUS, rdata.status) }]
        ]
      }
    });
  };
};
