home.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. const res1 = await getCount()
  348. const res2 = await getGoodsPage()
  349. const res3 = await getYearAmount()
  350. const res4 = await getReceivableAmount()
  351. const res5 = await getPayableAmount()
  352. // 年度
  353. const res6 = await getProduceAmount({
  354. createTimeStart: getDateNew('year') + '-01',
  355. createTimeEnd: getDateNew('year') + '-12',
  356. factoryId: null
  357. })
  358. // 本月
  359. const res7 = await getProduceAmount({
  360. createTimeStart: getDateNew('month'),
  361. createTimeEnd: getDateNew('month'),
  362. factoryId: null
  363. })
  364. const res9 = await getHotProduct()
  365. this.homeData.totalFinishedProducts = res1?.totalFinishedProducts ?? 0
  366. this.homeData.totalRawMaterials = res1?.totalRawMaterials ?? 0
  367. this.homeData.goodsCount = res2?.count ?? 0
  368. this.homeData.yearAmount = (res3 / 10000).toFixed(2)
  369. this.homeData.receivableAmount = res4 ?? 0
  370. this.homeData.payableAmount = res5 ?? 0
  371. this.homeData.yearProduceAmount = res6?.reduce((pre, cur) => {
  372. return pre + cur?.formedNum
  373. }, 0) ?? 0
  374. this.homeData.monthProduceAmount = res7?.reduce((pre, cur) => {
  375. return pre + cur?.formedNum
  376. }, 0) ?? 0
  377. this.homeData.pendingAmount = res6?.reduce((pre, cur) => {
  378. return pre + cur?.pendingProductionCount
  379. }, 0) ?? 0
  380. this.hotProductList = res9
  381. this.tableData = this.hotProductList.slice(0, 4)
  382. uni.hideLoading()
  383. }
  384. }
  385. }
  386. </script>
  387. <style>
  388. page {
  389. background-color: #f0f0f0;
  390. }
  391. </style>
  392. <style lang="scss" scoped>
  393. // /deep/.uni-page-wrapper{
  394. // background-color: pink;
  395. // }
  396. /deep/.uni-table {
  397. min-width: auto !important;
  398. border-radius: 0;
  399. }
  400. page {
  401. background-color: #f0f0f0;
  402. }
  403. .container {
  404. background-color: $page-bg;
  405. padding: 20rpx;
  406. .data-middle {
  407. display: flex;
  408. flex-wrap: wrap;
  409. justify-content: space-between;
  410. .cell {
  411. display: flex;
  412. width: 30%;
  413. padding: 20rpx 0;
  414. margin-bottom: 20rpx;
  415. flex-direction: column;
  416. background-color: rgb(22, 146, 50);
  417. justify-content: center;
  418. align-items: center;
  419. border-radius: 10rpx;
  420. color: #fff;
  421. .num {
  422. font-size: 28rpx;
  423. }
  424. .label {
  425. font-size: 20rpx;
  426. }
  427. }
  428. }
  429. .data-rank {
  430. width: 100%;
  431. padding: 10rpx 20rpx 0 20rpx;
  432. margin-bottom: 20rpx;
  433. background-color: #fff;
  434. border-radius: 20rpx 20rpx 0 0rpx;
  435. .tab-top {
  436. display: flex;
  437. margin-bottom: 20rpx;
  438. .tab-item {
  439. margin-right: 20rpx;
  440. .active {
  441. border-bottom: 2px solid rgb(22, 146, 50);
  442. }
  443. }
  444. }
  445. .table-title {
  446. width: 100%;
  447. display: flex;
  448. color: #333;
  449. flex-wrap: nowrap;
  450. justify-content: space-between;
  451. .code {
  452. width: 40%;
  453. word-break: normal
  454. }
  455. .name {
  456. width: 40%;
  457. word-break: normal
  458. }
  459. .total {
  460. width: 15%;
  461. word-break: normal
  462. }
  463. }
  464. .table-content {
  465. font-size: 28rpx;
  466. display: flex;
  467. padding: 10rpx 0;
  468. width: 100%;
  469. color: #333;
  470. flex-wrap: nowrap;
  471. justify-content: space-between;
  472. border-bottom: 1px solid #eee;
  473. .code {
  474. display: flex;
  475. width: 40%;
  476. .index {
  477. width: 20rpx;
  478. margin-right: 20rpx;
  479. }
  480. .value {
  481. word-break: break-all;
  482. flex: 1;
  483. }
  484. }
  485. .name {
  486. width: 40%;
  487. white-space: nowarp;
  488. over-flow: hidden;
  489. text-overflow: ellipsip;
  490. word-break: break-all;
  491. }
  492. .total {
  493. text-align: center;
  494. width: 15%;
  495. white-space: nowarp;
  496. over-flow: hidden;
  497. text-overflow: ellipsip;
  498. word-break: break-all;
  499. }
  500. }
  501. }
  502. .data-rank .table-content:last-child {
  503. border-bottom: none;
  504. }
  505. .data-bottom {
  506. display: flex;
  507. flex-wrap: wrap;
  508. justify-content: space-between;
  509. .cell {
  510. display: flex;
  511. width: 30%;
  512. padding: 20rpx 0;
  513. margin-bottom: 20rpx;
  514. flex-direction: column;
  515. background-color: #fff;
  516. justify-content: center;
  517. align-items: center;
  518. border-radius: 10rpx;
  519. color: #000;
  520. .num {
  521. font-size: 28rpx;
  522. }
  523. .label {
  524. font-size: 20rpx;
  525. }
  526. }
  527. }
  528. }
  529. </style>