home.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. const scanResult = res.result;
  270. if(scanResult && scanResult.includes("/pages/warehouse/hwQrcode/index")) {
  271. uni.navigateTo({
  272. url: `${scanResult}`,
  273. });
  274. return
  275. }
  276. this.Scancodedate(res.result)
  277. }
  278. })
  279. //_this.Scancodedate('res')
  280. },
  281. // 根据条码请求设备数据
  282. getData() {
  283. let par = {
  284. barType: this.barType,
  285. qrContent: this.qrContent
  286. }
  287. this.equipmentInfo = {}
  288. return postJ(this.apiUrl + '/scan/getAssetInfo', par)
  289. .then(res => {
  290. console.log(res.data)
  291. this.equipmentInfo = res.data
  292. })
  293. .catch(err => {
  294. console.log(err, 'err-----------------')
  295. uni.showToast({
  296. title: '系统错误!',
  297. icon: 'none',
  298. duration: 2000
  299. })
  300. })
  301. },
  302. // 扫码枪扫码
  303. cbScancodedate(data) {
  304. this.Scancodedate(data.code)
  305. },
  306. async Scancodedate(code) {
  307. this.qrContent = code.trim()
  308. // this.qrContent = 'w01000002100001@_@0' //code.trim()
  309. //this.qrContent = '005/w01000001120041/锤锤专用02-不拆包-批量/规格01//成型/成型工序@_@0'
  310. this.barType = this.setBarType(this.qrContent)
  311. await this.getData()
  312. if (this.equipmentInfo.assetCode) {
  313. if (this.equipmentInfo.assetType != 1) {
  314. uni.showToast({
  315. title: '请扫描生产设备码!',
  316. icon: 'none',
  317. duration: 2000
  318. })
  319. return
  320. }
  321. let par = {
  322. info: encodeURIComponent(JSON.stringify(this.equipmentInfo)),
  323. qrContent: this.qrContent
  324. }
  325. par = this.URLSearchParams(par)
  326. console.log('qrwewett')
  327. uni.navigateTo({
  328. url: '/pages/equipment_ledger/index?' + par
  329. })
  330. }
  331. },
  332. // 设置barType
  333. setBarType(val) {
  334. let index = val.indexOf('@_@')
  335. let result = 0
  336. if (index !== -1) {
  337. let item = val.substr(index + 3, 1)
  338. if (item) {
  339. result = Number(item)
  340. }
  341. }
  342. return result
  343. },
  344. // 切换排行版tab
  345. handleTabChange(item) {
  346. this.activeIndex = item.index
  347. this.tableData
  348. // console.log(item);
  349. },
  350. async getHomeData() {
  351. uni.showLoading({
  352. title: '加载中'
  353. })
  354. const res1 = await getCount()
  355. const res2 = await getGoodsPage()
  356. const res3 = await getYearAmount()
  357. const res4 = await getReceivableAmount()
  358. const res5 = await getPayableAmount()
  359. // 年度
  360. const res6 = await getProduceAmount({
  361. createTimeStart: getDateNew('year') + '-01',
  362. createTimeEnd: getDateNew('year') + '-12',
  363. factoryId: null
  364. })
  365. // 本月
  366. const res7 = await getProduceAmount({
  367. createTimeStart: getDateNew('month'),
  368. createTimeEnd: getDateNew('month'),
  369. factoryId: null
  370. })
  371. const res9 = await getHotProduct()
  372. this.homeData.totalFinishedProducts = res1?.totalFinishedProducts ?? 0
  373. this.homeData.totalRawMaterials = res1?.totalRawMaterials ?? 0
  374. this.homeData.goodsCount = res2?.count ?? 0
  375. this.homeData.yearAmount = (res3 / 10000).toFixed(2)
  376. this.homeData.receivableAmount = res4 ?? 0
  377. this.homeData.payableAmount = res5 ?? 0
  378. this.homeData.yearProduceAmount = res6?.reduce((pre, cur) => {
  379. return pre + cur?.formedNum
  380. }, 0) ?? 0
  381. this.homeData.monthProduceAmount = res7?.reduce((pre, cur) => {
  382. return pre + cur?.formedNum
  383. }, 0) ?? 0
  384. this.homeData.pendingAmount = res6?.reduce((pre, cur) => {
  385. return pre + cur?.pendingProductionCount
  386. }, 0) ?? 0
  387. this.hotProductList = res9
  388. this.tableData = this.hotProductList.slice(0, 4)
  389. uni.hideLoading()
  390. }
  391. }
  392. }
  393. </script>
  394. <style>
  395. page {
  396. background-color: #f0f0f0;
  397. }
  398. </style>
  399. <style lang="scss" scoped>
  400. // /deep/.uni-page-wrapper{
  401. // background-color: pink;
  402. // }
  403. /deep/.uni-table {
  404. min-width: auto !important;
  405. border-radius: 0;
  406. }
  407. page {
  408. background-color: #f0f0f0;
  409. }
  410. .container {
  411. background-color: $page-bg;
  412. padding: 20rpx;
  413. .data-middle {
  414. display: flex;
  415. flex-wrap: wrap;
  416. justify-content: space-between;
  417. .cell {
  418. display: flex;
  419. width: 30%;
  420. padding: 20rpx 0;
  421. margin-bottom: 20rpx;
  422. flex-direction: column;
  423. background-color: rgb(22, 146, 50);
  424. justify-content: center;
  425. align-items: center;
  426. border-radius: 10rpx;
  427. color: #fff;
  428. .num {
  429. font-size: 28rpx;
  430. }
  431. .label {
  432. font-size: 20rpx;
  433. }
  434. }
  435. }
  436. .data-rank {
  437. width: 100%;
  438. padding: 10rpx 20rpx 0 20rpx;
  439. margin-bottom: 20rpx;
  440. background-color: #fff;
  441. border-radius: 20rpx 20rpx 0 0rpx;
  442. .tab-top {
  443. display: flex;
  444. margin-bottom: 20rpx;
  445. .tab-item {
  446. margin-right: 20rpx;
  447. .active {
  448. border-bottom: 2px solid rgb(22, 146, 50);
  449. }
  450. }
  451. }
  452. .table-title {
  453. width: 100%;
  454. display: flex;
  455. color: #333;
  456. flex-wrap: nowrap;
  457. justify-content: space-between;
  458. .code {
  459. width: 40%;
  460. word-break: normal
  461. }
  462. .name {
  463. width: 40%;
  464. word-break: normal
  465. }
  466. .total {
  467. width: 15%;
  468. word-break: normal
  469. }
  470. }
  471. .table-content {
  472. font-size: 28rpx;
  473. display: flex;
  474. padding: 10rpx 0;
  475. width: 100%;
  476. color: #333;
  477. flex-wrap: nowrap;
  478. justify-content: space-between;
  479. border-bottom: 1px solid #eee;
  480. .code {
  481. display: flex;
  482. width: 40%;
  483. .index {
  484. width: 20rpx;
  485. margin-right: 20rpx;
  486. }
  487. .value {
  488. word-break: break-all;
  489. flex: 1;
  490. }
  491. }
  492. .name {
  493. width: 40%;
  494. white-space: nowarp;
  495. over-flow: hidden;
  496. text-overflow: ellipsip;
  497. word-break: break-all;
  498. }
  499. .total {
  500. text-align: center;
  501. width: 15%;
  502. white-space: nowarp;
  503. over-flow: hidden;
  504. text-overflow: ellipsip;
  505. word-break: break-all;
  506. }
  507. }
  508. }
  509. .data-rank .table-content:last-child {
  510. border-bottom: none;
  511. }
  512. .data-bottom {
  513. display: flex;
  514. flex-wrap: wrap;
  515. justify-content: space-between;
  516. .cell {
  517. display: flex;
  518. width: 30%;
  519. padding: 20rpx 0;
  520. margin-bottom: 20rpx;
  521. flex-direction: column;
  522. background-color: #fff;
  523. justify-content: center;
  524. align-items: center;
  525. border-radius: 10rpx;
  526. color: #000;
  527. .num {
  528. font-size: 28rpx;
  529. }
  530. .label {
  531. font-size: 20rpx;
  532. }
  533. }
  534. }
  535. }
  536. </style>