homeNew.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <template>
  2. <view class="ss">
  3. <!-- 头 -->
  4. <!-- <uni-nav-bar fixed="true" statusBar="true" right-icon="scan" title="首页" @clickLeft="back"
  5. @clickRight="HandlScanCode"></uni-nav-bar> -->
  6. <!-- <view class="container"> -->
  7. <!-- <navigation :workOrder="workOrder" ref="navigationRef"></navigation> -->
  8. <!-- 设备主管 -->
  9. <!-- <equipment v-if="roleId == 102" ref="equipmentRef"></equipment> -->
  10. <!-- 运维 -->
  11. <!-- <Mocha v-if="roleId == 157" ref="mochaRef"></Mocha> -->
  12. <!-- 模具舟皿 -->
  13. <!-- <mould v-if="roleId == 155" ref="mouldRef"></mould> -->
  14. <!-- 备品备件 -->
  15. <!-- <sparePart v-if="roleId == 150" ref="sparePartRef"></sparePart> -->
  16. <view class="data-middle">
  17. <view class="cell">
  18. <view class="label">
  19. 成品库存总量
  20. </view>
  21. <view class="num">
  22. {{homeData.totalFinishedProducts}}
  23. </view>
  24. </view>
  25. <view class="cell">
  26. <view class="label">
  27. 物料库存总量
  28. </view>
  29. <view class="num">
  30. {{homeData.totalRawMaterials}}
  31. </view>
  32. </view>
  33. <view class="cell" @click="toDeviceDetail">
  34. <view class="label">
  35. 设备监测
  36. </view>
  37. <view class="num">
  38. <text style="font-size: 22rpx;">在线:</text>{{homeData.deviceOnLineCount}}
  39. </view>
  40. <view class="num">
  41. <text style="font-size: 22rpx;">离线:</text><text style="color: #FFC553;">{{ homeData.deviceOffLineCount }}</text>
  42. </view>
  43. </view>
  44. <view class="cell">
  45. <view class="label">
  46. 年度合同额(万元)
  47. </view>
  48. <view class="num">
  49. {{homeData.yearAmount}}
  50. </view>
  51. </view>
  52. <view class="cell">
  53. <view class="label">
  54. 年度应收款(万元)
  55. </view>
  56. <view class="num">
  57. {{homeData.receivableAmount}}
  58. </view>
  59. </view>
  60. <view class="cell">
  61. <view class="label">
  62. 年度应付款(万元)
  63. </view>
  64. <view class="num">
  65. {{homeData.payableAmount}}
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 通知公告 -->
  70. <view class="notice-bar" v-if="noticeList.length > 0">
  71. <u-icon name="volume" size="30rpx" color="#ff9900"></u-icon>
  72. <swiper class="notice-swiper" vertical autoplay circular :interval="3000">
  73. <swiper-item v-for="(item, index) in noticeList" :key="index">
  74. <view class="notice-content" @click.stop="toNoticeDetail(item)">
  75. <text class="notice-text">{{ item.title }}</text>
  76. <text class="notice-date">{{ item.date }}</text>
  77. </view>
  78. </swiper-item>
  79. </swiper>
  80. </view>
  81. <manage ref="manageRef"></manage>
  82. <!-- </view> -->
  83. </view>
  84. </template>
  85. <script>
  86. import navigation from './components/navigation.vue'
  87. import equipment from './pages/equipment/equipment.vue'
  88. import Mocha from './pages/Mocha/Mocha.vue'
  89. import mould from './pages/mould/mould.vue'
  90. import sparePart from './pages/sparePart/sparePart.vue'
  91. import ScanCode from '@/components/ScanCode.vue'
  92. import manage from './pages/manage/manage.vue'
  93. import {
  94. getDateNew
  95. } from '@/utils/utils.js'
  96. import {
  97. postJ,
  98. post,
  99. get
  100. } from '@/utils/api'
  101. import {
  102. statistics
  103. } from '@/api/myTicket'
  104. import {
  105. getCount,
  106. getYearAmount,
  107. getPayableAmount,
  108. getReceivableAmount,
  109. getGoodsPage,
  110. getProduceAmount,
  111. // getPendingAmount,
  112. getHotProduct,
  113. getDeviceCount,
  114. getNoticeDocumentPage
  115. }
  116. from '@/api/home'
  117. export default {
  118. components: {
  119. navigation,
  120. equipment,
  121. Mocha,
  122. mould,
  123. sparePart,
  124. ScanCode,
  125. manage
  126. },
  127. onShow() {
  128. // NOTE: 当 homeNew 作为子组件嵌入 home.vue 时,以下 UniApp 页面级钩子不会被调用。
  129. // 相关逻辑已迁移到 mounted() 中执行。
  130. },
  131. onReady() {
  132. // NOTE: 当 homeNew 作为子组件嵌入 home.vue 时,UniApp 页面级钩子不会被调用。
  133. // getHomeData() 已迁移到 mounted() 中执行。
  134. },
  135. onLoad() {
  136. },
  137. onUnload() {
  138. uni.$off('scancodedate')
  139. },
  140. onHide() {
  141. uni.$off('scancodedate')
  142. },
  143. mounted() {
  144. this.init()
  145. this.getHomeData()
  146. setTimeout(() => {
  147. this.$refs.manageRef?.initCharts()
  148. }, 300)
  149. let _this = this
  150. uni.$off('scancodedate')
  151. uni.$on('scancodedate', function(data) {
  152. console.log(data, '-----scancodedate')
  153. _this.cbScancodedate(data)
  154. })
  155. },
  156. data() {
  157. return {
  158. noticeList: [],
  159. roleId: null,
  160. timer: null,
  161. qrContent: null,
  162. barType: null,
  163. // 扫码后的设备信息
  164. equipmentInfo: '',
  165. qrContent: '',
  166. barType: '',
  167. workOrder: {
  168. maintenanceNum: 0,
  169. patrolInspection: 0,
  170. quantityNum: 0,
  171. repairsNum: 0,
  172. total: 0
  173. }, // 工单统计数据
  174. activeIndex: 0,
  175. tabList: [{
  176. name: '热销品排行榜',
  177. index: 0,
  178. }, {
  179. name: '滞销品排行榜',
  180. index: 1,
  181. }],
  182. tableData: [],
  183. homeData: {
  184. totalFinishedProducts: '',
  185. totalRawMaterials: '',
  186. goodsCount: '',
  187. yearAmount: '',
  188. receivableAmount: '',
  189. payableAmount: '',
  190. yearProduceAmount: '',
  191. monthProduceAmount: '',
  192. pendingAmount: '',
  193. deviceOnLineCount: '',
  194. deviceOffLineCount: '',
  195. },
  196. hotProductList: [],
  197. }
  198. },
  199. created() {
  200. uni.getStorage({
  201. key: 'userInfo',
  202. success: res => {
  203. // console.log(res);
  204. this.roleId = res.data.roleId[0]
  205. }
  206. })
  207. this.getNoticeDocumentList()
  208. },
  209. onHide() {
  210. clearTimeout(this.timer);
  211. },
  212. onUnload() {
  213. clearTimeout(this.timer);
  214. },
  215. methods: {
  216. // 刷新 manage 子组件数据(供父组件 tab 切换时调用)
  217. refreshManage() {
  218. this.$refs.manageRef?.refreshData()
  219. },
  220. toDeviceDetail() {
  221. console.log('toDeviceDetail')
  222. uni.navigateTo({
  223. url: '/pages/home/components/DeviceDetail'
  224. })
  225. },
  226. getNoticeDocumentList() {
  227. getNoticeDocumentPage({
  228. pageNum: 1,
  229. size: 5,
  230. approvalStatus: 2
  231. }).then(res => {
  232. console.log('getNoticeDocumentPage', res)
  233. this.noticeList = res.list.map(item => ({
  234. ...item,
  235. title: item.title || item.content,
  236. date: getDateNew(item.createTime)
  237. }))
  238. console.log(this.noticeList)
  239. })
  240. },
  241. toNoticeDetail(item) {
  242. console.log('toNoticeDetail', item)
  243. uni.navigateTo({
  244. url: '/pages/home/pages/manage/documentDetail?id=' + item.id
  245. })
  246. },
  247. init() {
  248. this.getStatistics()
  249. this.$refs.navigationRef && this.$refs.navigationRef.getCount()
  250. this.$refs.equipmentRef && this.$refs.equipmentRef.getData()
  251. this.$refs.mochaRef && this.$refs.mochaRef.getData()
  252. this.$refs.mouldRef &&
  253. (this.$refs.mouldRef.getBoatInventoryCountList(),
  254. this.$refs.mouldRef.getModeInventoryCountList())
  255. this.$refs.sparePartRef && this.$refs.sparePartRef.getData()
  256. this.timer = setTimeout(() => {
  257. this.init()
  258. }, 12000)
  259. },
  260. // 获取工单统计数
  261. getStatistics() {
  262. statistics().then(res => {
  263. this.workOrder = res
  264. })
  265. },
  266. // 相机扫码
  267. HandlScanCode() {
  268. uni.scanCode({
  269. success: (res) => {
  270. this.Scancodedate(res.result)
  271. }
  272. })
  273. //_this.Scancodedate('res')
  274. },
  275. // 根据条码请求设备数据
  276. getData() {
  277. let par = {
  278. barType: this.barType,
  279. qrContent: this.qrContent
  280. }
  281. this.equipmentInfo = {}
  282. return postJ(this.apiUrl + '/scan/getAssetInfo', par)
  283. .then(res => {
  284. console.log(res.data)
  285. this.equipmentInfo = res.data
  286. })
  287. .catch(err => {
  288. console.log(err, 'err-----------------')
  289. uni.showToast({
  290. title: '系统错误!',
  291. icon: 'none',
  292. duration: 2000
  293. })
  294. })
  295. },
  296. // 扫码枪扫码
  297. cbScancodedate(data) {
  298. this.Scancodedate(data.code)
  299. },
  300. async Scancodedate(code) {
  301. this.qrContent = code.trim()
  302. // this.qrContent = 'w01000002100001@_@0' //code.trim()
  303. //this.qrContent = '005/w01000001120041/锤锤专用02-不拆包-批量/规格01//成型/成型工序@_@0'
  304. this.barType = this.setBarType(this.qrContent)
  305. await this.getData()
  306. if (this.equipmentInfo.assetCode) {
  307. if (this.equipmentInfo.assetType != 1) {
  308. uni.showToast({
  309. title: '请扫描生产设备码!',
  310. icon: 'none',
  311. duration: 2000
  312. })
  313. return
  314. }
  315. let par = {
  316. info: encodeURIComponent(JSON.stringify(this.equipmentInfo)),
  317. qrContent: this.qrContent
  318. }
  319. par = this.URLSearchParams(par)
  320. console.log('qrwewett')
  321. uni.navigateTo({
  322. url: '/pages/equipment_ledger/index?' + par
  323. })
  324. }
  325. },
  326. // 设置barType
  327. setBarType(val) {
  328. let index = val.indexOf('@_@')
  329. let result = 0
  330. if (index !== -1) {
  331. let item = val.substr(index + 3, 1)
  332. if (item) {
  333. result = Number(item)
  334. }
  335. }
  336. return result
  337. },
  338. // 切换排行版tab
  339. handleTabChange(item) {
  340. this.activeIndex = item.index
  341. this.tableData
  342. // console.log(item);
  343. },
  344. async getHomeData() {
  345. uni.showLoading({
  346. title: '加载中'
  347. })
  348. const res1 = await getCount()
  349. const res2 = await getGoodsPage()
  350. const res3 = await getYearAmount()
  351. const res4 = await getReceivableAmount()
  352. const res5 = await getPayableAmount()
  353. // 年度
  354. const res6 = await getProduceAmount({
  355. createTimeStart: getDateNew('year') + '-01',
  356. createTimeEnd: getDateNew('year') + '-12',
  357. factoryId: null
  358. })
  359. // 本月
  360. const res7 = await getProduceAmount({
  361. createTimeStart: getDateNew('month'),
  362. createTimeEnd: getDateNew('month'),
  363. factoryId: null
  364. })
  365. const res9 = await getHotProduct()
  366. const res10 = await getDeviceCount({
  367. size: 9999
  368. })
  369. let deviceData = res10.list.map((item) => {
  370. let iotList = [];
  371. if (item.iotPointDataList) {
  372. item.iotPointDataList.forEach((element) => {
  373. let data = item.iotModel.properties.find(
  374. (iotModel) => iotModel.identifier == element.identifier
  375. );
  376. if (data) {
  377. iotList.push({
  378. ...element,
  379. dataType: data.dataType
  380. });
  381. }
  382. });
  383. }
  384. item['iotList'] = item.iotDashboardPoint.length
  385. ? iotList.filter((iotListItem) =>
  386. item.iotDashboardPoint.find(
  387. (Point) =>
  388. Point.identifier == iotListItem.identifier &&
  389. Point.checked1
  390. )
  391. )
  392. : iotList.filter((iotListItem, index) => index < 4);
  393. return item;
  394. });
  395. this.homeData.deviceOnLineCount = deviceData.filter((item) => item.iotList.length > 0).length
  396. this.homeData.deviceOffLineCount = deviceData.filter((item) => item.iotList.length == 0).length
  397. this.homeData.totalFinishedProducts = res1?.totalFinishedProducts ?? 0
  398. this.homeData.totalRawMaterials = res1?.totalRawMaterials ?? 0
  399. this.homeData.goodsCount = res2?.count ?? 0
  400. this.homeData.yearAmount = (res3 / 10000).toFixed(2)
  401. this.homeData.receivableAmount = res4 ?? 0
  402. this.homeData.payableAmount = res5 ?? 0
  403. this.homeData.yearProduceAmount = res6?.reduce((pre, cur) => {
  404. return pre + cur?.formedNum
  405. }, 0) ?? 0
  406. this.homeData.monthProduceAmount = res7?.reduce((pre, cur) => {
  407. return pre + cur?.formedNum
  408. }, 0) ?? 0
  409. this.homeData.pendingAmount = res6?.reduce((pre, cur) => {
  410. return pre + cur?.pendingProductionCount
  411. }, 0) ?? 0
  412. this.hotProductList = res9
  413. this.tableData = this.hotProductList.slice(0, 4)
  414. uni.hideLoading()
  415. }
  416. }
  417. }
  418. </script>
  419. <style>
  420. page {
  421. background-color: #f0f0f0;
  422. }
  423. </style>
  424. <style lang="scss" scoped>
  425. // /deep/.uni-page-wrapper{
  426. // background-color: pink;
  427. // }
  428. /deep/.uni-table {
  429. min-width: auto !important;
  430. border-radius: 0;
  431. }
  432. page {
  433. background-color: #f0f0f0;
  434. }
  435. .container {
  436. background-color: $page-bg;
  437. padding: 20rpx;
  438. .data-middle {
  439. display: flex;
  440. flex-wrap: wrap;
  441. justify-content: space-between;
  442. .cell {
  443. display: flex;
  444. width: 32%;
  445. padding: 16rpx 0;
  446. margin-bottom: 16rpx;
  447. flex-direction: column;
  448. background-color: #169232;
  449. justify-content: center;
  450. align-items: center;
  451. border-radius: 8rpx;
  452. color: #fff;
  453. min-height: 164rpx;
  454. .num {
  455. font-size: 30rpx;
  456. }
  457. .label {
  458. font-size: 24rpx;
  459. margin-bottom: 10rpx;
  460. }
  461. }
  462. }
  463. /* 通知公告 */
  464. .notice-bar {
  465. display: flex;
  466. align-items: center;
  467. padding: 18rpx 20rpx;
  468. background: #fff;
  469. margin-bottom: 16rpx;
  470. .notice-swiper {
  471. flex: 1;
  472. height: 40rpx;
  473. margin-left: 12rpx;
  474. swiper-item {
  475. height: 40rpx;
  476. display: flex;
  477. align-items: center;
  478. }
  479. .notice-content {
  480. display: flex;
  481. align-items: center;
  482. justify-content: space-between;
  483. width: 100%;
  484. }
  485. .notice-text {
  486. font-size: 24rpx;
  487. color: #333;
  488. flex: 1;
  489. overflow: hidden;
  490. text-overflow: ellipsis;
  491. white-space: nowrap;
  492. }
  493. .notice-date {
  494. font-size: 22rpx;
  495. color: #999;
  496. margin-left: 16rpx;
  497. flex-shrink: 0;
  498. }
  499. }
  500. }
  501. .data-rank {
  502. width: 100%;
  503. padding: 10rpx 20rpx 0 20rpx;
  504. margin-bottom: 20rpx;
  505. background-color: #fff;
  506. border-radius: 20rpx 20rpx 0 0rpx;
  507. .tab-top {
  508. display: flex;
  509. margin-bottom: 20rpx;
  510. .tab-item {
  511. margin-right: 20rpx;
  512. .active {
  513. border-bottom: 2px solid rgb(22, 146, 50);
  514. }
  515. }
  516. }
  517. .table-title {
  518. width: 100%;
  519. display: flex;
  520. color: #333;
  521. flex-wrap: nowrap;
  522. justify-content: space-between;
  523. .code {
  524. width: 40%;
  525. word-break: normal
  526. }
  527. .name {
  528. width: 40%;
  529. word-break: normal
  530. }
  531. .total {
  532. width: 15%;
  533. word-break: normal
  534. }
  535. }
  536. .table-content {
  537. font-size: 28rpx;
  538. display: flex;
  539. padding: 10rpx 0;
  540. width: 100%;
  541. color: #333;
  542. flex-wrap: nowrap;
  543. justify-content: space-between;
  544. border-bottom: 1px solid #eee;
  545. .code {
  546. display: flex;
  547. width: 40%;
  548. .index {
  549. width: 20rpx;
  550. margin-right: 20rpx;
  551. }
  552. .value {
  553. word-break: break-all;
  554. flex: 1;
  555. }
  556. }
  557. .name {
  558. width: 40%;
  559. white-space: nowarp;
  560. over-flow: hidden;
  561. text-overflow: ellipsip;
  562. word-break: break-all;
  563. }
  564. .total {
  565. text-align: center;
  566. width: 15%;
  567. white-space: nowarp;
  568. over-flow: hidden;
  569. text-overflow: ellipsip;
  570. word-break: break-all;
  571. }
  572. }
  573. }
  574. .data-rank .table-content:last-child {
  575. border-bottom: none;
  576. }
  577. .data-bottom {
  578. display: flex;
  579. flex-wrap: wrap;
  580. justify-content: space-between;
  581. .cell {
  582. display: flex;
  583. width: 30%;
  584. padding: 20rpx 0;
  585. margin-bottom: 20rpx;
  586. flex-direction: column;
  587. background-color: #fff;
  588. justify-content: center;
  589. align-items: center;
  590. border-radius: 10rpx;
  591. color: #000;
  592. .num {
  593. font-size: 28rpx;
  594. }
  595. .label {
  596. font-size: 20rpx;
  597. }
  598. }
  599. }
  600. }
  601. </style>