/**
 * 将数字格式化为带千分位分隔符的字符串
 * @param {number} num - 要格式化的数字
 * @returns {string} 格式化后的字符串
 */
export function formatWithThousandSeparator(num) {
  if (typeof num !== 'number') {
    throw new TypeError('Input must be a number');
  }
  return num.toLocaleString('en-US');
}

export const planTableOption = {
  border: true,
  menuAlign: 'center',
  menu: false,
  searchMenuSpan: 6,
  editBtn: false,
  delBtn: false,
  dialogClickModal: false,
  align: 'center',
  addBtn: false,
  rowKey: 'id',
  rowParentKey: 'id',
  column: [
    {
      label: '序号',
      prop: 'index'
    },
    {
      label: '目标名称',
      prop: 'name'
    },
    {
      label: '目标分值',
      prop: 'planScore',
      formatter: function(row) {
        return row.planScore ? formatWithThousandSeparator(row.planScore) : 0;
      }
    },
    {
      label: '目标周期',
      prop: 'planPeriod'
    },
    {
      label: '承接对象',
      prop: 'providerName'
    },
    {
      label: '创建日期',
      prop: 'createTime'
    },

    {
      label: '已下发积分值',
      prop: 'availScore',
      formatter: function(row) {
        return row.availScore ? formatWithThousandSeparator(row.availScore) : 0;
      }
    },
    {
      label: '已分发比例（%）',
      prop: 'distScoreRate',
      formatter: function(row) {
        return row.distScoreRate ? `${row.distScoreRate}%` : '0%';
      }
    }
    // {
    //   label: '服务完成比例（%）',
    //   prop: 'distScoreRate'
    // }
    //  {
    //    label: '计划分发比例',
    //    prop: 'distRate'
    //  }
  ]
};

export const pkgTableOption = {
  border: true,
  menuAlign: 'center',
  menu: false,
  searchMenuSpan: 6,
  editBtn: false,
  delBtn: false,
  dialogClickModal: false,
  align: 'center',
  addBtn: false,
  rowKey: 'id',
  rowParentKey: 'id',
  column: [
    {
      label: '序号',
      prop: 'index'
    },
    {
      label: '执行包名称',
      prop: 'name'
    },
    {
      label: '执行包值',
      prop: 'pkgScore',
      formatter: function(row) {
        return row.pkgScore ? formatWithThousandSeparator(row.pkgScore) : 0;
      }
    },
    {
      label: '接包对象',
      prop: 'pickerName'
    },

    {
      label: '创建日期',
      prop: 'createTime'
    },
    {
      label: '下发分值',
      prop: 'distScore',
      formatter: function(row) {
        return row.distScore ? formatWithThousandSeparator(row.distScore) : 0;
      }
    },
    {
      label: '下发百分比（%）',
      prop: 'distRate',
      formatter: function(row) {
        return row.distRate ? `${row.distRate}%` : '0%';
      }
    },
    {
      label: '完成分值',
      prop: 'completedScore',
      formatter: function(row) {
        return row.completedScore ? formatWithThousandSeparator(row.completedScore) : 0;
      }
    },
    {
      label: '完成分值百分比（%）',
      prop: 'completedRate',
      formatter: function(row) {
        return row.completedRate ? `${row.completedRate}%` : '0%';
      }
    }
  ]
};

export const provideTableOption = {
  border: true,
  menuAlign: 'center',
  menu: false,
  searchMenuSpan: 6,
  editBtn: false,
  delBtn: false,
  dialogClickModal: false,
  align: 'center',
  addBtn: false,
  rowKey: 'id',
  rowParentKey: 'id',
  column: [
    {
      label: '序号',
      prop: 'index'
    },
    {
      label: '服务商名称',
      prop: 'providerName',
      formatter(row) {
        return row.providerName ? row.providerName : '---';
      }
    },
    {
      label: '执行包名称',
      prop: 'pkgName',
      formatter(row) {
        return row.pkgName ? row.pkgName : '---';
      }
    },
    {
      label: '服务产品',
      prop: 'products',
      width: '350px',
      slot: true,
      // formatter(row) {
      //   if (row.products) {
      //     let str = '';
      //     row.products.forEach((item, index) => {
      //       str += `${index + 1}、${item}；`;
      //     });

      //     return str;
      //   } else {
      //     return '---';
      //   }
      // }
    },
    {
      label: '所属区域',
      prop: 'areaCodes',
      //  slot: true,
      formatter(row) {
        if (row.areaCodes && row.areaCodes.length) {
          return row.areaCodes.join('，');
        } else {
          return '---';
        }
      }
    },
    {
      label: '企查查评分',
      prop: 'qccScore',
      formatter(row) {
        if (row.qccScore && row.qccScore.Score) {
          return row.qccScore.Score;
        } else {
          return '---';
        }
      }
    },
    {
      label: '服务商评分（%）',
      prop: 'serviceMark'
    }
    // {
    //   label: '服务商平均分',
    //   prop: 'average',
    //   formatter(row) {
    //     if (row.qccScore && row.qccScore.Score && row.serviceMark && row.serviceMark.evalRes) {
    //       const nums = row.qccScore.Score + row.serviceMark.evalRes.mark;
    //       return nums / 2;
    //     }
    //   }
    // }
  ]
};
// export const providerTreeTableOption = {
//   border: true,
//   menuAlign: 'center',
//   menu: false,
//   searchMenuSpan: 6,
//   editBtn: false,
//   delBtn: false,
//   dialogClickModal: false,
//   align: 'center',
//   addBtn: false,
//   rowKey: 'id',
//   rowParentKey: 'id',
//   column: [
//     {
//       label: '序号',
//       prop: 'index'
//     },
//     {
//       label: '执行包名称',
//       prop: 'pickerName'
//     },
//     {
//       label: '执行包分值',
//       prop: 'pkgScore'
//     },
//     {
//       label: '接包对象',
//       prop: 'pickerName'
//     },
//     {
//       label: '创建日期',
//       prop: 'createTime'
//     },
//     {
//       label: '完成积分值',
//       prop: 'completeScore'
//     },
//     {
//       label: '完成积分值百分比',
//       prop: 'completeRate'
//     },
//     {
//       label: '审核通过率  ',
//       prop: 'taskPassRate'
//     },
//     {
//       label: '审核通过积分值  ',
//       prop: 'taskPassedScore'
//     },
//     {
//       label: '审核通过百分比  ',
//       prop: 'taskPassedPercentage'
//     }
//   ]
// };

