confirm-receiving.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import tickleBehavior from "../../../../core/behavior/tickle.behavior";
  3. import { orderConfirmReceiptMethod } from "../../request";
  4. // module/article/pages/confirm-receiving/confirm-receiving.ts
  5. Page({
  6. behaviors: [
  7. PageContainerBehavior,
  8. tickleBehavior,
  9. ],
  10. data: {
  11. patientConditioningRecordId: '',
  12. orderId: '',
  13. goodsList: [] as Array<{
  14. id: number;
  15. name: string;
  16. description: string;
  17. image: string;
  18. checked: boolean;
  19. }>
  20. },
  21. async onLoad(options: any) {
  22. console.log("onLoad", options)
  23. if (options.patientConditioningRecordId) {
  24. this.setData({ patientConditioningRecordId: options.patientConditioningRecordId });
  25. }
  26. if (options.goodsList) {
  27. const goodsList = JSON.parse(decodeURIComponent(options.goodsList));
  28. // 为每个商品添加 checked 属性,默认全部选中
  29. const goodsListWithChecked = goodsList.map((item: any) => ({
  30. ...item,
  31. checked: true
  32. }));
  33. this.setData({ goodsList: goodsListWithChecked });
  34. }
  35. console.log("goodsList", this.data.goodsList)
  36. },
  37. properties: {
  38. },
  39. copyExpressNo(e: any) {
  40. wx.setClipboardData({
  41. data: e.currentTarget.dataset.no,
  42. success: () => wx.showToast({ title: '已复制', icon: 'none' })
  43. });
  44. },
  45. onCancel() {
  46. // 关闭弹窗或返回
  47. wx.navigateBack();
  48. },
  49. // 商品复选框变化
  50. onGoodsCheckChange(e: any) {
  51. const { index } = e.currentTarget.dataset;
  52. const checked = e.detail.checked;
  53. const goodsList = this.data.goodsList;
  54. goodsList[index].checked = checked;
  55. this.setData({ goodsList });
  56. },
  57. // 确认收货逻辑
  58. async onConfirmReceiving() {
  59. // 获取选中的商品id数组
  60. const selectedIds = this.data.goodsList
  61. .filter((item: any) => item.checked)
  62. .map((item: any) => item.id);
  63. if (selectedIds.length === 0) {
  64. wx.showToast({ title: '请至少选择一个商品', icon: 'none' });
  65. return;
  66. }
  67. console.log(selectedIds, "selectedIds======选中的商品id")
  68. let that = this;
  69. wx.showModal({
  70. title: '提示',
  71. content: '确认收货后,订单将无法修改,请确认无误后再进行操作',
  72. success: (res) => {
  73. if (res.confirm) {
  74. that.confirmReceiving(selectedIds);
  75. }
  76. }
  77. });
  78. },
  79. async confirmReceiving(selectedIds: number[]) {
  80. try {
  81. await orderConfirmReceiptMethod(this.data.patientConditioningRecordId, selectedIds);
  82. wx.showToast({ title: '收货成功', icon: 'success' });
  83. setTimeout(() => {
  84. wx.redirectTo({
  85. url: "/module/article/pages/success-page/success-page?title=收货成功",
  86. });
  87. }, 1000);
  88. } catch (error: any) {
  89. wx.showToast({ title: error.errMsg || '收货失败', icon: 'none' });
  90. }
  91. }
  92. })