home.vue 13 KB

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