shish 2 bulan lalu
induk
melakukan
960916a364

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

@@ -95,7 +95,24 @@
       </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"
+              @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>

+ 34 - 44
ghsApp/src/admin/home/order.vue

@@ -111,6 +111,13 @@ import DropShopSelect from '@/components/module/shopSelect';
 import OrderItem from './components/OrderItem';
 import DateSelect from '@/components/module/dateSelect';
 import { IMGHOST } from '@/config';
+import {
+  buildOrderShareTitle,
+  canShareSingleOrder,
+  getShareOrderIdFromEvent,
+  getSingleOrderSharePath,
+  shareOrderToWxMiniProgram
+} from '@/utils/orderShare';
 import { getList } from '@/api/member';
 export default {
   name: 'order',
@@ -229,19 +236,31 @@ 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);
+    const sharePayload = this.resolveSharePayload(res);
     return {
-      title: this.currentTitle,
+      title: sharePayload.title,
       desc: '',
       imageUrl: IMGHOST + '/custom/order_share.jpg',
-      path: path
+      path: sharePayload.path
     };
   },
   methods: {
+    resolveShareOrderInfo(res) {
+      const orderId = getShareOrderIdFromEvent(res);
+      if (orderId && this.list.data && this.list.data.length > 0) {
+        const item = this.list.data.find((it) => it.id === orderId);
+        if (item) {
+          return item;
+        }
+      }
+      return this.currentInfo || {};
+    },
+    resolveSharePayload(res) {
+      const info = this.resolveShareOrderInfo(res);
+      const path = getSingleOrderSharePath(info) || 'pagesOrder/showOrder';
+      const title = canShareSingleOrder(info) ? buildOrderShareTitle(info) : (this.currentTitle || '订单');
+      return { title, path };
+    },
     directFh(info) {
       let that = this;
       that.$util.confirmModal({ content: '确认自配送?' }, () => {
@@ -254,50 +273,21 @@ export default {
       });
     },
     shareOrder(info) {
-      const purchaseId = info.purchaseId || 0
-      const salt = info.cgSalt || (info.cgInfo && info.cgInfo.salt) || ''
-      if (!purchaseId || !salt) {
+      if (!canShareSingleOrder(info)) {
         this.$msg('暂无可分享订单');
         return false;
       }
-      const path = 'pagesOrder/showOrder?id=' + purchaseId + '&salt=' + salt
+      const path = getSingleOrderSharePath(info);
+      const title = buildOrderShareTitle(info);
       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;
       // #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);
-        }
+      shareOrderToWxMiniProgram({
+        dictInfo: this.dictInfo,
+        appKey: 'ghs',
+        path: path,
+        title: title
       });
       // #endif
     },

+ 97 - 39
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 :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 :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">
+        <!-- #ifdef MP-WEIXIN -->
         <button class="admin-button-com big blue" open-type="share" @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>
@@ -54,6 +59,16 @@ 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,
+  buildOrderShareTitle,
+  canShareSingleOrder,
+  getMergeHdSharePath,
+  getMergeSharePath,
+  getShareOrderIdFromEvent,
+  getSingleOrderSharePath,
+  shareOrderToWxMiniProgram
+} from "@/utils/orderShare";
 export default {
   name: "mergeOrder",
   components: {
@@ -73,6 +88,8 @@ export default {
       fhLabelShow:false,
       shareInfo: {},
       shareTitle: '订单列表',
+      shareMode: 'merge',
+      singleShareOrderId: 0,
     }
   },
   onPullDownRefresh() {
@@ -101,57 +118,98 @@ export default {
     this.ids = this.option.ids?this.option.ids:''
 
   },
-  onShareAppMessage() {
-    const share = this.getShareConfig()
+  onShareAppMessage(res) {
+    let orderId = this.singleShareOrderId || 0
+    const datasetOrderId = getShareOrderIdFromEvent(res)
+    if (datasetOrderId) {
+      orderId = datasetOrderId
+      this.shareMode = 'single'
+    }
+    if (this.shareMode === 'single') {
+      const singleShare = this.getSingleOrderShareConfig(orderId)
+      if (singleShare) {
+        return {
+          title: singleShare.title,
+          desc: '',
+          imageUrl: IMGHOST + '/custom/order_share.jpg',
+          path: singleShare.path
+        }
+      }
+    }
+    const path = getMergeSharePath(this.shareInfo)
+    const title = this.shareTitle || buildMergeShareTitle(this.shareInfo, this.list.data) || '订单列表'
     return {
-      title: share.title,
+      title: title,
       desc: '',
       imageUrl: IMGHOST + '/custom/order_share.jpg',
-      path: share.path
+      path: path || 'pagesOrder/showMergeOrder'
     }
   },
   methods: {
-    getShareConfig() {
-      const info = this.shareInfo || {}
-      const mergeId = info.mergeId || info.id || 0
-      const salt = info.salt || ''
-      const title = this.shareTitle || '订单列表'
+    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 path = getSingleOrderSharePath(info)
+      if (!path) {
+        return null
+      }
       return {
-        title,
-        hdPath: 'pagesPurchase/mergeOrder?mergeId=' + mergeId + '&salt=' + salt,
-        path: 'pagesOrder/showMergeOrder?mergeId=' + mergeId + '&salt=' + salt
+        title: buildOrderShareTitle(info),
+        path: path
       }
     },
+    shareSingleOrder(info) {
+      if (!canShareSingleOrder(info)) {
+        this.$msg('暂无可分享订单')
+        return false
+      }
+      this.shareMode = 'single'
+      this.singleShareOrderId = info.id || 0
+      const singleShare = this.getSingleOrderShareConfig(this.singleShareOrderId)
+      if (!singleShare) {
+        this.$msg('暂无可分享订单')
+        return false
+      }
+      // #ifdef APP-PLUS
+      shareOrderToWxMiniProgram({
+        dictInfo: this.getDictionariesInfo,
+        appKey: 'ghs',
+        path: singleShare.path,
+        title: singleShare.title
+      })
+      // #endif
+    },
     shareAllOrder(){
-      const info = this.shareInfo || {}
-      if (!info.mergeId || !info.salt) {
+      this.shareMode = 'merge'
+      const path = getMergeHdSharePath(this.shareInfo)
+      if (!path) {
         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)
       // #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'
-        }
+      shareOrderToWxMiniProgram({
+        dictInfo: this.getDictionariesInfo,
+        appKey: 'hd',
+        path: path,
+        title: this.shareTitle
       })
       // #endif
     },

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

@@ -0,0 +1,116 @@
+import { IMGHOST } from '@/config'
+
+/** 采购单 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: IMGHOST + '/custom/order_share.jpg',
+    miniProgram: {
+      id: miniOriginalId,
+      path: path,
+      type: 0,
+      webUrl: 'https://www.wixhb.com'
+    }
+  })
+}
+
+/** 从分享按钮 dataset 解析订单 id(小程序) */
+export function getShareOrderIdFromEvent(res) {
+  if (res && res.from === 'button' && res.target && res.target.dataset) {
+    return Number(res.target.dataset.orderId) || 0
+  }
+  return 0
+}