city_card/packagecard/cardDetail/cardDetail.js
2023-07-18 16:54:17 +08:00

487 lines
15 KiB
JavaScript
Executable File

const app = getApp()
Page({
data: {
preview: '',
showHide: false,
isLoading: false,
isMain: '',
cardPersonId: '',
choose_index: 0,
active: 0,
cardUrl: app.baseUrls.baseCardUrl,
areaList: [],
cardInfo: {},
bgImg: '',
fontFamilyList: [],
useFontFamily: '',
cardId: '',
cardHeight: '',
shareTicket: '',
encryptedData: '',
iv: '',
isFromOut: false,
token: '',
oldToken: '',
fromMine: false,
imgTempSrc: '',
currentIndex: 0,
windowWidth: app.globalData.windowWidth,
scale: 1,
pageType: null
},
tabChange: function (e) {
this.setData({
active: e.detail
})
if (this.data.active == 0) {
} else if (this.data.active == 1) {
// 服务
if (app.globalData.servicePageType == 1) {
wx.redirectTo({
url: '/pages/shop/catalog/bannerlist/bannerlist',
})
} else if (app.globalData.servicePageType == 2) {
wx.redirectTo({
url: '/pages/shop/catalog/column/column',
})
} else if (app.globalData.servicePageType == 3) {
wx.redirectTo({
url: '/pages/shop/catalog/list/list',
})
} else if (app.globalData.servicePageType == 4) {
wx.redirectTo({
url: '/pages/shop/bespeak/bespeak',
})
}
} else {
//我的
wx.redirectTo({
url: '/pages/mine/index/index',
})
}
// this.setData({
// active: e.detail
// }), 0 == this.data.active || (1 == this.data.active ? 1 == app.globalData.servicePageType ? wx.redirectTo({
// url: "/pages/shop/catalog/bannerlist/bannerlist"
// }) : 2 == app.globalData.servicePageType ? wx.redirectTo({
// url: "/pages/shop/catalog/column/column"
// }) : 3 == app.globalData.servicePageType ? wx.redirectTo({
// url: "/pages/shop/catalog/list/list"
// }) : 4 == app.globalData.servicePageType && wx.redirectTo({
// url: "/pages/shop/bespeak/bespeak"
// }) : wx.redirectTo({
// url: "/pages/mine/index/index"
// }));
},
createMyCard: function () {
var self = this
wx.showLoading({
title: '生成中...',
success() {
self.setData({
isLoading: true
})
}
})
var content = {
pictureTemplateId: self.data.cardId,
cardTemplateUseAreaList: []
}
for (let i = 0; i < self.data.areaList.length; i++) {
if (self.data.areaList[i].templateAreaType != '1') {
var info = {
cardTemplateUseId: "",
picturesTemplateAreaId: self.data.areaList[i].picturesTemplateAreaId,
templateAreaFile: self.data.areaList[i].templateAreaFile,
templateAreaFontValue: self.data.areaList[i].templateAreaFontValue
}
content.cardTemplateUseAreaList.push(info)
}
}
app.http.post(app.urls.creatCard, {
data: content,
header: {
token: app.globalData.token
}
}).then(res => {
console.log(res)
// "200" == t.statusCode && e.getMineCardList();
if (res.statusCode == '200') {
self.getMineCardList();
}
}).catch(res => {
console.log(res)
self.setData({
isLoading: false,
showHide: false
})
})
// var e = this;
// wx.showLoading({
// title: "生成中...",
// success: function () {
// e.setData({
// isLoading: !0
// });
// }
// });
// for (var a = {
// pictureTemplateId: e.data.cardId,
// cardTemplateUseAreaList: []
// }, r = 0; r < e.data.areaList.length; r++) if ("1" != e.data.areaList[r].templateAreaType) {
// var o = {
// cardTemplateUseId: "",
// picturesTemplateAreaId: e.data.areaList[r].picturesTemplateAreaId,
// templateAreaFile: e.data.areaList[r].templateAreaFile,
// templateAreaFontValue: e.data.areaList[r].templateAreaFontValue
// };
// a.cardTemplateUseAreaList.push(o);
// }
// app.http.post(t.urls.creatCard, {
// data: a,
// header: {
// token: t.globalData.token
// }
// }).then(function (t) {
// console.log(t), "200" == t.statusCode && e.getMineCardList();
// }).catch(function (t) {
// e.setData({
// isLoading: !1,
// showHide: !1
// });
// });
},
getMineCardList: function () {
var e = this;
app.http.get(app.urls.getMyCard, {
header: {
token: app.globalData.token
},
data: {}
}).then(function (t) {
e.setData({
cardList: t.data
}), t.data.length > 0 && (e.setDefaultCard(t.data[0].cardTemplateUseId), console.log(e.data.pageType),
"org" == e.data.pageType ? e.saveOrgCard(t.data[0].cardTemplateUseId) : e.saveCardIdToSyzl(t.data[0].cardTemplateUseId));
}).catch(function (t) {
wx.hideLoading({}), e.setData({
isLoading: !1,
showHide: !1
});
});
},
saveCardIdToSyzl: function (e) {
console.log("设置网格员名片" + e);
var a = this;
app.restAjax.put(app.restAjax.path(app.apis.doUpdateCard, [app.baseUrls.requestUrl, a.data.id]), {
cardSysId: e
}, {
headers: {
token: app.globalData.token
}
}, function (e, t) {
console.log(e), console.log(t), "200" == e && a.onShowHintDialog();
}, function (e, t) {
wx.hideLoading({}), wx.showToast({
icon: "none",
title: "设置名片失败"
}), console.log(e), console.log(t);
});
},
saveOrgCard: function (e) {
var a = this;
app.restAjax.put(app.restAjax.path(app.apis.doUpdateOrg, [app.baseUrls.requestUrl, a.data.id]), {
cardSysId: e
}, {
headers: {
token: app.globalData.token
}
}, function (e, t) {
"200" == e && a.onShowHintDialog();
}, function (e, t) {
wx.hideLoading({}), wx.showToast({
icon: "none",
title: "设置名片失败"
}), console.log(t);
});
},
setDefaultCard: function (e) {
app.http.put(app.urls.setDefaultCard.format({
cardTemplateUseId: e
}), {
header: {
token: app.globalData.token
}
}).then(function (e) { }).catch(function (e) { });
},
onShowHintDialog: function () {
var e = this;
wx.hideLoading({
success: function (t) {
e.setData({
isLoading: !1
}), wx.showModal({
content: "恭喜您名片创建成功,如需查看请到(我的 → 我的卡包)",
cancelText: "继续创建",
confirmText: "返回列表",
cancelColor: "#333333",
confirmColor: "#333333",
success: function (t) {
t.confirm ? e.backList() : e.continueCreate();
}
});
}
});
},
inputBlur: function (e) {
var t = e.detail.value, a = e.currentTarget.dataset.num, r = e.currentTarget.dataset.item, o = r.templateAreaFontLength;
"" != t && o > 0 && (t = t.substr(0, o), this.data.areaList[a].templateAreaFontValue = t,
this.data.areaList[a].focus = !1, this.setData({
areaList: this.data.areaList
})), "1" != r.templateAreaServerLink && this.getFileId(a);
},
choosePhoto: function (e) {
var t = e.currentTarget.dataset.cur, a = e.currentTarget.dataset.item;
console.log(t), this.setData({
currentIndex: t
});
var r = a.templateAreaWidth / a.templateAreaHeight;
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
success: function (e) {
console.log(e)
wx.navigateTo({
url: "/packagecard/common/corpperimg/cropperimg?imgSrc=" + e.tempFiles[0].tempFilePath + "&scale=" + r
});
}
})
},
doUploadImg: function (path) {
var _self = this
wx.showLoading({
title: '上传中...',
})
app.http.upload(app.urls.doUploadImg, {
path: path,
name: 'image',
header: {
token: app.globalData.token
}
}).then(res => {
wx.hideLoading({})
res = JSON.parse(res)
var change = 'areaList[' + _self.data.currentIndex + '].templateAreaFile'
_self.setData({
[change]: res.data
})
wx.showToast({
title: '上传成功',
duration: 1500
})
_self.setData({
imgTempSrc: '',
currentIndex: 0
})
}).catch(res => {
_self.setData({
imgTempSrc: '',
currentIndex: 0
})
})
// var r = this;
// wx.showLoading({
// title: "上传中..."
// }), app.http.upload(app.urls.doUploadImg, {
// path: a,
// name: "image",
// header: {
// token: app.globalData.token
// }
// }).then(function (t) {
// wx.hideLoading({}), t = JSON.parse(t);
// var a = "areaList[" + r.data.currentIndex + "].templateAreaFile";
// r.setData(e({}, a, t.data)), wx.showToast({
// title: "上传成功",
// duration: 1500
// }), r.setData({
// imgTempSrc: "",
// currentIndex: 0
// });
// }).catch(function (e) {
// r.setData({
// imgTempSrc: "",
// currentIndex: 0
// });
// });
},
getNameCard: function () {
var self = this;
app.http.get(app.urls.getCardDetail.format({
cardTemplateId: self.data.cardId
}), {
header: {
token: app.globalData.token
},
data: {}
}).then(res => {
var area = res.data.areaList
var scale = res.data.picturesTemplateWidth / self.data.windowWidth
res.data.picturesTemplateWidth = res.data.picturesTemplateWidth / scale
res.data.picturesTemplateHeight = res.data.picturesTemplateHeight / scale
for (let i = 0; i < area.length; i++) {
if (area[i].templateAreaFontCenter == '1') {
area[i].templateAreaFontCenter = 'left'
} else if (area[i].templateAreaFontCenter == '2') {
area[i].templateAreaFontCenter = 'center'
} else {
area[i].templateAreaFontCenter = 'right'
}
if (area[i].templateAreaFontBold == '0') {
area[i].templateAreaFontBold = 'normal'
} else if (area[i].templateAreaFontBold == '1') {
area[i].templateAreaFontBold = 'bold'
} else {
area[i]['templateAreaFontStyle'] = 'italic'
}
area[i].templateAreaFontSize = area[i].templateAreaFontSize / scale + 'px'
area[i].templateAreaHeight = area[i].templateAreaHeight / scale
area[i].templateAreaWidth = area[i].templateAreaWidth / scale
area[i].templateAreaDown = area[i].templateAreaDown / scale
area[i].templateAreaTop = area[i].templateAreaTop / scale
area[i].templateAreaRight = area[i].templateAreaRight / scale
area[i].templateAreaLeft = area[i].templateAreaLeft / scale
}
self.setData({
cardInfo: res.data,
areaList: area
})
})
.catch(err => {
})
// var e = this;
// e.data.fromMine && e.data.cardPersonId, app.http.get(app.urls.getCardDetail.format({
// cardTemplateId: e.data.cardId
// }), {
// header: {
// token: app.globalData.token
// },
// data: {}
// }).then(function (t) {
// var a = t.data.areaList, r = t.data.picturesTemplateWidth / e.data.windowWidth;
// t.data.picturesTemplateWidth = t.data.picturesTemplateWidth / r, t.data.picturesTemplateHeight = t.data.picturesTemplateHeight / r;
// for (var o = 0; o < a.length; o++) "1" == a[o].templateAreaFontCenter ? a[o].templateAreaFontCenter = "left" : "2" == a[o].templateAreaFontCenter ? a[o].templateAreaFontCenter = "center" : a[o].templateAreaFontCenter = "right",
// "0" == a[o].templateAreaFontBold ? a[o].templateAreaFontBold = "normal" : "1" == a[o].templateAreaFontBold ? a[o].templateAreaFontBold = "bold" : a[o].templateAreaFontStyle = "italic",
// a[o].templateAreaFontSize = a[o].templateAreaFontSize / r + "px", a[o].templateAreaHeight = a[o].templateAreaHeight / r,
// a[o].templateAreaWidth = a[o].templateAreaWidth / r, a[o].templateAreaDown = a[o].templateAreaDown / r,
// a[o].templateAreaTop = a[o].templateAreaTop / r, a[o].templateAreaRight = a[o].templateAreaRight / r,
// a[o].templateAreaLeft = a[o].templateAreaLeft / r;
// e.setData({
// cardInfo: t.data,
// areaList: a
// });
// }).catch(function (e) { });
},
getNameCradArea: function () {
var e = this, a = [];
app.restAjax.get(app.restAjax.path("{cardUrl}app/cardtemplatearea/listcardtemplateareabytemplateid/" + e.data.cardId, [app.tradeUrl]), {}, {
headers: {
token: app.globalData.token
}
}, function (t, r) {
for (var o = 0; o < r.length; o++) if (r[o].focus = !1, "1" != r[o].templateAreaType) a.push(r[o]); else {
var n = parseInt(r[o].templateAreaFontSize.replace("px", ""));
n = Math.floor(750 * n / wx.getSystemInfoSync().windowWidth) + "rpx", r[o].templateAreaFontSize = n,
a.push(r[o]);
}
e.setData({
areaList: a
});
}, function (e, a) {
t.dialog.msg(a.msg);
});
},
editInfo: function (t) {
var a = t.currentTarget.dataset.num, r = t.detail.value, o = "areaList[" + a + "].templateAreaFontValue";
this.setData(e({}, o, r));
},
giveFocus: function (t) {
console.log(t.currentTarget.dataset.cur);
var a = "areaList[" + t.currentTarget.dataset.cur + "].focus";
this.setData(e({}, a, !0));
},
continueCreate: function () {
this.setData({
showHide: !1
});
},
backList: function () {
wx.navigateBack({
delta: 1
});
},
getUserInfo: function () {
app.restAjax.get(app.restAjax.path("{loginUrl}app/user/get-app-user", [app.personIntroUrl]), {}, {
headers: {
token: app.globalData.token
}
}, function (e, a) {
app.globalData.userInfo = a;
}, function (e, a) {
app.dialog.msg(a.msg);
});
},
getFileId: function (a) {
var r = this, o = a, n = r.data.areaList[o].templateAreaFontValue;
console.log(n);
var i = r.data.areaList[o].picturesTemplateAreaId;
app.http.get(app.urls.getFileId.format({
picturesTemplateAreaId: i
}), {
header: {
token: app.globalData.token
},
data: {
content: n
}
}).then(function (t) {
console.log(t.data);
var a = "areaList[" + o + "].templateAreaFile";
r.setData(e({}, a, t.data.data));
}).catch(function (e) { });
},
onLoad: function (e) {
this.setData({
cardId: e.id,
token: app.globalData.token,
pageType: e.type,
id: e.taskId
});
console.log(app.globalData.token)
this.getNameCard();
},
postRecord: function (e) {
app.restAjax.post(app.restAjax.path("{loginUrl}app/cardtemplateforwardingrecord/savecardtemplateforwardingrecord", [app.tradeUrl]), {
encryptedData: e.encryptedData,
iv: e.iv,
templateUseId: this.data.cardId,
templateFromUserId: this.data.oldToken,
templateToUserId: this.data.token
}, {
headers: {
token: this.data.token
}
}, function (e, t) {
console.log("1" + t);
}, function (e, a) {
t.dialog.msg(a.msg);
});
},
openPage: function () { },
onShow: function () {
console.log(this.data.imgTempSrc), "" != this.data.imgTempSrc && this.doUploadImg(this.data.imgTempSrc);
}
});