| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- "use strict";
- const common_vendor = require("../../../common/vendor.js");
- const api_system_customer = require("../../../api/system/customer.js");
- const api_resource_oss = require("../../../api/resource/oss.js");
- const ErpNavBar = () => "../../../components/erp-nav-bar.js";
- const _sfc_main = {
- components: { ErpNavBar },
- data() {
- return {
- uploading: false,
- pendingAvatarOssId: null,
- myInfo: {
- avatarUrl: "",
- userName: "",
- phone: "",
- avatar: null,
- authClientRowId: "",
- authClientName: ""
- }
- };
- },
- async onLoad() {
- await this.loadInfo();
- },
- methods: {
- async loadInfo() {
- try {
- common_vendor.index.showLoading({ title: "加载中" });
- const res = await api_system_customer.getMyInfo();
- common_vendor.index.hideLoading();
- const d = res.data;
- this.myInfo = {
- avatarUrl: d.avatarUrl || "",
- userName: d.userName || "",
- phone: d.phone || "",
- avatar: d.avatar || null,
- authClientRowId: d.authClientRowId || "",
- authClientName: d.authClientName || ""
- };
- this.pendingAvatarOssId = null;
- } catch (e) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: "加载失败", icon: "none" });
- }
- },
- doChooseImage() {
- common_vendor.index.chooseImage({
- count: 1,
- sizeType: ["compressed"],
- sourceType: ["album", "camera"],
- success: async (res) => {
- const tempPath = res.tempFilePaths[0];
- this.myInfo.avatarUrl = tempPath;
- this.uploading = true;
- try {
- const uploadRes = await api_resource_oss.uploadFile(tempPath);
- this.pendingAvatarOssId = uploadRes.ossId;
- common_vendor.index.showToast({ title: "头像上传成功", icon: "success" });
- } catch (e) {
- common_vendor.index.showToast({ title: "头像上传失败", icon: "none" });
- this.myInfo.avatarUrl = "";
- } finally {
- this.uploading = false;
- }
- }
- });
- },
- doEditName() {
- common_vendor.index.showModal({
- title: "设置昵称",
- content: this.myInfo.userName,
- editable: true,
- confirmColor: "#C1001C",
- success: (res) => {
- if (res.confirm) {
- this.myInfo.userName = res.content || this.myInfo.userName;
- }
- }
- });
- },
- saveProfile() {
- if (this.uploading)
- return;
- common_vendor.index.showModal({
- title: "确认保存",
- content: `昵称:${this.myInfo.userName}
- 手机:${this.myInfo.phone}
- 请确认以上信息是否填写正确?`,
- confirmText: "确认",
- cancelText: "取消",
- confirmColor: "#C1001C",
- success: async (res) => {
- if (!res.confirm)
- return;
- try {
- common_vendor.index.showLoading({ title: "保存中" });
- const payload = { userName: this.myInfo.userName };
- if (this.pendingAvatarOssId !== null) {
- payload.avatar = this.pendingAvatarOssId;
- }
- await api_system_customer.updateMyInfo(payload);
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: "保存成功", icon: "success" });
- setTimeout(() => {
- common_vendor.index.navigateBack();
- }, 1200);
- } catch (e) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: e.message || "保存失败", icon: "none" });
- }
- }
- });
- }
- }
- };
- if (!Array) {
- const _component_erp_nav_bar = common_vendor.resolveComponent("erp-nav-bar");
- _component_erp_nav_bar();
- }
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.p({
- title: "个人资料设置"
- }),
- b: $data.myInfo.avatarUrl || "https://img.icons8.com/color/144/user.png",
- c: $data.uploading
- }, $data.uploading ? {} : {}, {
- d: common_vendor.o((...args) => $options.doChooseImage && $options.doChooseImage(...args), "48"),
- e: common_vendor.t($data.myInfo.userName),
- f: common_vendor.o((...args) => $options.doEditName && $options.doEditName(...args), "2c"),
- g: common_vendor.t($data.myInfo.phone),
- h: common_vendor.t($data.myInfo.authClientName || $data.myInfo.authClientRowId || "无"),
- i: common_vendor.o((...args) => $options.saveProfile && $options.saveProfile(...args), "ac"),
- j: $data.uploading
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2f058983"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/mine/settings/index.js.map
|