city_card/packagecard/cardDetail/cardDetail.js
2023-07-15 14:25:28 +08:00

339 lines
12 KiB
JavaScript
Executable File

var e = require("../../@babel/runtime/helpers/defineProperty"), t = getApp();
require("../../utils/util.js");
Page({
data: {
preview: "",
showHide: !1,
isLoading: !1,
isMain: "",
cardPersonId: "",
choose_index: 0,
active: 0,
cardUrl: t.baseUrls.baseCardUrl,
areaList: [],
cardInfo: {},
bgImg: "",
fontFamilyList: [],
useFontFamily: "",
cardId: "",
cardHeight: "",
shareTicket: "",
encryptedData: "",
iv: "",
isFromOut: !1,
token: "",
oldToken: "",
fromMine: !1,
imgTempSrc: "",
currentIndex: 0,
windowWidth: t.globalData.windowWidth,
scale: 1,
pageType: null
},
tabChange: function(e) {
this.setData({
active: e.detail
}), 0 == this.data.active || (1 == this.data.active ? 1 == t.globalData.servicePageType ? wx.redirectTo({
url: "/pages/shop/catalog/bannerlist/bannerlist"
}) : 2 == t.globalData.servicePageType ? wx.redirectTo({
url: "/pages/shop/catalog/column/column"
}) : 3 == t.globalData.servicePageType ? wx.redirectTo({
url: "/pages/shop/catalog/list/list"
}) : 4 == t.globalData.servicePageType && wx.redirectTo({
url: "/pages/shop/bespeak/bespeak"
}) : wx.redirectTo({
url: "/pages/mine/index/index"
}));
},
createMyCard: function() {
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);
}
t.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;
t.http.get(t.urls.getMyCard, {
header: {
token: t.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;
t.restAjax.put(t.restAjax.path(t.apis.doUpdateCard, [ t.baseUrls.requestUrl, a.data.id ]), {
cardSysId: e
}, {
headers: {
token: t.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;
t.restAjax.put(t.restAjax.path(t.apis.doUpdateOrg, [ t.baseUrls.requestUrl, a.data.id ]), {
cardSysId: e
}, {
headers: {
token: t.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) {
t.http.put(t.urls.setDefaultCard.format({
cardTemplateUseId: e
}), {
header: {
token: t.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.chooseImage({
count: 1,
sourceType: [ "album", "camera" ],
success: function(e) {
wx.navigateTo({
url: "/packagecard/common/corpperimg/cropperimg?imgSrc=" + e.tempFiles[0].path + "&scale=" + r
});
}
});
},
doUploadImg: function(a) {
var r = this;
wx.showLoading({
title: "上传中..."
}), t.http.upload(t.urls.doUploadImg, {
path: a,
name: "image",
header: {
token: t.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 e = this;
e.data.fromMine && e.data.cardPersonId, t.http.get(t.urls.getCardDetail.format({
cardTemplateId: e.data.cardId
}), {
header: {
token: t.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 = [];
t.restAjax.get(t.restAjax.path("{cardUrl}app/cardtemplatearea/listcardtemplateareabytemplateid/" + e.data.cardId, [ t.tradeUrl ]), {}, {
headers: {
token: t.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() {
t.restAjax.get(t.restAjax.path("{loginUrl}app/user/get-app-user", [ t.personIntroUrl ]), {}, {
headers: {
token: t.globalData.token
}
}, function(e, a) {
t.globalData.userInfo = a;
}, function(e, a) {
t.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;
t.http.get(t.urls.getFileId.format({
picturesTemplateAreaId: i
}), {
header: {
token: t.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: t.globalData.token,
pageType: e.type,
id: e.taskId
}), this.getNameCard();
},
postRecord: function(e) {
t.restAjax.post(t.restAjax.path("{loginUrl}app/cardtemplateforwardingrecord/savecardtemplateforwardingrecord", [ t.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);
}
});