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