add code
This commit is contained in:
parent
6dec2f7a4b
commit
a16e07098f
113
src/App.vue
113
src/App.vue
|
@ -541,6 +541,8 @@ export default {
|
||||||
id: 0,
|
id: 0,
|
||||||
code: '',
|
code: '',
|
||||||
flag: false,
|
flag: false,
|
||||||
|
changeFlag:false,
|
||||||
|
newValue:'',
|
||||||
options: {
|
options: {
|
||||||
margins: [100, 120, 100, 120],
|
margins: [100, 120, 100, 120],
|
||||||
watermark: {
|
watermark: {
|
||||||
|
@ -587,14 +589,15 @@ export default {
|
||||||
// 保存生成的PDF
|
// 保存生成的PDF
|
||||||
const blob = pdf.output("blob")
|
const blob = pdf.output("blob")
|
||||||
this.uploadFile(blob)
|
this.uploadFile(blob)
|
||||||
pdf.save(pdfName + '.pdf')
|
//pdf.save(pdfName + '.pdf')
|
||||||
},
|
},
|
||||||
uploadFile(blob) {
|
uploadFile(blob) {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
//formData.append('file', blob, 'myPDF.pdf')
|
//formData.append('file', blob, 'myPDF.pdf')
|
||||||
let api = '/api/Administrator/file/upload'
|
let api = '/api/Administrator/file/uploadPdf'
|
||||||
formData.append('files', blob, 'myPDF.pdf');
|
formData.append('file', blob, 'myPDF.pdf');
|
||||||
|
formData.append('order_id', 'orderidadfadfdf')
|
||||||
|
formData.append('template_id', 14)
|
||||||
// 使用fetch API上传文件到服务器
|
// 使用fetch API上传文件到服务器
|
||||||
fetch(api, {
|
fetch(api, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -687,7 +690,7 @@ export default {
|
||||||
login() {
|
login() {
|
||||||
|
|
||||||
//https://test.yqt.com/
|
//https://test.yqt.com/
|
||||||
let api = '/api/Administrator/Public/loginJson'
|
let api = '/api/Administrator/Public/login'
|
||||||
|
|
||||||
let param = { username: '15238311624', userpwd: '1624' }
|
let param = { username: '15238311624', userpwd: '1624' }
|
||||||
let headers = {
|
let headers = {
|
||||||
|
@ -699,7 +702,7 @@ export default {
|
||||||
},
|
},
|
||||||
getApiField() {
|
getApiField() {
|
||||||
//let api = '/api/Administrator/ProductColConfig/getUserConfig'
|
//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 => {
|
axios.get(api).then(res => {
|
||||||
//let field = res.data
|
//let field = res.data
|
||||||
let fieldArr = res.data.data.col_config
|
let fieldArr = res.data.data.col_config
|
||||||
|
@ -709,7 +712,7 @@ export default {
|
||||||
let showObj = {}
|
let showObj = {}
|
||||||
|
|
||||||
//console.log(fieldArr)
|
//console.log(fieldArr)
|
||||||
for(let i = 0; i < fieldArr.length; i++) {
|
for (let i = 0; i < fieldArr.length; i++) {
|
||||||
let key = fieldArr[i].field
|
let key = fieldArr[i].field
|
||||||
fieldObj[key] = fieldArr[i].name
|
fieldObj[key] = fieldArr[i].name
|
||||||
nameField[fieldArr[i].name] = key
|
nameField[fieldArr[i].name] = key
|
||||||
|
@ -719,7 +722,7 @@ export default {
|
||||||
|
|
||||||
let searchNameField = {}
|
let searchNameField = {}
|
||||||
let searchField = {}
|
let searchField = {}
|
||||||
for(let i = 0; i < fieldheader.length; i++) {
|
for (let i = 0; i < fieldheader.length; i++) {
|
||||||
let key = fieldheader[i].field
|
let key = fieldheader[i].field
|
||||||
searchField[key] = fieldheader[i].name
|
searchField[key] = fieldheader[i].name
|
||||||
searchNameField[fieldheader[i].name] = key
|
searchNameField[fieldheader[i].name] = key
|
||||||
|
@ -823,7 +826,7 @@ export default {
|
||||||
//str = str.replace(/"/g, "'")
|
//str = str.replace(/"/g, "'")
|
||||||
//console.log(str)
|
//console.log(str)
|
||||||
const ccc = this.instance.command.getValue()
|
const ccc = this.instance.command.getValue()
|
||||||
console.log('ccc',ccc.data)
|
console.log('ccc', ccc.data)
|
||||||
const aaa = this.instance.command.getText()
|
const aaa = this.instance.command.getText()
|
||||||
if (aaa.main.indexOf('{') == -1) {
|
if (aaa.main.indexOf('{') == -1) {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
|
@ -930,19 +933,22 @@ export default {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
let end = value.indexOf('}')
|
let end = value.indexOf('}')
|
||||||
if(end == -1) return value
|
if (end == -1) return value
|
||||||
let fieldKey = value.substring(start + 1, end)
|
let fieldKey = value.substring(start + 1, end)
|
||||||
let field = this.searchNameField[fieldKey]
|
let field = this.searchNameField[fieldKey]
|
||||||
console.log(field,fieldKey, this.searchNameField)
|
|
||||||
let newValue = ''
|
let newValue = ''
|
||||||
if (field == undefined) {
|
if (field == undefined) {
|
||||||
field = this.nameField[fieldKey]
|
field = this.nameField[fieldKey]
|
||||||
|
|
||||||
newValue = this.getFieldValues(field)
|
newValue = this.getFieldValues(field)
|
||||||
} else {
|
} else {
|
||||||
newValue = this.searchList[field]
|
newValue = this.searchList[field]
|
||||||
}
|
}
|
||||||
|
if(field == 'capitalization') {
|
||||||
|
newValue = this.convertCurrency(this.newValue)
|
||||||
|
}
|
||||||
value = value.replace('{' + fieldKey + '}', newValue)
|
value = value.replace('{' + fieldKey + '}', newValue)
|
||||||
|
this.newValue = newValue
|
||||||
return this.replaceData(value)
|
return this.replaceData(value)
|
||||||
},
|
},
|
||||||
chkTdList(tdList) {
|
chkTdList(tdList) {
|
||||||
|
@ -972,6 +978,54 @@ export default {
|
||||||
}
|
}
|
||||||
return trList
|
return trList
|
||||||
},
|
},
|
||||||
|
convertCurrency(money) {
|
||||||
|
// 汉字的数字
|
||||||
|
var cnNums = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
|
||||||
|
// 整数部分整数1至19所对应的单位
|
||||||
|
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) {
|
fillData(data) {
|
||||||
let config = JSON.parse(data)
|
let config = JSON.parse(data)
|
||||||
let res = []
|
let res = []
|
||||||
|
@ -1002,6 +1056,10 @@ export default {
|
||||||
}
|
}
|
||||||
trListItem.tdList = []
|
trListItem.tdList = []
|
||||||
for (let k = 0; k < this.orderData.length; k++) {
|
for (let k = 0; k < this.orderData.length; k++) {
|
||||||
|
if(this.changeFlag == true) {
|
||||||
|
this.changeFlag = false
|
||||||
|
break
|
||||||
|
}
|
||||||
let tempTdList = []
|
let tempTdList = []
|
||||||
let order = this.orderData[k]
|
let order = this.orderData[k]
|
||||||
let hasMergeTable = false
|
let hasMergeTable = false
|
||||||
|
@ -1035,6 +1093,10 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
let tempItem = this.handlerTdListItem(tdListItem, order)
|
let tempItem = this.handlerTdListItem(tdListItem, order)
|
||||||
|
if(this.changeFlag) {
|
||||||
|
tempItem = this.tableToHeader(tdListItem)
|
||||||
|
}
|
||||||
|
//console.log(tempItem)
|
||||||
/* let tdValue = tdListItem.value[0].value
|
/* let tdValue = tdListItem.value[0].value
|
||||||
let newValue = this.getFieldValue(tdValue, order)
|
let newValue = this.getFieldValue(tdValue, order)
|
||||||
let tempItem = { 'value': newValue, 'size': tdListItem.value[0].size }
|
let tempItem = { 'value': newValue, 'size': tdListItem.value[0].size }
|
||||||
|
@ -1065,7 +1127,7 @@ export default {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let value = configItem.value
|
let value = configItem.value
|
||||||
console.log(value);
|
//.log(value);
|
||||||
configItem.value = this.replaceData(value)
|
configItem.value = this.replaceData(value)
|
||||||
res.push(configItem)
|
res.push(configItem)
|
||||||
}
|
}
|
||||||
|
@ -1085,15 +1147,34 @@ export default {
|
||||||
}
|
}
|
||||||
return list
|
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) {
|
getFieldValue(value, orderData) {
|
||||||
if (value == '') return ''
|
if (value == '') return ''
|
||||||
let start = value.indexOf('{')
|
let start = value.indexOf('{')
|
||||||
if (start != -1) {
|
if (start != -1) {
|
||||||
let end = value.indexOf('}')
|
let end = value.indexOf('}')
|
||||||
if(end == -1) return value
|
if (end == -1) return value
|
||||||
let keyStr = value.substring(start + 1, end)
|
let keyStr = value.substring(start + 1, end)
|
||||||
let fieldKey = this.nameField[keyStr]
|
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 this.getFieldValue(value, orderData)
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
|
@ -1107,7 +1188,7 @@ export default {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let _this = this
|
let _this = this
|
||||||
let api = '/api/Administrator/PrintTemplate/getTemplate?id=1'
|
let api = '/api/Administrator/PrintTemplate/getTemplate?id=49'
|
||||||
axios.get(api).then((res) => {
|
axios.get(api).then((res) => {
|
||||||
res = JSON.parse(JSON.stringify(res))
|
res = JSON.parse(JSON.stringify(res))
|
||||||
let doc = {}
|
let doc = {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user