home.vue 13 KB

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