Просмотр исходного кода

Merge branch 'zhongqi-intraCityExpress'

shish 11 месяцев назад
Родитель
Сommit
de6aeb1cc5

+ 13 - 4
hdApp/src/admin/order/modify.vue

@@ -3,9 +3,7 @@
   <view class="affirm-page">
     <view class="affirm-view overscroll">
       <form>
-
-        <app-delivery-module ref="appDelivery" @changeAddress="changeAddress" :info.sync="orderInfo" />
-
+        <app-delivery-module ref="appDelivery" @changeAddress="changeAddress" :info.sync="orderInfo" :hasMap="hasMap" />
       </form>
     </view>
     <view class="under-bar">
@@ -22,6 +20,7 @@ import AppDeliveryModule from "@/components/app-delivery-modify";
 import { updateOrder } from "@/api/order";
 import { mapGetters } from "vuex";
 import { getDetB} from "@/api/order";
+import { getHasMap } from "@/api/express";
 export default {
   name: "modify",
   components: {
@@ -39,12 +38,16 @@ export default {
       categorySelectedData:{},
       currentImgData:[],
       dj:'',
-      orderInfo: {}
+      orderInfo: {},
+      hasMap: 0 // 是否具备定位功能 0不具备 1具备
     };
   },
   onLoad (option) {
     const token = uni.getStorageSync('token')
     this.headers.token = token
+    getHasMap().then(res => {
+      this.hasMap = (res.data && res.data.hasMap) ? res.data.hasMap : 0
+    })
   },
   computed: {
     ...mapGetters(["getLoginInfo"])
@@ -66,6 +69,12 @@ export default {
     confirmToSubmit () {
       let that = this
       that.form = {...that.$refs.appDelivery.form}
+
+      if(that.hasMap == 0 && that.form.sendType == 3) {
+        that.$msg('由于地图定位服务停用,无法使用骑手送')
+        return false
+      }
+      
       that.$util.confirmModal({content:'确认提交?'},() => {
           updateOrder({...that.form,id:that.orderInfo.id}).then((res) => {
             if(res.code == 1){

+ 43 - 9
hdApp/src/components/app-delivery-modify.vue

@@ -65,10 +65,20 @@
           <view class="tui-input" v-if="form.province || form.city" >{{ form.province + '-' + form.city }}</view> <view class="tui-placeholder" v-else>请选择</view>
         </tui-list-cell>
 
-        <tui-list-cell class="line-cell" :hover="false">
+        <!-- <tui-list-cell class="line-cell" :hover="false">
           <view class="tui-title">详细地址</view>
           <input v-model="form.address" placeholder-class="phcolor" placeholder-style="color:#ccc" class="tui-input" name="address" placeholder="请填写地址" @input="changeAddress()" />
-        </tui-list-cell>
+        </tui-list-cell> -->
+        <tui-list-cell v-if="hasMap == 0" class="line-cell" :hover="false">
+					<view class="tui-title">详细地址</view>
+					<input v-model="form.address" placeholder-class="phcolor" class="tui-input" name="address" @input="changeAddress" placeholder="请填写详细地址" />
+				</tui-list-cell>
+				<tui-list-cell v-else class="line-cell" :hover="false" :arrow="true" @click="selectRegion">
+					<view class="tui-title">详细地址</view>
+					<view class="tui-input" v-if="form.address">{{ form.address }}</view>
+					<view class="tui-placeholder" v-else>请填写详细地址</view>
+					<input v-model="form.address" name="address" hidden />
+				</tui-list-cell>
 
         <tui-list-cell class="line-cell" :hover="false">
           <view class="tui-title">门牌号</view>
@@ -98,12 +108,12 @@
 
     <!-- 省市联动 -->
     <simple-address ref="simpleAddress" :region="regionTree" :pickerValueDefault="cityPickerValueDefault" @onConfirm="getCityConfirm" ></simple-address>
-
+    <!-- 选择地区 -->
+		<app-area-sel :show.sync="showRegion" :city="form.city" @change="changeAreaFn" />
   </view>
 </template>
 
 <script>
-import { mapGetters } from "vuex";
 import TuiListCell from "@/components/plugin/list-cell";
 import AppDatePicker from "@/components/app-date-picker";
 import SimpleAddress from "@/components/plugin/simple-address";
@@ -125,6 +135,10 @@ export default {
 			type: Object,
 			default: {}
 		},
+    hasMap: { // 是否具备定位功能 0不具备 1具备
+      type: Number,
+      default: 0
+    }
   },
   data() {
     return {
@@ -137,6 +151,7 @@ export default {
         receiveMobile: "",
         province: "",
         city: "",
+        dist: "",
         address: "",
         showAddress:"",
         floor: "",
@@ -155,9 +170,9 @@ export default {
       regionTree:[],
       cityPickerValueDefault: [0, 0],
       timeOptions: [
-			['00', '01', '02','03','04','05','06','07','08','09','10','11','12','13', '14','15','16','17','18','19','20','21','22','23'],
-			['00', '05', '10','15','20','25','30','35','40','45','50','55']
-		],
+        ['00', '01', '02','03','04','05','06','07','08','09','10','11','12','13', '14','15','16','17','18','19','20','21','22','23'],
+        ['00', '05', '10','15','20','25','30','35','40','45','50','55']
+      ]
     };
   },
   mounted() {
@@ -209,7 +224,6 @@ export default {
 
           this.form.lat = newVal.lat
           this.form.long = newVal.long
-
         }
 			},
 			immediate:true
@@ -247,7 +261,27 @@ export default {
     getCityConfirm(e) {
       this.form.province = e.provinceName;
       this.form.city = e.cityName;
-    }
+    },
+    selectRegion() {
+			if (!this.form.city) {
+				this.$msg('请先选择城市!')
+				return false
+			}
+			this.showRegion = true
+		},
+    changeAreaFn(e) {
+			this.form.address = e.name
+			let locationStr = e.location
+			let fruits = locationStr.split(",").map(fruit => fruit.trim())
+			this.form.lat = fruits[1]
+			this.form.long = fruits[0]
+			this.form.showAddress = e.address
+
+			// 提取地区信息,按遇到第一个"市"字后,把"市"后面的字符串作为地区
+			const districtStr = e.district || '';
+			const cityIndex = districtStr.indexOf('市');
+			this.form.dist = cityIndex !== -1 ? districtStr.substring(cityIndex + 1) : districtStr;
+		},
   }
 };
 </script>

+ 2 - 1
hdApp/src/pages.json

@@ -411,7 +411,8 @@
 		{
 			"root": "admin/express",
 			"pages": [
-				{ "path": "create", "style": { "navigationBarTitleText": "配送信息" } }
+				{ "path": "create", "style": { "navigationBarTitleText": "配送信息" } },
+				{ "path": "success", "style": { "navigationBarTitleText": "配送成功" } }
 			]
 		},
 		{

+ 4 - 0
mallApp/src/api/order/index.js

@@ -1,5 +1,9 @@
 import https from '@/plugins/luch-request_0.0.7/request'
 
+export const newFreight = data => {
+	return https.post("/order/new-freight", data);
+};
+
 export const freight = data => {
 	return https.get("/order/freight", data);
 };

+ 0 - 1
mallApp/src/components/RichMediaViewer/index.vue

@@ -229,7 +229,6 @@ export default {
 
     // 初始化内容列表,添加懒加载状态
     initializeContentList(content) {
-      console.log('initializeContentList -- content: ', content)
       return content.map(item => {
         const newItem = { ...item }
 

+ 49 - 13
mallApp/src/pages/billing/affirmGhs.vue

@@ -135,7 +135,7 @@
 <script>
 import TuiListCell from "@/components/plugin/list-cell";
 import productMins from "@/mixins/cgProduct";
-import { buyItem,freight } from "@/api/order"
+import { buyItem,freight,newFreight } from "@/api/order"
 import { currentInfo } from "@/api/user"
 // import { mapActions, mapGetters } from "vuex";
 export default {
@@ -164,12 +164,7 @@ export default {
 				showAddress:'',
 				hasMap:0
 			},
-			userInfo:{
-				lat:'',
-				long:'',
-				fullAddress:'',
-				showAddress:''
-			},
+			userInfo:{},
       		timeOptions: [
 				['00', '01', '02','03','04','05','06','07','08','09','10','11','12','13', '14','15','16','17','18','19','20','21','22','23'],
 				['00', '05', '10','15','20','25','30','35','40','45','50','55']
@@ -239,8 +234,9 @@ export default {
 					that.userInfo = res.data.info
 					that.form.province = that.userInfo.province
 					that.form.city = that.userInfo.city
-					that.form.floor = that.userInfo.floor
+					that.form.dist = that.userInfo.dist
 					that.form.address = that.userInfo.address
+					that.form.floor = that.userInfo.floor
 					that.form.long = that.userInfo.long
 					that.form.lat = that.userInfo.lat
 					that.form.showAddress = that.userInfo.showAddress
@@ -280,9 +276,29 @@ export default {
 				that.form.sendCost = 0
 				return
 			}
-			freight({weight:weight,lat:that.userInfo.lat,long:that.userInfo.long}).then(res => {
+			// freight({weight:weight,lat:that.userInfo.lat,long:that.userInfo.long}).then(res => {
+			// 	if(res.code == 1){
+			// 		that.form.sendCost = res.data.fee?parseFloat(Number(res.data.fee)):0
+			// 	}
+			// }).catch(()=>{});
+			// newFreight
+			let packageNum = that.allCountFun && that.allCountFun.bigLength ? Number(that.allCountFun.bigLength) : 1
+			let cargoName = '花材'
+			let newFreightParams = {
+				cargo_name: cargoName,
+				price: that.allPriceFun,
+				weight: weight,
+				package_num: packageNum,
+				user_lng: that.userInfo.long,
+				user_lat: that.userInfo.lat,
+				user_name: that.userInfo.name || that.userInfo.realName || '',
+				user_phone: that.userInfo.mobile || that.userInfo.phone || '',
+				user_address: that.userInfo.province + that.userInfo.city + that.userInfo.dist + that.userInfo.address + that.userInfo.floor
+			}
+			newFreight(newFreightParams).then(res => {
+				console.log('newFreight',res)
 				if(res.code == 1){
-					that.form.sendCost = res.data.fee?parseFloat(Number(res.data.fee)):0
+					that.form.sendCost = res.data.est_fee?parseFloat(Number(res.data.est_fee/100)):0
 				}
 			}).catch(()=>{});
 		},
@@ -304,15 +320,35 @@ export default {
 					return false
 				}
 			}
+			if(this.form.sendType == 2 && this.form.sendCost <= 0) {
+				this.$msg('选择代叫跑腿,必须获取运费')
+				return false
+			}
+			if(this.form.sendType == 2 && this.form.hasMap == 0) {
+				this.$msg('由于地图定位服务停用,无法使用代叫跑腿')
+				return false
+			}
 			uni.showLoading({mask:true})
 			buyItem(params).then(res => {
 				uni.hideLoading()
-				this.removeMemory()
 				if(res.code && res.code == 1){
 					let account = this.option.account ? this.option.account : 0
-					this.$util.pageTo({ url: "/pages/callback/pay", type: 2, query: { pageStatus: 1, ...res.data,hdId:hdId,account:account } })
+					let totalPrice = Number(res.data.totalPrice) + Number(this.form.sendCost)
+					
+					if (Math.abs(totalPrice - this.modifyPrice) < 0.001) {
+						res.data.totalPrice = totalPrice
+					}else{
+						this.$msg('运费计算错误')
+						return
+					}
+					this.$util.pageTo({ url: "/pages/callback/pay", type: 2, query: { pageStatus: 1, ...res.data, hdId: hdId, account: account } })
 				}
-			});
+				this.removeMemory()
+			}).catch((e)=>{
+				console.log('buyItem error: ', e)
+				uni.hideLoading()
+				this.removeMemory()
+			})
 		},
 		modifyItem() {
 			let account = this.option.account ? this.option.account : 0

+ 100 - 42
mallApp/src/pages/order/buy.vue

@@ -50,36 +50,27 @@
   </view>
 </template>
 <script>
-import { mapGetters } from "vuex";
-import AppTabs from "@/components/plugin/tabs";
 import TuiListCell from "@/components/plugin/list-cell";
 import AppDeliveryModule from "@/components/app-delivery";
-import AppTrademark from "@/components/module/app-trademark";
 import AppListModule from "@/components/module/app-order-list2";
-import AppCouponSel from "@/components/app-coupon-sel";
-import AlertModule from "@/components/plugin/alert";
 import { getShopUser } from "@/utils/auth";
 import { getOrderShop } from "@/utils/config";
-import { createOrder,freight } from "@/api/order";
+import { createOrder,newFreight } from "@/api/order";
 import { getUserDistance, getHasMap } from "@/api/express";
 export default {
   name: "buy",
   components: {
-    AppTabs,
     AppDeliveryModule,
     TuiListCell,
-    AppListModule,
-    AppCouponSel,
-    AppTrademark,
-    AlertModule
+    AppListModule
   },
   data() {
     return {
+      option: {},
       goodsInfo: {},
-      tabIndex: 0,
-      showAlert: false,
       form: {
         sendDistance:"",
+        sendCost: 0,
         goodsId: "",
         goodsStyleId: "",
         goodsNum: "",
@@ -88,85 +79,146 @@ export default {
         lat:'',
         long:''
       },
-      discountArr: false,
       freightPrice: 0,
-      goodsNum: 1,
       showDistance: 0,
       goodsTotalPrice: 0,
-      memberDiscount: 1,
-      couponDiscountAmount: 0,
       hasMap: 0 // 是否具备定位功能 0不具备 1具备
     };
   },
+  onLoad(option) {
+    this.option = option || {};
+    this.init();
+  },
   mounted() {},
   computed: {
-    ...mapGetters({ orderShop: "getOrderShop" }),
-    ...mapGetters({ shopUser: "getShopUser" }),
     mayPayAmount(){
-      let price = this.goodsInfo.price * this.goodsInfo.buyNum
+      let price = (this.goodsInfo.price || 0) * (this.goodsInfo.buyNum || 0)
       price = Number(this.freightPrice)+Number(price)
       return parseFloat(price.toFixed(2))
     }
   },
   methods: {
     init() {
-      let goodsInfo = uni.getStorageSync("buyGoodsDetil")
+      let goodsInfo = uni.getStorageSync("buyGoodsDetil") || {}
 
       getOrderShop()
       getShopUser();
 
-      goodsInfo.buyNum = this.option.goodsNum;
-      this.goodsInfo = goodsInfo;
+      const goodsNum = Number(this.option.goodsNum || goodsInfo.buyNum || 0)
+      goodsInfo.buyNum = goodsNum
+      this.goodsInfo = goodsInfo
 
-      this.form.goodsId = this.option.goodsId
-      this.form.goodsNum = this.option.goodsNum
+      this.form.goodsId = this.option.goodsId || ""
+      this.form.goodsNum = goodsNum
 
-      this.goodsTotalPrice = goodsInfo.price * this.option.goodsNum;
-      this.goodsTotalPrice = this.goodsTotalPrice.toFixed(2)
-      this.goodsTotalPrice = parseFloat(this.goodsTotalPrice)
+      const total = Number(goodsInfo.price || 0) * goodsNum
+      this.goodsTotalPrice = parseFloat(total.toFixed(2))
 
       getHasMap().then(res => {
-        this.hasMap = res.data.hasMap || 0
+        this.hasMap = (res.data && res.data.hasMap) ? res.data.hasMap : 0
       })
 
     },
 		changeSendType(num){
 			this.form.sendType = num
 			if(num == 2){
-        this.changeAddress()
+				this.$nextTick(()=>{
+					this.changeAddress()
+				})
 			}
 		},
     changeAddress() {
-      let lat = this.$refs.appDelivery.region.latitude;
-      let long = this.$refs.appDelivery.region.longitude;
+      const ref = this.$refs.appDelivery
+      if(!ref || !ref.region) return
+      let lat = ref.region.latitude;
+      let long = ref.region.longitude;
       this.form.lat = lat
       this.form.long = long
-      getUserDistance({ lat: lat, lng: long }).then(res => {
-        this.freightPrice = res.data.fee?parseFloat(res.data.fee):0;
-        this.showDistance = res.data.showDistance;
-      });
+      // getUserDistance({ lat: lat, lng: long }).then(res => {
+      //   const data = res.data || {}
+      //   this.freightPrice = data.fee?parseFloat(data.fee):0;
+      //   this.showDistance = data.showDistance || 0;
+      //   this.form.sendDistance = this.showDistance
+      // });
+      // 当需要的数据都具备时,调用 newFreight 计算运费
+      try {
+        const deliveryForm = (ref && ref.form) ? ref.form : {};
+        const goodsInfo = this.goodsInfo || {};
+        const cargoName = goodsInfo.goodsName || goodsInfo.name || '商品';
+        const packageNum = Number(goodsInfo.buyNum || this.form.goodsNum || 0);
+        // 商品总重量 = 单件重量(kg,缺省视为 1) * 数量
+        const unitWeight = goodsInfo.weight ? Number(goodsInfo.weight) : 1; // 单件重量,缺省视为 1 公斤
+        const totalWeight = Number((unitWeight * packageNum).toFixed(2));
+        const userName = deliveryForm.receiveUserName || '';
+        const userPhone = deliveryForm.receiveMobile || '';
+
+        // 仅当必要数据都具备时才调用 newFreight
+        const hasLocation = lat && long;
+        const hasValidNum = packageNum > 0;
+        const hasValidWeight = totalWeight > 0;
+        const hasContact = !!userName && !!userPhone;
+        if (!(hasLocation && hasValidNum && hasValidWeight && hasContact)) {
+          return;
+        }
+
+        const params = {
+          cargo_name: cargoName,
+          price: this.goodsTotalPrice,
+          weight: totalWeight,
+          package_num: packageNum,
+          user_lng: long,
+          user_lat: lat,
+          user_name: userName,
+          user_phone: userPhone,
+          user_address: ref.region.province + ref.region.city + ref.region.dist + ref.region.address + ref.region.floor
+        };
+
+        newFreight(params).then(res => {
+          console.log('newFreight',res)
+          if (res && res.code == 1) {
+            const data = res.data || {};
+            this.freightPrice = data.est_fee ? parseFloat(Number(data.est_fee/100)) : 0;
+            this.showDistance = (data.distance/1000 || 0).toFixed(2);
+            this.form.sendDistance = (data.distance/1000 || 0).toFixed(2);
+            this.form.sendCost = this.freightPrice
+          }
+        }).catch(() => {});
+      } catch (e) {}
     },
-    formSubmit(e) {
+    formSubmit() {
       this.createOrderFn()
     },
     createOrderFn() {
       let form = {}
       if (this.form.sendType == 2) {
-        form = this.$refs.appDelivery.form
+        if(this.form.hasMap == 0) {
+          this.$msg('由于地图定位服务停用,无法使用代叫跑腿')
+          return
+        }
+        if(this.form.freightPrice <= 0) {
+          this.$msg('选择代叫跑腿,必须获取运费')
+          return
+        }
+        const deliveryRef = this.$refs.appDelivery
+        if(!deliveryRef || !deliveryRef.form){
+          this.$msg("请完善配送信息")
+          return
+        }
+        form = deliveryRef.form
         let receiveUserName = form.receiveUserName;
         if (this.$util.isEmpty(receiveUserName)) {
           this.$msg("请填写收花人姓名");
-          return false;
+          return;
         }
         let receiveMobile = form.receiveMobile;
         if (this.$util.isEmpty(receiveMobile)) {
           this.$msg("请填写收花人电话");
-          return false;
+          return;
         }
         let address = form.address;
         if (this.$util.isEmpty(address)) {
           this.$msg("请填写地址");
-          return false;
+          return;
         }
       }
       uni.showLoading({mask:true})
@@ -175,7 +227,13 @@ export default {
       createOrder({...form, ...this.form,hdId:hdId}).then(res => {
         uni.hideLoading()
         uni.removeStorageSync("buyGoodsDetil")
-        this.$util.pageTo({ url: "/pages/callback/pay", type: 2, query: { pageStatus: 1, ...res.data,hdId:hdId,account:account } })
+        this.$util.pageTo({ 
+          url: "/pages/callback/pay",
+          type: 2,
+          query: { pageStatus: 1, ...res.data, hdId:hdId, account:account, freightPrice: this.freightPrice } 
+        })
+      }).catch(()=>{
+        uni.hideLoading()
       })
     }
   }