爱简收旧衣按件回收前端代码仓库
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.

337 lines
12 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. statusBarHeight: 0,
  9. navBarHeight: 0,
  10. // px
  11. navBarHeightRpx: 0,
  12. // rpx
  13. fromRecycle: false,
  14. address: "",
  15. selectedAddress: null,
  16. selectedTime: "",
  17. agreed: false,
  18. selectedItems: [],
  19. showTimePicker: false,
  20. currentDateTab: 0,
  21. dateTabs: [],
  22. // 动态生成
  23. timeSlots: ["11:00~13:00", "13:00~15:00", "15:00~17:00"],
  24. selectedTimeSlot: 0,
  25. steps: [],
  26. // 改为空数组,由接口获取
  27. showAllItems: false,
  28. addressId: ""
  29. };
  30. },
  31. onShow() {
  32. common_vendor.index.__f__("log", "at pages/subcomponent/pickup.vue:171", "当前选中的地址:", this.selectedAddress);
  33. if (this.selectedAddress) {
  34. this.address = this.selectedAddress.address;
  35. this.addressId = this.selectedAddress.id;
  36. this.$forceUpdate();
  37. }
  38. },
  39. onLoad(options) {
  40. this.fromRecycle = options.fromRecycle === "true";
  41. if (this.fromRecycle && options.items) {
  42. try {
  43. this.selectedItems = JSON.parse(decodeURIComponent(options.items));
  44. } catch (e) {
  45. common_vendor.index.__f__("error", "at pages/subcomponent/pickup.vue:189", "解析衣物信息失败:", e);
  46. }
  47. }
  48. common_vendor.index.$on("addressSelected", (address) => {
  49. this.selectedAddress = address;
  50. this.address = address.address;
  51. this.addressId = address.id;
  52. if (address.addressDetails)
  53. this.selectedAddress.addressDetails = address.addressDetails;
  54. this.$forceUpdate();
  55. });
  56. common_vendor.index.$on("clearRecycleData", () => {
  57. common_vendor.index.$emit("clearRecycleOrderData");
  58. });
  59. const sysInfo = common_vendor.index.getSystemInfoSync();
  60. this.statusBarHeight = sysInfo.statusBarHeight;
  61. let navBarHeight = 44;
  62. try {
  63. const menuButtonInfo = common_vendor.index.getMenuButtonBoundingClientRect();
  64. navBarHeight = menuButtonInfo.bottom + menuButtonInfo.top - sysInfo.statusBarHeight;
  65. } catch (e) {
  66. }
  67. this.navBarHeight = navBarHeight;
  68. this.navBarHeightRpx = Math.round(navBarHeight * 750 / sysInfo.windowWidth);
  69. this.getAddressList();
  70. this.dateTabs = this.generateDateTabs();
  71. this.getAreaList();
  72. },
  73. onUnload() {
  74. common_vendor.index.$off("addressSelected");
  75. common_vendor.index.$off("clearRecycleData");
  76. },
  77. computed: {
  78. totalCount() {
  79. return this.selectedItems.reduce((sum, item) => sum + item.quantity, 0);
  80. },
  81. totalPriceRange() {
  82. if (this.selectedItems.length === 0)
  83. return "0-0";
  84. const total = this.selectedItems.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0);
  85. return `${(total * 0.92).toFixed(2)}~${(total * 1.1).toFixed(2)}`;
  86. },
  87. canSubmit() {
  88. return this.agreed && this.selectedItems.length > 0 && this.selectedTime && this.displayAddress;
  89. },
  90. displayAddress() {
  91. if (this.selectedAddress) {
  92. return (this.selectedAddress.address || "") + (this.selectedAddress.addressDetails ? " " + this.selectedAddress.addressDetails : "");
  93. }
  94. return "";
  95. }
  96. },
  97. methods: {
  98. async onRefresh() {
  99. await new Promise((resolve) => setTimeout(resolve, 1e3));
  100. common_vendor.index.stopPullRefresh();
  101. },
  102. goBack() {
  103. common_vendor.index.navigateBack();
  104. },
  105. showMoreMenu() {
  106. common_vendor.index.showModal({ title: "更多", content: "这里可以放更多操作" });
  107. },
  108. showScan() {
  109. common_vendor.index.showModal({ title: "扫码", content: "这里可以实现扫码功能" });
  110. },
  111. selectAddress() {
  112. common_vendor.index.navigateTo({ url: "/pages/subcomponent/select?mode=select" });
  113. },
  114. openTimePicker() {
  115. this.showTimePicker = true;
  116. },
  117. closeTimePicker() {
  118. this.showTimePicker = false;
  119. },
  120. selectDateTab(index) {
  121. this.currentDateTab = index;
  122. },
  123. selectTimeSlot(index) {
  124. this.selectedTimeSlot = index;
  125. },
  126. confirmTime() {
  127. const tab = this.dateTabs[this.currentDateTab];
  128. const dateObj = tab.date;
  129. const timeStr = this.timeSlots[this.selectedTimeSlot];
  130. const startTime = timeStr.split("~")[0];
  131. const yyyy = dateObj.getFullYear();
  132. const mm = (dateObj.getMonth() + 1).toString().padStart(2, "0");
  133. const dd = dateObj.getDate().toString().padStart(2, "0");
  134. this.selectedTime = `${yyyy}-${mm}-${dd} ${startTime}:00`;
  135. this.closeTimePicker();
  136. },
  137. resetPicker() {
  138. this.currentDateTab = 0;
  139. this.selectedTimeSlot = 0;
  140. },
  141. toggleAgreement() {
  142. this.agreed = !this.agreed;
  143. },
  144. showServiceAgreement() {
  145. common_vendor.index.showModal({ title: "回收服务协议", content: "这里展示回收服务协议内容" });
  146. },
  147. showPrivacyPolicy() {
  148. common_vendor.index.showModal({ title: "隐私政策", content: "这里展示隐私政策内容" });
  149. },
  150. submitOrder() {
  151. if (!this.agreed) {
  152. common_vendor.index.showToast({ title: "请先同意服务协议", icon: "none" });
  153. return;
  154. }
  155. if (!this.displayAddress || this.displayAddress === "请选择取件地址") {
  156. common_vendor.index.showToast({ title: "请选择取件地址", icon: "none" });
  157. return;
  158. }
  159. if (!this.selectedTime) {
  160. common_vendor.index.showToast({ title: "请选择上门时间", icon: "none" });
  161. return;
  162. }
  163. if (this.selectedItems.length === 0) {
  164. common_vendor.index.showToast({ title: "请选择回收物品", icon: "none" });
  165. return;
  166. }
  167. const list = this.selectedItems.map((item) => ({
  168. shopId: item.id,
  169. num: item.quantity
  170. }));
  171. common_vendor.index.__f__("log", "at pages/subcomponent/pickup.vue:326", {
  172. addressId: this.addressId,
  173. strTime: this.selectedTime,
  174. list
  175. }, "createOrder");
  176. common_vendor.index.showLoading({ title: "提交中..." });
  177. this.$api("createOrder", {
  178. addressId: this.addressId,
  179. strTime: this.selectedTime,
  180. list: JSON.stringify(list)
  181. }, (res) => {
  182. if (res && res.success) {
  183. common_vendor.index.__f__("log", "at pages/subcomponent/pickup.vue:340", res, "createOrder-res");
  184. common_vendor.index.showToast({ title: "预约成功", icon: "success" });
  185. common_vendor.index.redirectTo({
  186. url: `/pages/subcomponent/detail?id=${res.result.id}`
  187. });
  188. }
  189. });
  190. },
  191. toggleExpandOrder() {
  192. this.showAllItems = !this.showAllItems;
  193. },
  194. async getAddressList() {
  195. const res = await this.$api("getAddressList", {});
  196. if (res && res.code === 200 && res.result && res.result.records) {
  197. const defaultAddr = res.result.records.find((item) => item.defaultFlag === "Y");
  198. if (defaultAddr) {
  199. this.selectedAddress = defaultAddr;
  200. this.address = defaultAddr.address;
  201. this.addressId = defaultAddr.id;
  202. if (defaultAddr.addressDetails)
  203. this.selectedAddress.addressDetails = defaultAddr.addressDetails;
  204. } else {
  205. this.selectedAddress = null;
  206. this.address = "";
  207. }
  208. }
  209. },
  210. generateDateTabs() {
  211. const weekMap = ["日", "一", "二", "三", "四", "五", "六"];
  212. const result = [];
  213. const today = /* @__PURE__ */ new Date();
  214. for (let i = 0; i < 6; i++) {
  215. const d = new Date(today);
  216. d.setDate(today.getDate() + i);
  217. const mm = (d.getMonth() + 1).toString().padStart(2, "0");
  218. const dd = d.getDate().toString().padStart(2, "0");
  219. let label = "";
  220. if (i === 0)
  221. label = `今天 ${mm}-${dd}`;
  222. else if (i === 1)
  223. label = `明天 ${mm}-${dd}`;
  224. else if (i === 2)
  225. label = `后天 ${mm}-${dd}`;
  226. else
  227. label = `${weekMap[d.getDay()]} ${mm}-${dd}`;
  228. result.push({ label, date: new Date(d) });
  229. }
  230. return result;
  231. },
  232. getAreaList() {
  233. this.$api("getAreaList", {}, (res) => {
  234. if (res.code == 200 && Array.isArray(res.result)) {
  235. const sorted = res.result.slice().sort((a, b) => a.sort - b.sort);
  236. this.steps = sorted.map((item) => ({
  237. icon: item.image,
  238. text: item.title
  239. }));
  240. }
  241. });
  242. }
  243. }
  244. };
  245. if (!Array) {
  246. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  247. _easycom_uni_icons2();
  248. }
  249. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  250. if (!Math) {
  251. _easycom_uni_icons();
  252. }
  253. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  254. return common_vendor.e({
  255. a: common_vendor.p({
  256. type: "left",
  257. size: "20"
  258. }),
  259. b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  260. c: $data.statusBarHeight + 88 + "rpx",
  261. d: $data.statusBarHeight + "px",
  262. e: common_vendor.f($data.steps, (step, i, i0) => {
  263. return common_vendor.e({
  264. a: step.icon,
  265. b: i === 0
  266. }, i === 0 ? {
  267. c: common_vendor.t(step.text)
  268. } : {
  269. d: common_vendor.t(step.text)
  270. }, {
  271. e: i
  272. });
  273. }),
  274. f: common_vendor.t($options.displayAddress || "请选择"),
  275. g: !$options.displayAddress ? 1 : "",
  276. h: common_vendor.o((...args) => $options.selectAddress && $options.selectAddress(...args)),
  277. i: common_vendor.t($data.selectedTime || "请选择"),
  278. j: !$data.selectedTime ? 1 : "",
  279. k: common_vendor.o((...args) => $options.openTimePicker && $options.openTimePicker(...args)),
  280. l: common_vendor.f($data.showAllItems ? $data.selectedItems : $data.selectedItems.slice(0, 3), (item, index, i0) => {
  281. return {
  282. a: item.icon,
  283. b: common_vendor.t(item.name),
  284. c: common_vendor.t(item.desc),
  285. d: common_vendor.t(item.unitPrice),
  286. e: common_vendor.t(item.quantity),
  287. f: common_vendor.t(item.unitPrice * item.quantity),
  288. g: index
  289. };
  290. }),
  291. m: $data.selectedItems.length > 3
  292. }, $data.selectedItems.length > 3 ? {
  293. n: common_vendor.t($data.showAllItems ? "收起" : `展开(共${$data.selectedItems.length}件)`),
  294. o: common_vendor.t($data.showAllItems ? "▲" : "▼"),
  295. p: common_vendor.o((...args) => $options.toggleExpandOrder && $options.toggleExpandOrder(...args))
  296. } : {}, {
  297. q: $data.agreed
  298. }, $data.agreed ? {} : {}, {
  299. r: $data.agreed ? 1 : "",
  300. s: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)),
  301. t: common_vendor.o((...args) => $options.showServiceAgreement && $options.showServiceAgreement(...args)),
  302. v: common_vendor.o((...args) => $options.showPrivacyPolicy && $options.showPrivacyPolicy(...args)),
  303. w: common_vendor.t($options.totalCount),
  304. x: common_vendor.t($options.totalPriceRange),
  305. y: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)),
  306. z: $data.showTimePicker
  307. }, $data.showTimePicker ? {
  308. A: common_vendor.o((...args) => $options.closeTimePicker && $options.closeTimePicker(...args)),
  309. B: common_vendor.o((...args) => $options.resetPicker && $options.resetPicker(...args)),
  310. C: common_vendor.f($data.dateTabs, (tab, index, i0) => {
  311. return {
  312. a: common_vendor.t(tab.label),
  313. b: index,
  314. c: common_vendor.n({
  315. active: $data.currentDateTab === index
  316. }),
  317. d: common_vendor.o(($event) => $options.selectDateTab(index), index)
  318. };
  319. }),
  320. D: common_vendor.f($data.timeSlots, (slot, idx, i0) => {
  321. return {
  322. a: common_vendor.t(slot),
  323. b: idx,
  324. c: common_vendor.n({
  325. active: $data.selectedTimeSlot === idx
  326. }),
  327. d: common_vendor.o(($event) => $options.selectTimeSlot(idx), idx)
  328. };
  329. }),
  330. E: common_vendor.o((...args) => $options.confirmTime && $options.confirmTime(...args))
  331. } : {}, {
  332. F: $data.navBarHeightRpx + "rpx"
  333. });
  334. }
  335. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-c732bc46"]]);
  336. wx.createPage(MiniProgramPage);
  337. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/subcomponent/pickup.js.map