index.js 4.8 KB

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