爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
6.4 KiB

  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const pages_mixins_pullRefreshMixin = require("../mixins/pullRefreshMixin.js");
  4. const _sfc_main = {
  5. mixins: [pages_mixins_pullRefreshMixin.pullRefreshMixin],
  6. data() {
  7. return {
  8. searchText: "",
  9. users: [],
  10. // 改为空数组,由接口获取
  11. statusBarHeight: 0,
  12. showSuggestList: false,
  13. suggestList: [],
  14. searchBarOffset: 0,
  15. searchBarTop: 0,
  16. contentOffset: 0,
  17. navBarRealHeight: 0,
  18. searchBarHeight: 70
  19. // px
  20. };
  21. },
  22. computed: {
  23. filteredUsers() {
  24. if (!this.searchText)
  25. return this.users;
  26. return this.users.filter(
  27. (u) => u.name.includes(this.searchText) || u.phone.includes(this.searchText) || u.role && u.role.includes(this.searchText)
  28. );
  29. },
  30. navbarStyle() {
  31. return `padding-top: ${this.statusBarHeight}px;`;
  32. }
  33. },
  34. onLoad() {
  35. common_vendor.index.getSystemInfo({
  36. success: (res) => {
  37. this.statusBarHeight = res.statusBarHeight || 20;
  38. }
  39. });
  40. this.$nextTick(() => {
  41. common_vendor.index.createSelectorQuery().select(".navbar").boundingClientRect((rect) => {
  42. if (rect) {
  43. this.navBarRealHeight = rect.height;
  44. }
  45. }).exec();
  46. });
  47. this.refreshData();
  48. },
  49. methods: {
  50. goBack() {
  51. common_vendor.index.navigateBack();
  52. },
  53. onInput(e) {
  54. const val = e.detail.value;
  55. this.searchText = val;
  56. if (val) {
  57. this.suggestList = this.users.map((u) => u.phone).filter((phone) => phone.includes(val));
  58. this.showSuggestList = this.suggestList.length > 0;
  59. } else {
  60. this.showSuggestList = false;
  61. }
  62. },
  63. clearInput() {
  64. this.searchText = "";
  65. this.showSuggestList = false;
  66. },
  67. cancelSearch() {
  68. this.clearInput();
  69. },
  70. highlightMatch(phone, keyword) {
  71. if (!keyword)
  72. return [{ name: "span", children: [phone] }];
  73. const idx = phone.indexOf(keyword);
  74. if (idx === -1)
  75. return [{ name: "span", children: [phone] }];
  76. const before = phone.slice(0, idx);
  77. const match = phone.slice(idx, idx + keyword.length);
  78. const after = phone.slice(idx + keyword.length);
  79. return [
  80. { name: "span", children: [before] },
  81. { name: "span", attrs: { style: "color:#ff8917" }, children: [match] },
  82. { name: "span", children: [after] }
  83. ];
  84. },
  85. goUserDetail(user) {
  86. const avatar = user.avatar || user.avatarUrl || "";
  87. common_vendor.index.navigateTo({
  88. url: "/pages/manager/user-detail",
  89. success: (res) => {
  90. res.eventChannel.emit("userDetail", { ...user, avatar });
  91. }
  92. });
  93. },
  94. async refreshData() {
  95. try {
  96. const res = await this.$api("getInfoTeamListPage", {
  97. pageSize: 1e3,
  98. current: 1
  99. });
  100. if (res && res.code === 200 && res.result && Array.isArray(res.result.records)) {
  101. this.users = res.result.records.map((user) => ({
  102. id: user.id,
  103. name: user.name || user.nickName || "-",
  104. phone: user.phone || "-",
  105. role: user.isTuiRole === "Y" ? "推广官" : "",
  106. blocked: user.isBlack === "Y",
  107. avatar: user.headImage || user.avatar || user.avatarUrl || ""
  108. }));
  109. }
  110. } catch (error) {
  111. common_vendor.index.__f__("error", "at pages/manager/user.vue:171", "获取用户列表失败:", error);
  112. common_vendor.index.showToast({
  113. title: "获取用户列表失败",
  114. icon: "none"
  115. });
  116. }
  117. },
  118. async onRefresh() {
  119. await this.refreshData && this.refreshData();
  120. }
  121. },
  122. onPullDownRefresh() {
  123. this.refreshData && this.refreshData();
  124. common_vendor.index.stopPullDownRefresh();
  125. }
  126. };
  127. if (!Array) {
  128. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  129. _easycom_uni_icons2();
  130. }
  131. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  132. if (!Math) {
  133. _easycom_uni_icons();
  134. }
  135. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  136. return common_vendor.e({
  137. a: common_vendor.p({
  138. type: "back",
  139. size: "24",
  140. color: "#222"
  141. }),
  142. b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  143. c: common_vendor.s($options.navbarStyle),
  144. d: common_vendor.p({
  145. type: "search",
  146. size: "22",
  147. color: "#bfbfbf"
  148. }),
  149. e: common_vendor.o([($event) => $data.searchText = $event.detail.value, (...args) => $options.onInput && $options.onInput(...args)]),
  150. f: $data.searchText,
  151. g: $data.searchText.length
  152. }, $data.searchText.length ? {
  153. h: common_vendor.p({
  154. type: "closeempty",
  155. size: "22",
  156. color: "#bfbfbf"
  157. }),
  158. i: common_vendor.o((...args) => $options.clearInput && $options.clearInput(...args))
  159. } : {}, {
  160. j: $data.searchText.length
  161. }, $data.searchText.length ? {
  162. k: common_vendor.o((...args) => $options.cancelSearch && $options.cancelSearch(...args))
  163. } : {}, {
  164. l: $data.navBarRealHeight + "px",
  165. m: $data.showSuggestList
  166. }, $data.showSuggestList ? {
  167. n: common_vendor.f($data.suggestList, (item, idx, i0) => {
  168. return {
  169. a: "1d5a9178-3-" + i0,
  170. b: $options.highlightMatch(item, $data.searchText),
  171. c: idx
  172. };
  173. }),
  174. o: common_vendor.p({
  175. type: "search",
  176. size: "22",
  177. color: "#bfbfbf"
  178. }),
  179. p: $data.navBarRealHeight + $data.searchBarHeight + "px"
  180. } : {}, {
  181. q: !$data.showSuggestList
  182. }, !$data.showSuggestList ? {
  183. r: common_vendor.f($options.filteredUsers, (user, idx, i0) => {
  184. return common_vendor.e({
  185. a: common_vendor.t(user.name),
  186. b: common_vendor.t(user.phone),
  187. c: user.role
  188. }, user.role ? common_vendor.e({
  189. d: user.role === "推广官"
  190. }, user.role === "推广官" ? {} : {
  191. e: common_vendor.t(user.role)
  192. }) : {}, {
  193. f: user.blocked
  194. }, user.blocked ? {} : {}, {
  195. g: idx,
  196. h: common_vendor.o(($event) => $options.goUserDetail(user), idx)
  197. });
  198. }),
  199. s: $data.navBarRealHeight + $data.searchBarHeight + "px"
  200. } : {});
  201. }
  202. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-1d5a9178"]]);
  203. wx.createPage(MiniProgramPage);
  204. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/manager/user.js.map