Browse Source

抢单

master
396316021 1 year ago
parent
commit
38f9ff0929
  1. 13
      api/other.js
  2. 7
      pages.json
  3. 37
      pages/ChatDetail/index.vue
  4. 27
      pages/SeizeOrders/index.vue

13
api/other.js

@ -39,4 +39,17 @@ export function feedback(data){
method: "post",
data:data
})
}
/**
* 抢单
* @param data
* @returns {Promise | Promise<unknown>}
*/
export function seizeChat(data){
return request({
url:`/user/seize-chat`,
method: "post",
data:data
})
}

7
pages.json

@ -165,6 +165,13 @@
"navigationBarTitleText": "优惠券",
"enablePullDownRefresh": true
}
},
{
"path": "pages/SeizeOrders/index",
"style": {
"navigationBarTitleText": "抢单",
"enablePullDownRefresh": true
}
}
],
"globalStyle": {

37
pages/ChatDetail/index.vue

@ -63,6 +63,7 @@ import MzButton from '../../components/MzButton/Index.vue';
import {getToken} from "@/api/chat";
import log from "@/utils/log";
import {waitToken} from "../../api/chat";
import {seizeChat} from "../../api/other";
export default {
components: {
@ -94,9 +95,11 @@ export default {
title:"在线咨询"
},
onLoad(options) {
if(this.$store.state.userInfo.is_waitstaff !== 1 ){
let user = uni.getStorageSync('user');
if(user.is_waitstaff !== 1 ){
this.getToken(options.id, options.type ?? 1);
}else if(options.is_seize == 1){
this.connectChat(options.id);
}else{
if(options.type ==='2'){
this.getToken(options.id, options.type ?? 1);
@ -147,6 +150,36 @@ export default {
})
})
},
connectChat(chat_id) {
seizeChat({chat_id:chat_id}).then(data => {
this.chat_id = data.data.chat_id;
this.type = data.data.type;
this.user_id = data.data.user_id;
uni.connectSocket({
url: data.data.chat_url
});
uni.onSocketOpen((res) => {
this.ableChat = true;
console.log('WebSocket连接已打开!');
});
uni.onSocketClose((res) => {
this.ableChat = false;
console.log('WebSocket 已关闭!');
});
uni.onSocketMessage((res) => {
this.newMessage(res);
})
}).catch(err => {
api.error(err.msg).then(() => {
uni.redirectTo({url:'/pages/Index/index'})
return;
});
})
},
getWaitToken(order_id) {
waitToken(order_id).then(data => {
this.chat_id = data.data.chat_id;

27
pages/SeizeOrders/index.vue

@ -0,0 +1,27 @@
<script>
import {seizeChat} from "../../api/other";
export default {
name: "index",
methods: {
handleSeize(id){
seizeChat({
chat_id:id
}).then((res) => {
console.log(res)
});
}
},
onLoad(option) {
this.handleSeize(option.id);
},
}
</script>
<template>
</template>
<style scoped lang="scss">
</style>
Loading…
Cancel
Save