other-detail.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. import DictionariesBehavior from "../../../../core/behavior/dictionaries.behavior";
  2. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  3. import { handleWeChatPayment } from "../../../../utils/util";
  4. import {
  5. getTickleContext,
  6. } from "../../../../core/behavior/tickle.behavior";
  7. import { getOrderDetailMethod, orderPayMethod } from "../../request";
  8. // module/order/pages/select-goods/other-detail.ts
  9. Page({
  10. behaviors: [PageContainerBehavior, DictionariesBehavior],
  11. data: {
  12. title: "",
  13. id: "",
  14. totalGoodsCount: 0,
  15. goodsList: [] as Array<{
  16. category: string;
  17. goods: Array<{
  18. id: string;
  19. name: string;
  20. description?: string;
  21. image: string;
  22. price: number;
  23. quantity: number;
  24. status?: string;
  25. statusClass?: string;
  26. }>;
  27. }>,
  28. // 三个分类的商品列表
  29. sellTypeFirstItems: [] as Array<any>, // 实体商品(快递类型在上,线下取货类型在下)
  30. sellTypeSecondItems: [] as Array<any>, // 线下服务
  31. sellTypeThirdItems: [] as Array<any>, // 线上权益
  32. selectAll: true,
  33. selectedCount: 0,
  34. totalPrice: 0,
  35. orderDetail: {},
  36. remarkLength: 0,
  37. showDetail: false,
  38. isPaymentLoading: false,
  39. orderStatus: "", // 订单状态:pending, paid, closed, completed
  40. },
  41. onLoad(options: any) {
  42. const remark = (this.data.orderDetail as any)?.remark || '';
  43. this.setData({
  44. remarkLength: remark.length
  45. });
  46. if (options.id) {
  47. this.setData({ id: options.id });
  48. }
  49. if (options.status) {
  50. this.statusType(options.status);
  51. }
  52. },
  53. onShow() {
  54. if (this.data.id) {
  55. this.load(this.data.id);
  56. }
  57. },
  58. observers: {},
  59. statusType(status: any) {
  60. const code = status == null ? "" : String(status);
  61. switch (code) {
  62. case "0":
  63. this.setData({ orderStatus: "pending", title: "待付款" });
  64. break;
  65. case "6":
  66. this.setData({ orderStatus: "received", title: "已付款" });
  67. break;
  68. case "2":
  69. this.setData({ orderStatus: "closed", title: "交易关闭" });
  70. break;
  71. case "345":
  72. this.setData({ orderStatus: "completed", title: "交易成功" });
  73. break;
  74. default:
  75. this.setData({ orderStatus: "", title: "" });
  76. break;
  77. }
  78. },
  79. // 订单详情
  80. async load(id: string) {
  81. wx.showLoading({ title: "加载中" });
  82. try {
  83. const res = await getOrderDetailMethod(id);
  84. if (res && res.data) {
  85. this.setData({ orderDetail: res.data });
  86. if (
  87. !res.data.liaison ||
  88. !res.data.phone ||
  89. !res.data.provinceName ||
  90. !res.data.cityName ||
  91. !res.data.areaName ||
  92. !res.data.detailAddress
  93. ) {
  94. this.setData({
  95. showDetail: true,
  96. });
  97. } else {
  98. this.setData({
  99. showDetail: false,
  100. });
  101. this.setData({
  102. name: res.data.liaison ? `${res.data.liaison}` : "",
  103. phone: res.data.phone ? `${res.data.phone}` : "",
  104. address: `${res.data.provinceName}${res.data.cityName ? `${res.data.cityName}` : ""
  105. }${res.data.areaName ? `${res.data.areaName}` : ""}${res.data.detailAddress ? `${res.data.detailAddress}` : ""
  106. }`,
  107. });
  108. }
  109. // 0:待付款
  110. // 2 交易关闭
  111. // 6 待收货
  112. // 345 交易成功
  113. this.statusType(res.data.orderStatus);
  114. // 处理三个分类的商品数据
  115. const processItems = (items: any[]) => {
  116. if (!items || !Array.isArray(items)) {
  117. return [];
  118. }
  119. return items.map((item: any) => {
  120. // 0是一口价 1按穴位/经络次数计费
  121. const pricingType = item?.conditioningProgramDetail?.pricingType;
  122. return {
  123. id: item.id || '',
  124. patientConditioningRecordId: item?.patientConditioningRecordId || '',//调理记录id
  125. name: item.conditioningProgramName || '',
  126. description: (() => {
  127. const convertDose = item?.conditioningProgramDetail?.cpFixedPricingRule?.convertDose
  128. const dose = convertDose ?? '';
  129. const unit = item?.conditioningProgramDetail?.cpFixedPricingRule?.convertUnit ?? '次';
  130. return pricingType === '0' ? `${dose} ${unit}` : `1次`;
  131. })(),
  132. sellType: item?.sellType || '', //商品类型 1-实体商品 2-线下服务 3-线上权益
  133. //start实体商品所用到的字段
  134. receiptStatus: item?.receiptStatus || '', //收货状态 0-待发货 1-已发货 2-已收货 这个字段用于实体商品的收获状态
  135. receiptTime: item?.receiptTime || '', //收货时间
  136. receiptType: item?.receiptType || '', //收货类型 0-快递 1-线下取货
  137. expressType: item?.expressType || '', //快递类型 0-邮政速递 1-顺丰速运 2-京东快递 3-中通快递 4-圆通速递 5-申通快递 6-韵达快递 7-极兔速递
  138. expressNo: item?.expressNo || '', //快递单号
  139. expressTypeName: this.getExpressTypeName(item?.expressType), //快递公司名称
  140. expressTypeIcon: this.getExpressTypeIcon(item?.expressType), //快递公司图标
  141. //end实体商品所用到的字段
  142. progress: item?.progress || '', //进度 0-进行中 1-已完成 2-未开始 3-已取消 这个字段用于线下服务商品以及线上权益商品的进度状态
  143. image: item.conditioningProgramPhoto || '',
  144. price: item?.unitPrice || 0,
  145. quantity: item?.totalMeasure || 0,
  146. statusClass: this.getStatusClass(item?.sellType, item?.progress, item?.receiptStatus),
  147. statusText: this.getGoodsStatusText(item?.sellType, item?.progress, item?.receiptStatus),
  148. }
  149. });
  150. };
  151. // 分别处理三个数组
  152. let sellTypeFirstItems = processItems(res.data?.sellTypeFirstItems || []);
  153. const sellTypeSecondItems = processItems(res.data?.sellTypeSecondItems || []);
  154. const sellTypeThirdItems = processItems(res.data?.sellTypeThirdItems || []);
  155. // 对实体商品进行排序:快递类型(receiptType === '0')在上,线下取货类型(receiptType === '1')在下
  156. sellTypeFirstItems = sellTypeFirstItems.sort((a: any, b: any) => {
  157. const aType = a.receiptType || '';
  158. const bType = b.receiptType || '';
  159. if (aType === '0' && bType === '1') {
  160. return -1;
  161. }
  162. if (aType === '1' && bType === '0') {
  163. return 1;
  164. }
  165. return 0;
  166. });
  167. this.setData({
  168. sellTypeFirstItems,
  169. sellTypeSecondItems,
  170. sellTypeThirdItems,
  171. });
  172. }
  173. } catch (error: any) {
  174. wx.showToast({
  175. title: error.errMsg,
  176. icon: "none",
  177. });
  178. }
  179. wx.hideLoading();
  180. },
  181. // 去预约
  182. goAppointment(e: any) {
  183. const { id } = e.currentTarget.dataset;
  184. // 去非药物治疗页面
  185. wx.navigateTo({
  186. url: `/module/care/pages/offlineTreatment/offlineTreatment?id=${id}`,
  187. });
  188. },
  189. // 立即支付
  190. async onPayment() {
  191. if (this.data.isPaymentLoading) {
  192. return;
  193. }
  194. this.setData({ isPaymentLoading: true });
  195. try {
  196. // 调用支付接口
  197. const payResult = await orderPayMethod(this.data.id, (this.data.orderDetail as any)?.remark);
  198. if (payResult && payResult.data) {
  199. const paymentParams = payResult.data;
  200. handleWeChatPayment(paymentParams, (res: any) => {
  201. // 支付成功,跳转到成功页面
  202. wx.redirectTo({
  203. url: "/module/article/pages/success-page/success-page?title=订单支付成功",
  204. });
  205. }, (error: any) => {
  206. this.setData({ isPaymentLoading: false });
  207. if (error?.errMsg === 'requestPayment:fail cancel') {
  208. // 支付取消跳到支付订单页面
  209. wx.navigateBack({ delta: 1 });
  210. }
  211. // wx.showToast({
  212. // title: error.errMsg,
  213. // icon: "none",
  214. // });
  215. });
  216. } else {
  217. wx.showToast({
  218. title: payResult.errMsg,
  219. icon: "none",
  220. });
  221. }
  222. } catch (error: any) {
  223. wx.showToast({
  224. title: error.errMsg,
  225. icon: "none",
  226. });
  227. } finally {
  228. this.setData({ isPaymentLoading: false });
  229. }
  230. },
  231. // 备注输入处理
  232. onRemarkInput(e: any) {
  233. const value = e.detail.value;
  234. const length = value.length;
  235. // 限制最大长度为200
  236. if (length > 200) {
  237. return;
  238. }
  239. this.setData({
  240. 'orderDetail.remark': value,
  241. remarkLength: length
  242. });
  243. },
  244. // 复制订单号
  245. copyOrderNo(e: any) {
  246. const orderNo = e.currentTarget.dataset.orderno;
  247. if (!orderNo) {
  248. getTickleContext.call(this).showWarnMessage("订单号为空");
  249. return;
  250. }
  251. wx.setClipboardData({
  252. data: orderNo,
  253. success: () => {
  254. wx.showToast({
  255. title: '已复制',
  256. icon: 'none'
  257. });
  258. }
  259. });
  260. },
  261. // 获取状态类名
  262. // sellType: 商品类型 1-实体商品 2-线下服务 3-线上权益
  263. // progress: 进度状态(用于线下服务和线上权益):0-进行中 1-已完成 2-未开始
  264. // receiptStatus: 收货状态(用于实体商品):0-待发货 1-已发货 2-已收货
  265. getStatusClass(sellType?: string | number, progress?: string | number, receiptStatus?: string | number): string {
  266. const type = String(sellType || '');
  267. // 实体商品 (sellType === 1) 使用 receiptStatus(三种状态)
  268. if (type === "1") {
  269. const status = String(receiptStatus || '');
  270. if (status === "0") {
  271. return "status-pending"; // 待发货
  272. } else if (status === "1") {
  273. return "status-received"; // 已发货
  274. } else if (status === "2") {
  275. return "status-completed"; // 已收货
  276. }
  277. }
  278. // 线下服务 (sellType === 2) 和线上权益 (sellType === 3) 使用 progress(三种状态)
  279. else if (type === "2" || type === "3") {
  280. const status = String(progress || '');
  281. if (status === "0") {
  282. return "status-pending"; // 进行中
  283. } else if (status === "1") {
  284. return "status-completed"; // 已完成
  285. } else if (status === "2") {
  286. return "status-closed"; // 未开始
  287. }
  288. }
  289. return "";
  290. },
  291. // 获取商品状态文本
  292. getGoodsStatusText(sellType?: string | number, progress?: string | number, receiptStatus?: string | number): string {
  293. const type = String(sellType || '');
  294. // 实体商品 (sellType === 1) 使用 receiptStatus(三种状态)
  295. if (type === "1") {
  296. const status = String(receiptStatus || '');
  297. if (status === "0") {
  298. return "待发货";
  299. } else if (status === "1") {
  300. return "已发货";
  301. } else if (status === "2") {
  302. return "已收货";
  303. }
  304. }
  305. // 线下服务 (sellType === 2) 和线上权益 (sellType === 3) 使用 progress(三种状态)
  306. else if (type === "2" || type === "3") {
  307. const status = String(progress || '');
  308. if (status === "0") {
  309. return "进行中";
  310. } else if (status === "1") {
  311. return "已完成";
  312. } else if (status === "2") {
  313. return "未开始";
  314. }
  315. }
  316. return "";
  317. },
  318. // 获取快递公司名称
  319. getExpressTypeName(expressType?: string | number): string {
  320. const expressTypeMap: Record<string, string> = {
  321. "0": "邮政速递",
  322. "1": "顺丰速运",
  323. "2": "京东快递",
  324. "3": "中通快递",
  325. "4": "圆通速递",
  326. "5": "申通快递",
  327. "6": "韵达快递",
  328. "7": "极兔速递",
  329. };
  330. return expressTypeMap[String(expressType || '')] || "";
  331. },
  332. // 获取快递公司图标
  333. getExpressTypeIcon(expressType?: string | number): string {
  334. const expressIconMap: Record<string, string> = {
  335. "0": "icon-youzhengkuaidi", // 邮政速递
  336. "1": "icon-shunfengkuaidi", // 顺丰速运
  337. "2": "icon-jingdong", // 京东快递
  338. "3": "icon-zhongtong", // 中通快递
  339. "4": "icon-yuantongkuaidi", // 圆通速递
  340. "5": "icon-shentong", // 申通快递
  341. "6": "icon-yunda", // 韵达快递
  342. "7": "icon-jitukuaidi", // 极兔速递
  343. };
  344. return expressIconMap[String(expressType || '')] || "";
  345. },
  346. // 获取订单状态文本
  347. getStatusText(status: string | number): string {
  348. const statusTextMap: Record<string, string> = {
  349. "0": "待付款",
  350. "6": "已付款",
  351. "2": "交易关闭",
  352. "345": "交易成功",
  353. };
  354. return statusTextMap[String(status)] || "";
  355. },
  356. // 确认收货
  357. onConfirmReceipt(e: any) {
  358. const { patientconditioningrecordid } = e.currentTarget.dataset;
  359. if (patientconditioningrecordid) {
  360. const shippedGoods = this.data.sellTypeFirstItems.filter((item: any) => item.receiptStatus === '1');
  361. if (shippedGoods.length === 0) {
  362. wx.showToast({
  363. title: '没有可确认收货的商品',
  364. icon: 'none'
  365. });
  366. return;
  367. }
  368. // 去确认收货页面
  369. wx.navigateTo({
  370. url: `/module/article/pages/confirm-receiving/confirm-receiving?patientConditioningRecordId=${patientconditioningrecordid as string}&goodsList=${encodeURIComponent(JSON.stringify(shippedGoods))}`,
  371. fail: (err) => {
  372. wx.showToast({
  373. title: err.errMsg || '跳转失败',
  374. icon: 'none'
  375. });
  376. }
  377. });
  378. } else {
  379. wx.showToast({
  380. title: '调理记录id为空',
  381. icon: 'none'
  382. });
  383. }
  384. },
  385. });