Browse Source

接口对接

lilei 4 năm trước cách đây
mục cha
commit
1169b69015
3 tập tin đã thay đổi với 118 bổ sung35 xóa
  1. 2 2
      App.vue
  2. 30 0
      api/delivery.js
  3. 86 33
      pages/userAuth/userAuth.vue

+ 2 - 2
App.vue

@@ -1,6 +1,6 @@
 <script>
 <script>
-	const uat_URL = 'https://lese.test.sxzxyj.net/gc-channel/' // 预发布
-	// const uat_URL = 'http://192.168.16.105:8303/gc-channel/' // 本地
+	// const uat_URL = 'https://lese.test.sxzxyj.net/gc-channel/' // 预发布
+	const uat_URL = 'http://192.168.16.134:8303/gc-channel/' // 本地
 	const pro_URL = 'https://lese.sxzxyj.net/gc-channel/'  // 生产
 	const pro_URL = 'https://lese.sxzxyj.net/gc-channel/'  // 生产
 	const buildType = 1 // 打包环境对应类型,1 生产 0 预发布
 	const buildType = 1 // 打包环境对应类型,1 生产 0 预发布
 	const buildURL = buildType ? pro_URL : uat_URL // 打包后实际对应的url
 	const buildURL = buildType ? pro_URL : uat_URL // 打包后实际对应的url

+ 30 - 0
api/delivery.js

@@ -0,0 +1,30 @@
+import axios from '@/libs/axios.js';
+
+// 根据电子秤设备查找网点及兑换规则信息
+export const findBySrcDeviceNo = params => {
+  return axios.request({
+    url: `steelyard/findBySrcDeviceNo/${params.srcDeviceCode}`,
+    method: 'get'
+  })
+};
+
+// 投放记录列表查询
+export const getDeliveryLog = params => {
+	let url = `deliveryLog/query/${params.pageNo}/${params.pageSize}`
+	delete params.pageNo
+	delete params.pageSize
+	return axios.request({
+		url: url,
+		method: 'post',
+		data: params
+	})
+};
+
+// 保存投放称重结果
+export const saveDelivery = params => {
+	return axios.request({
+	  url: `deliveryLog/delivery`,
+	  method: 'post',
+	  data: params
+	})
+}

+ 86 - 33
pages/userAuth/userAuth.vue

@@ -6,24 +6,24 @@
 		<view class="step1" v-if="current==0">
 		<view class="step1" v-if="current==0">
 			<view class="form-row form-flex">
 			<view class="form-row form-flex">
 				<view><text class="red">*</text>网点名称</view>
 				<view><text class="red">*</text>网点名称</view>
-				<view>啊撒旦解放拉风小区</view>
+				<view>{{stationName}}</view>
 			</view>
 			</view>
 			<view class="form-row form-flex">
 			<view class="form-row form-flex">
 				<view><text class="red">*</text>投递手机号</view>
 				<view><text class="red">*</text>投递手机号</view>
 				<view>
 				<view>
-					<u-input v-model="formData.phone" type="number" input-align="right" :custom-style="{color: '#666'}" :maxlength="11" placeholder="请输入手机号码"></u-input>
+					<u-input v-model="formData.customerMobile" type="number" input-align="right" :custom-style="{color: '#666'}" :maxlength="11" placeholder="请输入手机号码"></u-input>
 				</view>
 				</view>
 			</view>
 			</view>
 			<view class="form-row">
 			<view class="form-row">
 				<view><text class="red">*</text>投递类型</view>
 				<view><text class="red">*</text>投递类型</view>
 				<view class="form-grid">
 				<view class="form-grid">
-					<view v-for="(item,index) in rubbishtype" :key="item.id" :class="index==0?'active':''">
+					<view v-for="(item,index) in rubbishtype" :key="item.id" @click="selRubbishType(item)" :class="formData.rubbishType==item.rubbishType?'active':''">
 						<view class="imgs">
 						<view class="imgs">
-							<u-image :src="`/static/${item.code}.png`" width="70rpx" height="70rpx"></u-image>
+							<u-image :src="`/static/${item.rubbishType}.png`" width="70rpx" height="70rpx"></u-image>
 						</view>
 						</view>
 						<view class="info">
 						<view class="info">
-							<view>{{item.dispName}}</view>
-							<view class="texts">200g/1乐豆</view>
+							<view>{{item.rubbishTypeDictValue}}</view>
+							<view class="texts">{{item.rubbishWeight}}g/{{item.goleNum}}乐豆</view>
 						</view>
 						</view>
 					</view>
 					</view>
 				</view>
 				</view>
@@ -32,17 +32,17 @@
 		<view class="step2" v-if="current==1">
 		<view class="step2" v-if="current==1">
 			<view class="form-row form-flex">
 			<view class="form-row form-flex">
 				<view>投递手机号</view>
 				<view>投递手机号</view>
