wsx 11 месяцев назад
Родитель
Сommit
727f78b916
3 измененных файлов с 374 добавлено и 183 удалено
  1. 32 2
      api/home/index.js
  2. 174 35
      pages/home/home.vue
  3. 168 146
      utils/utils.js

+ 32 - 2
api/home/index.js

@@ -5,9 +5,10 @@ import {
 } from '@/utils/request'
 import Vue from 'vue'
 
+
 // 成品总量和物流总量
 export async function getCount(params) {
-	const data = await get(Vue.prototype.apiUrl + `wms/index/query`, params)
+	const data = await get(Vue.prototype.apiUrl + `/wms/index/query`, params)
 	if (data.code == 0) {
 		return data.data
 	}
@@ -48,4 +49,33 @@ export async function getGoodsPage(params) {
 		return data.data
 	}
 	return Promise.reject(new Error(data.message))
-}
+}
+
+// 获取年度生产总量
+export async function getProduceAmount(params) {
+	const data = await get(Vue.prototype.apiUrl + `/mes/index/completionCount`, params)
+	// console.log(data);
+	if (data.code == 0) {
+		return data.data
+	}
+	return Promise.reject(new Error(data.message))
+}
+
+// 获取待生产总量
+export async function getPendingAmount(params) {
+	const data = await get(Vue.prototype.apiUrl + `/mes/index/count`, params)
+	if (data.code == 0) {
+		return data.data
+	}
+	return Promise.reject(new Error(data.message))
+}
+
+// 热销榜单
+export async function getHotProduct(params) {
+	const data = await get(Vue.prototype.apiUrl + `/eom/saleorder/getHotProductList`, params)
+	if (data.code == 0) {
+		return data.data
+	}
+	return Promise.reject(new Error(data.message))
+}
+

+ 174 - 35
pages/home/home.vue

@@ -1,5 +1,5 @@
 <template>
-	<view>
+	<view class="">
 		<!-- 头 -->
 		<uni-nav-bar fixed="true" statusBar="true" right-icon="scan" title="首页" @clickLeft="back"
 			@clickRight="HandlScanCode"></uni-nav-bar>
@@ -82,18 +82,35 @@
 				</view>
 
 
-				<uni-table class="table" ref="table" emptyText="暂无更多数据">
+				<!-- <uni-table class="table" ref="table" emptyText="暂无更多数据">
 					<uni-tr class="table-title">
-						<uni-th align="center">产品编码</uni-th>
+						<uni-th align="center" width="100">产品编码</uni-th>
 						<uni-th align="center">名称</uni-th>
-						<uni-th align="center">销量</uni-th>
+						<uni-th align="center" width="100">销量</uni-th>
 					</uni-tr>
-					<uni-tr v-for="(item, index) in 4" :key="index">
-						<uni-td>1.cp1001</uni-td>
-						<uni-td>产品名称</uni-td>
-						<uni-td align="center">5000(pcs)</uni-td>
+					<uni-tr v-for="(item, index) in tableData" :key="index">
+						<uni-td>{{index+1}}.{{item.productCode}}</uni-td>
+						<uni-td>{{item.productName}}</uni-td>
+						<uni-td align="center">{{item.totalSaleCount}}</uni-td>
 					</uni-tr>
-				</uni-table>
+				</uni-table> -->
+
+				<view class="table-title" style="text-align: center;">
+					<view class="code">产品编码</view>
+					<view class="name">名称</view>
+					<view class="total">销量</view>
+				</view>
+				<view class="table-content" v-for="(item,index) in tableData">
+					<view class="code">
+						<view class="index">{{index+1}}.</view>
+						<view class="value">{{item.productCode}}</view>
+
+					</view>
+					<view class="name">{{item.productName}}</view>
+					<view class="total">{{item.totalSaleCount}}</view>
+				</view>
+
+
 
 			</view>
 
@@ -104,7 +121,7 @@
 			<view class="data-bottom">
 				<view class="cell">
 					<view class="num">
-						28
+						{{this.homeData.yearProduceAmount}}
 					</view>
 					<view class="label">
 						年度生产总量
@@ -113,7 +130,7 @@
 
 				<view class="cell">
 					<view class="num">
-						28
+						{{this.homeData.monthProduceAmount}}
 					</view>
 					<view class="label">
 						月生产总量
