confirm-receiving.ts 2.7 KB

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