home.vue 14 KB

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