robotRanking.vue 29 KB

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