index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <div class="pageIndexClass">
  3. <div style="background-color: #fff; padding: 15px 15px 0">
  4. <el-tabs v-model="sourceList.pagination.current" type="card" class="demo-tabs" @tab-change="changeCurrent">
  5. <el-tab-pane label="日报表" name="日报表"></el-tab-pane>
  6. <el-tab-pane label="月报表" name="月报表"></el-tab-pane>
  7. <el-tab-pane label="其他" name="其他"></el-tab-pane>
  8. </el-tabs>
  9. <el-form :inline="true" :model="sourceList.pagination">
  10. <el-form-item label="其他" v-if="sourceList.pagination.current == '其他'">
  11. <el-date-picker v-model="sourceList.pagination.beginTime" type="date" placeholder="开始日期" value-format="YYYY-MM-DD 00:00:00"
  12. :disabled-date="disabledFn" />
  13. <div style="padding:0 10px">
  14. -
  15. </div>
  16. <el-date-picker v-model="sourceList.pagination.endTime" type="date" placeholder="结束日期" value-format="YYYY-MM-DD 23:59:59"
  17. :disabled-date="disabledFn" />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button v-if="sourceList.pagination.current == '其他'" type="primary" @click="onQuery" class="query">搜索</el-button>
  21. <el-button v-if="sourceList.pagination.current == '其他'" @click="onReset()">重置</el-button>
  22. <el-button type="primary" @click="exportExcel">导出Excel</el-button>
  23. </el-form-item>
  24. </el-form>
  25. </div>
  26. <div style="background:#fff;padding:15px;margin-top:10px">
  27. <!-- 如果是日报表,则所有列宽度平均 -->
  28. <el-table v-if="sourceList.pagination.current == '日报表'" :data="sourceList.data" :height="tableHeight" style="width: 100%" v-loading="loading" border id="my-table">
  29. <el-table-column prop="groupName" label="组别" fixed="left" />
  30. <el-table-column prop="saleUserName" label="业务员" fixed="left" />
  31. <template v-if="dayList && dayList.length>0">
  32. <el-table-column v-for="col in dayList" :key="col" :label="col" align="center">
  33. <el-table-column prop="address" label="系统" min-width="" align="right">
  34. <template #default="{ row, $index }">
  35. <div style="width: 100%" :class="today==col?'isToday':''" v-if="row[col] && row[col].sumContractAmount">
  36. {{moneyFormat(row[col].sumContractAmount,2)}}
  37. </div>
  38. </template>
  39. </el-table-column>
  40. <el-table-column prop="address" label="聚水潭" min-width="" align="right">
  41. <template #default="{ row, $index }">
  42. <div style="width: 100%" :class="today==col?'isToday':''" v-if="row[col] && row[col].sumJstAmount">
  43. {{moneyFormat(row[col].sumJstAmount,2)}}
  44. </div>
  45. </template>
  46. </el-table-column>
  47. </el-table-column>
  48. </template>
  49. <el-table-column align="right" fixed="right">
  50. <template #header>
  51. <div>
  52. 系统
  53. <br>
  54. 月累计
  55. </div>
  56. </template>
  57. <template #default="{ row, $index }">
  58. <div style="width: 100%">
  59. {{moneyFormat(row.sumContractAmount,2)}}
  60. </div>
  61. </template>
  62. </el-table-column>
  63. <el-table-column align="right" fixed="right">
  64. <template #header>
  65. <div>
  66. 聚水潭
  67. <br>
  68. 月累计
  69. </div>
  70. </template>
  71. <template #default="{ row, $index }">
  72. <div style="width: 100%">
  73. {{moneyFormat(row.sumJstAmount,2)}}
  74. </div>
  75. </template>
  76. </el-table-column>
  77. <el-table-column align="right" fixed="right">
  78. <template #header>
  79. <div>
  80. 合计
  81. <br>
  82. 月累计
  83. </div>
  84. </template>
  85. <template #default="{ row, $index }">
  86. <div style="width: 100%">
  87. {{moneyFormat(row.sumAmount,2)}}
  88. </div>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="月目标" align="right" fixed="right">
  92. <template #default="{ row, $index }">
  93. <div style="width: 100%">
  94. {{moneyFormat(row.targetAmount,2)}}
  95. </div>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="月达成率" align="right" fixed="right">
  99. <template #default="{ row, $index }">
  100. <div style="width: 100%">
  101. {{moneyFormat(row.finishRate,2)}} %
  102. </div>
  103. </template>
  104. </el-table-column>
  105. <el-table-column prop="ranking" label="排名" align="center" fixed="right" />
  106. </el-table>
  107. <!-- 否则,使用固定值 -->
  108. <el-table v-else :data="sourceList.data" :height="tableHeight" style="width: 100%" v-loading="loading" border id="my-table">
  109. <el-table-column prop="groupName" label="组别" width="110" fixed="left" />
  110. <el-table-column prop="saleUserName" label="业务员" width="80" fixed="left" />
  111. <template v-if="dayList && dayList.length>0">
  112. <el-table-column v-for="col in dayList" :key="col" :label="col" align="center">
  113. <el-table-column prop="address" label="系统" min-width="100" align="right">
  114. <template #default="{ row, $index }">
  115. <div style="width: 100%" :class="today==col?'isToday':''" v-if="row[col] && row[col].sumContractAmount">
  116. {{moneyFormat(row[col].sumContractAmount,2)}}
  117. </div>
  118. </template>
  119. </el-table-column>
  120. <el-table-column prop="address" label="聚水潭" min-width="100" align="right">
  121. <template #default="{ row, $index }">
  122. <div style="width: 100%" :class="today==col?'isToday':''" v-if="row[col] && row[col].sumJstAmount">
  123. {{moneyFormat(row[col].sumJstAmount,2)}}
  124. </div>
  125. </template>
  126. </el-table-column>
  127. </el-table-column>
  128. </template>
  129. <el-table-column width="columnWithWidth" align="right" fixed="right">
  130. <template #header>
  131. <div>
  132. 系统
  133. <br>
  134. 月累计
  135. </div>
  136. </template>
  137. <template #default="{ row, $index }">
  138. <div style="width: 100%">
  139. {{moneyFormat(row.sumContractAmount,2)}}
  140. </div>
  141. </template>
  142. </el-table-column>
  143. <el-table-column width="95" align="right" fixed="right">
  144. <template #header>
  145. <div>
  146. 聚水潭
  147. <br>
  148. 月累计
  149. </div>
  150. </template>
  151. <template #default="{ row, $index }">
  152. <div style="width: 100%">
  153. {{moneyFormat(row.sumJstAmount,2)}}
  154. </div>
  155. </template>
  156. </el-table-column>
  157. <el-table-column width="95" align="right" fixed="right">
  158. <template #header>
  159. <div>
  160. 合计
  161. <br>
  162. 月累计
  163. </div>
  164. </template>
  165. <template #default="{ row, $index }">
  166. <div style="width: 100%">
  167. {{moneyFormat(row.sumAmount,2)}}
  168. </div>
  169. </template>
  170. </el-table-column>
  171. <el-table-column label="月目标" width="90" align="right" fixed="right">
  172. <template #default="{ row, $index }">
  173. <div style="width: 100%">
  174. {{moneyFormat(row.targetAmount,2)}}
  175. </div>
  176. </template>
  177. </el-table-column>
  178. <el-table-column label="月达成率" width="90" align="right" fixed="right">
  179. <template #default="{ row, $index }">
  180. <div style="width: 100%">
  181. {{moneyFormat(row.finishRate,2)}} %
  182. </div>
  183. </template>
  184. </el-table-column>
  185. <el-table-column prop="ranking" label="排名" width="60" align="center" fixed="right" />
  186. </el-table>
  187. </div>
  188. </div>
  189. </template>
  190. <script setup>
  191. import byTable from "@/components/byTable/index";
  192. import { getMonthBetween } from "@/utils/date.js";
  193. import moment from "moment";
  194. import FileSaver from "file-saver";
  195. import * as XLSX from "xlsx";
  196. import { nextTick } from "vue";
  197. const { proxy } = getCurrentInstance();
  198. const tableHeight = ref(0);
  199. const getTableHeight = () => {
  200. tableHeight.value = window.innerHeight - 150 - 79 - 55;
  201. };
  202. getTableHeight();
  203. window.addEventListener("resize", () => {
  204. getTableHeight();
  205. });
  206. const today = ref(moment().format("yyyy-MM-DD"));
  207. const beginTime = ref(
  208. moment().startOf("month").format("yyyy-MM-DD") + " 00:00:00"
  209. );
  210. const endTime = ref(moment().endOf("month").format("YYYY-MM-DD") + " 23:59:59");
  211. const weekBegin = ref(
  212. moment().startOf("week").format("yyyy-MM-DD") + " 00:00:00"
  213. );
  214. const weekEnd = ref(moment().endOf("week").format("yyyy-MM-DD") + " 23:59:59");
  215. const sourceList = ref({
  216. data: [],
  217. pagination: {
  218. pageNum: 1,
  219. pageSize: 10,
  220. beginTime: "",
  221. endTime: "",
  222. // current: "本月",
  223. current: "月报表",
  224. },
  225. });
  226. const columnWithWidth = undefined;
  227. const loading = ref(false);
  228. const getList = (req) => {
  229. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  230. console.log(sourceList.value.pagination, "123123");
  231. loading.value = true;
  232. proxy
  233. .post("/deptPerf/monthlyReporting", sourceList.value.pagination)
  234. .then((res) => {
  235. sourceList.value.data = res;
  236. setTimeout(() => {
  237. loading.value = false;
  238. }, 500);
  239. });
  240. };
  241. const dayList = ref([]);
  242. const onQuery = () => {
  243. loading.value = true;
  244. if (
  245. sourceList.value.pagination.beginTime &&
  246. sourceList.value.pagination.endTime
  247. ) {
  248. dayList.value = getMonthBetween(
  249. sourceList.value.pagination.beginTime.slice(0, 10),
  250. sourceList.value.pagination.endTime.slice(0, 10)
  251. );
  252. nextTick(() => {
  253. setTimeout(() => scrollIntoEle(), 1000);
  254. });
  255. }
  256. getList();
  257. };
  258. const changeCurrent = (val) => {
  259. console.log(val);
  260. switch (val) {
  261. // case "本周":
  262. // sourceList.value.pagination.beginTime = weekBegin.value;
  263. // sourceList.value.pagination.endTime = weekEnd.value;
  264. // break;
  265. case "日报表":
  266. sourceList.value.pagination.beginTime = today.value + " 00:00:00";
  267. sourceList.value.pagination.endTime = today.value + " 23:59:59";
  268. break;
  269. case "月报表":
  270. sourceList.value.pagination.beginTime = beginTime.value;
  271. sourceList.value.pagination.endTime = endTime.value;
  272. break;
  273. case "其他":
  274. sourceList.value.pagination.beginTime = beginTime.value;
  275. sourceList.value.pagination.endTime = endTime.value;
  276. break;
  277. }
  278. onQuery();
  279. };
  280. const onReset = (val='其他') => {
  281. sourceList.value.pagination.current = val;
  282. sourceList.value.pagination.beginTime = beginTime.value;
  283. sourceList.value.pagination.endTime = endTime.value;
  284. onQuery();
  285. };
  286. onReset('月报表');
  287. // const nowYearMonth = ref(moment().format("YYYY-MM"));
  288. const disabledFn = (date) => {
  289. if (
  290. moment(date).isBefore(beginTime.value) ||
  291. moment(date).isAfter(endTime.value)
  292. ) {
  293. return true;
  294. } else {
  295. return false;
  296. }
  297. };
  298. const scrollIntoEle = () => {
  299. let eles = document.querySelectorAll(".isToday");
  300. if (eles && eles[0]) {
  301. eles[0].scrollIntoView({
  302. // behavior: "smooth",
  303. block: "start",
  304. inline: "start",
  305. });
  306. }
  307. };
  308. const exportExcel = () => {
  309. proxy.msgTip("正在导出,请稍后", 2);
  310. const wb = XLSX.utils.table_to_book(document.querySelector("#my-table")); // 关联dom节点
  311. // 设置百分比列的单元格样式
  312. const percentStyle = {
  313. font: { bold: true },
  314. fill: { fgColor: { rgb: "FFFF00" } },
  315. border: { top: { style: "thin" }, bottom: { style: "thin" } },
  316. };
  317. if (wb.Sheets.Sheet1) {
  318. // 达成率单元格的key开头
  319. let cellKey = "";
  320. for (const key in wb.Sheets.Sheet1) {
  321. let value = wb.Sheets.Sheet1[key];
  322. if (value && value.v == "月达成率") {
  323. cellKey = key.match(/[a-zA-Z]+/g)[0];
  324. }
  325. // key有包含cellKey的
  326. if (cellKey && key.includes(cellKey)) {
  327. // 单元格的样式
  328. wb.Sheets.Sheet1[key].s = percentStyle;
  329. // 用于指定单元格中显示值的格式,例如日期格式、百分比格式等
  330. wb.Sheets.Sheet1[key].z = "0.00%";
  331. }
  332. }
  333. }
  334. const wbout = XLSX.write(wb, {
  335. bookType: "xlsx",
  336. bookSST: true,
  337. type: "array",
  338. });
  339. try {
  340. FileSaver.saveAs(
  341. new Blob([wbout], {
  342. type: "application/octet-stream",
  343. }),
  344. "销售报表.xlsx"
  345. );
  346. } catch (e) {
  347. console.log(e, wbout);
  348. }
  349. return wbout;
  350. };
  351. </script>
  352. <style lang="scss" scoped>
  353. :deep(
  354. .el-table .el-table__header-wrapper th,
  355. .el-table .el-table__fixed-header-wrapper th
  356. ) {
  357. height: auto !important;
  358. }
  359. :deep(.el-table th.el-table__cell) {
  360. background: #fff !important;
  361. }
  362. :deep(.el-table .el-table__cell) {
  363. padding: 0 !important;
  364. }
  365. :deep(.el-table .cell) {
  366. padding: 0 6px !important;
  367. font-size: 12px !important;
  368. }
  369. .query {
  370. background: #20b2aa;
  371. color: #fff;
  372. border: 1px solid #20b2aa;
  373. }
  374. .isToday {
  375. // background: red !important;
  376. // color: #fff !important;
  377. color: #409eff;
  378. }
  379. </style>