@@ -122,18 +139,13 @@
 
 				<view class="cell">
 					<view class="num">
-						28
+						{{homeData.pendingAmount}}
 					</view>
 					<view class="label">
 						待生产总量
 					</view>
 				</view>
 
-
-
-
-
-
 			</view>
 
 
@@ -155,6 +167,10 @@
 	import mould from './pages/mould/mould.vue'
 	import sparePart from './pages/sparePart/sparePart.vue'
 	import ScanCode from '@/components/ScanCode.vue'
+
+	import {
+		getDateNew
+	} from '@/utils/utils.js'
 	import {
 		postJ,
 		post,
@@ -168,7 +184,10 @@
 		getYearAmount,
 		getPayableAmount,
 		getReceivableAmount,
-		getGoodsPage
+		getGoodsPage,
+		getProduceAmount,
+		// getPendingAmount,
+		getHotProduct
 	}
 	from '@/api/home'
 	export default {
@@ -233,8 +252,13 @@
 					goodsCount: '',
 					yearAmount: '',
 					receivableAmount: '',
-					payableAmount: ''
-				}
+					payableAmount: '',
+					yearProduceAmount: '',
+					monthProduceAmount: '',
+					pendingAmount: ''
+				},
+				hotProductList: [],
+
 			}
 		},
 		created() {
@@ -343,25 +367,66 @@
 			// 切换排行版tab
 			handleTabChange(item) {
 				this.activeIndex = item.index
+				this.tableData
 				// console.log(item);
 			},
 			async getHomeData() {
+				uni.showLoading({
+					title: '加载中'
+				})
+
+				let params = {
+					startDate: '',
+					endDate: '',
+					factoriesId: 0
+				}
+				let nowYear = getDateNew('year') + '-01-01'
+				let nowMonth = getDateNew('month') + '-01'
+				let now = getDateNew()
+				console.log(now, nowYear, nowMonth);
+				params.endDate = now
+
+
+
+
+
 				const res1 = await getCount()
 				const res2 = await getGoodsPage()
 				const res3 = await getYearAmount()
 				const res4 = await getReceivableAmount()
 				const res5 = await getPayableAmount()
-				
-				console.log(res3);
+				const res6 = await getProduceAmount({
+					...params,
+					startDate: nowYear
+				})
+				const res7 = await getProduceAmount({
+					...params,
+					startDate: nowMonth
+				})
+
+
+				const res9 = await getHotProduct()
 
 
-				this.homeData.totalFinishedProducts = res1.totalFinishedProducts
-				this.homeData.totalRawMaterials = res1.totalRawMaterials
-				this.homeData.goodsCount = res2.count
-				this.homeData.yearAmount =  (res3/10000).toFixed(2)
-				this.homeData.receivableAmount = res4
-				this.homeData.payableAmount = res5
+				this.homeData.totalFinishedProducts = res1?.totalFinishedProducts ?? 0
+				this.homeData.totalRawMaterials = res1?.totalRawMaterials ?? 0
+				this.homeData.goodsCount = res2?.count ?? 0
+				this.homeData.yearAmount = (res3 / 10000).toFixed(2)
+				this.homeData.receivableAmount = res4 ?? 0
+				this.homeData.payableAmount = res5 ?? 0
+				this.homeData.yearProduceAmount = res6?.reduce((pre, cur) => {
+					return pre + cur?.formedNum
+				}, 0) ?? 0
 
+				this.homeData.monthProduceAmount = res7?.reduce((pre, cur) => {
+					return pre + cur?.formedNum
+				}, 0) ?? 0
+				this.homeData.pendingAmount = res6?.reduce((pre, cur) => {
+					return pre + cur?.pendingProductionCount
+				}, 0) ?? 0
+				this.hotProductList = res9
+				this.tableData = this.hotProductList.slice(0, 4)
+				uni.hideLoading()
 
 			}
 
@@ -380,6 +445,7 @@
 	}
 
 	.container {
+		background-color: $page-bg;
 		padding: 20rpx;
 
 		.data-middle {
@@ -404,7 +470,6 @@
 				}
 
 				.label {
-
 					font-size: 20rpx;
 				}
 			}
