home.vue 12 KB

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