import {  SDLUtil } from '@/utils';

export default {
  methods: {
    //main.js RealGrid.setDefault 이외 페이지 별도 설정
    grid_setGridOptions(gv, pParam) {
      var param = pParam || {};
      param.options = param.options || {};
      param.displayOptions = param.displayOptions || {};

      gv.setOptions(param.options);
      /*
      param.options = {
        checkBar: { visible: true, showAll: true },
        stateBar: { visible: false },
        panel: { visible: false },
        footer: { visible: false },
        edit: { updatable: false, insertable: false, appendable: false, deletable: false },
        header: { minHeight: 20, resizable: true },
      };*/

      /*param.providerOptions = {
        softDeleting: true, // true:rowstate만 변경, false:바로 삭제
        deleteCreated: true, // true:[softDeleting=true]인 경우라도 create는 바로 삭제
      };*/

      gv.setDisplayOptions(param.displayOptions);

      // checkable
      //gv.setCheckableExpression("state = 'c'", true);

      //gv.setCopyOptions({ enabled: false });

      return param;
    },
    grid_getCheckedRowArray(_grid) {
      var list = [];

      var checkedList = _grid.getCheckedRows();
      for (var i = 0; i < checkedList.length; i++) {
        if (_grid.getDataSource().getRowState(checkedList[i]) == 'created') {
          _grid.getDataSource().removeRow(checkedList[i]);
        } else {
          list.push(_grid.getDataSource().getJsonRow(checkedList[i]));
        }
      }

      return list;
    },
    grid_getGridExcel(_grid,param) {

    let pageMeta =  this.$route.meta;
      let iUserObj = SDLUtil.getLoginedUserInfo();
      iUserObj.commonMessage =
        'SAMSUNG SECRET\n' +
        '삼성반도체 임직원을 위한 시스템으로서 인가된분만 사용할수 있습니다.\n(As a system for employees of Samsung, only authorized persons can use it.)\n' +
        '불법으로 사용시에는 법적제재를 받을수 있습니다.\n(If used illegally, you may be subject to legal sanctions.)';

      let date = new Date().toLocaleDateString('de-DE');

      var systemIdent = 'Confidential\n\nUSER NAME : ' + iUserObj.userName + '\nUSER DEPT : ' + iUserObj.deptNameEn + '\nMENU NAME : ' + pageMeta.pageName + '\nDATE TIME : ' + date + '\n' + iUserObj.commonMessage;
      //    var systemIdent ="aa"
      _grid.exportGrid({
        type: 'excel',
        target: 'local',
        fileName: (param?.fileName||pageMeta.pageName.replace(/\s+/g, ''))+this.$moment().format('_YYYYMMDDHHMMSS')+'.xlsx',
        showProgress: true,
        progressMessage: 'Excel Download....',
        indicator: 'default',
        //header: header,
        //footer: footer,
        //compatibility: excelType,
        documentTitle: {
          //부제
          message: systemIdent,
          visible: true,
          styles: {
            textAlignment: 'near',
            foreground: '#800000',
            fontBold: true,
          },
          height: 130,
        },
        done: function () {
          //내보내기 완료 후 실행되는 함수
          alert('done excel export');
        },
      });
    },
  },
};

/**
 * SDLUtil.getLoginedUserInfo()
 * 
 * 
 * userInfo:{
  "deptName": "클라우드전환실행그룹(통합Managed Appl.서비스)",
  "timeZoneId": "Asia/Seoul",
  "mobile": "+82-10-2526-7743",
  "language": "ko_KR",
  "empNo": "BP351",
  "userName": "진문영",
  "grdNameEn": "",
  "userId": "M221216045308C318832",
  "compName": "삼성SDS",
  "grdCode": "B5C",
  "compCode": "C60",
  "userNameEn": "MoonYoung Jin",
  "compNameEn": "SAMSUNG SDS",
  "deptNameEn": "Cloud Appl. Transformation Implementation Group",
  "grdName": "현장관리자",
  "systemAdminUser": false,
  "timeZoneCode": "GMT+9:00",
  "clientIp": "0:0:0:0:0:0:0:1",
  "deptCode": "C60AJ826",
  "email": "my03.jin@partner.samsung.com",
  "knoxId": "my03.jin",
  "iat": 1733105054,
  "exp": 1733119454,
  "sub": "M221216045308C318832"
}

$route.meta

 $route.meta::{
  "deleted": false,
  "parentId": "AZNSNJLMASF_waHz",
  "menuId": "AZNSNNn8ASl_waHz",
  "label": "Formula Mgmt",
  "labelJson": {
    "en_US": "Formula Mgmt",
    "ko_KR": "Formula Mgmt"
  },
  "menuLevel": 2,
  "menuSequence": 1,
  "externalUrlUsed": false,
  "externalUrl": "",
  "used": true,
  "checked": false,
  "pages": [
    {
      "authorizationType": "READ",
      "deleted": false,
      "menuId": "AZNSNNn8ASl_waHz",
      "pageId": "AZNsDXZsAGx_waGY",
      "pageName": "Formula List",
      "pagePath": "/embo/formula/list",
      "componentName": "formula/formulaList",
      "defaulted": true,
      "used": true
    }
  ],
  "menuUserAuthList": [
    "READ"
  ],
  "menuUrl": "/embo/formula/list",
  "componentName": "formula/formulaList",
  "defaultPage": {
    "authorizationType": "READ",
    "deleted": false,
    "menuId": "AZNSNNn8ASl_waHz",
    "pageId": "AZNsDXZsAGx_waGY",
    "pageName": "Formula List",
    "pagePath": "/embo/formula/list",
    "componentName": "formula/formulaList",
    "defaulted": true,
    "used": true
  },
  "authorizationType": "READ",
  "pageId": "AZNsDXZsAGx_waGY",
  "pageName": "Formula List",
  "pagePath": "/embo/formula/list",
  "defaulted": true
}
 * 
 * 
 */
