import { WeaLocaleProvider } from "ecCom";
import { format_with_regex } from "../../../util";

const { getLabel } = WeaLocaleProvider;
export const condition = [
  {
    items: [
      {
        colSpan: 2,
        checkbox: false,
        checkboxValue: false,
        conditionType: "SELECT",
        domkey: ["taxAgent"],
        fieldcol: 18,
        label: getLabel(111, "个税扣缴义务人"),
        labelcol: 6,
        options: [],
        multiple: true,
        viewAttr: 2
      },
      {
        colSpan: 2,
        checkbox: false,
        checkboxValue: false,
        conditionType: "SELECT",
        domkey: ["salarySob"],
        fieldcol: 18,
        label: getLabel(538010, "薪资账套"),
        labelcol: 6,
        options: [],
        multiple: true,
        viewAttr: 2
      },
      {
        browserConditionParam: {
          completeParams: {},
          conditionDataParams: {},
          dataParams: {},
          destDataParams: {},
          hasAddBtn: false,
          hasAdvanceSerach: true,
          idSeparator: ",",
          isAutoComplete: 1,
          isDetail: 0,
          isMultCheckbox: false,
          isSingle: false,
          linkUrl: "",
          pageSize: 10,
          quickSearchName: "",
          replaceDatas: [],
          title: getLabel(111, "分部"),
          type: "164",
          viewAttr: 2
        },
        colSpan: 2,
        conditionType: "BROWSER",
        domkey: ["subCompany"],
        fieldcol: 18,
        isQuickSearch: false,
        label: getLabel(111, "分部"),
        labelcol: 6,
        viewAttr: 2
      },
      {
        browserConditionParam: {
          completeParams: {},
          conditionDataParams: {},
          dataParams: {},
          destDataParams: {},
          hasAddBtn: false,
          hasAdvanceSerach: true,
          idSeparator: ",",
          isAutoComplete: 1,
          isDetail: 0,
          isMultCheckbox: false,
          isSingle: false,
          linkUrl: "",
          pageSize: 10,
          quickSearchName: "",
          replaceDatas: [],
          title: getLabel(111, "部门"),
          type: "57",
          viewAttr: 2
        },
        colSpan: 2,
        conditionType: "BROWSER",
        domkey: ["department"],
        fieldcol: 18,
        isQuickSearch: false,
        label: getLabel(111, "部门"),
        labelcol: 6,
        viewAttr: 2
      },
      {
        browserConditionParam: {
          completeParams: {},
          conditionDataParams: {},
          dataParams: {},
          destDataParams: {},
          hasAddBtn: false,
          hasAdvanceSerach: true,
          idSeparator: ",",
          isAutoComplete: 1,
          isDetail: 0,
          isMultCheckbox: false,
          isSingle: false,
          linkUrl: "",
          pageSize: 10,
          quickSearchName: "",
          replaceDatas: [],
          title: getLabel(111, "岗位"),
          type: "278",
          viewAttr: 2
        },
        colSpan: 2,
        conditionType: "BROWSER",
        domkey: ["position"],
        fieldcol: 18,
        isQuickSearch: false,
        label: getLabel(111, "岗位"),
        labelcol: 6,
        viewAttr: 2
      },
      {
        browserConditionParam: {
          completeParams: {},
          conditionDataParams: {},
          dataParams: {},
          destDataParams: {},
          hasAddBtn: false,
          hasAdvanceSerach: true,
          idSeparator: ",",
          isAutoComplete: 1,
          isDetail: 0,
          isMultCheckbox: false,
          isSingle: false,
          linkUrl: "",
          pageSize: 10,
          quickSearchName: "",
          replaceDatas: [],
          title: getLabel(111, "人员"),
          type: "17",
          viewAttr: 2
        },
        colSpan: 2,
        conditionType: "BROWSER",
        domkey: ["employee"],
        fieldcol: 18,
        isQuickSearch: false,
        label: getLabel(111, "人员"),
        labelcol: 6,
        viewAttr: 2
      },
      {
        colSpan: 2,
        checkbox: false,
        checkboxValue: false,
        conditionType: "SELECT",
        domkey: ["status"],
        fieldcol: 18,
        label: getLabel(111, "人事状态"),
        labelcol: 6,
        options: [],
        multiple: true,
        viewAttr: 2
      },
      {
        colSpan: 2,
        conditionType: "RANGEPICKER",
        domkey: ["hiredate1", "hiredate2"],
        fieldcol: 18,
        label: getLabel(111, "入职日期"),
        labelcol: 6,
        viewAttr: 2
      }
    ],
    title: "",
    defaultshow: true
  }
];
export const shareCondition = [
  {
    items: [
      {
        colSpan: 1,
        checkbox: false,
        checkboxValue: false,
        conditionType: "SELECT",
        domkey: ["reportIds"],
        fieldcol: 12,
        label: "分享报表",
        lanId: 111,
        labelcol: 6,
        options: [],
        multiple: true,
        rules: "required|string",
        viewAttr: 3
      },
      {
        colSpan: 1,
        checkbox: false,
        checkboxValue: false,
        conditionType: "INPUT",
        domkey: ["pushTitle"],
        fieldcol: 18,
        label: "主题",
        lanId: 111,
        labelcol: 6,
        rules: "required|string",
        viewAttr: 3
      },
      {
        browserConditionParam: {
          completeParams: {},
          conditionDataParams: {},
          dataParams: {},
          destDataParams: {},
          hasAddBtn: false,
          hasAdvanceSerach: true,
          idSeparator: ",",
          isAutoComplete: 1,
          isDetail: 0,
          isMultCheckbox: false,
          isSingle: false,
          linkUrl: "",
          pageSize: 10,
          quickSearchName: "",
          replaceDatas: [],
          type: "17",
          viewAttr: 3
        },
        colSpan: 1,
        conditionType: "BROWSER",
        domkey: ["sharedBy"],
        fieldcol: 14,
        isQuickSearch: false,
        label: "被分享人",
        lanId: 111,
        labelcol: 6,
        rules: "required|string",
        viewAttr: 3
      },
      {
        colSpan: 2,
        conditionType: "DATEPICKER",
        domkey: ["startTime"],
        fieldcol: 12,
        label: "报表查看有效开始时间",
        lanId: 111,
        labelcol: 6,
        value: "",
        viewAttr: 2
      },
      {
        colSpan: 2,
        conditionType: "DATEPICKER",
        domkey: ["endTime"],
        fieldcol: 12,
        label: "报表查看有效结束时间",
        lanId: 111,
        labelcol: 6,
        value: "",
        viewAttr: 2
      },
      {
        colSpan: 1,
        checkbox: false,
        checkboxValue: false,
        conditionType: "INPUT",
        domkey: ["mark"],
        fieldcol: 18,
        label: "分享说明",
        lanId: 111,
        labelcol: 6,
        viewAttr: 2
      }
      // {
      //   colSpan: 1,
      //   conditionType: "SWITCH",
      //   domkey: ["remind"],
      //   fieldcol: 12,
      //   isQuickSearch: false,
      //   label: "已查看提醒",
      //   lanId: 111,
      //   labelcol: 6,
      //   viewAttr: 2
      // }
    ],
    title: "",
    defaultshow: true
  }
];
export const sharePersonCondition = [
  {
    items: [
      {
        browserConditionParam: {
          completeParams: {},
          conditionDataParams: {},
          dataParams: {},
          destDataParams: {},
          hasAddBtn: false,
          hasAdvanceSerach: true,
          idSeparator: ",",
          isAutoComplete: 1,
          isDetail: 0,
          isMultCheckbox: false,
          isSingle: false,
          linkUrl: "",
          pageSize: 10,
          quickSearchName: "",
          replaceDatas: [],
          type: "17",
          viewAttr: 3
        },
        colSpan: 1,
        conditionType: "BROWSER",
        domkey: ["sharedBy"],
        fieldcol: 14,
        isQuickSearch: false,
        label: "被分享人",
        lanId: 111,
        labelcol: 6,
        rules: "required|string",
        viewAttr: 3
      }
    ],
    title: "",
    defaultshow: true
  }
];
export const shareLogCondition = [
  {
    items: [
      {
        colSpan: 1,
        conditionType: "INPUT",
        domkey: ["reportName"],
        fieldcol: 12,
        label: "分享报表",
        lanId: 111,
        labelcol: 6,
        viewAttr: 1
      },
      {
        colSpan: 1,
        conditionType: "INPUT",
        domkey: ["effectiveTime"],
        fieldcol: 12,
        label: "报表查看有效时间",
        lanId: 111,
        labelcol: 6,
        viewAttr: 1
      },
      {
        colSpan: 1,
        conditionType: "INPUT",
        domkey: ["remark"],
        fieldcol: 12,
        label: "分享说明",
        lanId: 111,
        labelcol: 6,
        viewAttr: 1
      }
    ],
    title: "",
    defaultshow: true
  }
];