@@ -420,6 +485,7 @@
 
 			.tab-top {
 				display: flex;
+				margin-bottom: 20rpx;
 
 				.tab-item {
 					margin-right: 20rpx;
@@ -430,20 +496,93 @@
 				}
 			}
 
-			.table {
-				.table-title {
-					/deep/ .uni-table-th {
-						font-size: 26rpx;
-						font-weight: 400;
-						color: #000;
+
+			.table-title {
+				width: 100%;
+				display: flex;
+				color: #333;
+				flex-wrap: nowrap;
+				justify-content: space-between;
+
+				.code {
+					width: 40%;
+					word-break: normal
+				}
+
+				.name {
+					width: 40%;
+					word-break: normal
+				}
+
+				.total {
+					width: 15%;
+					word-break: normal
+				}
+
+			}
+
+			.table-content {
+				display: flex;
+				padding: 10rpx 0;
+				width: 100%;
+				color: #333;
+				flex-wrap: nowrap;
+				justify-content: space-between;
+				border-bottom: 1px solid #eee;
+
+
+				.code {
+					display: flex;
+					width: 40%;
+
+					.index {
+						width: 20rpx;
+						margin-right: 20rpx;
+					}
+
+					.value {
+						word-break: break-all;
+						flex: 1;
 					}
+				}
 
+				.name {
+					width: 40%;
+					white-space: nowarp;
+					over-flow: hidden;
+					text-overflow: ellipsip;
+				}
+
+				.total {
+					text-align: center;
+					width: 15%;
+					white-space: nowarp;
+					over-flow: hidden;
+					text-overflow: ellipsip;
 				}
 			}
 
 
+
+
+			.table {
+				// .table-title {
+				// 	/deep/ .uni-table-th {
+				// 		font-size: 26rpx;
+				// 		font-weight: 400;
+				// 		color: #000;
+				// 	}
+				// }
+
+
+			}
+
+
 		}
 
+		.data-rank .table-content:last-child {
+			border-bottom: none;
+		}
 
 		.data-bottom {
 			display: flex;

+ 168 - 146
utils/utils.js

@@ -13,169 +13,191 @@ export function getDate(type) {
 	return `${year}-${month}-${day}`;
 }
 
-export function stopScroll(){
-	  var box=function(e)
-	  {passive: false ;};
-	  document.body.style.overflow='hidden';
-	  document.addEventListener("touchmove",box,false);
+export function getDateNew(type = 'day') {
+	const date = new Date();
+	let year = date.getFullYear();
+	let month = date.getMonth() + 1;
+	let day = date.getDate();
+
+	if (type === 'end') {
+		day = day + 1;
+	}
+	month = month > 9 ? month : '0' + month;
+	day = day > 9 ? day : '0' + day;
+	if (type === 'year') return `${year}`
+	if (type === 'month') return `${year}-${month}`
+
+	return `${year}-${month}-${day}`;
 }
 
-export function startScroll(){
-	 var box=function(e){passive: false };
- 	 document.body.style.overflow='';//出现滚动条
-	 document.removeEventListener("touchmove",box,false);
+export function stopScroll() {
+	var box = function(e) {
+		passive: false;
+	};
+	document.body.style.overflow = 'hidden';
+	document.addEventListener("touchmove", box, false);
+}
+
+export function startScroll() {
+	var box = function(e) {
+		passive: false
+	};
+	document.body.style.overflow = ''; //出现滚动条
+	document.removeEventListener("touchmove", box, false);
 }
 // 生成随机数
 export const getRuleNo = (suffix = 'R') => {
 	const randomNum = Math.floor(Math.random() * 1000000)
-  
+
 	return `${suffix}${parseTime(new Date(), '{y}{m}{d}')}${randomNum}`
-  }
-export function parseTime (time, cFormat) {
+}
+export function parseTime(time, cFormat) {
 	if (arguments.length === 0 || !time) {
-	  return null
+		return null
 	}
 	const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
 	let date
 	if (typeof time === 'object') {
-	  date = time
+		date = time
 	} else {
-	  if (typeof time === 'string') {
-		if (/^[0-9]+$/.test(time)) {
-		  // support "1548221490638"
-		  time = parseInt(time)
-		} else {
-		  // support safari
-		  // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
-		  time = time.replace(new RegExp(/-/gm), '/')
+		if (typeof time === 'string') {
+			if (/^[0-9]+$/.test(time)) {
+				// support "1548221490638"
+				time = parseInt(time)
+			} else {
+				// support safari
+				// https://stackoverflow.com/questions/4310953/invalid-date-in-safari
+				time = time.replace(new RegExp(/-/gm), '/')
+			}
 		}
-	  }
-  
-	  if (typeof time === 'number' && time.toString().length === 10) {
-		time = time * 1000
-	  }
-	  date = new Date(time)
+
+		if (typeof time === 'number' && time.toString().length === 10) {
+			time = time * 1000
+		}
+		date = new Date(time)
 	}
 	const formatObj = {
-	  y: date.getFullYear(),
-	  m: date.getMonth() + 1,
-	  d: date.getDate(),
-	  h: date.getHours(),
-	  i: date.getMinutes(),
-	  s: date.getSeconds(),
-	  a: date.getDay()
+		y: date.getFullYear(),
+		m: date.getMonth() + 1,
+		d: date.getDate(),
+		h: date.getHours(),
+		i: date.getMinutes(),
+		s: date.getSeconds(),
+		a: date.getDay()
 	}
 	const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
-	  const value = formatObj[key]
-	  // Note: getDay() returns 0 on Sunday
-	  if (key === 'a') {
-		return ['日', '一', '二', '三', '四', '五', '六'][value]
-	  }
-	  return value.toString().padStart(2, '0')
+		const value = formatObj[key]
+		// Note: getDay() returns 0 on Sunday
+		if (key === 'a') {
+			return ['日', '一', '二', '三', '四', '五', '六'][value]
+		}
+		return value.toString().padStart(2, '0')
 	})
 	return time_str
-  }
-  
-  /**
-   * 将毫秒,转换成时间字符串。例如说,xx 分钟
-   *
-   * @param ms 毫秒
-   * @returns {string} 字符串
-   */
-  export function getDates(ms) {
-    const day = Math.floor(ms / (24 * 60 * 60 * 1000));
-    const hour =  Math.floor((ms / (60 * 60 * 1000) - day * 24));
-    const minute =  Math.floor(((ms / (60 * 1000)) - day * 24 * 60 - hour * 60));
-    const second =  Math.floor((ms / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60));
-    if (day > 0) {
-      return day + "天" + hour + "小时" + minute + "分钟";
-    }
-    if (hour > 0) {
-      return hour + "小时" + minute + "分钟";
-    }
-    if (minute > 0) {
-      return minute + "分钟";
-    }
-    if (second > 0) {
-      return second + "秒";
-    } else {
-      return 0 + "秒";
-    }
-  }
-  //机构一维数组转树形结构
-  export function toTreeData(option) {
-    var _a, _b;
-    if (Array.isArray(option)) {
-      option = {
-        data: arguments[0],
-        idField: arguments[1],
-        parentIdField: arguments[2],
-        childrenField: arguments[3],
-        parentId: arguments[4],
-        addParentIds: arguments[5],
-        parentIdsField: arguments[6],
-        parentIds: arguments[7]
-      };
-    }
-    const data = option.data;
-    const idField = option.idField || option.idKey || "id";
-    const parentIdField = option.parentIdField || option.pidKey || "parentId";
-    const childrenField = option.childrenField || option.childKey || "children";
-    const parentIdIsNull = typeof option.parentId === "undefined" && typeof option.pid === "undefined";
-    const parentId = parentIdIsNull ? [] : (_a = option.parentId) != null ? _a : option.pid;
-    const addParentIds = (_b = option.addParentIds) != null ? _b : option.addPIds;
-    const parentIdsField = option.parentIdsField || option.parentsKey || "parentIds";
-    const parentIds = option.parentIds;
-    if (parentIdIsNull) {
-      data.forEach((d) => {
-        let flag = true;
-        for (let i = 0; i < data.length; i++) {
-          if (d[parentIdField] == data[i][idField]) {
-            flag = false;
-            break;
-          }
-        }
-        if (flag) {
-          parentId.push(d[parentIdField]);
-        }
-      });
-    }
-    const result = [];
-    data.forEach((d) => {
-      if (d[idField] == d[parentIdField]) {
-        throw new Error(
-          [
-            "data error: {",
-            idField + ": ",
-            JSON.stringify(d[idField]),
-            parentIdField + ": ",
-            JSON.stringify(d[parentIdField]),
-            "}"
-          ].join("")
-        );
-      }
-      const isArr = Array.isArray(parentId);
-      const isParent = isArr ? parentId.includes(d[parentIdField]) : d[parentIdField] == parentId;
-      if (isParent) {
-        const r = { ...d };
-        const children = toTreeData({
-          data,
-          idField,
-          parentIdField,
-          childrenField,
-          parentId: d[idField],
-          addParentIds,
-          parentIdsField,
-          parentIds: (parentIds != null ? parentIds : []).concat([d[idField]])
-        });
-        if (children.length > 0) {
-          r[childrenField] = children;
-        }
-        if (addParentIds) {
-          r[parentIdsField] = parentIds != null ? parentIds : [];
-        }
-        result.push(r);
-      }
-    });
-    return result;
-  }
+}
+
+/**
+ * 将毫秒,转换成时间字符串。例如说,xx 分钟
+ *
+ * @param ms 毫秒
+ * @returns {string} 字符串
+ */
+export function getDates(ms) {
+	const day = Math.floor(ms / (24 * 60 * 60 * 1000));
+	const hour = Math.floor((ms / (60 * 60 * 1000) - day * 24));
+	const minute = Math.floor(((ms / (60 * 1000)) - day * 24 * 60 - hour * 60));
+	const second = Math.floor((ms / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60));
+	if (day > 0) {
+		return day + "天" + hour + "小时" + minute + "分钟";
+	}
+	if (hour > 0) {
+		return hour + "小时" + minute + "分钟";
+	}
+	if (minute > 0) {
+		return minute + "分钟";
+	}
+	if (second > 0) {
+		return second + "秒";
+	} else {
+		return 0 + "秒";
+	}
+}
+//机构一维数组转树形结构
+export function toTreeData(option) {
+	var _a, _b;
+	if (Array.isArray(option)) {
+		option = {
+			data: arguments[0],
+			idField: arguments[1],
+			parentIdField: arguments[2],
+			childrenField: arguments[3],
+			parentId: arguments[4],
+			addParentIds: arguments[5],
+			parentIdsField: arguments[6],
+			parentIds: arguments[7]
+		};
+	}
+	const data = option.data;
+	const idField = option.idField || option.idKey || "id";
+	const parentIdField = option.parentIdField || option.pidKey || "parentId";
+	const childrenField = option.childrenField || option.childKey || "children";
+	const parentIdIsNull = typeof option.parentId === "undefined" && typeof option.pid === "undefined";
+	const parentId = parentIdIsNull ? [] : (_a = option.parentId) != null ? _a : option.pid;
+	const addParentIds = (_b = option.addParentIds) != null ? _b : option.addPIds;
+	const parentIdsField = option.parentIdsField || option.parentsKey || "parentIds";
+	const parentIds = option.parentIds;
+	if (parentIdIsNull) {
+		data.forEach((d) => {
+			let flag = true;
+			for (let i = 0; i < data.length; i++) {
+				if (d[parentIdField] == data[i][idField]) {
+					flag = false;
+					break;
+				}
+			}
+			if (flag) {
+				parentId.push(d[parentIdField]);
+			}
+		});
+	}
+	const result = [];
+	data.forEach((d) => {
+		if (d[idField] == d[parentIdField]) {
+			throw new Error(
+				[
+					"data error: {",
+					idField + ": ",
+					JSON.stringify(d[idField]),
+					parentIdField + ": ",
+					JSON.stringify(d[parentIdField]),
+					"}"
+				].join("")
+			);
+		}
+		const isArr = Array.isArray(parentId);
+		const isParent = isArr ? parentId.includes(d[parentIdField]) : d[parentIdField] == parentId;
+		if (isParent) {
+			const r = {
+				...d
+			};
+			const children = toTreeData({
+				data,
+				idField,
+				parentIdField,
+				childrenField,
+				parentId: d[idField],
+				addParentIds,
+				parentIdsField,
+				parentIds: (parentIds != null ? parentIds : []).concat([d[idField]])
+			});
+			if (children.length > 0) {
+				r[childrenField] = children;
+			}
+			if (addParentIds) {
+				r[parentIdsField] = parentIds != null ? parentIds : [];
+			}
+			result.push(r);
+		}
+	});
+	return result;
+}