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