Ver código fonte

Merge branch 'master' into fix/hd-sun-code-invite-bind

shish 2 meses atrás
pai
commit
6f94708342

+ 27 - 1
ghsApp/src/admin/home/components/OrderItem.vue

@@ -95,7 +95,25 @@
       </view>
       <view class="list-bottom">
         <view class="list-button">
-          <view><button @click.stop="shareOrder(item)" open-type="share" class="admin-button-com bule">分享</button> </view>
+          <!-- #ifdef MP-WEIXIN -->
+          <view>
+            <button
+              open-type="share"
+              :data-order-id="item.id"
+              :data-share-type="shareBtnType"
+              @click.stop="shareOrder(item)"
+              class="admin-button-com bule"
+            >分享</button>
+          </view>
+          <!-- #endif -->
+          <!-- #ifdef APP-PLUS -->
+          <view><button @click.stop="shareOrder(item)" class="admin-button-com bule">分享</button></view>
+          <!-- #endif -->
+          <!-- #ifndef MP-WEIXIN -->
+          <!-- #ifndef APP-PLUS -->
+          <view><button @click.stop="shareOrder(item)" class="admin-button-com bule">分享</button></view>
+          <!-- #endif -->
+          <!-- #endif -->
           <block v-if="currentStatus == 2">
             <block v-if="item.book == 0">
               <view><button @click.stop="directFh(item)" class="admin-button-com bule">自配送</button> </view>