export const providerTreeTableOption = {
  border: true,
  menuAlign: 'center',

  searchMenuSpan: 6,
  editBtn: false,
  delBtn: false,
  dialogClickModal: false,
  align: 'center',
  addBtn: false,
  rowKey: 'id',
  rowParentKey: 'id',
  column: [
    {
      label: '序号',
      prop: 'index'
    },
    {
      label: '服务商名称',
      prop: 'name'
    },
    {
      label: '服务商执行包总数',
      prop: 'deptPkgCount'
    },
    {
      label: '服务商执行包总分值',
      prop: 'deptPkgScoreTotal',
      formatter: function(row) {
        return row.deptPkgScoreTotal ? formatWithThousandSeparator(row.deptPkgScoreTotal) : 0;
      }
    },
    {
      label: '服务商执行包总任务数',
      prop: 'deptTaskCount',
      formatter: function(row) {
        return row.deptTaskCount ? formatWithThousandSeparator(row.deptTaskCount) : 0;
      }
    },
    {
      label: '服务商执行包完成总任务分值',
      prop: 'deptTaskScoreTotal',
      formatter: function(row) {
        return row.deptTaskScoreTotal ? formatWithThousandSeparator(row.deptTaskScoreTotal) : 0;
      }
    }
  ]
};

export const supervisionTableOption = {
  border: true,
  menuAlign: 'center',
  menu: false,
  searchMenuSpan: 6,
  editBtn: false,
  delBtn: false,
  dialogClickModal: false,
  align: 'center',
  addBtn: false,
  rowKey: 'id',
  rowParentKey: 'id',
  column: [
    {
      label: '序号',
      prop: 'index'
    },
    {
      label: '服务商名称',
      prop: 'deptName'
    },
    {
      label: '被抽查次数',
      prop: 'supTotal',
      formatter: function(row) {
        if (row.taskSupStat) return row.taskSupStat.supTotal;
      }
    },
    {
      label: '被抽查次积分值',
      prop: 'passedScoreTotal',
      formatter: function(row) {
        return row.taskSupStat ? formatWithThousandSeparator(row.taskSupStat.passedScoreTotal) : 0;
      }
    },
    // {
    //   label: '服务总数',
    //   prop: 'total',
    //   formatter: function(row) {
    //     return row.taskSupStat.total;
    //   }
    // },
    {
      label: '被抽查积分值占比',
      prop: 'supervisionRate',
      formatter: function(row) {
        if (row.taskSupStat && row.taskSupStat.total == 0) return '0%';
        let percentage = (row.taskSupStat.supTotal / row.taskSupStat.total) * 100;
        return `${percentage.toFixed(2)}%`;
      }
    },
    {
      label: '抽查通过率',
      prop: 'supervisionPassedRate',
      formatter: function(row) {
        if (row.taskSupStat && row.taskSupStat.supTotal == 0) return '0%';
        let percentage = (row.taskSupStat.passedTotal / row.taskSupStat.supTotal) * 100;
        return `${percentage.toFixed(2)}%`;
      }
    }
    // {
    //   label: '抽查预警率',
    //   prop: 'supervisionWarnRate',
    //   formatter: function(row) {
    //     if (row.taskSupStat.supTotal == 0) return '0%';
    //     let percentage = (row.taskSupStat.rejectTotal / row.taskSupStat.supTotal) * 100;
    //     return `${percentage.toFixed(2)}%`;
    //   }
    // }
  ]
};
