home.vue 14 KB

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