homeNew.vue 14 KB

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