city_card/pages/mine/myCardDetail/myCardDetail.js
2023-07-18 16:54:17 +08:00

330 lines
12 KiB
JavaScript

var e = getApp();
Page({
data: {
preview: "",
showHide: !1,
isLoading: !1,
isMain: "",
cardPersonId: "",
choose_index: 0,
active: 0,
cardUrl: e.baseUrls.baseCardUrl,
areaList: [],
cardInfo: {},
bgImg: "",
fontFamilyList: [],
useFontFamily: "",
cardId: "",
cardHeight: "",
shareTicket: "",
encryptedData: "",
iv: "",
isFromOut: !1,
token: "",
oldToken: "",
imgTempSrc: "",
currentIndex: 0,
windowWidth: e.globalData.windowWidth,
isShowBind: !1,
id: ""
},
deleteCard: function() {
var t = this;
wx.showModal({
cancelColor: "#000",
title: "提示",
content: "确认删除该名片?",
success: function(a) {
a.confirm && e.http.delete(e.urls.deleteCard.format({
ids: t.data.cardId
}), {
header: {
token: t.data.token
}
}).then(function(e) {
"200" == e.statusCode && wx.showToast({
title: "删除成功",
icon: "success",
success: function() {
var e = getCurrentPages(), a = e.length >= 2 ? e[e.length - 2] : void 0, r = "1" == t.data.cardInfo.cardTemplateUseDefault;
a.setData({
isRefresh: !0,
isDelPage: r
}), wx.navigateBack({});
}
});
}).catch(function(t) {});
}
});
},
updateCard: function(t) {
for (var a = [], r = 0; r < this.data.areaList.length; r++) {
var o = {
cardTemplateUseId: this.data.areaList[r].cardTemplateUseId,
cardTemplateUseAreaId: this.data.areaList[r].cardTemplateUseAreaId,
templateAreaFile: this.data.areaList[r].templateAreaFile,
templateAreaFontValue: this.data.areaList[r].templateAreaFontValue
};
a.push(o);
}
var n = {
cardTemplateUseAreaList: a,
cardTemplateUseDefault: this.data.cardInfo.cardTemplateUseDefault,
cardTemplateUsePassword: this.data.cardInfo.cardTemplateUsePassword,
cardTemplateUseSwitch: this.data.cardInfo.cardTemplateUseSwitch,
cardTemplateUseId: this.data.cardInfo.cardTemplateUseId
};
e.http.put(e.urls.updateMyCard.format({
cardTemplateUseId: this.data.cardId
}), {
header: {
token: e.globalData.token
},
data: n
}).then(function(t) {
"200" == t.statusCode && wx.showToast({
title: "修改成功",
icon: "success",
success: function() {
var t = getCurrentPages();
(t.length >= 2 ? t[t.length - 2] : void 0).setData({
isRefresh: !0
}), wx.navigateBack({});
}
});
}).catch(function(t) {});
},
onShow: function(t) {
"" != this.data.imgTempSrc && this.doUploadImg(this.data.imgTempSrc);
},
inputBlur: function(t) {
var e = t.detail.value, a = t.currentTarget.dataset.num, r = t.currentTarget.dataset.item, o = r.templateAreaFontLength;
"" != e && o > 0 && (e = e.substr(0, o), this.data.areaList[a].templateAreaFontValue = e,
this.data.areaList[a].focus = !1, this.setData({
areaList: this.data.areaList
})), "1" != r.templateAreaServerLink && this.getFileId(a);
},
choosePhoto: function(t) {
var e = t.currentTarget.dataset.cur, a = t.currentTarget.dataset.item;
this.setData({
currentIndex: e
});
var r = a.templateAreaWidth / a.templateAreaHeight;
wx.chooseImage({
count: 1,
sourceType: [ "album", "camera" ],
success: function(t) {
wx.navigateTo({
url: "/packagecard/common/corpperimg/cropperimg?imgSrc=" + t.tempFiles[0].path + "&scale=" + r
});
}
});
},
doUploadImg: function(a) {
var r = this;
wx.showLoading({
title: "上传中..."
}), e.http.upload(e.urls.doUploadImg, {
path: a,
name: "image",
header: {
token: e.globalData.token
}
}).then(function(e) {
wx.hideLoading({}), e = JSON.parse(e);
var a = "areaList[" + r.data.currentIndex + "].templateAreaFile";
r.setData(t({}, a, e.data)), wx.showToast({
title: "上传成功",
duration: 1500
}), r.setData({
imgTempSrc: "",
currentIndex: 0
});
}).catch(function(t) {
r.setData({
imgTempSrc: "",
currentIndex: 0
});
});
},
getPhoneNumber: function(t) {
console.log(t.detail.errMsg), console.log(t.detail.iv), console.log(t.detail.encryptedData);
},
getNameCard: function() {
var t = this;
e.http.get(e.urls.getMyCardDetail.format({
cardTemplateUseId: t.data.cardId
}), {
header: {
token: e.globalData.token
},
data: {}
}).then(function(e) {
var a = e.data.areaList, r = e.data.cardTemplateUseWidth / t.data.windowWidth;
console.log(r + "===" + t.data.windowWidth), e.data.cardTemplateUseWidth = e.data.cardTemplateUseWidth / r,
e.data.cardTemplateUseHeight = e.data.cardTemplateUseHeight / r;
for (var o = 0; o < a.length; o++) 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,
"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";
t.setData({
cardInfo: e.data,
areaList: a
});
}).catch(function(t) {});
},
saveCardIdToSyzl: function(t) {
console.log(t);
var a = {
cardSysId: t
};
console.log(e.globalData.gridMiniCardId), e.restAjax.put(e.restAjax.path(e.apis.doUpdateCard, [ e.baseUrls.requestUrl, this.data.id ]), a, {
headers: {
token: this.data.token
}
}, function(t, e) {
console.log(e), wx.showToast({
title: "设置成功",
icon: "success",
success: function() {
var t = getCurrentPages();
(t.length >= 2 ? t[t.length - 2] : void 0).setData({
isRefresh: !0
}), wx.navigateBack({});
}
});
}, function(t, e) {
console.log(e);
});
},
saveOrgCard: function(t) {
var a = {
cardSysId: t
};
e.restAjax.put(e.restAjax.path(e.apis.doUpdateOrg, [ e.baseUrls.requestUrl, this.data.id ]), a, {
headers: {
token: this.data.token
}
}, function(t, e) {
wx.showToast({
title: "设置成功",
icon: "success",
success: function() {
var t = getCurrentPages();
(t.length >= 2 ? t[t.length - 2] : void 0).setData({
isRefresh: !0
}), wx.navigateBack({});
}
});
}, function(t, e) {
console.log(e);
});
},
getNameCradArea: function() {
var t = this, a = [];
e.restAjax.get(e.restAjax.path("{cardUrl}app/cardtemplatearea/listcardtemplateareabytemplateid/" + t.data.cardId, [ e.tradeUrl ]), {}, {
headers: {
token: e.globalData.token
}
}, function(e, 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]);
}
t.setData({
areaList: a
});
}, function(t, a) {
e.dialog.msg(a.msg);
});
},
editInfo: function(e) {
var a = e.currentTarget.dataset.num, r = e.detail.value, o = "areaList[" + a + "].templateAreaFontValue";
this.setData(t({}, o, r));
},
giveFocus: function(e) {
var a = "areaList[" + e.currentTarget.dataset.cur + "].focus";
this.setData(t({}, a, !0));
},
continueCreate: function() {
this.setData({
showHide: !1
});
},
backList: function() {
wx.navigateBack({
delta: 1
});
},
getUserInfo: function() {
e.restAjax.get(e.restAjax.path("{loginUrl}app/user/get-app-user", [ e.personIntroUrl ]), {}, {
headers: {
token: e.globalData.token
}
}, function(t, a) {
e.globalData.userInfo = a;
}, function(t, a) {
e.dialog.msg(a.msg);
});
},
getFileId: function(a) {
var r = this, o = a, n = r.data.areaList[o].templateAreaFontValue, s = r.data.areaList[o].picturesTemplateAreaId;
e.http.get(e.urls.getFileId.format({
picturesTemplateAreaId: s
}), {
header: {
token: e.globalData.token
},
data: {
content: n
}
}).then(function(e) {
console.log(e.data);
var a = "areaList[" + o + "].templateAreaFile";
r.setData(t({}, a, e.data.data));
}).catch(function(t) {});
},
setDefaultCard: function() {
var t = this;
e.http.put(e.urls.setDefaultCard.format({
cardTemplateUseId: t.data.cardId
}), {
header: {
token: t.data.token
}
}).then(function(e) {
console.log(e), "200" == e.statusCode && (console.log(t.data.pageType), "org" == t.data.pageType ? t.saveOrgCard(t.data.cardId) : t.saveCardIdToSyzl(t.data.cardId));
}).catch(function(t) {});
},
onLoad: function(t) {
this.setData({
cardId: t.id,
token: e.globalData.token,
pageType: t.type,
id: t.taskId
}), console.log(this.data.pageType), this.getNameCard();
},
postRecord: function(t) {
e.restAjax.post(e.restAjax.path("{loginUrl}app/cardtemplateforwardingrecord/savecardtemplateforwardingrecord", [ e.tradeUrl ]), {
encryptedData: t.encryptedData,
iv: t.iv,
templateUseId: this.data.cardId,
templateFromUserId: this.data.oldToken,
templateToUserId: this.data.token
}, {
headers: {
token: this.data.token
}
}, function(t, e) {
console.log("1" + e);
}, function(t, a) {
e.dialog.msg(a.msg);
});
},
openPage: function() {},
bindService: function() {}
});