This commit is contained in:
lq 2024-07-31 11:33:50 +08:00
parent 6dec2f7a4b
commit a16e07098f

View File

@ -541,6 +541,8 @@ export default {
id: 0,
code: '',
flag: false,
changeFlag:false,
newValue:'',
options: {
margins: [100, 120, 100, 120],
watermark: {
@ -587,14 +589,15 @@ export default {
// PDF
const blob = pdf.output("blob")
this.uploadFile(blob)
pdf.save(pdfName + '.pdf')
//pdf.save(pdfName + '.pdf')
},
uploadFile(blob) {
const formData = new FormData()
//formData.append('file', blob, 'myPDF.pdf')
let api = '/api/Administrator/file/upload'
formData.append('files', blob, 'myPDF.pdf');
let api = '/api/Administrator/file/uploadPdf'
formData.append('file', blob, 'myPDF.pdf');
formData.append('order_id', 'orderidadfadfdf')
formData.append('template_id', 14)
// 使fetch API
fetch(api, {
method: 'POST',
@ -687,7 +690,7 @@ export default {
login() {
//https://test.yqt.com/
let api = '/api/Administrator/Public/loginJson'
let api = '/api/Administrator/Public/login'
let param = { username: '15238311624', userpwd: '1624' }
let headers = {
@ -699,7 +702,7 @@ export default {
},
getApiField() {
//let api = '/api/Administrator/ProductColConfig/getUserConfig'
let api = '/api//Administrator/PrintTemplate/getUserConfig?type=1'
let api = '/api/Administrator/PrintTemplate/getUserConfig?type=1'
axios.get(api).then(res => {
//let field = res.data
let fieldArr = res.data.data.col_config
@ -709,7 +712,7 @@ export default {
let showObj = {}
//console.log(fieldArr)
for(let i = 0; i < fieldArr.length; i++) {
for (let i = 0; i < fieldArr.length; i++) {
let key = fieldArr[i].field
fieldObj[key] = fieldArr[i].name
nameField[fieldArr[i].name] = key
@ -719,7 +722,7 @@ export default {
let searchNameField = {}
let searchField = {}
for(let i = 0; i < fieldheader.length; i++) {
for (let i = 0; i < fieldheader.length; i++) {
let key = fieldheader[i].field
searchField[key] = fieldheader[i].name
searchNameField[fieldheader[i].name] = key
@ -823,7 +826,7 @@ export default {
//str = str.replace(/&quot;/g, "'")
//console.log(str)
const ccc = this.instance.command.getValue()
console.log('ccc',ccc.data)
console.log('ccc', ccc.data)
const aaa = this.instance.command.getText()
if (aaa.main.indexOf('{') == -1) {
ElMessage({
@ -930,19 +933,22 @@ export default {
return value
}
let end = value.indexOf('}')
if(end == -1) return value
if (end == -1) return value
let fieldKey = value.substring(start + 1, end)
let field = this.searchNameField[fieldKey]
console.log(field,fieldKey, this.searchNameField)
let newValue = ''
if (field == undefined) {
field = this.nameField[fieldKey]
newValue = this.getFieldValues(field)
} else {
newValue = this.searchList[field]
}
if(field == 'capitalization') {
newValue = this.convertCurrency(this.newValue)
}
value = value.replace('{' + fieldKey + '}', newValue)
this.newValue = newValue
return this.replaceData(value)
},
chkTdList(tdList) {
@ -972,6 +978,54 @@ export default {
}
return trList
},
convertCurrency(money) {
//
var cnNums = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
// 119
var cnIntUnits = ["", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟", "个"];
//
var cnDecUnits = ["角", "分", "厘", "厘"];
//
money = money.toString();
//
var intPart = money.split(".")[0];
var decPart = money.split(".")[1];
var intLen = intPart.length;
//
var outputCharacters = "";
var zeroCount = 0;
for (var i = 0; i < intLen; i++) {
var n = intPart.charAt(i) - "0";
if (n === 0) {
zeroCount++;
} else {
if (zeroCount > 0) {
outputCharacters += cnNums[0];
}
zeroCount = 0;
outputCharacters += cnNums[n] + cnIntUnits[intLen - i - 1];
}
}
//
var decLen = decPart.length;
for (var j = 0; j < decLen; j++) {
n = decPart.charAt(j) - "0";
if (n !== 0) {
outputCharacters += cnNums[n] + cnDecUnits[j];
}
}
if (zeroCount < intLen) {
outputCharacters += cnIntUnits[intLen - zeroCount];
}
// 0
if (intPart === "0") {
//outputCharacters = cnNums[0] + cnIntUnits[0];
}
//
return outputCharacters;
},
fillData(data) {
let config = JSON.parse(data)
let res = []
@ -1002,6 +1056,10 @@ export default {
}
trListItem.tdList = []
for (let k = 0; k < this.orderData.length; k++) {
if(this.changeFlag == true) {
this.changeFlag = false
break
}
let tempTdList = []
let order = this.orderData[k]
let hasMergeTable = false
@ -1035,6 +1093,10 @@ export default {
}
let tempItem = this.handlerTdListItem(tdListItem, order)
if(this.changeFlag) {
tempItem = this.tableToHeader(tdListItem)
}
//console.log(tempItem)
/* let tdValue = tdListItem.value[0].value
let newValue = this.getFieldValue(tdValue, order)
let tempItem = { 'value': newValue, 'size': tdListItem.value[0].size }
@ -1065,7 +1127,7 @@ export default {
} else {
let value = configItem.value
console.log(value);
//.log(value);
configItem.value = this.replaceData(value)
res.push(configItem)
}
@ -1085,15 +1147,34 @@ export default {
}
return list
},
tableToHeader(tdItem) {
let list = JSON.stringify(tdItem)
list = JSON.parse(list)
for (let i = 0; i < list['value'].length; i++) {
let item = list['value'][i];
let tdValue = item['value']
let newValue = this.replaceData(tdValue)
item['value'] = newValue
}
return list
},
getFieldValue(value, orderData) {
if (value == '') return ''
let start = value.indexOf('{')
if (start != -1) {
let end = value.indexOf('}')
if(end == -1) return value
if (end == -1) return value
let keyStr = value.substring(start + 1, end)
let fieldKey = this.nameField[keyStr]
value = value.replace('{' + keyStr + '}', orderData[fieldKey])
if(fieldKey == undefined) {
this.changeFlag = true
}
if(fieldKey == 'capitalization') {
value = value.replace('{' + keyStr + '}', this.convertCurrency(this.newValue))
}else{
value = value.replace('{' + keyStr + '}', orderData[fieldKey])
this.newValue = orderData[fieldKey]
}
return this.getFieldValue(value, orderData)
}
return value
@ -1107,7 +1188,7 @@ export default {
return false
}
let _this = this
let api = '/api/Administrator/PrintTemplate/getTemplate?id=1'
let api = '/api/Administrator/PrintTemplate/getTemplate?id=49'
axios.get(api).then((res) => {
res = JSON.parse(JSON.stringify(res))
let doc = {}