index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const api_system_customer = require("../../../api/system/customer.js");
  4. const api_resource_oss = require("../../../api/resource/oss.js");
  5. const ErpNavBar = () => "../../../components/erp-nav-bar.js";
  6. const _sfc_main = {
  7. components: { ErpNavBar },
  8. data() {
  9. return {
  10. uploading: false,
  11. pendingAvatarOssId: null,
  12. myInfo: {
  13. avatarUrl: "",
  14. userName: "",
  15. phone: "",
  16. avatar: null,
  17. authCustomerId: ""
  18. }
  19. };
  20. },
  21. async onLoad() {
  22. await this.loadInfo();
  23. },
  24. methods: {
  25. async loadInfo() {
  26. try {
  27. common_vendor.index.showLoading({ title: "加载中" });
  28. const res = await api_system_customer.getMyInfo();
  29. common_vendor.index.hideLoading();
  30. const d = res.data;
  31. this.myInfo = {
  32. avatarUrl: d.avatarUrl || "",
  33. userName: d.userName || "",
  34. phone: d.phone || "",
  35. avatar: d.avatar || null,
  36. authCustomerId: d.authCustomerId || ""
  37. };
  38. this.pendingAvatarOssId = null;
  39. } catch (e) {
  40. common_vendor.index.hideLoading();
  41. common_vendor.index.showToast({ title: "加载失败", icon: "none" });
  42. }
  43. },
  44. doChooseImage() {
  45. common_vendor.index.chooseImage({
  46. count: 1,
  47. sizeType: ["compressed"],
  48. sourceType: ["album", "camera"],
  49. success: async (res) => {
  50. const tempPath = res.tempFilePaths[0];
  51. this.myInfo.avatarUrl = tempPath;
  52. this.uploading = true;
  53. try {
  54. const uploadRes = await api_resource_oss.uploadFile(tempPath);
  55. this.pendingAvatarOssId = uploadRes.ossId;
  56. common_vendor.index.showToast({ title: "头像上传成功", icon: "success" });
  57. } catch (e) {
  58. common_vendor.index.showToast({ title: "头像上传失败", icon: "none" });
  59. this.myInfo.avatarUrl = "";
  60. } finally {
  61. this.uploading = false;
  62. }
  63. }
  64. });
  65. },
  66. doEditName() {
  67. common_vendor.index.showModal({
  68. title: "设置昵称",
  69. content: this.myInfo.userName,
  70. editable: true,
  71. confirmColor: "#C1001C",
  72. success: (res) => {
  73. if (res.confirm) {
  74. this.myInfo.userName = res.content || this.myInfo.userName;
  75. }
  76. }
  77. });
  78. },
  79. saveProfile() {
  80. if (this.uploading)
  81. return;
  82. common_vendor.index.showModal({
  83. title: "确认保存",
  84. content: `昵称:${this.myInfo.userName}
  85. 手机:${this.myInfo.phone}
  86. 请确认以上信息是否填写正确?`,
  87. confirmText: "确认",
  88. cancelText: "取消",
  89. confirmColor: "#C1001C",
  90. success: async (res) => {
  91. if (!res.confirm)
  92. return;
  93. try {
  94. common_vendor.index.showLoading({ title: "保存中" });
  95. const payload = { userName: this.myInfo.userName };
  96. if (this.pendingAvatarOssId !== null) {
  97. payload.avatar = this.pendingAvatarOssId;
  98. }
  99. await api_system_customer.updateMyInfo(payload);
  100. common_vendor.index.hideLoading();
  101. common_vendor.index.showToast({ title: "保存成功", icon: "success" });
  102. setTimeout(() => {
  103. common_vendor.index.navigateBack();
  104. }, 1200);
  105. } catch (e) {
  106. common_vendor.index.hideLoading();
  107. common_vendor.index.showToast({ title: e.message || "保存失败", icon: "none" });
  108. }
  109. }
  110. });
  111. }
  112. }
  113. };
  114. if (!Array) {
  115. const _component_erp_nav_bar = common_vendor.resolveComponent("erp-nav-bar");
  116. _component_erp_nav_bar();
  117. }
  118. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  119. return common_vendor.e({
  120. a: common_vendor.p({
  121. title: "个人资料设置"
  122. }),
  123. b: $data.myInfo.avatarUrl || "https://img.icons8.com/color/144/user.png",
  124. c: $data.uploading
  125. }, $data.uploading ? {} : {}, {
  126. d: common_vendor.o((...args) => $options.doChooseImage && $options.doChooseImage(...args), "b5"),
  127. e: common_vendor.t($data.myInfo.userName),
  128. f: common_vendor.o((...args) => $options.doEditName && $options.doEditName(...args), "f1"),
  129. g: common_vendor.t($data.myInfo.phone),
  130. h: common_vendor.t($data.myInfo.authCustomerId || "无"),
  131. i: common_vendor.o((...args) => $options.saveProfile && $options.saveProfile(...args), "d6"),
  132. j: $data.uploading
  133. });
  134. }
  135. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2f058983"]]);
  136. wx.createPage(MiniProgramPage);
  137. //# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/mine/settings/index.js.map