home.vue 14 KB

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