@@ -244,6 +262,9 @@ import { cancelDeliveryOrder } from '@/api/express/delivery';
 import { createCallExpressOrder, cancelCallExpressOrder,getOrderFee } from '@/api/shop/shop-express';
 export default {
   name: 'OrderItem',
+  options: {
+    virtualHost: true
+  },
   components: {},
   props: {
     item: {
@@ -252,6 +273,11 @@ export default {
     moreOrderRemind:{
       type: Boolean,
       default: true
+    },
+    /** 小程序分享按钮标记:merge 合并页单条分享传 single */
+    shareBtnType: {
+      type: String,
+      default: ''
     }
   },
   data() {

+ 45 - 52
ghsApp/src/admin/home/order.vue

@@ -110,7 +110,14 @@ import AppSearchModule from '@/components/module/app-search';
 import DropShopSelect from '@/components/module/shopSelect';
 import OrderItem from './components/OrderItem';
 import DateSelect from '@/components/module/dateSelect';
-import { IMGHOST } from '@/config';
+import {
+  buildMpShareMessage,
+  buildSingleSharePayload,
+  canShareSingleOrder,
+  getSingleOrderSharePath,
+  resolveMpShareMessage,
+  shareSingleOrderOnApp
+} from '@/utils/orderShare';
 import { getList } from '@/api/member';
 export default {
   name: 'order',
@@ -188,7 +195,9 @@ export default {
       currentTitle: '',
       searchList: [],
       showSearch: false,
-      customId: 0
+      customId: 0,
+      pendingSharePayload: null,
+      singleShareOrderId: 0
     };
   },
   onPullDownRefresh() {
@@ -229,19 +238,35 @@ export default {
   },
   onShareAppMessage(res) {
     this.fromDetail.status = 1;
-    const info = this.currentInfo || {}
-    const purchaseId = info.purchaseId || 0
-    const salt = info.cgSalt || (info.cgInfo && info.cgInfo.salt) || ''
-    const path = purchaseId && salt ? 'pagesOrder/showOrder?id=' + purchaseId + '&salt=' + salt : 'pagesOrder/showOrder'
-    console.log(path);
-    return {
-      title: this.currentTitle,
-      desc: '',
-      imageUrl: IMGHOST + '/custom/order_share.jpg',
-      path: path
-    };
+    const mpMessage = resolveMpShareMessage({
+      pendingSharePayload: this.pendingSharePayload,
+      res: res,
+      fallbackOrderId: this.singleShareOrderId,
+      getSingleShareByOrderId: (orderId) => {
+        const item = this.findListOrderById(orderId);
+        if (!item) {
+          return null;
+        }
+        const payload = buildSingleSharePayload(item);
+        return payload ? { title: payload.title, path: payload.path } : null;
+      }
+    });
+    if (mpMessage) {
+      return mpMessage;
+    }
+    const info = this.currentInfo || {};
+    return buildMpShareMessage({
+      title: this.currentTitle || '订单',
+      path: getSingleOrderSharePath(info) || 'pagesOrder/showOrder'
+    });
   },
   methods: {
+    findListOrderById(orderId) {
+      if (!orderId || !this.list.data || !this.list.data.length) {
+        return null;
+      }
+      return this.list.data.find((it) => it.id === orderId) || null;
+    },
     directFh(info) {
       let that = this;
       that.$util.confirmModal({ content: '确认自配送?' }, () => {
@@ -254,51 +279,19 @@ export default {
       });
     },
     shareOrder(info) {
-      const purchaseId = info.purchaseId || 0
-      const salt = info.cgSalt || (info.cgInfo && info.cgInfo.salt) || ''
-      if (!purchaseId || !salt) {
+      const payload = buildSingleSharePayload(info);
+      if (!payload) {
+        this.pendingSharePayload = null;
         this.$msg('暂无可分享订单');
         return false;
       }
-      const path = 'pagesOrder/showOrder?id=' + purchaseId + '&salt=' + salt
+      this.pendingSharePayload = payload;
+      this.singleShareOrderId = info.id || 0;
       this.currentInfo = info;
       this.fromDetail.status = 1;
-      let that = this;
-      let miniOriginalId =
-        that.dictInfo.miniOriginalId && that.dictInfo.miniOriginalId.current && that.dictInfo.miniOriginalId.current.ghs
-          ? that.dictInfo.miniOriginalId.current.ghs
-          : '';
-      let actPrice = info.actPrice ? parseFloat(info.actPrice) : 0;
-      let customName = info.customName ? info.customName : '';
-      let title = customName + ' ' + info.addTime.substr(5, 11) + ' ¥' + actPrice;
-      if (info.payTime != '0000-00-00 00:00:00') {
-        title = customName + ' ' + info.payTime.substr(5, 11) + ' ¥' + actPrice;
-      }
-      if (info.tkPrice && Number(info.tkPrice) > 0) {
-        title = title + ' 已退¥' + parseFloat(info.tkPrice);
-      }
-      this.currentTitle = title;
+      this.currentTitle = payload.title;
       // #ifdef APP-PLUS
-      uni.share({
-        provider: 'weixin', //分享服务提供商(即weixin|qq|sinaweibo)
-        scene: 'WXSceneSession', //场景,可取值参考下面说明。
-        type: 5, //分享形式
-        title: title, //分享内容的标题
-        summary: '暂无', //分享内容的摘要
-        imageUrl: IMGHOST + '/custom/order_share.jpg', //图片一定要有,不然会分享失败
-        miniProgram: {
-          id: miniOriginalId, //小程序原始id,发起分享的 App 与小程序属于同一微信开放平台账号
-          path: path,
-          type: 0, // 0-正式版; 1-测试版; 2-体验版
-          webUrl: 'https://www.wixhb.com'
-        },
-        success: function (res) {
-          console.log(res);
-        },
-        fail: function (err) {
-          console.log(err);
-        }
-      });
+      shareSingleOrderOnApp({ dictInfo: this.dictInfo, info: info });
       // #endif
     },
     //这个有多处要同步修改,关键词:fh_express_pop

+ 98 - 46
ghsApp/src/admin/order/mergeOrder.vue

@@ -4,10 +4,10 @@
       <block v-if="!$util.isEmpty(list.data)">
         <div class="list" v-for="(item, index) in list.data" :key="index">
           <div v-if="!$util.isEmpty(item.orderInfo)">
-            <OrderItem :item="item.orderInfo" @printOrder="printOrder"></OrderItem>
+            <OrderItem share-btn-type="single" :item="item.orderInfo" @printOrder="printOrder" @shareOrder="shareSingleOrder"></OrderItem>
           </div>
           <div v-else>
-            <OrderItem :ref="`orderRef${item.id}`" :item="item" @printOrder="printOrder" @directFh="directFh" @fillNoFh="fillNoFh" :moreOrderRemind="false"></OrderItem>
+            <OrderItem share-btn-type="single" :ref="`orderRef${item.id}`" :item="item" @printOrder="printOrder" @directFh="directFh" @fillNoFh="fillNoFh" @shareOrder="shareSingleOrder" :moreOrderRemind="false"></OrderItem>
           </div>
         </div>
       </block>
@@ -18,7 +18,12 @@
 
     <view class="bottom-bar-view" v-if="!$util.isEmpty(ids)">
       <view class="bar-content">
-        <button class="admin-button-com big blue" open-type="share" @click="shareAllOrder()">全部分享</button>
+        <!-- #ifdef MP-WEIXIN -->
+        <button class="admin-button-com big blue" open-type="share" data-share-type="merge" @click="shareAllOrder()">全部分享</button>
+        <!-- #endif -->
+        <!-- #ifdef APP-PLUS -->
+        <button class="admin-button-com big blue" @click="shareAllOrder()">全部分享</button>
+        <!-- #endif -->
         <button class="admin-button-com big blue" style="margin-left: 50upx;" @click="batchFh()">全部发货</button>
         <button class="admin-button-com big blue" style="margin-left: 50upx;" @click="batchPrint()">合并打印</button>
       </view>
@@ -53,7 +58,16 @@ import { mapGetters } from "vuex";
 import orderMixin from "@/mixins/order";
 import OrderItem from "../home/components/OrderItem"
 import { getMergeOrderList,cloudPrintOrder,mergePrintFn,allFhAction,orderFh} from "@/api/order";
-import { IMGHOST } from "@/config";
+import {
+  buildMergeShareTitle,
+  buildSingleSharePayload,
+  canShareSingleOrder,
+  getMergeSharePath,
+  resolveMpShareMessage,
+  shareMergeAllOnApp,
+  shareSingleOrderOnApp,
+  buildMpShareMessage
+} from "@/utils/orderShare";
 export default {
   name: "mergeOrder",
   components: {
@@ -73,6 +87,9 @@ export default {
       fhLabelShow:false,
       shareInfo: {},
       shareTitle: '订单列表',
+      shareMode: 'merge',
+      singleShareOrderId: 0,
+      pendingSharePayload: null,
     }
   },
   onPullDownRefresh() {
@@ -101,58 +118,93 @@ export default {
     this.ids = this.option.ids?this.option.ids:''
 
   },
-  onShareAppMessage() {
-    const share = this.getShareConfig()
-    return {
-      title: share.title,
-      desc: '',
-      imageUrl: IMGHOST + '/custom/order_share.jpg',
-      path: share.path
-    }
+  onShareAppMessage(res) {
+    const mpMessage = resolveMpShareMessage({
+      pendingSharePayload: this.pendingSharePayload,
+      res: res,
+      fallbackOrderId: this.singleShareOrderId,
+      getSingleShareByOrderId: (orderId) => this.getSingleOrderShareConfig(orderId),
+      getMergeShare: () => ({
+        title: this.shareTitle || buildMergeShareTitle(this.shareInfo, this.list.data) || '订单列表',
+        path: getMergeSharePath(this.shareInfo) || 'pagesOrder/showMergeOrder'
+      })
+    })
+    return mpMessage || buildMpShareMessage({
+      title: '订单列表',
+      path: 'pagesOrder/showMergeOrder'
+    })
   },
   methods: {
-    getShareConfig() {
-      const info = this.shareInfo || {}
-      const mergeId = info.mergeId || info.id || 0
-      const salt = info.salt || ''
-      const title = this.shareTitle || '订单列表'
-      return {
-        title,
-        hdPath: 'pagesPurchase/mergeOrder?mergeId=' + mergeId + '&salt=' + salt,
-        path: 'pagesOrder/showMergeOrder?mergeId=' + mergeId + '&salt=' + salt
+    findOrderById(orderId) {
+      if (!orderId || !this.list.data) {
+        return null
+      }
+      for (let i = 0; i < this.list.data.length; i++) {
+        const row = this.list.data[i]
+        if (row.orderInfo && row.orderInfo.id === orderId) {
+          return row.orderInfo
+        }
+        if (row.id === orderId) {
+          return row
+        }
       }
+      return null
+    },
+    getSingleOrderShareConfig(orderId) {
+      const info = this.findOrderById(orderId || this.singleShareOrderId)
+      if (!info) {
+        return null
+      }
+      const payload = buildSingleSharePayload(info)
+      if (!payload) {
+        return null
+      }
+      return { title: payload.title, path: payload.path }
+    },
+    shareSingleOrder(info) {
+      if (!canShareSingleOrder(info)) {
+        this.pendingSharePayload = null
+        this.$msg('暂无可分享订单')
+        return false
+      }
+      this.shareMode = 'single'
+      this.singleShareOrderId = info.id || 0
+      const payload = buildSingleSharePayload(info)
+      if (!payload) {
+        this.pendingSharePayload = null
+        this.$msg('暂无可分享订单')
+        return false
+      }
+      this.pendingSharePayload = payload
+      // #ifdef APP-PLUS
+      shareSingleOrderOnApp({ dictInfo: this.getDictionariesInfo, info: info })
+      // #endif
     },
     shareAllOrder(){
-      const info = this.shareInfo || {}
-      if (!info.mergeId || !info.salt) {
+      this.shareMode = 'merge'
+      this.singleShareOrderId = 0
+      const mpPath = getMergeSharePath(this.shareInfo)
+      if (!mpPath) {
+        this.pendingSharePayload = null
         this.$msg('暂无可分享订单')
         return false
       }
-      const firstOrder = this.list.data && this.list.data.length > 0 ? this.list.data[0] : {}
-      const customName = firstOrder.customName ? firstOrder.customName : ''
-      const count = this.list.data ? this.list.data.length : 0
-      const totalPrice = info.totalPrice != null && info.totalPrice !== '' ? parseFloat(info.totalPrice) : 0
-      this.shareTitle = customName + ' 共' + count + '个订单 ¥' + totalPrice
-      const share = this.getShareConfig()
+      this.shareTitle = buildMergeShareTitle(this.shareInfo, this.list.data)
+      this.pendingSharePayload = {
+        type: 'merge',
+        title: this.shareTitle,
+        path: mpPath
+      }
       // #ifdef APP-PLUS
-      const miniOriginalId =
-        this.getDictionariesInfo && this.getDictionariesInfo.miniOriginalId && this.getDictionariesInfo.miniOriginalId.current && this.getDictionariesInfo.miniOriginalId.current.hd
-          ? this.getDictionariesInfo.miniOriginalId.current.hd
-          : ''
-      uni.share({
-        provider: 'weixin',
-        scene: 'WXSceneSession',
-        type: 5,
-        title: share.title,
-        summary: '暂无',
-        imageUrl: IMGHOST + '/custom/order_share.jpg',
-        miniProgram: {
-          id: miniOriginalId,
-          path: share.hdPath,
-          type: 0,
-          webUrl: 'https://www.wixhb.com'
-        }
+      const appPayload = shareMergeAllOnApp({
+        dictInfo: this.getDictionariesInfo,
+        shareInfo: this.shareInfo,
+        listData: this.list.data
       })
+      if (!appPayload) {
+        this.$msg('暂无可分享订单')
+        return false
+      }
       // #endif
     },
     //这个有多处要同步修改,关键词:fh_express_pop

+ 220 - 0
ghsApp/src/utils/orderShare.js

@@ -0,0 +1,220 @@
+import { IMGHOST } from '@/config'
+
+/** 分享封面图(小程序 / App 共用) */
+export const ORDER_SHARE_IMAGE = IMGHOST + '/custom/order_share.jpg'
+
+/**
+ * 订单分享双端约定:
+ * - 微信小程序:按钮 open-type="share",点击时写入 pendingSharePayload,onShareAppMessage 优先读取
+ * - App:按钮仅 @click,调用 shareOrderToWxMiniProgram 分享微信小程序卡片
+ * 单条订单走 ghs 小程序 pagesOrder/showOrder;合并单小程序走 showMergeOrder,App 全部分享走 hd 小程序
+ */
+
+/** 采购单 salt */
+export function getCgSalt(info) {
+  if (!info) {
+    return ''
+  }
+  return info.cgSalt || (info.cgInfo && info.cgInfo.salt) || ''
+}
+
+/** 单条订单分享标题(与详情页一致) */
+export function buildOrderShareTitle(info) {
+  if (!info || !info.addTime) {
+    return '订单'
+  }
+  const actPrice = info.actPrice ? parseFloat(info.actPrice) : 0
+  const customName = info.customName ? info.customName : ''
+  let title = customName + ' ' + info.addTime.substr(5, 11) + ' ¥' + actPrice
+  if (info.payTime != '0000-00-00 00:00:00') {
+    title = customName + ' ' + info.payTime.substr(5, 11) + ' ¥' + actPrice
+  }
+  if (info.tkPrice && Number(info.tkPrice) > 0) {
+    title = title + ' 已退¥' + parseFloat(info.tkPrice)
+  }
+  return title
+}
+
+/** 单条订单小程序路径 */
+export function getSingleOrderSharePath(info) {
+  const purchaseId = info && info.purchaseId ? info.purchaseId : 0
+  const salt = getCgSalt(info)
+  if (!purchaseId || !salt) {
+    return ''
+  }
+  return 'pagesOrder/showOrder?id=' + purchaseId + '&salt=' + salt
+}
+
+/** 单条订单是否可分享 */
+export function canShareSingleOrder(info) {
+  return !!getSingleOrderSharePath(info)
+}
+
+/** 合并订单分享路径(供货商小程序) */
+export function getMergeSharePath(shareInfo) {
+  const info = shareInfo || {}
+  const mergeId = info.mergeId || info.id || 0
+  const salt = info.salt || ''
+  if (!mergeId || !salt) {
+    return ''
+  }
+  return 'pagesOrder/showMergeOrder?mergeId=' + mergeId + '&salt=' + salt
+}
+
+/** 合并订单分享路径(花店小程序,App 分享用) */
+export function getMergeHdSharePath(shareInfo) {
+  const info = shareInfo || {}
+  const mergeId = info.mergeId || info.id || 0
+  const salt = info.salt || ''
+  if (!mergeId || !salt) {
+    return ''
+  }
+  return 'pagesPurchase/mergeOrder?mergeId=' + mergeId + '&salt=' + salt
+}
+
+export function buildMergeShareTitle(shareInfo, listData) {
+  const info = shareInfo || {}
+  const firstRow = listData && listData.length > 0 ? listData[0] : null
+  const firstOrder = firstRow && firstRow.orderInfo ? firstRow.orderInfo : firstRow
+  const customName = firstOrder && firstOrder.customName ? firstOrder.customName : ''
+  const count = listData ? listData.length : 0
+  const totalPrice = info.totalPrice != null && info.totalPrice !== '' ? parseFloat(info.totalPrice) : 0
+  return customName + ' 共' + count + '个订单 ¥' + totalPrice
+}
+
+/** miniOriginalId:ghs=供货商小程序,hd=花店小程序 */
+export function getMiniOriginalId(dictInfo, appKey) {
+  const current = dictInfo && dictInfo.miniOriginalId && dictInfo.miniOriginalId.current
+  if (!current) {
+    return ''
+  }
+  return current[appKey] || ''
+}
+
+/**
+ * App 端分享微信小程序卡片
+ * @param {Object} options
+ * @param {Object} options.dictInfo vuex 字典
+ * @param {string} options.appKey ghs | hd
+ * @param {string} options.path 小程序页面路径
+ * @param {string} options.title 分享标题
+ */
+export function shareOrderToWxMiniProgram({ dictInfo, appKey, path, title }) {
+  const miniOriginalId = getMiniOriginalId(dictInfo, appKey)
+  uni.share({
+    provider: 'weixin',
+    scene: 'WXSceneSession',
+    type: 5,
+    title: title || '订单',
+    summary: '暂无',
+    imageUrl: ORDER_SHARE_IMAGE,
+    miniProgram: {
+      id: miniOriginalId,
+      path: path,
+      type: 0,
+      webUrl: 'https://www.wixhb.com'
+    }
+  })
+}
+
+/** 从分享按钮 dataset 解析(小程序) */
+export function getShareMetaFromEvent(res) {
+  const meta = { shareType: '', orderId: 0 }
+  if (res && res.from === 'button' && res.target && res.target.dataset) {
+    const ds = res.target.dataset
+    meta.shareType = ds.shareType || ''
+    meta.orderId = Number(ds.orderId) || 0
+  }
+  return meta
+}
+
+/** @deprecated 使用 getShareMetaFromEvent */
+export function getShareOrderIdFromEvent(res) {
+  return getShareMetaFromEvent(res).orderId
+}
+
+/** 小程序 onShareAppMessage 返回结构 */
+export function buildMpShareMessage({ title, path }) {
+  return {
+    title: title || '订单',
+    desc: '',
+    imageUrl: ORDER_SHARE_IMAGE,
+    path: path || 'pagesOrder/showOrder'
+  }
+}
+
+/** 单条分享 payload:小程序 pending + App 共用 */
+export function buildSingleSharePayload(info) {
+  const path = getSingleOrderSharePath(info)
+  if (!path) {
+    return null
+  }
+  return {
+    type: 'single',
+    title: buildOrderShareTitle(info),
+    path: path
+  }
+}
+
+/** App:单条订单分享到 ghs 小程序 */
+export function shareSingleOrderOnApp({ dictInfo, info }) {
+  const payload = buildSingleSharePayload(info)
+  if (!payload) {
+    return null
+  }
+  shareOrderToWxMiniProgram({
+    dictInfo: dictInfo,
+    appKey: 'ghs',
+    path: payload.path,
+    title: payload.title
+  })
+  return payload
+}
+
+/** App:合并订单全部分享到 hd 小程序 */
+export function shareMergeAllOnApp({ dictInfo, shareInfo, listData }) {
+  const path = getMergeHdSharePath(shareInfo)
+  if (!path) {
+    return null
+  }
+  const title = buildMergeShareTitle(shareInfo, listData)
+  shareOrderToWxMiniProgram({
+    dictInfo: dictInfo,
+    appKey: 'hd',
+    path: path,
+    title: title
+  })
+  return { type: 'merge', title: title, path: path }
+}
+
+/**
+ * 合并页 / 列表页:小程序 onShareAppMessage 解析
+ * @param {Object} ctx
+ * @param {Object|null} ctx.pendingSharePayload 点击时写入
+ * @param {Object} ctx.res onShareAppMessage 参数
+ * @param {Function} ctx.getSingleShareByOrderId (orderId) => { title, path } | null
+ * @param {number} ctx.fallbackOrderId 点击时记录的单号
+ * @param {Function} [ctx.getMergeShare] 返回合并分享 { title, path },仅合并页传入
+ */
+export function resolveMpShareMessage(ctx) {
+  const pending = ctx.pendingSharePayload
+  if (pending && pending.path) {
+    return buildMpShareMessage(pending)
+  }
+  const { shareType, orderId: datasetOrderId } = getShareMetaFromEvent(ctx.res)
+  const orderId = datasetOrderId || ctx.fallbackOrderId || 0
+  const isSingleShare = shareType === 'single' || (orderId > 0 && shareType !== 'merge')
+  if (isSingleShare && ctx.getSingleShareByOrderId) {
+    const singleShare = ctx.getSingleShareByOrderId(orderId)
+    if (singleShare) {
+      return buildMpShareMessage(singleShare)
+    }
+  }
+  if (shareType === 'merge' && ctx.getMergeShare) {
+    const mergeShare = ctx.getMergeShare()
+    if (mergeShare) {
+      return buildMpShareMessage(mergeShare)
+    }
+  }
+  return null
+}