-				<view>{{formData.phone}}</view>
+				<view>{{formData.customerMobile}}</view>
 			</view>
 			</view>
 			<view class="form-row form-flex">
 			<view class="form-row form-flex">
 				<view>用户乐豆余额</view>
 				<view>用户乐豆余额</view>
-				<view class="flex-row"><text>560</text><u-image width="30rpx" height="30rpx" src="/static/ledou.png"></u-image></view>
+				<view class="flex-row"><text>{{currentGold}}</text><u-image width="30rpx" height="30rpx" src="/static/ledou.png"></u-image></view>
 			</view>
 			</view>
 			<view class="form-row form-flex">
 			<view class="form-row form-flex">
 				<view>投递类型</view>
 				<view>投递类型</view>
 				<view>
 				<view>
-					废旧衣服
-					<text class="des">(200g/1乐豆)</text>
+					{{curRubbishType.rubbishTypeDictValue}}
+					<text class="des">({{curRubbishType.rubbishWeight}}g/{{curRubbishType.goleNum}}乐豆)</text>
 				</view>
 				</view>
 			</view>
 			</view>
 			<view class="form-row form-flex">
 			<view class="form-row form-flex">
@@ -51,11 +51,11 @@
 			</view>
 			</view>
 			<view class="form-row form-flex">
 			<view class="form-row form-flex">
 				<view>可兑换乐豆数</view>
 				<view>可兑换乐豆数</view>
-				<view class="flex-row"><text class="nums">10</text><u-image width="30rpx" height="30rpx" src="/static/ledou.png"></u-image></view>
+				<view class="flex-row"><text class="nums">{{goldNum}}</text><u-image width="30rpx" height="30rpx" src="/static/ledou.png"></u-image></view>
 			</view>
 			</view>
 		</view>
 		</view>
 		<view class="buttons">
 		<view class="buttons">
-			<view v-if="current==0" ><u-button shape="circle" :custom-style="customStyle" @click="next()" type="primary">下一步</u-button></view>
+			<view v-if="current==0" ><u-button shape="circle" :loading="loading" :custom-style="customStyle" @click="next()" type="primary">下一步</u-button></view>
 			<view v-if="current==1"><u-button shape="circle" @click="prev()">上一步</u-button></view>
 			<view v-if="current==1"><u-button shape="circle" @click="prev()">上一步</u-button></view>
 			<view v-if="current==1"><u-button shape="circle" @click="submit()" :custom-style="customStyle" type="primary">提交</u-button></view>
 			<view v-if="current==1"><u-button shape="circle" @click="submit()" :custom-style="customStyle" type="primary">提交</u-button></view>
 		</view>
 		</view>
@@ -79,6 +79,8 @@
 </template>
 </template>
 
 
 <script>
 <script>
+	import {findBySrcDeviceNo, saveDelivery} from '@/api/delivery.js'
+	import {queryldByMobile} from '@/api/officialPartnerGoldLog.js'
 	export default {
 	export default {
 		data() {
 		data() {
 			return {
 			return {
@@ -93,18 +95,30 @@
 				}, {
 				}, {
 					name: '称重'
 					name: '称重'
 				}],
 				}],
+				stationName: '', // 网点名称
 				formData:{
 				formData:{
-					address: '',
-					phone: '',
-					washType: '0',
-					washWeight:0
+					customerMobile: '', // 客户电话
+					rubbishType: '', // 投递类型
+					rubbishWeight:0, // 投递重量
+					srcDeviceCode: '',
 				},
 				},
+				currentGold: 0, // 用户乐豆余额
 				blueConnect: true,
 				blueConnect: true,
 				deviceId: null,
 				deviceId: null,
-				rubbishtype: []
+				rubbishtype: [],
+				curRubbishType: null,
+				loading: false
 			}
 			}
 		},
 		},
 		computed: {
 		computed: {
+			// 计算可兑换乐豆
+			goldNum(){
+				let ret = 0
+				if(this.curRubbishType){
+					ret = this.balanceData / this.curRubbishType.rubbishWeight / this.curRubbishType.goleNum
+				}
+				return Math.floor(ret)
+			},
 			balanceData() {
 			balanceData() {
 				this.cancel()
 				this.cancel()
 				
 				
@@ -142,13 +156,15 @@
 				}
 				}
 				
 				
 				console.log(weight,uit,fh,'weight end')
 				console.log(weight,uit,fh,'weight end')
-				this.washWeight = weight
+				this.formData.rubbishWeight = weight
 				return fh + weight
 				return fh + weight
 			}
 			}
 		},
 		},
 		onLoad(options) {
 		onLoad(options) {
 			let _this = this
 			let _this = this
-			this.deviceId = options.deviceId
+			this.deviceId = options.deviceId.toLowerCase()
+			this.deviceId = this.deviceId.replace(/:/g,'')
+			
 			// 连接中断
 			// 连接中断
 			uni.$on('blueConnectClose',function(){
 			uni.$on('blueConnectClose',function(){
 				_this.reConnect(1)
 				_this.reConnect(1)
@@ -167,14 +183,31 @@
 				}
 				}
 			})
 			})
 			
 			
