123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- // subpackages/orderdetails/orderdetails.js
- // import { models, db, _ } from '../../utils/cloudbase.js'
- import { getDB, getModels, getCommand, getTempFileURLs } from '../../utils/cloudbase.js'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- dingwei: '',
- fuzhi: '',
- yesbaoguo: '',
- item: {},
- adresseslist: {}
- },
- async onLoad(options) {
- const itemData = decodeURIComponent(options.data);
- // console.log(itemData, 'itemData');
- const item = JSON.parse(itemData);
- console.log(item, 'item');
- // 格式化时间
- item.createdAtText = this.formatTime(item.createdAt);
- this.setData({
- item: item
- }, () => {
- this.getadresses()
- });
- const fileIDs = [
- 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/dingwei.png',
- 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/fuzhi.png',
- 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/yesbaoguo.png'
- ];
- const fileList = await getTempFileURLs(fileIDs)
- this.setData({
- dingwei: fileList[0].tempFileURL,
- fuzhi: fileList[1].tempFileURL,
- yesbaoguo: fileList[2].tempFileURL,
- })
-
- // // 并发下载多个 fileID
- // Promise.all(
- // fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
- // ).then(results => {
- // // 每个 result 对应一个下载结果
- // const tempFilePaths = results.map(r => r.tempFilePath);
- // console.log('全部下载成功:', tempFilePaths);
- // this.setData({
- // dingwei: tempFilePaths[0],
- // fuzhi: tempFilePaths[1],
- // yesbaoguo: tempFilePaths[2],
- // });
- // }).catch(err => {
- // console.error('有文件下载失败:', err);
- // });
- },
- formatTime(ts) {
- const date = new Date(ts);
- const y = date.getFullYear();
- const m = String(date.getMonth() + 1).padStart(2, '0');
- const d = String(date.getDate()).padStart(2, '0');
- const hh = String(date.getHours()).padStart(2, '0');
- const mm = String(date.getMinutes()).padStart(2, '0');
- const ss = String(date.getSeconds()).padStart(2, '0');
- return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
- },
- async getadresses() {
- const models = await getModels()
- const { data } = await models.adresses.get({
- filter: {
- where: {
- $and: [
- {
- _id: {
- $eq: this.data.item.adresses_id, // 推荐传入_id数据标识进行操作
- },
- },
- ]
- }
- },
- // envType: pre 体验环境, prod 正式环境
- envType: "prod",
- });
-
- // 返回查询到的数据
- this.setData({
- adresseslist: data
- })
- },
- copyText(e) {
- const copyText = e.currentTarget.dataset.copytext;
- wx.setClipboardData({
- data: copyText,
- success: function () {
- wx.showToast({
- title: '复制成功',
- icon: 'success'
- });
- },
- fail: function () {
- wx.showToast({
- title: '复制失败',
- icon: 'none'
- });
- }
- });
- },
- // 处理第一个按钮的点击事件
- handleAction1: async function (event) {
- const status = Number(event.currentTarget.dataset.index);
- console.log(status, 'statusstatusstatus');
- const item = this.data.item;
- const models = await getModels()
- switch (status) {
- case 1:
- wx.navigateTo({
- url: '/subpackages/orderdetails/orderdetails?data=' + encodeURIComponent(JSON.stringify(item))
- });
- // 执行查看详情的逻辑
- break;
- case 0:
- // 执行取消订单的逻辑
- const { data } = await models.orders.update({
- data: {
- status: 3, // 状态
- },
- filter: {
- where: {
- $and: [
- {
- _id: {
- $eq: item.orders_id, // 推荐传入_id数据标识进行操作
- },
- },
- ]
- }
- },
- // envType: pre 体验环境, prod 正式环境
- envType: "prod",
- });
-
- // 返回更新成功的条数
- console.log(data);
- // { count: 1}
- if( data.count > 0) {
- wx.showToast({
- title: '订单取消成功',
- icon: 'success',
- duration: 1500,
- success() {
- wx.navigateBack();
- }
- });
- } else {
- wx.showToast({ title: '订单取消失败', icon: 'none' });
- }
- break;
- case 2:
- // 执行申请售后的逻辑
- wx.navigateTo({
- url: '/subpackages/afterservice/afterservice?data=' + encodeURIComponent(JSON.stringify(item))
- });
- break;
- default:
- console.log("未知状态");
- }
- },
- // 处理第二个按钮的点击事件
- handleAction2: function (event) {
- const status = Number(event.currentTarget.dataset.index);
- const item = this.data.item;
- switch (status) {
- case 1:
- this.getyesordels(item)
- break;
- case 0:
- const selectedItems = [
- item
- ];
- console.log(selectedItems,'selectedItems');
- // 执行立即支付的逻辑
- wx.setStorageSync('checkoutItems', selectedItems);
- wx.navigateTo({
- url: '/subpackages/submitorder/submitorder'
- });
- break;
- case 2:
- console.log("再来一单");
- const rawItem = item;
- // 定义要排除的字段
- const excludeKeys = [
- "adresses_id",
- "delete",
- "merchandise_id",
- "num_index",
- "order_id",
- "orders_id",
- "real_money",
- "schools_id",
- "specs_index",
- "status",
- "user_id",
- "groupbuy_id"
- ];
- // 过滤掉不需要的字段
- const itemss = Object.fromEntries(
- Object.entries(rawItem).filter(([key]) => !excludeKeys.includes(key))
- );
- wx.navigateTo({
- url: '/subpackages/productdetails/productdetails?data=' + encodeURIComponent(JSON.stringify(itemss))
- });
- break;
- default:
- console.log("未知状态");
- }
- },
- // 确认收货
- async getyesordels (list) {
- console.log(list, 'list');
- const userInfo = wx.getStorageSync('userInfo');
- const userId = userInfo && userInfo._id ? userInfo._id : ''; // 根据你的userInfo结构取ID
- const schoolId = userInfo && userInfo.school_id ? userInfo.school_id : ''; // 根据你的userInfo结构取ID
- const models = await getModels()
-
- const { data } = await models.orders.update({
- data: {
- status: 2, // 状态
- },
- filter: {
- where: {
- $and: [
- {
- _id: {
- $eq: list.orders_id, // 推荐传入_id数据标识进行操作
- },
- },
- {
- merchandise_id: {
- $eq: list.merchandise_id, // 推荐传入_id数据标识进行操作
- },
- },
- {
- user_id: {
- $eq: userId, // 推荐传入_id数据标识进行操作
- },
- },
- {
- school_id: {
- $eq: schoolId, // 推荐传入_id数据标识进行操作
- },
- },
- ]
- }
- },
- envType: "prod",
- });
- console.log(data.count, 'data.count');
- if (Number(data.count) > 0) {
- wx.showToast({
- title: '确认收货成功',
- icon: 'success',
- duration: 1500,
- success() {
- wx.navigateBack();
- }
- });
- // // ✅ 重新获取数据
- // this.setData({
- // pageNumber: 1,
- // hasMore: true,
- // orders: []
- // }, () => {
- // this.getdatalist(false);
- // });
- } else {
- wx.showToast({
- title: '确认收货失败',
- icon: 'error',
- duration: 1500
- });
- }
- },
- })
|