|
@@ -116,11 +116,138 @@
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ uploadNewPresent() {
|
|
|
+ let that = this;
|
|
|
+ let imgURL = this.imgUrl;
|
|
|
+ let tag = this.tag;
|
|
|
+ let gender = this.gender;
|
|
|
+ let userId = localStorage.getItem("frontend-userid");
|
|
|
+ imgURL = '/' + imgURL.split('/')[3] + '/' + imgURL.split('/')[4] + '/' + imgURL.split('/')[5];
|
|
|
+ let present = [{
|
|
|
+ goodid: this.presentId,
|
|
|
+ name: this.presentName,
|
|
|
+ goodsNo: "0", modelId: "0",
|
|
|
+ ownerId: userId.toString(),
|
|
|
+ goodFirstKind: gender,
|
|
|
+ goodSecondKind: tag.toString(),
|
|
|
+ sellPrice: "0.0", marketPrice: "0.0", costPrice: "0.0",
|
|
|
+ upTime: getNowFormatDate(), downTime: getNowFormatDate(), createTime: getNowFormatDate(),
|
|
|
+ storeNums: "0",
|
|
|
+ img: imgURL,
|
|
|
+ isDel: "0", content: "none", keywords: "none",
|
|
|
+ description: that.desc,
|
|
|
+ searchWords: "", weight: "0.0", point: "0", unit: "0", brandId: "0",
|
|
|
+ visit: "0", favorite: "0", sort: "0", listImg: "xx.jpg",
|
|
|
+ smallImg: "xx.jpg", specArray: "{}", exp: "0"
|
|
|
+ }];
|
|
|
+ // console.log(present);
|
|
|
+ let url = "updateBatch";
|
|
|
+ if (that.presentId === '') url = "saveBatch";
|
|
|
+ BasicFunction.get_data("smartGoods/" + url, function (response) {
|
|
|
+ // console.log("------ Data Rcvd in PresentReg --------");
|
|
|
+ // console.log(response);
|
|
|
+ if (response.ret === "10000") {
|
|
|
+ Toast.success('上传成功!');
|
|
|
+ that.$router.push('share');
|
|
|
+ } else {
|
|
|
+ Toast.fail("上传失败,请检查网络");
|
|
|
+ that.loading = false;
|
|
|
+ }
|
|
|
+ }, present);
|
|
|
+ },
|
|
|
+ compressImg: function () {
|
|
|
+ let that = this;
|
|
|
+ let fileObj = this.photo;
|
|
|
+ photoCompress(fileObj, {
|
|
|
+ quality: 0.2
|
|
|
+ }, function (base64Codes) {
|
|
|
+ let formData = new FormData();
|
|
|
+ //console.log("压缩后:" + base.length / 1024 + " " + base);
|
|
|
+ var bl = convertBase64UrlToBlob(base64Codes);
|
|
|
+ // formData.append('file', fileObj);
|
|
|
+ console.log(fileObj);
|
|
|
+ formData.append("file", bl); // 文件对象
|
|
|
+ console.log(bl);
|
|
|
+ console.log("file_" + Date.parse(new Date()) + ".jpg");
|
|
|
+ that.updateUploadPresent(formData);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ saveOrUpdateGift: function (present) {
|
|
|
+ let that = this;
|
|
|
+ let url = "updateBatch";
|
|
|
+ if (that.presentId == undefined || that.presentId == null || that.presentId === '') url = "saveBatch";
|
|
|
+ BasicFunction.get_data("smartGoods/" + url, function (response) {
|
|
|
+ // console.log("------ Data Rcvd in PresentReg --------");
|
|
|
+ // console.log(response);
|
|
|
+ if (response.ret === "10000") {
|
|
|
+ Toast.success('上传成功!');
|
|
|
+ that.$router.push('share');
|
|
|
+ } else {
|
|
|
+ Toast.fail("上传失败,请检查网络");
|
|
|
+ that.loading = false;
|
|
|
+ }
|
|
|
+ }, present);
|
|
|
+ }, updateUploadPresent: function (formData) {
|
|
|
+ let that = this;
|
|
|
+ let tag = this.tag;
|
|
|
+ let gender = this.gender;
|
|
|
+ let userId = localStorage.getItem("frontend-userid");
|
|
|
+ BasicFunction.get_data("fileserver/upload?sign=abcdefg", function (res) {
|
|
|
+ try {
|
|
|
+ let imgURL = res.model;
|
|
|
+ if (res.ret === '10000' && res.model != undefined && imgURL.length > 0) {
|
|
|
+ // console.log('img:' + imgURL);
|
|
|
+ let present = [{
|
|
|
+ goodid: that.presentId,
|
|
|
+ name: that.presentName,
|
|
|
+ goodsNo: "0",
|
|
|
+ modelId: "0",
|
|
|
+ ownerId: userId.toString(),
|
|
|
+ goodFirstKind: gender,
|
|
|
+ goodSecondKind: tag.toString(),
|
|
|
+ sellPrice: "0.0",
|
|
|
+ marketPrice: "0.0",
|
|
|
+ costPrice: "0.0",
|
|
|
+ upTime: getNowFormatDate(),
|
|
|
+ downTime: getNowFormatDate(),
|
|
|
+ createTime: getNowFormatDate(),
|
|
|
+ storeNums: "0",
|
|
|
+ img: imgURL,
|
|
|
+ isDel: "0",
|
|
|
+ content: "none",
|
|
|
+ keywords: "none",
|
|
|
+ description: that.desc,
|
|
|
+ searchWords: "",
|
|
|
+ weight: "0.0",
|
|
|
+ point: "0",
|
|
|
+ unit: "0",
|
|
|
+ brandId: "0",
|
|
|
+ visit: "0",
|
|
|
+ favorite: "0",
|
|
|
+ sort: "0",
|
|
|
+ listImg: "xx.jpg",
|
|
|
+ smallImg: "xx.jpg",
|
|
|
+ specArray: "{}",
|
|
|
+ exp: "0"
|
|
|
+ }];
|
|
|
+ that.saveOrUpdateGift(present);
|
|
|
+ } else {
|
|
|
+ Toast.fail('上传图片失败,请检查网络');
|
|
|
+ that.loading = false;
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.warn(e);
|
|
|
+ Toast.fail('上传图片失败,请检查网络');
|
|
|
+ that.loading = false;
|
|
|
+ }
|
|
|
+ }, formData);
|
|
|
+ },
|
|
|
publishPresent() {
|
|
|
Toast.loading({
|
|
|
mask: true,
|
|
|
- message: '图片上传较慢,请耐心等待...',
|
|
|
- duration: 3000
|
|
|
+ message: '此过程大约需要15s,你的礼品正在拼命上传,请耐心等待...',
|
|
|
+ duration: 20000
|
|
|
});
|
|
|
this.loading = true;
|
|
|
// 检验输入
|
|
@@ -153,9 +280,6 @@
|
|
|
}
|
|
|
// 上传礼物信息
|
|
|
let userId = localStorage.getItem("frontend-userid");
|
|
|
- let tag = this.tag;
|
|
|
- let gender = this.gender;
|
|
|
-
|
|
|
// console.log('------- photo -------');
|
|
|
// console.log(this.photo);
|
|
|
if(userId == null || userId === undefined){
|
|
@@ -166,141 +290,16 @@
|
|
|
let that = this;
|
|
|
// 如果没有改变图片,直接上传
|
|
|
if (this.imgUrl && this.imgUrl === this.photo) {
|
|
|
- let imgURL = this.imgUrl;
|
|
|
- imgURL = '/' + imgURL.split('/')[3] + '/' + imgURL.split('/')[4] + '/' + imgURL.split('/')[5];
|
|
|
- let present = [{
|
|
|
- goodid: this.presentId,
|
|
|
- name: this.presentName,
|
|
|
- goodsNo: "0", modelId: "0",
|
|
|
- ownerId: userId.toString(),
|
|
|
- goodFirstKind: gender,
|
|
|
- goodSecondKind: tag.toString(),
|
|
|
- sellPrice: "0.0", marketPrice: "0.0", costPrice: "0.0",
|
|
|
- upTime: getNowFormatDate(), downTime: getNowFormatDate(), createTime: getNowFormatDate(),
|
|
|
- storeNums: "0",
|
|
|
- img: imgURL,
|
|
|
- isDel: "0", content: "none", keywords: "none",
|
|
|
- description: that.desc,
|
|
|
- searchWords: "", weight: "0.0", point: "0", unit: "0", brandId: "0",
|
|
|
- visit: "0", favorite: "0", sort: "0", listImg: "xx.jpg",
|
|
|
- smallImg: "xx.jpg", specArray: "{}", exp: "0"
|
|
|
- }];
|
|
|
- // console.log(present);
|
|
|
- let url = "updateBatch";
|
|
|
- if (that.presentId === '') url = "saveBatch";
|
|
|
- BasicFunction.get_data("smartGoods/" + url, function (response) {
|
|
|
- // console.log("------ Data Rcvd in PresentReg --------");
|
|
|
- // console.log(response);
|
|
|
- if (response.ret === "10000") {
|
|
|
- that.$router.push('share');
|
|
|
- } else {
|
|
|
- Toast.fail("上传失败,请检查网络");
|
|
|
- that.loading = false;
|
|
|
- }
|
|
|
- }, present);
|
|
|
- }
|
|
|
- else {
|
|
|
- let formData = new FormData();
|
|
|
- // formData.append('file', this.photo);
|
|
|
- let fileObj = this.photo;
|
|
|
-
|
|
|
- if (fileObj.size / 1024 > 1025) { //大于1M,进行压缩上传
|
|
|
- photoCompress(fileObj, {
|
|
|
- quality: 0.2
|
|
|
- }, function (base64Codes) {
|
|
|
- //console.log("压缩后:" + base.length / 1024 + " " + base);
|
|
|
- var bl = convertBase64UrlToBlob(base64Codes);
|
|
|
- // formData.append('file', fileObj);
|
|
|
- console.log(fileObj);
|
|
|
- formData.append("file", bl); // 文件对象
|
|
|
- console.log(bl);
|
|
|
- console.log("file_" + Date.parse(new Date()) + ".jpg");
|
|
|
- });
|
|
|
- } else { //小于等于1M 原图上传
|
|
|
- formData.append('file', this.photo);
|
|
|
- }
|
|
|
-
|
|
|
- // 先上传图片
|
|
|
- BasicFunction.get_data("fileserver/upload?sign=abcdefg", function (res) {
|
|
|
- // console.log('----- upload photo result -----');
|
|
|
- // console.log(res);
|
|
|
- // if (res.model === undefined || res.model.length === 0) {
|
|
|
- // Toast.fail('上传失败,请重试');
|
|
|
- // return;
|
|
|
- // }
|
|
|
- try {
|
|
|
- let imgURL = res.model;
|
|
|
- if (res.ret === '10000') {
|
|
|
- // console.log('img:' + imgURL);
|
|
|
- let present = [{
|
|
|
- goodid: that.presentId,
|
|
|
- name: that.presentName,
|
|
|
- goodsNo: "0",
|
|
|
- modelId: "0",
|
|
|
- ownerId: userId.toString(),
|
|
|
- goodFirstKind: gender,
|
|
|
- goodSecondKind: tag.toString(),
|
|
|
- sellPrice: "0.0",
|
|
|
- marketPrice: "0.0",
|
|
|
- costPrice: "0.0",
|
|
|
- upTime: getNowFormatDate(),
|
|
|
- downTime: getNowFormatDate(),
|
|
|
- createTime: getNowFormatDate(),
|
|
|
- storeNums: "0",
|
|
|
- img: imgURL,
|
|
|
- isDel: "0",
|
|
|
- content: "none",
|
|
|
- keywords: "none",
|
|
|
- description: that.desc,
|
|
|
- searchWords: "",
|
|
|
- weight: "0.0",
|
|
|
- point: "0",
|
|
|
- unit: "0",
|
|
|
- brandId: "0",
|
|
|
- visit: "0",
|
|
|
- favorite: "0",
|
|
|
- sort: "0",
|
|
|
- listImg: "xx.jpg",
|
|
|
- smallImg: "xx.jpg",
|
|
|
- specArray: "{}",
|
|
|
- exp: "0"
|
|
|
- }];
|
|
|
- // console.log(present);
|
|
|
- let url = "updateBatch";
|
|
|
- if (that.presentId === '') url = "saveBatch";
|
|
|
- BasicFunction.get_data("smartGoods/" + url, function (response) {
|
|
|
- // console.log("------ Data Rcvd in PresentReg --------");
|
|
|
- // console.log(response);
|
|
|
- if (response.ret === "10000") {
|
|
|
- that.$router.push('share');
|
|
|
- } else {
|
|
|
- Toast.fail("上传失败,请检查网络");
|
|
|
- that.loading = false;
|
|
|
- }
|
|
|
- }, present);
|
|
|
- } else {
|
|
|
- Toast.fail('上传图片失败,请检查网络');
|
|
|
- that.loading = false;
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- console.warn(e);
|
|
|
- Toast.fail('上传图片失败,请检查网络');
|
|
|
- that.loading = false;
|
|
|
- }
|
|
|
- }, formData);
|
|
|
+ that.uploadNewPresent();
|
|
|
+ } else {
|
|
|
+ that.compressImg();
|
|
|
}
|
|
|
},
|
|
|
onRead: function (e) {
|
|
|
this.photo = e;
|
|
|
- }
|
|
|
- },
|
|
|
- created: function () {
|
|
|
- if (!localStorage.getItem('frontend-userid')) {
|
|
|
- this.$router.push('login');
|
|
|
- return;
|
|
|
- }
|
|
|
- if(this.$route.query.present) {
|
|
|
- let present = this.$route.query.present;
|
|
|
+ },
|
|
|
+ onReadExisting(giftDo){
|
|
|
+ let present = giftDo;
|
|
|
// console.log('----- Present Info -----');
|
|
|
// console.log(present);
|
|
|
this.presentId = present.id;
|
|
@@ -311,6 +310,33 @@
|
|
|
this.imgUrl = present.imgUrl;
|
|
|
this.photo = present.imgUrl;
|
|
|
}
|
|
|
+ },
|
|
|
+ created: function () {
|
|
|
+ if (!localStorage.getItem('frontend-userid')) {
|
|
|
+ this.$router.push('login');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let presentId = this.$route.query.presentId;
|
|
|
+ if(presentId == null || presentId == undefined){
|
|
|
+ presentId = BasicFunction.utils_get_parm("presentId");
|
|
|
+ }
|
|
|
+ if(presentId == undefined || presentId == null){
|
|
|
+ Toast.fail('请重新进入礼物页哦');
|
|
|
+ this.$router.push('index');
|
|
|
+ }
|
|
|
+
|
|
|
+ let that = this;
|
|
|
+ BasicFunction.get_data('smartGoods/list?goodId=' + presentId, function (res) {
|
|
|
+ if (res.ret === '10000') {
|
|
|
+ if(res.model === undefined || res.model == null || res.model.list == undefined || res.model.list.length <= 0){
|
|
|
+ Toast.fail('礼物查看遇到问题,请稍等一下再试吧');
|
|
|
+ that.$router.push('index');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ that.giftDo = res.model.list[0];
|
|
|
+ that.onReadExisting(that.giftDo);
|
|
|
+ }
|
|
|
+ }, {});
|
|
|
}
|
|
|
}
|
|
|
|