数据源定义

This commit is contained in:
郑茂强 2018-10-17 10:33:04 +08:00
parent fb34e26c3f
commit 00e8253c33
2 changed files with 269 additions and 5 deletions

View File

@ -0,0 +1,180 @@
const data = {
orderNo: "101808023922",
clientName: "SongQingyang3",
soldDate: "2018-08-23",
contactName: "K01",
contactNo: "12345678901",
deliveryAddress: "D01",
addOn: "测试PTP-G刀偏置",
boards: [
{
id: 1234,
material: "颗粒板",
color: "暖白",
boardInfos: [
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478862",
boardName: "背板",
length: 944,
width: 59,
thickness: 18,
quantity: 10,
area: 0.568,
mutation: "",
shape: "",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "1"
},
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478862",
boardName: "层板",
length: 944,
width: 598,
thickness: 18,
quantity: 1,
area: 0.568,
mutation: "",
shape: "造型",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "2"
},
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478875",
boardName: "右侧板",
length: 1198,
width: 548,
thickness: 18,
quantity: 1,
area: 0.66,
mutation: "",
shape: "造型",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "3"
}
]
},
{
id: 1235,
material: "生态板 ",
color: "暖黑",
boardInfos: [
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478862",
boardName: "背板",
length: 944,
width: 598,
thickness: 18,
quantity: 1,
area: 0.568,
mutation: "",
shape: "",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "4"
},
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478861",
boardName: "背板",
length: 944,
width: 598,
thickness: 18,
quantity: 1,
area: 0.568,
mutation: "",
shape: "",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "5"
}
]
},
{
id: 1235,
material: "生态板 ",
color: "暖黑",
boardInfos: [
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478862",
boardName: "背板",
length: 944,
width: 59,
thickness: 18,
quantity: 10,
area: 0.568,
mutation: "",
shape: "",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "1"
},
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478862",
boardName: "背板",
length: 944,
width: 59,
thickness: 18,
quantity: 10,
area: 0.568,
mutation: "",
shape: "",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "1"
},
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478862",
boardName: "背板",
length: 944,
width: 598,
thickness: 18,
quantity: 1,
area: 0.568,
mutation: "",
shape: "",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "4"
},
{
houseName: "F01",
closetName: "G01",
boardNo: "B1816478861",
boardName: "背板",
length: 944,
width: 598,
thickness: 18,
quantity: 1,
area: 0.568,
mutation: "",
shape: "",
direction: "1/1/1/1 ",
stripe: "正纹",
boardAddOn: "5"
}
]
}
]
};
export default data;

View File

@ -85,16 +85,100 @@ class ControlPanel {
}
// 数据源类
class DataResource {
data: OrderDetails;
constructor(inputdata: OrderDetails) {
this.data = inputdata;
data: OrderDetailsFormat;
constructor(orderDetails: OrderDetailsFormat) {
this.data = orderDetails;
}
getOrderNo() {
return this.data.orderNo;
}
getClientName() {
return this.data.clientName;
}
getSoldDate() {
return this.data.soldDate;
}
getContactName() {
return this.data.contactName;
}
getContactNo() {
return this.data.contactNo;
}
getDeliveryAddress() {
return this.data.deliveryAddress;
}
getAddOn() {
return this.data.addOn;
}
getBoards() {
return this.data.boards;
}
getBoardMaterial() {
const BoardMaterial = [];
for (let item of this.data.boards) {
BoardMaterial.push(item.material);
}
return BoardMaterial; // BoardMaterial=['string', 'string']
}
getBoardColor() {
const BoardColor = [];
for (let item of this.data.boards) {
BoardColor.push(item.color);
}
return BoardColor; // BoardColor=['string', 'string']
}
getBoardInfo(key: string) {
const houseName = [];
for (const board of this.data.boards) {
const tem = [];
for (const boardInfo of board.boardInfos) {
if (Object.keys(boardInfo).indexOf(key) !== -1) {
tem.push(boardInfo[key]);
} else {
console.log("没有找到对应的key");
return;
}
}
houseName.push(tem);
}
return houseName; // 返回数据结构hosueName=[['string||number''string||number'],[]]
}
getEachBanCaiToTal(boardKey: string) {
const banCaiTotalArray = [];
for (const board of this.data.boards) {
let tem = 0;
for (const boardInfo of board.boardInfos) {
if (
Object.keys(boardInfo).indexOf(boardKey) !== -1 &&
typeof boardInfo[boardKey] === "number"
) {
tem += Number(boardInfo[boardKey]);
}
}
banCaiTotalArray.push(tem);
}
return banCaiTotalArray; // 返回数据类型 eg :banCaiTotal=[number,number,....]
}
getAllBanCaiTotal(boardKey: string) {
let banCaiTotal = 0;
for (const board of this.data.boards) {
for (const boardInfo of board.boardInfos) {
if (
Object.keys(boardInfo).indexOf(boardKey) !== -1 &&
typeof boardInfo[boardKey] === "number"
) {
banCaiTotal += Number(boardInfo[boardKey]);
}
}
}
return banCaiTotal; // 返回数据类型 eg :banCaiTotal:80
}
sortOutData() {}
}
// typescript 类型定义
interface OrderDetails {
interface OrderDetailsFormat {
[index: string]: string | object;
orderNo: string;
clientName: string;