You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
6.3 KiB
156 lines
6.3 KiB
!(function () { |
|
var Model = BI.inherit(Fix.Model, { |
|
state: function () { |
|
var o=this.options; |
|
return { |
|
items: [], |
|
connection: "", |
|
schema: "", |
|
tableName: "", |
|
excelItems: [], |
|
infoId: o.infoId, |
|
result: {attachId: "", fileName: "",titleRow:-1,sheetNo:-1}, |
|
sheetItems: {show: false, items: []}, |
|
importStatus: ""//导入的状态 |
|
}; |
|
}, |
|
|
|
childContext: ["items", "connection", "schema", "aliasName", "tableName", "excelItems", "infoId"], |
|
|
|
computed: {}, |
|
|
|
watch: { |
|
excelItems:function (v) { |
|
if (this.model.infoId == "add"){ |
|
this.addItems() |
|
} |
|
} |
|
}, |
|
|
|
actions: { |
|
initData: function (callback) { |
|
var self = this, o = this.options; |
|
|
|
if(self.model.infoId === "add"){ |
|
callback && callback(); |
|
return; |
|
} |
|
|
|
Dec.HW.queryData({ |
|
name: o.aliasName |
|
}, function (res) { |
|
self.model.items = BI.hwColTypeDeal(res.data.colAttr); |
|
self.model.connection = res.data.tableAttr.connection; |
|
self.model.schema = res.data.tableAttr.schema; |
|
self.model.tableName = res.data.tableAttr.tableName; |
|
BI.isFunction(callback) && callback(); |
|
}); |
|
}, |
|
getExcelSheetNumber: function (attachId, fileName) { |
|
var self = this; |
|
Dec.HW.getExcelItmes({attachId: attachId, fileName: fileName}, function (res) { |
|
if (res.success) { |
|
self.model.result.attachId = attachId; |
|
self.model.result.fileName = fileName; |
|
self.getSheetFiled(res.data); |
|
} else { |
|
self.model.importStatus="abort"; |
|
} |
|
}) |
|
}, |
|
getSheetFiled: function (data) { |
|
var self = this; |
|
if (data.length == 1) {//只有一个sheet 的话 就不让选择了直接 |
|
Dec.HW.getSheetFiled({ |
|
attachId: self.model.result.attachId, |
|
sheetNo: 0, |
|
fileName: self.model.result.fileName |
|
}); |
|
BI.Utils.getExcelData(self.model.result.attachId, { |
|
name: "", |
|
type: BICst.TABLE.EXCEL, |
|
excelFields: [], |
|
additionalAttach: [], |
|
transferName: "", |
|
reset: true |
|
}, function (res) { |
|
console.log(res); |
|
if (res.success) { |
|
var fields = res.data.fields; |
|
self.model.result.sheetNo = 0; |
|
self.model.result.titleRow = 0; |
|
self.model.excelItems = fields; |
|
|
|
// items 匹配相同的列名 |
|
BI.each(self.model.items, function (index, item) { |
|
var sameNameItem = BI.filter(self.model.excelItems, function (i, v) { |
|
return v.text == item.name |
|
}); |
|
if (sameNameItem.length != 0){ |
|
item.excelCol = sameNameItem[0].value; |
|
} |
|
}); |
|
|
|
self.model.importStatus="finish"; |
|
} else { |
|
self.model.importStatus="abort"; |
|
BI.Msg.toast(res.msg,{level:"error"}); |
|
} |
|
}); |
|
} else { |
|
self.model.sheetItems = {show: true, items: data}; |
|
} |
|
}, |
|
getSheetFiledWithNo: function (sheetNo, callback) { |
|
var self = this; |
|
Dec.HW.getSheetFiled({ |
|
attachId: self.model.result.attachId, |
|
sheetNo: sheetNo, |
|
fileName: self.model.result.fileName |
|
}, function (res) { |
|
if (res.success) { |
|
self.model.result.sheetNo=sheetNo; |
|
self.model.result.titleRow=res.data[0].titleRow; |
|
self.model.excelItems = res.data; |
|
|
|
// items 匹配相同的列名 |
|
BI.each(self.model.items, function (index, item) { |
|
var sameNameItem = BI.filter(self.model.excelItems, function (i, v) { |
|
return v.text == item.colName |
|
}); |
|
if (sameNameItem.length != 0){ |
|
item.excelCol = sameNameItem[0].value; |
|
} |
|
}); |
|
self.model.importStatus="finish"; |
|
callback && callback(true); |
|
} else { |
|
self.model.importStatus="abort"; |
|
BI.Msg.toast(res.msg,{level:"error"}); |
|
callback && callback(false); |
|
} |
|
}); |
|
}, |
|
setImportStatus:function (v) { |
|
this.model.importStatus=v; |
|
}, |
|
addItems:function () { |
|
var self = this; |
|
var result = BI.map(self.model.excelItems,function (index, item) { |
|
return { |
|
id:BI.UUID(), |
|
colName: item.name || item.colName, |
|
colType: item.type || 16, |
|
colLength: "10000", |
|
excelCol: index |
|
} |
|
}); |
|
|
|
console.log("excelAdd", self.model.items) |
|
self.model.items=BI.concat(self.model.items, result); |
|
console.log("excelAdd2", self.model.items) |
|
} |
|
} |
|
}); |
|
BI.model("dec.hw.table.info.model", Model); |
|
})();
|
|
|