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

352 lines
11 KiB

  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const pages_mixins_pullRefreshMixin = require("../mixins/pullRefreshMixin.js");
  4. const common_assets = require("../../common/assets.js");
  5. const _sfc_main = {
  6. mixins: [pages_mixins_pullRefreshMixin.pullRefreshMixin],
  7. data() {
  8. return {
  9. address: "",
  10. selectedAddress: null,
  11. displayAddress: "请选择取件地址",
  12. addressDetail: {
  13. province: "",
  14. city: "",
  15. district: "",
  16. street: "",
  17. address: "",
  18. name: "",
  19. phone: "",
  20. isDefault: false
  21. },
  22. appointmentTime: "预约 周四 11:00~13:00",
  23. timeDetail: {
  24. date: "",
  25. time: "",
  26. displayText: ""
  27. },
  28. totalCount: 16,
  29. estimatePrice: "73.6-75.8",
  30. agreed: true,
  31. showTimePicker: false,
  32. currentDateTab: 0,
  33. pickerValue: [0, 0, 0],
  34. years: [],
  35. months: [],
  36. days: [],
  37. selectedDate: "",
  38. timeSlot: "11:00~13:00",
  39. // 固定时间段
  40. selectedItems: [
  41. {
  42. name: "羽绒服",
  43. desc: "允许脏破烂,160码以上",
  44. unitPrice: 8,
  45. quantity: 8
  46. },
  47. {
  48. name: "品牌羽绒服",
  49. desc: "允许脏破烂,160码以上",
  50. unitPrice: 10,
  51. quantity: 1
  52. }
  53. ],
  54. totalPriceRange: "¥ 73.6-75.8"
  55. };
  56. },
  57. computed: {
  58. displayAddress() {
  59. if (this.selectedAddress) {
  60. return this.selectedAddress.address;
  61. }
  62. return "请选择取件地址";
  63. },
  64. totalPriceRange() {
  65. const totalPrice = this.selectedItems.reduce((total, item) => total + item.unitPrice * item.quantity, 0);
  66. return `¥ ${totalPrice.toFixed(2)}-${(totalPrice + 2).toFixed(2)}`;
  67. },
  68. canSubmit() {
  69. return this.agreed && this.selectedAddress && this.timeDetail.date && this.selectedItems.length > 0;
  70. }
  71. },
  72. methods: {
  73. async onRefresh() {
  74. await new Promise((resolve) => setTimeout(resolve, 1e3));
  75. common_vendor.index.stopPullRefresh();
  76. },
  77. goBack() {
  78. common_vendor.index.navigateBack();
  79. },
  80. selectAddress() {
  81. common_vendor.index.navigateTo({
  82. url: "/pages/component/select"
  83. });
  84. },
  85. openTimePicker() {
  86. this.showTimePicker = true;
  87. if (!this.years.length) {
  88. this.initDatePicker();
  89. }
  90. },
  91. closeTimePicker() {
  92. this.showTimePicker = false;
  93. },
  94. initDatePicker() {
  95. const currentDate = /* @__PURE__ */ new Date();
  96. const currentYear = currentDate.getFullYear();
  97. this.years = Array.from({ length: 5 }, (_, i) => currentYear + i);
  98. this.months = Array.from({ length: 12 }, (_, i) => i + 1);
  99. this.updateDays(currentYear, currentDate.getMonth() + 1);
  100. this.pickerValue = [0, currentDate.getMonth(), currentDate.getDate() - 1];
  101. },
  102. updateDays(year, month) {
  103. const daysInMonth = new Date(year, month, 0).getDate();
  104. this.days = Array.from({ length: daysInMonth }, (_, i) => i + 1);
  105. },
  106. selectDateTab(index) {
  107. this.currentDateTab = index;
  108. if (index < 3) {
  109. const date = /* @__PURE__ */ new Date();
  110. date.setDate(date.getDate() + index);
  111. const yearIndex = this.years.findIndex((year) => year === date.getFullYear());
  112. this.pickerValue = [
  113. yearIndex,
  114. date.getMonth(),
  115. date.getDate() - 1
  116. ];
  117. this.updateDays(date.getFullYear(), date.getMonth() + 1);
  118. }
  119. },
  120. onPickerChange(e) {
  121. this.currentDateTab = 3;
  122. const values = e.detail.value;
  123. const year = this.years[values[0]];
  124. const month = this.months[values[1]];
  125. this.updateDays(year, month);
  126. if (values[2] >= this.days.length) {
  127. values[2] = this.days.length - 1;
  128. }
  129. this.pickerValue = values;
  130. },
  131. resetPicker() {
  132. this.initDatePicker();
  133. this.currentDateTab = 0;
  134. },
  135. confirmTime() {
  136. const year = this.years[this.pickerValue[0]];
  137. const month = this.months[this.pickerValue[1]];
  138. const day = this.days[this.pickerValue[2]];
  139. const date = new Date(year, month - 1, day);
  140. const weekDays = ["日", "一", "二", "三", "四", "五", "六"];
  141. const weekDay = weekDays[date.getDay()];
  142. this.timeDetail = {
  143. date: `${year}-${month}-${day}`,
  144. time: this.timeSlot,
  145. displayText: `预约 周${weekDay} ${this.timeSlot}`
  146. };
  147. this.appointmentTime = this.timeDetail.displayText;
  148. this.closeTimePicker();
  149. },
  150. handleAddressSelected(address) {
  151. common_vendor.index.__f__("log", "at pages/subcomponent/order_edit.vue:356", "接收到选中的地址:", address);
  152. this.selectedAddress = address;
  153. this.address = address.address;
  154. this.$forceUpdate();
  155. },
  156. handleTimeSelected(time) {
  157. this.timeDetail = time;
  158. this.appointmentTime = time.displayText;
  159. },
  160. showRules() {
  161. common_vendor.index.navigateTo({
  162. url: "/pages/rules/recycle"
  163. });
  164. },
  165. toggleAgreement() {
  166. this.agreed = !this.agreed;
  167. },
  168. viewAgreement() {
  169. common_vendor.index.navigateTo({
  170. url: "/pages/agreement/service"
  171. });
  172. },
  173. viewPrivacy() {
  174. common_vendor.index.navigateTo({
  175. url: "/pages/agreement/privacy"
  176. });
  177. },
  178. submitOrder() {
  179. if (!this.agreed) {
  180. return common_vendor.index.showToast({
  181. title: "请先同意服务协议",
  182. icon: "none"
  183. });
  184. }
  185. if (!this.selectedAddress) {
  186. return common_vendor.index.showToast({
  187. title: "请选择取件地址",
  188. icon: "none"
  189. });
  190. }
  191. if (!this.timeDetail.date) {
  192. return common_vendor.index.showToast({
  193. title: "请选择上门时间",
  194. icon: "none"
  195. });
  196. }
  197. if (this.selectedItems.length === 0) {
  198. return common_vendor.index.showToast({
  199. title: "请选择回收物品",
  200. icon: "none"
  201. });
  202. }
  203. common_vendor.index.showLoading({
  204. title: "提交中..."
  205. });
  206. ({
  207. address: this.selectedAddress,
  208. time: this.timeDetail,
  209. items: this.selectedItems,
  210. totalCount: this.totalCount,
  211. totalPrice: this.totalPriceRange
  212. });
  213. setTimeout(() => {
  214. common_vendor.index.hideLoading();
  215. common_vendor.index.showToast({
  216. title: "修改成功",
  217. icon: "success"
  218. });
  219. setTimeout(() => {
  220. common_vendor.index.navigateBack();
  221. }, 1500);
  222. }, 1e3);
  223. },
  224. decreaseQuantity(index) {
  225. if (this.selectedItems[index].quantity > 1) {
  226. this.selectedItems[index].quantity--;
  227. }
  228. },
  229. increaseQuantity(index) {
  230. this.selectedItems[index].quantity++;
  231. }
  232. },
  233. onLoad(options) {
  234. if (options.id) {
  235. this.addressDetail = {
  236. province: "海南省",
  237. city: "海口市",
  238. district: "秀英区",
  239. street: "秀英街道",
  240. address: "5单元1...",
  241. name: "张三",
  242. phone: "13800138000"
  243. };
  244. this.timeDetail = {
  245. date: "2024-03-21",
  246. time: "11:00-13:00",
  247. displayText: "周四 11:00~13:00"
  248. };
  249. }
  250. common_vendor.index.$on("addressSelected", (address) => {
  251. common_vendor.index.__f__("log", "at pages/subcomponent/order_edit.vue:465", "接收到选中的地址:", address);
  252. this.selectedAddress = address;
  253. this.address = address.address;
  254. this.$forceUpdate();
  255. });
  256. },
  257. onUnload() {
  258. common_vendor.index.$off("addressSelected");
  259. },
  260. onShow() {
  261. common_vendor.index.__f__("log", "at pages/subcomponent/order_edit.vue:477", "当前选中的地址:", this.selectedAddress);
  262. if (this.selectedAddress) {
  263. this.address = this.selectedAddress.address;
  264. this.$forceUpdate();
  265. }
  266. const selectedTime = getApp().globalData.selectedTime;
  267. if (selectedTime) {
  268. this.handleTimeSelected(selectedTime);
  269. getApp().globalData.selectedTime = null;
  270. }
  271. },
  272. created() {
  273. this.initDatePicker();
  274. },
  275. watch: {
  276. showTimePicker(val) {
  277. if (val) {
  278. this.updateDays(this.pickerValue[0], this.pickerValue[1]);
  279. }
  280. }
  281. }
  282. };
  283. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  284. return common_vendor.e({
  285. a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  286. b: common_assets._imports_0$3,
  287. c: common_assets._imports_1$2,
  288. d: common_assets._imports_2$2,
  289. e: common_assets._imports_3$1,
  290. f: common_vendor.t($options.displayAddress),
  291. g: common_vendor.o((...args) => $options.selectAddress && $options.selectAddress(...args)),
  292. h: common_vendor.t($data.appointmentTime),
  293. i: common_vendor.o((...args) => $options.openTimePicker && $options.openTimePicker(...args)),
  294. j: common_vendor.f($data.selectedItems, (item, index, i0) => {
  295. return {
  296. a: item.icon,
  297. b: common_vendor.t(item.name),
  298. c: common_vendor.o((...args) => $options.showRules && $options.showRules(...args), index),
  299. d: common_vendor.t(item.desc),
  300. e: common_vendor.t(item.unitPrice),
  301. f: common_vendor.o(($event) => $options.decreaseQuantity(index), index),
  302. g: common_vendor.t(item.quantity),
  303. h: common_vendor.o(($event) => $options.increaseQuantity(index), index),
  304. i: index
  305. };
  306. }),
  307. k: $data.agreed
  308. }, $data.agreed ? {} : {}, {
  309. l: $data.agreed ? 1 : "",
  310. m: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)),
  311. n: common_vendor.t($data.totalCount),
  312. o: common_vendor.t($options.totalPriceRange),
  313. p: !$options.canSubmit,
  314. q: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)),
  315. r: $data.showTimePicker
  316. }, $data.showTimePicker ? {
  317. s: common_vendor.o((...args) => $options.closeTimePicker && $options.closeTimePicker(...args)),
  318. t: common_vendor.o((...args) => $options.resetPicker && $options.resetPicker(...args)),
  319. v: common_vendor.f(["今天", "明天", "后天", "自定义"], (tab, index, i0) => {
  320. return {
  321. a: common_vendor.t(tab),
  322. b: index,
  323. c: $data.currentDateTab === index ? 1 : "",
  324. d: common_vendor.o(($event) => $options.selectDateTab(index), index)
  325. };
  326. }),
  327. w: common_vendor.f($data.years, (year, k0, i0) => {
  328. return {
  329. a: common_vendor.t(year),
  330. b: year
  331. };
  332. }),
  333. x: common_vendor.f($data.months, (month, k0, i0) => {
  334. return {
  335. a: common_vendor.t(month),
  336. b: month
  337. };
  338. }),
  339. y: common_vendor.f($data.days, (day, k0, i0) => {
  340. return {
  341. a: common_vendor.t(day),
  342. b: day
  343. };
  344. }),
  345. z: $data.pickerValue,
  346. A: common_vendor.o((...args) => $options.onPickerChange && $options.onPickerChange(...args)),
  347. B: common_vendor.o((...args) => $options.confirmTime && $options.confirmTime(...args))
  348. } : {});
  349. }
  350. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2cee0a47"]]);
  351. wx.createPage(MiniProgramPage);
  352. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/subcomponent/order_edit.js.map