robotRanking.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. <template>
  2. <div class="robotRanking flex-col">
  3. <div class="box1 flex-col">
  4. <s-header :name="$t('robotRanking.machineSalesRanking')" :noback="true" :isFixed="false"></s-header>
  5. <div class="box3 flex-col">
  6. <div class="main1 flex-col">
  7. <div class="mod1 flex-col">
  8. <div class="block1 flex-col justify-between">
  9. <div class="section1 flex-row justify-between">
  10. <div class="ImageText1 flex-col">
  11. <div class="group4 flex-row justify-between">
  12. <div class="layer3 flex-col"></div>
  13. <div class="TextGroup1 flex-col">
  14. <span class="word3">{{
  15. $t("robotRanking.machineSalesRanking")
  16. }}</span>
  17. </div>
  18. </div>
  19. </div>
  20. <div @click="noticeClk" class="l-flex-RC o-ml-70">
  21. <div class="group5 flex-row justify-between">
  22. <img class="label2" src="@/assets/device/searchIcon.png" />
  23. <div class="TextGroup2 flex-col">
  24. <span class="txt3">{{ $t("robotRanking.rankMethod") }}</span>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <img class="img1" referrerpolicy="no-referrer"
  30. src="https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng8947935ab81635fdedd8124b11e305eef66286421b69c84fef22233014a3fa9a" />
  31. </div>
  32. </div>
  33. <div class="l-f l-flex-e o-plr-15">
  34. <span class="robotLabelName l-in c-text-13" style="color: #404d74">{{ $t("robotRanking.dailySalesRanking")
  35. }}:</span>
  36. <kTabs @tabclk="(e) => tabclk(e, 'day')" :tabList="tabDayList"></kTabs>
  37. </div>
  38. <div v-if="!totalNoData('day')" ref="dayChartBox" class="mod3 flex-col"></div>
  39. <kNoData v-else></kNoData>
  40. <div class="groove"></div>
  41. <div class="l-f l-flex-e o-plr-15">
  42. <span class="robotLabelName l-in o-mr-6 c-text-13" style="color: #404d74">{{
  43. $t("robotRanking.salesRankingThisWeek") }}:</span>
  44. <kTabs @tabclk="(e) => tabclk(e, 'week')" :tabList="tabWeekList"></kTabs>
  45. </div>
  46. <div v-if="!totalNoData('week')" ref="weekChartBox" class="mod5 flex-col"></div>
  47. <kNoData v-else></kNoData>
  48. <div class="groove"></div>
  49. <div class="l-f l-flex-e o-plr-15">
  50. <span class="robotLabelName l-in o-mr-6 c-text-13" style="color: #404d74">{{
  51. $t("robotRanking.salesRankingThisMonth") }}:</span>
  52. <kTabs @tabclk="(e) => tabclk(e, 'month')" :tabList="tabMonthList"></kTabs>
  53. </div>
  54. <div v-if="!totalNoData('month')" ref="monthChartBox" class="mod9 flex-col"></div>
  55. <kNoData v-else></kNoData>
  56. <div class="groove"></div>
  57. <div class="l-f l-flex-e o-plr-15">
  58. <span class="robotLabelName l-in o-mr-6 c-text-13" style="color: #404d74">{{
  59. $t("robotRanking.salesRankingThisYear") }}:</span>
  60. <kTabs @tabclk="(e) => tabclk(e, 'year')" :tabList="tabYearList"></kTabs>
  61. </div>
  62. <div v-if="!totalNoData('year')" ref="yearChartBox" class="mod11 flex-col"></div>
  63. <kNoData v-else></kNoData>
  64. <div class="groove"></div>
  65. </div>
  66. </div>
  67. </div>
  68. <!-- 筛选弹窗 -->
  69. <kDialog :dialogTitle="$t('subLedgerManage.search.title')" :confirmBtnTxt="$t('subLedgerManage.search.screen')"
  70. ref="kDialogRef" @confirmclk="confirmClk">
  71. <template #content>
  72. <div class="cust_vantBorder">
  73. <!-- <van-field @click-input="busiInpClk" readonly clearable v-model="searchForm.businessName"
  74. :placeholder="$t('subLedgerManage.search.busiPlaceholder')" :label="$t('subLedgerManage.search.business')">
  75. <template #right-icon>
  76. <div class="l-flex-RC">
  77. <van-icon v-if="searchForm.businessName" @click="searchForm.businessName = ''" class="o-mr-6"
  78. name="clear" />
  79. <van-icon @click="busiInpClk" name="arrow-down" />
  80. </div>
  81. </template>
  82. </van-field> -->
  83. <van-field @click-input="changeTypeInpClk" readonly clearable v-model="searchForm.changeTypeName"
  84. :placeholder="$t('robotRanking.changeTypePlace')" :label="$t('robotRanking.changeType')">
  85. <template #right-icon>
  86. <div class="l-flex-RC">
  87. <van-icon v-if="searchForm.changeTypeName" @click="
  88. searchForm.changeTypeName = '';
  89. searchForm.changeType = '';
  90. " class="o-mr-6" name="clear" />
  91. <van-icon @click="changeTypeInpClk" name="arrow-down" />
  92. </div>
  93. </template>
  94. </van-field>
  95. <van-field @click-input="machineTypeInpClk" readonly clearable v-model="searchForm.machineTypeName"
  96. :placeholder="$t('robotRanking.machineTypePlace')" :label="$t('robotRanking.machineType')">
  97. <template #right-icon>
  98. <div class="l-flex-RC">
  99. <van-icon v-if="searchForm.machineTypeName" @click="
  100. searchForm.machineTypeName = '';
  101. searchForm.machineType = '';
  102. " class="o-mr-6" name="clear" />
  103. <van-icon @click="machineTypeInpClk" name="arrow-down" />
  104. </div>
  105. </template>
  106. </van-field>
  107. <van-field v-if="isAdmin()" @click-input="companyTypeInpClk" readonly clearable
  108. v-model="searchForm.companyTypeName" :placeholder="$t('robotRanking.companyTypePlaceholder')"
  109. :label="$t('robotRanking.companyTypeLabel')">
  110. <template #right-icon>
  111. <div class="l-flex-RC">
  112. <van-icon v-if="searchForm.companyTypeName" @click="
  113. searchForm.companyTypeName = '';
  114. searchForm.companyType = '';
  115. " class="o-mr-6" name="clear" />
  116. <van-icon @click="companyTypeInpClk" name="arrow-down" />
  117. </div>
  118. </template>
  119. </van-field>
  120. </div>
  121. </template>
  122. </kDialog>
  123. <!-- 商家选择框 -->
  124. <van-popup v-model:show="busiPopShow" position="bottom">
  125. <van-picker :title="$t('subLedgerManage.search.busiPlaceholder')" :columns="busiPopList"
  126. :columns-field-names="busiPopFieldName" @confirm="busiPopConfirm" @cancel="busiPopShow = false" />
  127. </van-popup>
  128. <!-- 统计方式弹窗 -->
  129. <van-popup v-model:show="changeTypeShow" position="bottom">
  130. <van-picker :default-index="chgTypeDefaIdx" :title="$t('robotRanking.changeTypePlace')" :columns="changeTypePopList"
  131. :columns-field-names="yearPopFieldName" @confirm="changeTypePopConfirm" @cancel="changeTypeShow = false" />
  132. </van-popup>
  133. <!-- 设备类型弹窗 -->
  134. <van-popup v-model:show="machineTypeShow" position="bottom">
  135. <van-picker :default-index="maTypeDefaIdx" :title="$t('robotRanking.machineTypePlace')"
  136. :columns="machineTypePopList" :columns-field-names="yearPopFieldName" @confirm="machineTypePopConfirm"
  137. @cancel="machineTypeShow = false" />
  138. </van-popup>
  139. <!-- 公司平台弹窗 -->
  140. <van-popup v-model:show="companyTypeShow" position="bottom">
  141. <van-picker :default-index="maTypeDefaIdx" :title="$t('robotRanking.companyTypePlaceholder')"
  142. :columns="companyTypePopList" :columns-field-names="yearPopFieldName" @confirm="companyTypePopConfirm"
  143. @cancel="companyTypeShow = false" />
  144. </van-popup>
  145. <!-- 日的日期选择弹窗 -->
  146. <van-calendar @confirm="calendarDayConfirm" v-model:show="dayShow" color="#4d6add" :min-date="minDate"
  147. :show-confirm="false" />
  148. <!-- 周的日期选择弹窗 -->
  149. <van-calendar @confirm="(e) => {
  150. calendarWeekOrMonConfirm(e, 1);
  151. }
  152. " v-model:show="weekShow" :allow-same-day="true" color="#4d6add" :min-date="minDate" type="range" />
  153. <!-- 月的日期选择弹窗 -->
  154. <van-calendar @confirm="(e) => {
  155. calendarWeekOrMonConfirm(e, 2);
  156. }
  157. " v-model:show="monthShow" :allow-same-day="true" color="#4d6add" :min-date="minDate" type="range" />
  158. <!-- 年的日期选择弹窗 -->
  159. <van-popup v-model:show="yearShow" position="bottom">
  160. <van-picker :title="$t('robotRanking.yearPopTitle')" :columns="yearPopList" :columns-field-names="yearPopFieldName"
  161. @confirm="yearPopConfirm" @cancel="yearShow = false" />
  162. </van-popup>
  163. <!-- <nav-bar></nav-bar> -->
  164. </div>
  165. </template>
  166. <script>
  167. // 导入无数据组件
  168. import kNoData from "../components/commom/kNoData/index.vue";
  169. import { onMounted, ref, reactive, computed, nextTick } from "vue";
  170. import sHeader from "../components/SimpleHeader";
  171. // import navBar from "../components/NavBar";
  172. import { getRankingList } from "../service/robotRanking";
  173. import { getLoginUser, styleUrl } from "../common/js/utils";
  174. import kTabs from "../components/commom/kTabs/index.vue";
  175. import kDialog from "../components/commom/kDialog/index.vue";
  176. import moment from "moment";
  177. import { showToast } from "vant";
  178. import { useI18n } from "vue-i18n";
  179. export default {
  180. setup() {
  181. // 引入语言
  182. const { t } = useI18n();
  183. // 日周月年的数据
  184. const totalObj = reactive({
  185. dayData: {},
  186. weekData: {},
  187. monthData: {},
  188. yearData: {},
  189. });
  190. // 日周月年图表没有数据
  191. const totalNoData = computed(() => (idx) => {
  192. let dataObj;
  193. switch (idx) {
  194. case "day":
  195. dataObj = totalObj.dayData;
  196. break;
  197. case "week":
  198. dataObj = totalObj.weekData;
  199. break;
  200. case "month":
  201. dataObj = totalObj.monthData;
  202. break;
  203. case "year":
  204. dataObj = totalObj.yearData;
  205. break;
  206. }
  207. if (!dataObj || dataObj?.categories?.length === 0) {
  208. return true;
  209. }
  210. return false;
  211. });
  212. // 统计方式弹窗
  213. const changeTypeInpClk = () => {
  214. changeTypeShow.value = true;
  215. };
  216. // 是否管理员
  217. const isAdmin = () => { return (user && user.type === 0); }
  218. // 公司平台弹窗
  219. const companyTypeInpClk = () => {
  220. companyTypeShow.value = true;
  221. };
  222. // 设备类型弹窗
  223. const machineTypeInpClk = () => {
  224. machineTypeShow.value = true;
  225. };
  226. const changeTypeShow = ref(false);
  227. const machineTypeShow = ref(false);
  228. const companyTypeShow = ref(false);
  229. // 默认选中
  230. const chgTypeDefaIdx = ref(1);
  231. const maTypeDefaIdx = ref("");
  232. const changeTypePopList = [
  233. {
  234. name: t("robotRanking.patternStatistics"),
  235. id: 1,
  236. },
  237. {
  238. name: t("robotRanking.salesStatistics"),
  239. id: 0,
  240. },
  241. ];
  242. const machineTypePopList = [
  243. {
  244. name: t("robotRanking.whole"),
  245. id: "",
  246. },
  247. {
  248. name: t("robotRanking.MG"),
  249. id: "0",
  250. },
  251. {
  252. name: t("robotRanking.POP"),
  253. id: "1",
  254. },
  255. ];
  256. const companyTypePopList = [
  257. {
  258. name: t("robotRanking.whole"),
  259. id: "",
  260. },
  261. {
  262. name: t("robotRanking.sz"),
  263. id: "0",
  264. },
  265. {
  266. name: t("robotRanking.sc"),
  267. id: "1",
  268. },
  269. ];
  270. const changeTypePopConfirm = ({ selectedOptions }) => {
  271. searchForm.changeType = selectedOptions[0].id;
  272. searchForm.changeTypeName = selectedOptions[0].name;
  273. changeTypeShow.value = false;
  274. };
  275. const machineTypePopConfirm = ({ selectedOptions }) => {
  276. searchForm.machineType = selectedOptions[0].id;
  277. searchForm.machineTypeName = selectedOptions[0].name;
  278. machineTypeShow.value = false;
  279. };
  280. const companyTypePopConfirm = ({ selectedOptions }) => {
  281. searchForm.companyType = selectedOptions[0].id;
  282. searchForm.companyTypeName = selectedOptions[0].name;
  283. companyTypeShow.value = false;
  284. };
  285. // 年的日期选择弹窗
  286. // 点击确定
  287. const yearPopConfirm = (e) => {
  288. // console.log("e的值是11", e);
  289. const year = e.id;
  290. const startDate =
  291. moment().year(year).startOf("year").format("YYYY-MM-DD") + " 00:00:00";
  292. const endDate =
  293. moment().year(year).endOf("year").format("YYYY-MM-DD") + " 23:59:59";
  294. getEquipRankList("year", startDate, endDate);
  295. yearShow.value = false;
  296. };
  297. // 获取当前年前4年后1年
  298. let yearPopList = [];
  299. for (let i = -1; i < 5; i++) {
  300. const year = moment().subtract(i, "years").format("YYYY");
  301. yearPopList.push({
  302. name: year,
  303. id: year,
  304. });
  305. }
  306. const yearPopFieldName = reactive({
  307. text: "name",
  308. value: "id",
  309. });
  310. const yearShow = ref(false);
  311. const currentDate = ref(new Date());
  312. const yearFormatter = (type, val) => {
  313. if (type === "year") {
  314. return val;
  315. }
  316. return val;
  317. };
  318. // 周和月的日期选择弹窗
  319. const weekShow = ref(false);
  320. const monthShow = ref(false);
  321. const calendarWeekOrMonConfirm = (e, idx) => {
  322. const startDate = e[0];
  323. const endDate = e[1];
  324. let weekOrMont = "month";
  325. // 如果是周计算开始和结束日期相差多少天,因为周不能超过7天
  326. if (idx === 1) {
  327. weekOrMont = "week";
  328. const differDays = moment(endDate).diff(moment(startDate), "days");
  329. if (differDays >= 7) {
  330. showToast(t("robotRanking.seleWeekDateRangeNotSeveDays"));
  331. return;
  332. }
  333. }
  334. const startTime = moment(e[0]).format("YYYY-MM-DD") + " 00:00:00";
  335. const endTime = moment(e[1]).format("YYYY-MM-DD") + " 23:59:59";
  336. getEquipRankList(weekOrMont, startTime, endTime);
  337. if (idx === 1) {
  338. weekShow.value = false;
  339. } else {
  340. monthShow.value = false;
  341. }
  342. };
  343. // 日的日期选择弹窗
  344. // 日历选择触发
  345. const calendarDayConfirm = (e) => {
  346. const startDate = moment(e).format("YYYY-MM-DD") + " 00:00:00";
  347. const endDate = moment(e).format("YYYY-MM-DD") + " 23:59:59";
  348. getEquipRankList("day", startDate, endDate);
  349. dayShow.value = false;
  350. };
  351. // 最小日期选择
  352. const minDate = new Date(2018, 1, 1);
  353. const dayShow = ref(false);
  354. // 日,周,月,年的tab栏数据
  355. const tabDayList = ref([
  356. {
  357. name: t("robotRanking.today"),
  358. icon: "",
  359. id: 1,
  360. },
  361. {
  362. name: t("robotRanking.yesterday"),
  363. icon: "",
  364. id: 2,
  365. },
  366. {
  367. name: t("robotRanking.other"),
  368. icon: "arrow-down",
  369. id: 3,
  370. },
  371. ]);
  372. const tabWeekList = ref([
  373. {
  374. name: t("robotRanking.thisWeek"),
  375. icon: "",
  376. id: 1,
  377. },
  378. {
  379. name: t("robotRanking.lastWeek"),
  380. icon: "",
  381. id: 2,
  382. },
  383. {
  384. name: t("robotRanking.other"),
  385. icon: "arrow-down",
  386. id: 3,
  387. },
  388. ]);
  389. const tabMonthList = ref([
  390. {
  391. name: t("robotRanking.thisMonth"),
  392. icon: "",
  393. id: 1,
  394. },
  395. {
  396. name: t("robotRanking.lastMonth"),
  397. icon: "",
  398. id: 2,
  399. },
  400. {
  401. name: t("robotRanking.other"),
  402. icon: "arrow-down",
  403. id: 3,
  404. },
  405. ]);
  406. const tabYearList = ref([
  407. {
  408. name: t("robotRanking.thisYear"),
  409. icon: "",
  410. id: 1,
  411. },
  412. {
  413. name: t("robotRanking.lastYear"),
  414. icon: "",
  415. id: 2,
  416. },
  417. {
  418. name: t("robotRanking.other"),
  419. icon: "arrow-down",
  420. id: 3,
  421. },
  422. ]);
  423. // 默认进来的时间
  424. const defaultTime = reactive({
  425. // 今日
  426. todayStart: moment().format("YYYY-MM-DD") + " 00:00:00",
  427. todayEnd: moment().format("YYYY-MM-DD") + " 23:59:59",
  428. // 昨日
  429. colastdayStart:
  430. moment()
  431. .day(moment().day() - 1)
  432. .format("YYYY-MM-DD") + " 00:00:00",
  433. colastdayEnd:
  434. moment()
  435. .day(moment().day() - 1)
  436. .format("YYYY-MM-DD") + " 23:59:59",
  437. // 这周
  438. weekStart: moment().weekday(1).format("YYYY-MM-DD") + " 00:00:00",
  439. weekEnd: moment().weekday(7).format("YYYY-MM-DD") + " 23:59:59",
  440. // 上周
  441. lastWeekStart: moment().week(moment().week() - 1).startOf('week').add(1, 'days').format("YYYY-MM-DD") + " 00:00:00",
  442. // moment()
  443. // .week(moment().week() - 1)
  444. // .startOf("week")
  445. // .format("YYYY-MM-DD") + " 00:00:00",
  446. lastWeekEnd: moment().week(moment().week() - 1).endOf('week').add(1, 'days').format("YYYY-MM-DD") + " 23:59:59",
  447. // moment()
  448. // .week(moment().week() - 1)
  449. // .endOf("week")
  450. // .format("YYYY-MM-DD") + " 23:59:59",
  451. // 这个月
  452. monthStart: moment().startOf("month").format("YYYY-MM-DD") + " 00:00:00",
  453. monthEnd: moment().endOf("month").format("YYYY-MM-DD") + " 23:59:59",
  454. // 上个月
  455. lastmonthStart:
  456. moment()
  457. .month(moment().month() - 1)
  458. .startOf("month")
  459. .format("YYYY-MM-DD") + " 00:00:00",
  460. lastmonthEnd:
  461. moment()
  462. .month(moment().month() - 1)
  463. .endOf("month")
  464. .format("YYYY-MM-DD") + " 23:59:59",
  465. // 今年
  466. yearStart: moment().startOf("year").format("YYYY-MM-DD") + " 00:00:00",
  467. yearEnd: moment().endOf("year").format("YYYY-MM-DD") + " 23:59:59",
  468. // 上年
  469. lastYearStart:
  470. moment()
  471. .year(moment().year() - 1)
  472. .startOf("year")
  473. .format("YYYY-MM-DD") + " 00:00:00",
  474. lastYearEnd:
  475. moment()
  476. .year(moment().year() - 1)
  477. .endOf("year")
  478. .format("YYYY-MM-DD") + " 23:59:59",
  479. });
  480. // 点击tab
  481. const tabclk = (e, type) => {
  482. let startDate = "";
  483. let endDate = "";
  484. switch (type) {
  485. case "day":
  486. switch (e.name) {
  487. case 0:
  488. startDate = defaultTime.todayStart;
  489. endDate = defaultTime.todayEnd;
  490. break;
  491. case 1:
  492. startDate = defaultTime.colastdayStart;
  493. endDate = defaultTime.colastdayEnd;
  494. break;
  495. case 2:
  496. // 打开日历弹窗
  497. dayShow.value = true;
  498. break;
  499. }
  500. break;
  501. case "week":
  502. switch (e.name) {
  503. case 0:
  504. startDate = defaultTime.weekStart;
  505. endDate = defaultTime.weekEnd;
  506. break;
  507. case 1:
  508. startDate = defaultTime.lastWeekStart;
  509. endDate = defaultTime.lastWeekEnd;
  510. break;
  511. case 2:
  512. // 打开周的日期选择弹窗
  513. weekShow.value = true;
  514. break;
  515. }
  516. break;
  517. case "month":
  518. switch (e.name) {
  519. case 0:
  520. startDate = defaultTime.monthStart;
  521. endDate = defaultTime.monthEnd;
  522. break;
  523. case 1:
  524. startDate = defaultTime.lastmonthStart;
  525. endDate = defaultTime.lastmonthEnd;
  526. break;
  527. case 2:
  528. // 打开月的日期选择弹窗
  529. monthShow.value = true;
  530. break;
  531. }
  532. break;
  533. case "year":
  534. switch (e.name) {
  535. case 0:
  536. startDate = defaultTime.yearStart;
  537. endDate = defaultTime.yearEnd;
  538. break;
  539. case 1:
  540. startDate = defaultTime.lastYearStart;
  541. endDate = defaultTime.lastYearEnd;
  542. break;
  543. case 2:
  544. // 打开年的日期弹窗
  545. yearShow.value = true;
  546. break;
  547. }
  548. break;
  549. }
  550. // 如果是点击其他,不用请求
  551. if (e.name !== 2) {
  552. // 获取日、周、月、年的排行数据
  553. getEquipRankList(type, startDate, endDate);
  554. }
  555. };
  556. const changeType = ref(0);
  557. const companyType = ref(""); // 公司平台
  558. const machineType = ref(""); // 设备类型
  559. let chartObj = {
  560. day: null,
  561. week: null,
  562. month: null,
  563. year: null,
  564. };
  565. // 获取日、周、月、年的排行数据
  566. const getEquipRankList = (chartType, startDate, endDate) => {
  567. let param = {
  568. adminId: user.id,
  569. ifForeign: user.ifForeign,
  570. changeType: changeType.value, //必填,默认为一0:销售额统计,1:花型统计
  571. companyType: companyType.value,
  572. machineType: machineType.value,
  573. chartType,
  574. startDate,
  575. endDate,
  576. };
  577. getRankingList(param).then(async (res) => {
  578. const { data } = res;
  579. switch (chartType) {
  580. case "day":
  581. totalObj.dayData = data.data;
  582. // console.log("日返回值", data);
  583. break;
  584. case "week":
  585. totalObj.weekData = data.data;
  586. // console.log("周返回值", data);
  587. break;
  588. case "month":
  589. totalObj.monthData = data.data;
  590. // console.log("月返回值", data);
  591. break;
  592. case "year":
  593. totalObj.yearData = data.data;
  594. // console.log("年返回值", data);
  595. break;
  596. }
  597. // 有数据返回则处理
  598. if (data.code && data.data) {
  599. // echarts的配置
  600. const chartOption = {
  601. tooltip: {
  602. trigger: "axis",
  603. axisPointer: {
  604. type: "shadow",
  605. },
  606. },
  607. // 固定屏幕显示多少个,其余的滑动
  608. dataZoom: [
  609. // {
  610. // type: 'slider',
  611. // xAxisIndex: 0,
  612. // filterMode: 'none',
  613. // // 开始的值
  614. // startValue: null,
  615. // // 结束的值
  616. // endValue: null,
  617. // // 锁定滑动的区域
  618. // // zoomLock:true,
  619. // },
  620. {
  621. type: "inside",
  622. xAxisIndex: 0,
  623. filterMode: "none",
  624. startValue: null,
  625. endValue: null,
  626. zoomLock: true,
  627. },
  628. ],
  629. grid: {
  630. left: "3%",
  631. right: "4%",
  632. bottom: "10%",
  633. containLabel: true,
  634. },
  635. legend: {
  636. bottom: 0,
  637. right: 10,
  638. itemWidth: 10,
  639. itemHeight: 10,
  640. icon: "rect",
  641. },
  642. yAxis: { type: "value" },
  643. xAxis: {
  644. type: "category",
  645. axisLabel: {
  646. rotate: 45,
  647. },
  648. data: [],
  649. },
  650. series: [],
  651. };
  652. await nextTick();
  653. let chartBox;
  654. switch (chartType) {
  655. case "day":
  656. chartBox = dayChartBox.value;
  657. break;
  658. case "week":
  659. chartBox = weekChartBox.value;
  660. break;
  661. case "month":
  662. chartBox = monthChartBox.value;
  663. break;
  664. case "year":
  665. chartBox = yearChartBox.value;
  666. break;
  667. }
  668. if (chartBox) {
  669. const dayChartOption = Object.assign({}, chartOption);
  670. dayChartOption.xAxis.data = data.data.categories;
  671. dayChartOption.series = [
  672. {
  673. ...data.data.series[0],
  674. type: "bar",
  675. itemStyle: { color: "#e59a6d" },
  676. name: t("home.productNum"),
  677. label: {
  678. show: true,
  679. position: "top",
  680. },
  681. },
  682. {
  683. ...data.data.series[1],
  684. type: "bar",
  685. itemStyle: { color: "#4d6add" },
  686. name: t("home.salesAmount"),
  687. label: {
  688. show: true,
  689. position: "top",
  690. },
  691. },
  692. ];
  693. dayChartOption.dataZoom[0]["startValue"] =
  694. data.data.categories[0];
  695. dayChartOption.dataZoom[0]["endValue"] =
  696. data.data.categories[4];
  697. // 解决resize不起作用,配合onMounted里的方法使用
  698. switch (chartType) {
  699. case "day":
  700. chartObj.day = window.echarts.init(chartBox, null, {
  701. renderer: "canvas",
  702. useDirtyRect: false,
  703. });
  704. chartObj.day && chartObj.day.setOption(dayChartOption);
  705. break;
  706. case "week":
  707. chartObj.week = window.echarts.init(chartBox, null, {
  708. renderer: "canvas",
  709. useDirtyRect: false,
  710. });
  711. chartObj.week && chartObj.week.setOption(dayChartOption);
  712. break;
  713. case "month":
  714. chartObj.month = window.echarts.init(chartBox, null, {
  715. renderer: "canvas",
  716. useDirtyRect: false,
  717. });
  718. chartObj.month && chartObj.month.setOption(dayChartOption);
  719. break;
  720. case "year":
  721. chartObj.year = window.echarts.init(chartBox, null, {
  722. renderer: "canvas",
  723. useDirtyRect: false,
  724. });
  725. chartObj.year && chartObj.year.setOption(dayChartOption);
  726. break;
  727. }
  728. }
  729. }
  730. });
  731. };
  732. const user = getLoginUser();
  733. // 日、周、月、年的图表
  734. const dayChartBox = ref();
  735. const weekChartBox = ref();
  736. const monthChartBox = ref();
  737. const yearChartBox = ref();
  738. // 初始化页面获取列表
  739. onMounted(async () => {
  740. // 加载样式
  741. styleUrl('robotRanking');
  742. // 默认筛选选中
  743. searchForm.changeTypeName = t("robotRanking.salesStatistics");
  744. searchForm.changeType = 0;
  745. searchForm.companyTypeName = t("robotRanking.whole");
  746. searchForm.machineTypeName = t("robotRanking.whole");
  747. // 查询是否有订单数据权限
  748. const isOrderData = user.menuCodeList.some((item) => {
  749. return item === "M4";
  750. })
  751. // 如果是type为admin或者商家或者是有订单数据权限M4的子商家才可以查看
  752. if (user.type === 0 || user.type === 2 || isOrderData) {
  753. init();
  754. }
  755. window.addEventListener("resize", () => {
  756. chartObj.day && chartObj.day.resize();
  757. chartObj.week && chartObj.week.resize();
  758. chartObj.month && chartObj.month.resize();
  759. chartObj.year && chartObj.year.resize();
  760. });
  761. });
  762. // 刚进页面获取
  763. const init = () => {
  764. // 获取日的排行数据
  765. getEquipRankList("day", defaultTime.todayStart, defaultTime.todayEnd);
  766. // 获取周的排行数据
  767. getEquipRankList("week", defaultTime.weekStart, defaultTime.weekEnd);
  768. // 获取月的排行数据
  769. getEquipRankList("month", defaultTime.monthStart, defaultTime.monthEnd);
  770. // 获取年的排行数据
  771. getEquipRankList("year", defaultTime.yearStart, defaultTime.yearEnd);
  772. };
  773. const searchForm = reactive({
  774. businessName: "",
  775. changeTypeName: "",
  776. changeType: "",
  777. machineTypeName: "",
  778. machineType: "",
  779. companyTypeName: "",
  780. companyType: ""
  781. });
  782. const kDialogRef = ref(null);
  783. const busiPopShow = ref(false);
  784. const busiPopList = reactive([
  785. {
  786. name: "商户1",
  787. id: "1",
  788. },
  789. {
  790. name: "商户2",
  791. id: "2",
  792. },
  793. ]);
  794. const busiPopFieldName = reactive({
  795. text: "name",
  796. value: "id",
  797. });
  798. // 点击筛选
  799. const noticeClk = () => {
  800. kDialogRef.value.openDialog();
  801. };
  802. // 点击右侧按钮
  803. const confirmClk = () => {
  804. if (searchForm.changeType === "") {
  805. changeType.value = 1;
  806. } else {
  807. changeType.value = searchForm.changeType;
  808. }
  809. companyType.value = searchForm.companyType;
  810. machineType.value = searchForm.machineType;
  811. init();
  812. };
  813. // 筛选弹窗
  814. // 点击商家输入框
  815. const busiInpClk = () => {
  816. // console.log(111111111);
  817. busiPopShow.value = true;
  818. };
  819. const busiPopConfirm = (e) => {
  820. // console.log("e的值是", e);
  821. busiPopShow.value = false;
  822. searchForm.businessName = e.name;
  823. };
  824. const busiPopCancel = () => {
  825. busiPopShow.value = false;
  826. };
  827. return {
  828. dayChartBox,
  829. weekChartBox,
  830. monthChartBox,
  831. yearChartBox,
  832. tabclk,
  833. tabDayList,
  834. tabWeekList,
  835. tabMonthList,
  836. tabYearList,
  837. noticeClk,
  838. kDialogRef,
  839. busiInpClk,
  840. busiPopShow,
  841. busiPopConfirm,
  842. busiPopList,
  843. busiPopFieldName,
  844. busiPopCancel,
  845. confirmClk,
  846. searchForm,
  847. dayShow,
  848. minDate,
  849. calendarDayConfirm,
  850. weekShow,
  851. monthShow,
  852. calendarWeekOrMonConfirm,
  853. yearFormatter,
  854. currentDate,
  855. yearShow,
  856. yearPopList,
  857. yearPopConfirm,
  858. yearPopFieldName,
  859. changeTypeShow,
  860. changeTypePopList,
  861. changeTypePopConfirm,
  862. changeTypeInpClk,
  863. companyTypeInpClk,
  864. companyTypePopConfirm,
  865. companyTypePopList,
  866. companyTypeShow,
  867. machineTypeInpClk,
  868. machineTypePopConfirm,
  869. machineTypePopList,
  870. machineTypeShow,
  871. totalNoData,
  872. maTypeDefaIdx,
  873. chgTypeDefaIdx,
  874. isAdmin,
  875. };
  876. },
  877. components: { sHeader, kTabs, kDialog, kNoData },
  878. };
  879. </script>
  880. <style lang="less" scoped>
  881. @import "../styles/robotRanking/index";
  882. </style>