orderdetails.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // subpackages/orderdetails/orderdetails.js
  2. // import { models, db, _ } from '../../utils/cloudbase.js'
  3. import { getDB, getModels, getCommand, getTempFileURLs } from '../../utils/cloudbase.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. dingwei: '',
  10. fuzhi: '',
  11. yesbaoguo: '',
  12. item: {},
  13. adresseslist: {}
  14. },
  15. async onLoad(options) {
  16. const itemData = decodeURIComponent(options.data);
  17. // console.log(itemData, 'itemData');
  18. const item = JSON.parse(itemData);
  19. console.log(item, 'item');
  20. // 格式化时间
  21. item.createdAtText = this.formatTime(item.createdAt);
  22. this.setData({
  23. item: item
  24. }, () => {
  25. this.getadresses()
  26. });
  27. const fileIDs = [
  28. 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/dingwei.png',
  29. 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/fuzhi.png',
  30. 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/yesbaoguo.png'
  31. ];
  32. const fileList = await getTempFileURLs(fileIDs)
  33. this.setData({
  34. dingwei: fileList[0].tempFileURL,
  35. fuzhi: fileList[1].tempFileURL,
  36. yesbaoguo: fileList[2].tempFileURL,
  37. })
  38. // // 并发下载多个 fileID
  39. // Promise.all(
  40. // fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  41. // ).then(results => {
  42. // // 每个 result 对应一个下载结果
  43. // const tempFilePaths = results.map(r => r.tempFilePath);
  44. // console.log('全部下载成功:', tempFilePaths);
  45. // this.setData({
  46. // dingwei: tempFilePaths[0],
  47. // fuzhi: tempFilePaths[1],
  48. // yesbaoguo: tempFilePaths[2],
  49. // });
  50. // }).catch(err => {
  51. // console.error('有文件下载失败:', err);
  52. // });
  53. },
  54. formatTime(ts) {
  55. const date = new Date(ts);
  56. const y = date.getFullYear();
  57. const m = String(date.getMonth() + 1).padStart(2, '0');
  58. const d = String(date.getDate()).padStart(2, '0');
  59. const hh = String(date.getHours()).padStart(2, '0');
  60. const mm = String(date.getMinutes()).padStart(2, '0');
  61. const ss = String(date.getSeconds()).padStart(2, '0');
  62. return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
  63. },
  64. async getadresses() {
  65. const models = await getModels()
  66. const { data } = await models.adresses.get({
  67. filter: {
  68. where: {
  69. $and: [
  70. {
  71. _id: {
  72. $eq: this.data.item.adresses_id, // 推荐传入_id数据标识进行操作
  73. },
  74. },
  75. ]
  76. }
  77. },
  78. // envType: pre 体验环境, prod 正式环境
  79. envType: "prod",
  80. });
  81. // 返回查询到的数据
  82. this.setData({
  83. adresseslist: data
  84. })
  85. },
  86. copyText(e) {
  87. const copyText = e.currentTarget.dataset.copytext;
  88. wx.setClipboardData({
  89. data: copyText,
  90. success: function () {
  91. wx.showToast({
  92. title: '复制成功',
  93. icon: 'success'
  94. });
  95. },
  96. fail: function () {
  97. wx.showToast({
  98. title: '复制失败',
  99. icon: 'none'
  100. });
  101. }
  102. });
  103. },
  104. // 处理第一个按钮的点击事件
  105. handleAction1: async function (event) {
  106. const status = Number(event.currentTarget.dataset.index);
  107. console.log(status, 'statusstatusstatus');
  108. const item = this.data.item;
  109. const models = await getModels()
  110. switch (status) {
  111. case 1:
  112. wx.navigateTo({
  113. url: '/subpackages/orderdetails/orderdetails?data=' + encodeURIComponent(JSON.stringify(item))
  114. });
  115. // 执行查看详情的逻辑
  116. break;
  117. case 0:
  118. // 执行取消订单的逻辑
  119. const { data } = await models.orders.update({
  120. data: {
  121. status: 3, // 状态
  122. },
  123. filter: {
  124. where: {
  125. $and: [
  126. {
  127. _id: {
  128. $eq: item.orders_id, // 推荐传入_id数据标识进行操作
  129. },
  130. },
  131. ]
  132. }
  133. },
  134. // envType: pre 体验环境, prod 正式环境
  135. envType: "prod",
  136. });
  137. // 返回更新成功的条数
  138. console.log(data);
  139. // { count: 1}
  140. if( data.count > 0) {
  141. wx.showToast({
  142. title: '订单取消成功',
  143. icon: 'success',
  144. duration: 1500,
  145. success() {
  146. wx.navigateBack();
  147. }
  148. });
  149. } else {
  150. wx.showToast({ title: '订单取消失败', icon: 'none' });
  151. }
  152. break;
  153. case 2:
  154. // 执行申请售后的逻辑
  155. wx.navigateTo({
  156. url: '/subpackages/afterservice/afterservice?data=' + encodeURIComponent(JSON.stringify(item))
  157. });
  158. break;
  159. default:
  160. console.log("未知状态");
  161. }
  162. },
  163. // 处理第二个按钮的点击事件
  164. handleAction2: function (event) {
  165. const status = Number(event.currentTarget.dataset.index);
  166. const item = this.data.item;
  167. switch (status) {
  168. case 1:
  169. this.getyesordels(item)
  170. break;
  171. case 0:
  172. const selectedItems = [
  173. item
  174. ];
  175. console.log(selectedItems,'selectedItems');
  176. // 执行立即支付的逻辑
  177. wx.setStorageSync('checkoutItems', selectedItems);
  178. wx.navigateTo({
  179. url: '/subpackages/submitorder/submitorder'
  180. });
  181. break;
  182. case 2:
  183. console.log("再来一单");
  184. const rawItem = item;
  185. // 定义要排除的字段
  186. const excludeKeys = [
  187. "adresses_id",
  188. "delete",
  189. "merchandise_id",
  190. "num_index",
  191. "order_id",
  192. "orders_id",
  193. "real_money",
  194. "schools_id",
  195. "specs_index",
  196. "status",
  197. "user_id",
  198. "groupbuy_id"
  199. ];
  200. // 过滤掉不需要的字段
  201. const itemss = Object.fromEntries(
  202. Object.entries(rawItem).filter(([key]) => !excludeKeys.includes(key))
  203. );
  204. wx.navigateTo({
  205. url: '/subpackages/productdetails/productdetails?data=' + encodeURIComponent(JSON.stringify(itemss))
  206. });
  207. break;
  208. default:
  209. console.log("未知状态");
  210. }
  211. },
  212. // 确认收货
  213. async getyesordels (list) {
  214. console.log(list, 'list');
  215. const userInfo = wx.getStorageSync('userInfo');
  216. const userId = userInfo && userInfo._id ? userInfo._id : ''; // 根据你的userInfo结构取ID
  217. const schoolId = userInfo && userInfo.school_id ? userInfo.school_id : ''; // 根据你的userInfo结构取ID
  218. const models = await getModels()
  219. const { data } = await models.orders.update({
  220. data: {
  221. status: 2, // 状态
  222. },
  223. filter: {
  224. where: {
  225. $and: [
  226. {
  227. _id: {
  228. $eq: list.orders_id, // 推荐传入_id数据标识进行操作
  229. },
  230. },
  231. {
  232. merchandise_id: {
  233. $eq: list.merchandise_id, // 推荐传入_id数据标识进行操作
  234. },
  235. },
  236. {
  237. user_id: {
  238. $eq: userId, // 推荐传入_id数据标识进行操作
  239. },
  240. },
  241. {
  242. school_id: {
  243. $eq: schoolId, // 推荐传入_id数据标识进行操作
  244. },
  245. },
  246. ]
  247. }
  248. },
  249. envType: "prod",
  250. });
  251. console.log(data.count, 'data.count');
  252. if (Number(data.count) > 0) {
  253. wx.showToast({
  254. title: '确认收货成功',
  255. icon: 'success',
  256. duration: 1500,
  257. success() {
  258. wx.navigateBack();
  259. }
  260. });
  261. // // ✅ 重新获取数据
  262. // this.setData({
  263. // pageNumber: 1,
  264. // hasMore: true,
  265. // orders: []
  266. // }, () => {
  267. // this.getdatalist(false);
  268. // });
  269. } else {
  270. wx.showToast({
  271. title: '确认收货失败',
  272. icon: 'error',
  273. duration: 1500
  274. });
  275. }
  276. },
  277. })