homeNew.vue 15 KB

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