const colorList = ["#709DF7", "#73DEB3", "#7585A2", "#F7C739", "#5FC3E3", "#AEE279", "#FF7F81"];
export const mapBarOptions = (params) => ({
  tooltip: {
    trigger: "axis",
    axisPointer: {
      type: "shadow"
    },
    backgroundColor: "#FFF",
    borderColor: "#FFF",
    borderWidth: "1",
    borderRadius: "5",
    textStyle: {
      color: "#333"
    },
    formatter: function (params) {
      let str = params[0].axisValue + "<br>";
      for (let item of params) {
        str += `<div>${item.marker}${item.seriesName}<span style='display:inline-block;width: 10px'></span><span style='font-weight: bold'>${format_with_regex(item.value)}</span></div>`;
      }
      return str;
    }
  },
  legend: {
    type: "scroll",
    icon: "rect",
    top: "0%",
    right: "center",
    itemGap: 10,
    textStyle: {
      fontSize: 12,//字体大小
      color: "#B8B8B8"//字体颜色
    }
  },
  grid: {
    top: "10%",
    right: "2%",
    left: "2%",
    bottom: "10%",
    containLabel: true
  },
  xAxis: {
    type: "category",
    axisTick: {
      alignWithLabel: true,
      show: false
    },
    data: params.xAxis,
    axisLabel: {
      interval: 0,
      margin: 10,
      textStyle: {
        fontSize: 11
      }
    }
  },
  yAxis: {
    name: params.name,
    type: "value",
    axisLabel: {
      padding: [3, 0, 0, 0],
      formatter: "{value}",
      color: "#666",
      textStyle: {
        fontSize: 11
      }
    },
    nameTextStyle: {
      color: "#787E95",
      fontSize: 12
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: "transparent"
      }
    },
    axisTick: {
      show: false // 不显示坐标轴刻度线
    },
    splitLine: {
      show: false,
      lineStyle: {
        color: "rgba(66, 192, 255, 0.1)"
      }
    }
  },
  series: _.map(params.data, (item, index) => {
    return {
      name: item.name,
      barMaxWidth: 30,
      barMinWidth: 10,
      barGap: 0,
      data: _.map(item.data, (it) => it.replace(/,/g, "")),
      type: "bar",
      itemStyle: {
        normal: {
          color: function (params) {
            return colorList[params.seriesIndex] || colorList[Math.floor((Math.random() * colorList.length))];
          }
        }
      },
      label: {
        show: true,
        position: "insideBottom",
        distance: 15,
        align: "left",
        verticalAlign: "middle",
        rotate: "90",
        formatter: function (params) {
          if (parseInt(params.value) === 0) {
            return ``;
          } else {
            return [
              `{a|${format_with_regex(params.value)}} {b|${params.seriesName}}`
            ];
          }
        },
        textStyle: {
          textShadowColor: "transparent",
          color: "#fff"
        },
        rich: {
          a: {
            fontWeight: "bold",
            fontSize: 14,
            color: "#333",
            marginRight: 10
          },
          b: {
            fontSize: 12,
            color: "#333"
          }
        }
      }
    };
  }),
  dataZoom: [
    {
      type: "inside",
      start: params.xAxis.length <= 7 ? 0 : 25,
      end: params.xAxis.length <= 7 ? 100 : 75,
    },
    {
      type: "slider",
      show: true,
      bottom: 20
    }
  ]
});
export const mapLineOptions = (params) => ({
  tooltip: {
    // 坐标轴指示器，坐标轴触发有效
    trigger: "axis",
    axisPointer: {
      // 默认为直线，可选为：'line' | 'shadow'
      type: "line"
    }
  },
  legend: {
    icon: "circle",
    top: "0%",
    right: "center",
    itemGap: 20,
    textStyle: {
      fontSize: 12,//字体大小
      color: "#787E95"//字体颜色
    }
  },
  grid: {
    top: "10%",
    left: "3%",
    right: "2%",
    bottom: "3%",
    containLabel: true
  },
  xAxis: [
    {
      type: "category",
      boundaryGap: false,
      data: params.xAxis,
      axisTick: {
        alignWithLabel: true,
        show: false
      },
      // 修改坐标值样式
      axisLabel: {
        color: "#B8B8B8",
        fontSize: 12,
        show: true
      },
      axisLine: {
        show: false
      }
    }
  ],
  yAxis: [
    {
      type: "value",
      // 修改坐标值样式
      axisLabel: {
        color: "#787E95",
        fontSize: 14
      },
      nameTextStyle: {
        color: "#787E95",
        fontSize: 16
      },
      // 修改坐标轴线样式
      axisLine: {
        show: true,
        lineStyle: {
          color: "transparent"
        }
      },
      axisTick: {
        show: false // 不显示坐标轴刻度线
      },
      splitLine: {
        lineStyle: {
          color: "rgba(93,126,158,1)"
        }
      }
    }
  ],
  series: _.map(params.data, (item, index) => {
    return {
      name: item.name,
      data: _.map(item.data, (it) => parseFloat(it.replace(/,/g, ""))),
      type: "line",
      itemStyle: {
        normal: {
          color: function (params) {
            return colorList[params.seriesIndex] || colorList[Math.floor((Math.random() * colorList.length))];
          },
          lineStyle: {
            color: colorList[index] || colorList[Math.floor((Math.random() * colorList.length))]
          }
        }
      }
    };
  })
});
export const mapPieOptions = (params) => ({
  tooltip: {
    show: true,
    formatter: function (params) {
      let str = params.seriesName + "<br>";
      str += params.marker + params.name + ":" + format_with_regex(params.value) + "(" + params.percent + "%" + ")" + "<br>";
      return str;
    }
  },
  legend: {
    type: "scroll",
    icon: "rect",
    top: "0%",
    left: "2%",
    orient: "vertical",
    itemGap: 10,
    textStyle: {
      fontSize: 12,//字体大小
      color: "#787E95"//字体颜色
    }
  },
  series: _.map(params.data, item => {
    return {
      name: item.name,
      data: _.map(item.data, (it) => ({ ...it, value: it.value.replace(/,/g, "") })),
      type: "pie",
      radius: "60%",
      avoidLabelOverlap: true,
      animation: false,
      labelLine: {
        show: true,
        normal: {
          length: 5,
          align: "center"
        }
      },
      itemStyle: {
        normal: {
          color: function (colors) {
            return colorList[colors.dataIndex] || colorList[Math.floor((Math.random() * colorList.length))];
          }
        }
      }
    };
  })
});