-			// 投递类型
-			this.rubbishtype = this.$store.state.vuex_rubbishType
+			// 通过设备id查询网点信息
+			this.findBySrcDeviceNo()
 		},
 		},
 		onUnload() {
 		onUnload() {
 			uni.$off('blueConnectClose')
 			uni.$off('blueConnectClose')
 			uni.$off('blueConnectCallback')
 			uni.$off('blueConnectCallback')
 		},
 		},
 		methods: {
 		methods: {
+			// 获取网点信息
+			findBySrcDeviceNo(){
+				findBySrcDeviceNo({srcDeviceCode:this.deviceId}).then(res=>{
+					console.log(res,'====')
+					if(res.status == 200){
+						this.rubbishtype = res.data.list
+						this.stationName = res.data.stationEntity.name
+						this.formData.srcDeviceCode = this.deviceId
+					}
+				})
+			},
+			// 选择投递类型
+			selRubbishType(item){
+				this.formData.rubbishType = item.rubbishType
+				this.curRubbishType = item
+			},
+			// 重连蓝牙设备
 			reConnect(type){
 			reConnect(type){
 				this.blueConnect = false
 				this.blueConnect = false
 				uni.showModal({
 				uni.showModal({
@@ -190,36 +223,45 @@
 				})
 				})
 			},
 			},
 			next(){
 			next(){
-				if(this.formData.phone == ''){
+				if(this.formData.customerMobile == ''){
 					uni.showToast({
 					uni.showToast({
 						icon: 'none',
 						icon: 'none',
 						title: '请输入手机号码'
 						title: '请输入手机号码'
 					})
 					})
 					return
 					return
 				}
 				}
-				if(this.formData.washType == ''){
+				if(this.formData.customerMobile.length!=11){
 					uni.showToast({
 					uni.showToast({
 						icon: 'none',
 						icon: 'none',
-						title: '请选择投递类型'
+						title: '请输入正确的手机号码'
 					})
 					})
 					return
 					return
 				}
 				}
-				if(this.formData.phone.length!=11){
+				if(this.formData.rubbishType == ''){
 					uni.showToast({
 					uni.showToast({
 						icon: 'none',
 						icon: 'none',
-						title: '请输入正确的手机号码'
+						title: '请选择投递类型'
 					})
 					})
 					return
 					return
 				}
 				}
-				this.current = this.current + 1
+				
+				this.loading = true
+				// 查询用户余额
+				queryldByMobile({mobile: this.formData.customerMobile}).then(res => {
+					if(res.status == 200){
+						this.current = this.current + 1
+						this.currentGold = res.data.currentGold
+					}
+					this.loading = false
+				})
 			},
 			},
 			prev(){
 			prev(){
 				this.current = this.current - 1
 				this.current = this.current - 1
 			},
 			},
 			submit(){
 			submit(){
 				let that = this
 				let that = this
-				console.log(this.washWeight,'this.washWeight')
-				if(this.washWeight<=0){
+				console.log(this.formData.rubbishWeight,'this.formData.rubbishWeight')
+				if(this.formData.rubbishWeight<=0){
 					uni.showToast({
 					uni.showToast({
 						icon: 'none',
 						icon: 'none',
 						title: '请投放物品!'
 						title: '请投放物品!'
@@ -229,8 +271,11 @@
 				// 判断设备仍然连接中
 				// 判断设备仍然连接中
 				uni.getBluetoothDevices({
 				uni.getBluetoothDevices({
 				  success(res) {
 				  success(res) {
-				    console.log(res.devices,that.deviceId)
-					let has = res.devices.find(item => item.deviceId == that.deviceId)
+					let has = res.devices.find(item => {
+						let deviceId = item.deviceId.toLowerCase()
+						return deviceId.replace(/:/g,'') == that.deviceId
+					})
+					console.log(has,'判断设备仍然连接中')
 					if(that.blueConnect && has){
 					if(that.blueConnect && has){
 						that.showOk = true
 						that.showOk = true
 						that.modelContent = `
 						that.modelContent = `
@@ -252,7 +297,16 @@
 			},
 			},
 			// 确认提交
 			// 确认提交
 			confirm(){
 			confirm(){
-				
+				console.log(this.formData,'formData')
+				saveDelivery(this.formData).then(res => {
+					if(res.status == 200){
+						uni.navigateBack()
+					}
+					uni.showToast({
+						icon: 'none',
+						title: res.message
+					})
+				})
 			}
 			}
 		}
 		}
 	}
 	}
@@ -308,7 +362,6 @@
 		display: flex;
 		display: flex;
 		align-items: center;
 		align-items: center;
 		flex-wrap: wrap;
 		flex-wrap: wrap;
-		justify-content: space-around;
 		> view{
 		> view{
 			width: 46%;
 			width: 46%;
 			border: 1px solid #eee;
 			border: 1px solid #eee;