【代码优化】商城:门店自提的员工绑定

pull/561/MERGE
YunaiV 2024-10-13 09:47:12 +08:00
parent ca9a389ae8
commit dcf1ad6b38
7 changed files with 122 additions and 136 deletions

View File

@ -13,10 +13,11 @@ export interface DeliveryPickUpStoreVO {
latitude: number latitude: number
longitude: number longitude: number
status: number status: number
verifyUserIds: number[] // 绑定用户编号组数
} }
// 查询自提门店列表 // 查询自提门店列表
export const getDeliveryPickUpStorePage = async (params) => { export const getDeliveryPickUpStorePage = async (params: any) => {
return await request.get({ url: '/trade/delivery/pick-up-store/page', params }) return await request.get({ url: '/trade/delivery/pick-up-store/page', params })
} }
@ -26,8 +27,8 @@ export const getDeliveryPickUpStore = async (id: number) => {
} }
// 查询自提门店精简列表 // 查询自提门店精简列表
export const getListAllSimple = async (): Promise<DeliveryPickUpStoreVO[]> => { export const getSimpleDeliveryPickUpStoreList = async (): Promise<DeliveryPickUpStoreVO[]> => {
return await request.get({ url: '/trade/delivery/pick-up-store/list-all-simple' }) return await request.get({ url: '/trade/delivery/pick-up-store/simple-list' })
} }
// 新增自提门店 // 新增自提门店
@ -45,12 +46,7 @@ export const deleteDeliveryPickUpStore = async (id: number) => {
return await request.delete({ url: '/trade/delivery/pick-up-store/delete?id=' + id }) return await request.delete({ url: '/trade/delivery/pick-up-store/delete?id=' + id })
} }
//绑定自提店员 // 绑定自提店员
export const bindStoreStaffId = async (data: any) => { export const bindStoreStaffId = async (data: any) => {
return await request.post({ url: '/trade/delivery/pick-up-store/bind', data }) return await request.post({ url: '/trade/delivery/pick-up-store/bind', data })
} }
//查询门店绑定情况
export const getDeliveryPickUpStoreStaff = async (id: number) => {
return await request.get({ url: '/trade/delivery/pick-up-store/get-store-staff?id=' + id })
}

View File

@ -72,7 +72,13 @@
<Icon class="mr-5px" icon="ep:refresh" /> <Icon class="mr-5px" icon="ep:refresh" />
重置 重置
</el-button> </el-button>
<el-button @click="handlePickup" type="success" plain v-hasPermi="['trade:order:pick-up']" :disabled="isUse"> <el-button
@click="handlePickup"
type="success"
plain
v-hasPermi="['trade:order:pick-up']"
:disabled="isUse"
>
<Icon class="mr-5px" icon="ep:check" /> <Icon class="mr-5px" icon="ep:check" />
核销 核销
</el-button> </el-button>
@ -221,26 +227,20 @@ import { DeliveryTypeEnum } from '@/utils/constants'
import { TradeOrderSummaryRespVO } from '@/api/mall/trade/order' import { TradeOrderSummaryRespVO } from '@/api/mall/trade/order'
import { DeliveryPickUpStoreVO } from '@/api/mall/trade/delivery/pickUpStore' import { DeliveryPickUpStoreVO } from '@/api/mall/trade/delivery/pickUpStore'
import OrderPickUpForm from '@/views/mall/trade/order/form/OrderPickUpForm.vue' import OrderPickUpForm from '@/views/mall/trade/order/form/OrderPickUpForm.vue'
import { ref, onMounted } from "vue"; import { ref, onMounted } from 'vue'
import { useUserStore } from '@/store/modules/user'
const message = useMessage() // const message = useMessage() //
const port = ref(""); const port = ref('')
const ports = ref([]); const ports = ref([])
const reader = ref(""); const reader = ref('')
defineOptions({ name: 'PickUpOrder' }) defineOptions({ name: 'PickUpOrder' })
// const loading = ref(true) //
const loading = ref(true) const total = ref(2) //
// const list = ref<TradeOrderApi.OrderVO[]>([]) //
const total = ref(2) const queryFormRef = ref<FormInstance>() //
//
const list = ref<TradeOrderApi.OrderVO[]>([])
//
const queryFormRef = ref<FormInstance>()
const serialPort = ref(false)
const isUse = ref(true)
//
const INIT_QUERY_PARAMS = { const INIT_QUERY_PARAMS = {
// //
pageNo: 1, pageNo: 1,
@ -251,15 +251,15 @@ const INIT_QUERY_PARAMS = {
// //
deliveryType: DeliveryTypeEnum.PICK_UP.type, deliveryType: DeliveryTypeEnum.PICK_UP.type,
// //
pickUpStoreId: undefined pickUpStoreId: -1
} } //
// const queryParams = ref({ ...INIT_QUERY_PARAMS }) //
const queryParams = ref({ ...INIT_QUERY_PARAMS }) const queryType = reactive({ queryParam: 'no' }) // queryParam
// queryParam const summary = ref<TradeOrderSummaryRespVO>() //
const queryType = reactive({ queryParam: 'no' })
// const serialPort = ref(false) //
const summary = ref<TradeOrderSummaryRespVO>() const isUse = ref(true) //
// select // select
const dynamicSearchList = ref([ const dynamicSearchList = ref([
@ -308,7 +308,7 @@ const handleQuery = async () => {
const resetQuery = () => { const resetQuery = () => {
queryFormRef.value?.resetFields() queryFormRef.value?.resetFields()
queryParams.value = { ...INIT_QUERY_PARAMS } queryParams.value = { ...INIT_QUERY_PARAMS }
if(pickUpStoreList.value.length > 0) { if (pickUpStoreList.value.length > 0) {
queryParams.value.pickUpStoreId = pickUpStoreList.value[0].id queryParams.value.pickUpStoreId = pickUpStoreList.value[0].id
} }
handleQuery() handleQuery()
@ -317,7 +317,12 @@ const resetQuery = () => {
/** 自提门店精简列表 */ /** 自提门店精简列表 */
const pickUpStoreList = ref<DeliveryPickUpStoreVO[]>([]) const pickUpStoreList = ref<DeliveryPickUpStoreVO[]>([])
const getPickUpStoreList = async () => { const getPickUpStoreList = async () => {
pickUpStoreList.value = await PickUpStoreApi.getListAllSimple() pickUpStoreList.value = await PickUpStoreApi.getSimpleDeliveryPickUpStoreList()
//
const userId = useUserStore().getUser.id
pickUpStoreList.value = pickUpStoreList.value.filter((item) =>
item.verifyUserIds?.includes(userId)
)
} }
/** 显示核销表单 */ /** 显示核销表单 */
@ -330,85 +335,92 @@ const handlePickup = () => {
const connectToSerialPort = async () => { const connectToSerialPort = async () => {
try { try {
// //
if ("serial" in navigator && navigator.serial != null && typeof navigator.serial === 'object' && "requestPort" in navigator.serial) { if (
'serial' in navigator &&
navigator.serial != null &&
typeof navigator.serial === 'object' &&
'requestPort' in navigator.serial
) {
// //
port.value = await navigator.serial.requestPort(); port.value = await navigator.serial.requestPort()
} else { } else {
message.error("浏览器不支持扫码枪连接,请更换浏览器重试") message.error('浏览器不支持扫码枪连接,请更换浏览器重试')
return return
} }
// 访 // 访
ports.value = await navigator.serial.getPorts(); ports.value = await navigator.serial.getPorts()
// console.log(port.value, ports.value); // console.log(port.value, ports.value);
console.log(port.value); // console.log(port.value)
// //
await port.value.open({ baudRate: 9600 , dataBits: 8 , stopBits: 2}); await port.value.open({ baudRate: 9600, dataBits: 8, stopBits: 2 })
// console.log(typeof port.value); // console.log(typeof port.value);
message.success("成功连接扫码枪") message.success('成功连接扫码枪')
serialPort.value = true; serialPort.value = true
// readData(port.value); // readData(port.value);
readData(); readData()
} catch (error) { } catch (error) {
// //
console.log("Error connecting to serial port:", error); console.log('Error connecting to serial port:', error)
} }
}; }
/** 监听扫码枪输入 */ /** 监听扫码枪输入 */
const readData = async () => { const readData = async () => {
reader.value = port.value.readable.getReader(); reader.value = port.value.readable.getReader()
let data = ""; // let data = '' //
// //
while (true) { while (true) {
const { value, done } = await reader.value.read(); const { value, done } = await reader.value.read()
if (done) { if (done) {
// //
reader.value.releaseLock(); reader.value.releaseLock()
break; break
} }
// //
const serialData = new TextDecoder().decode(value); const serialData = new TextDecoder().decode(value)
data = `${data}${serialData}`; data = `${data}${serialData}`
if (serialData.includes("\r")) { if (serialData.includes('\r')) {
// //
let codeData = data.replace("\r",""); let codeData = data.replace('\r', '')
data = ""; // data = '' //
console.log(`二维码数据:${codeData}`); console.log(`二维码数据:${codeData}`)
// //
pickUpForm.value.open(codeData) pickUpForm.value.open(codeData)
} }
} }
}; }
/** 断开扫码枪 */ /** 断开扫码枪 */
const cutPort = async () => { const cutPort = async () => {
if (port.value !== "") { if (port.value !== '') {
await reader.value.cancel(); await reader.value.cancel()
await port.value.close(); await port.value.close()
port.value = ""; port.value = ''
console.log("断开扫码枪连接"); console.log('断开扫码枪连接')
message.success("已成功断开扫码枪连接") message.success('已成功断开扫码枪连接')
serialPort.value = false; serialPort.value = false
} else { } else {
message.warning("请先连接或打开扫码枪") message.warning('请先连接或打开扫码枪')
} }
}; }
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
await getPickUpStoreList() await getPickUpStoreList()
if(pickUpStoreList.value.length > 0){ if (pickUpStoreList.value.length === 0) {
message.error('当前登录人没绑定任何自提点')
loading.value = false
isUse.value = true
return
}
//
queryParams.value.pickUpStoreId = pickUpStoreList.value[0].id queryParams.value.pickUpStoreId = pickUpStoreList.value[0].id
isUse.value = false isUse.value = false
await getList() await getList()
}else{
message.error("当前登录人没绑定任何自提点")
loading.value = false
isUse.value = true
}
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -10,18 +10,18 @@
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="门店名称" prop="name"> <el-form-item label="门店名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入门店名称" :disabled="true"/> <el-input v-model="formData.name" placeholder="请输入门店名称" readonly />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="门店店员" prop="storeStaffIds"> <el-form-item label="门店店员" prop="verifyUserIds">
<el-button type="primary" @click="storeStaffTableSelect.open()"></el-button> <el-button type="primary" @click="storeStaffTableSelect.open()"></el-button>
</el-form-item> </el-form-item>
<!-- 店员列表 --> <!-- 店员列表 -->
<ContentWrap v-if="usersList.length > 0"> <ContentWrap v-if="formData.verifyUsers.length > 0">
<el-table :data="usersList"> <el-table :data="formData.verifyUsers">
<el-table-column label="编号" align="center" prop="id" /> <el-table-column label="编号" align="center" prop="id" />
<el-table-column <el-table-column
label="用户昵称" label="用户昵称"
@ -56,15 +56,16 @@
<el-button @click="dialogVisible = false"> </el-button> <el-button @click="dialogVisible = false"> </el-button>
</template> </template>
</Dialog> </Dialog>
<StoreStaffTableSelect ref="storeStaffTableSelect" @change="changeStoreStaff"/>
<!-- 选择员工弹窗 -->
<StoreStaffTableSelect ref="storeStaffTableSelect" @change="handleSelect" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import * as DeliveryPickUpStoreApi from '@/api/mall/trade/delivery/pickUpStore' import * as DeliveryPickUpStoreApi from '@/api/mall/trade/delivery/pickUpStore'
import StoreStaffTableSelect from './components/StoreStaffTableSelect.vue' import StoreStaffTableSelect from './components/StoreStaffTableSelect.vue'
import {DICT_TYPE} from "@/utils/dict"; import { DICT_TYPE } from '@/utils/dict'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() //
const dialogVisible = ref(false) // const dialogVisible = ref(false) //
const dialogTitle = ref('') // const dialogTitle = ref('') //
@ -72,12 +73,10 @@ const formLoading = ref(false) // 表单的加载中1修改时的数据加
const formData = ref({ const formData = ref({
id: undefined, id: undefined,
name: '', name: '',
storeStaffIds: [], verifyUserIds: [],
storeStaffs: [], verifyUsers: []
})
const formRules = reactive({
name: [{ required: true, message: '门店名称不能为空', trigger: 'blur' }],
}) })
const formRules = reactive({})
const formRef = ref() // Ref const formRef = ref() // Ref
const storeStaffTableSelect = ref() // Ref const storeStaffTableSelect = ref() // Ref
@ -88,7 +87,7 @@ const open = async (id: number) => {
resetForm() resetForm()
formLoading.value = true formLoading.value = true
try { try {
await getList(id) formData.value = await DeliveryPickUpStoreApi.getDeliveryPickUpStore(id)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -97,7 +96,6 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
/** 提交表单 */ /** 提交表单 */
const submitForm = async () => { const submitForm = async () => {
formData.value.storeStaffIds = usersList.value.map(item => item.id) as [];
// //
if (!formRef) return if (!formRef) return
const valid = await formRef.value.validate() const valid = await formRef.value.validate()
@ -105,42 +103,31 @@ const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
try { try {
const data = formData.value const data = {
id: formData.value.id,
verifyUserIds: formData.value.verifyUsers.map((item: any) => item.id)
}
await DeliveryPickUpStoreApi.bindStoreStaffId(data) await DeliveryPickUpStoreApi.bindStoreStaffId(data)
message.success("绑定成功") message.success('绑定成功')
dialogVisible.value = false dialogVisible.value = false
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
} }
/** 删除按钮操作 */ /** 处理选择员工操作 */
const handleDelete = async (id: number) => { const handleSelect = (checkedUsers: []) => {
try { formData.value.verifyUsers = checkedUsers
//
await message.delConfirm()
//
const index = usersList.value.findIndex(item => {
if (item.id == id){
return true;
}
})
usersList.value.splice(index, 1);
//await DeliveryPickUpStoreStaffApi.deleteDeliveryPickUpStoreStaff(id,formData.value.id)
message.success(t('common.delSuccess'))
//
//await getList(formData.value.id)
} catch {}
} }
/** /** 删除按钮操作 */
* 查询自提点员工绑定关系 const handleDelete = async (id: number) => {
*/ const index = formData.value.verifyUsers.findIndex((item: any) => {
const getList = async (id: number) => { if (item.id == id) {
formData.value = await DeliveryPickUpStoreApi.getDeliveryPickUpStoreStaff(id) return true
if(formData.value.storeStaffs){
usersList.value = formData.value.storeStaffs;
} }
})
formData.value.verifyUsers.splice(index, 1)
} }
/** 重置表单 */ /** 重置表单 */
@ -148,14 +135,9 @@ const resetForm = () => {
formData.value = { formData.value = {
id: undefined, id: undefined,
name: '', name: '',
storeStaffIds: [], verifyUserIds: [],
storeStaffs: [], verifyUsers: []
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }
const usersList = ref([])
const changeStoreStaff = (checkedUsers : []) => {
usersList.value = checkedUsers
}
</script> </script>

View File

@ -1,3 +1,4 @@
<!-- TODO 芋艿这块后续抽个独立的组件出来 -->
<template> <template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="60%"> <Dialog :title="dialogTitle" v-model="dialogVisible" width="60%">
<el-row :gutter="20"> <el-row :gutter="20">
@ -147,8 +148,7 @@ const checkedUsers = ref([])
// keyIDvalue // keyIDvalue
const checkedStatus = ref<Record<string, boolean>>({}) const checkedStatus = ref<Record<string, boolean>>({})
const dialogTitle = '选择店员'
const dialogTitle = "选择店员"
const dialogVisible = ref(false) const dialogVisible = ref(false)
const loading = ref(true) // const loading = ref(true) //
const total = ref(0) // const total = ref(0) //
@ -221,11 +221,7 @@ const handleCheckAll = (checked: boolean) => {
* @param combinationActivity 活动 * @param combinationActivity 活动
* @param isCalcCheckAll 是否计算全选 * @param isCalcCheckAll 是否计算全选
*/ */
const handleCheckOne = ( const handleCheckOne = (checked: boolean, combinationActivity, isCalcCheckAll: boolean) => {
checked: boolean,
combinationActivity,
isCalcCheckAll: boolean
) => {
if (checked) { if (checked) {
checkedUsers.value.push(combinationActivity as never) checkedUsers.value.push(combinationActivity as never)
checkedStatus.value[combinationActivity.id] = true checkedStatus.value[combinationActivity.id] = true
@ -245,8 +241,7 @@ const handleCheckOne = (
} }
// //
const findCheckedIndex = (user) => const findCheckedIndex = (user) => checkedUsers.value.findIndex((item) => item.id === user.id)
checkedUsers.value.findIndex((item) => item.id === user.id)
// //
const calculateIsCheckAll = () => { const calculateIsCheckAll = () => {
@ -260,7 +255,7 @@ const calculateIsCheckAll = () => {
const handleEmitChange = () => { const handleEmitChange = () => {
// //
dialogVisible.value = false dialogVisible.value = false
emits("change", [...checkedUsers.value]) emits('change', [...checkedUsers.value])
} }
/** 确认选择时的触发事件 */ /** 确认选择时的触发事件 */

View File

@ -93,7 +93,7 @@
prop="createTime" prop="createTime"
width="180" width="180"
/> />
<el-table-column align="center" label="操作"> <el-table-column align="center" label="操作" min-width="110">
<template #default="scope"> <template #default="scope">
<el-button <el-button
v-hasPermi="['trade:delivery:pick-up-store:update']" v-hasPermi="['trade:delivery:pick-up-store:update']"
@ -104,7 +104,7 @@
编辑 编辑
</el-button> </el-button>
<el-button <el-button
v-hasPermi="['trade:delivery:pick-up-store:bind']" v-hasPermi="['trade:delivery:pick-up-store:update']"
link link
type="primary" type="primary"
@click="openFormBind(scope.row.id)" @click="openFormBind(scope.row.id)"
@ -123,10 +123,11 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</ContentWrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<DeliveryPickUpStoreForm ref="formRef" @success="getList" /> <DeliveryPickUpStoreForm ref="formRef" @success="getList" />
<!-- 表单弹窗绑定店员 --> <!-- 表单弹窗绑定店员 -->
<DeliveryPickUpStoreBindForm ref="formBindRef"/> <DeliveryPickUpStoreBindForm ref="formBindRef" />
</template> </template>
<script lang="ts" name="DeliveryPickUpStore" setup> <script lang="ts" name="DeliveryPickUpStore" setup>
import * as DeliveryPickUpStoreApi from '@/api/mall/trade/delivery/pickUpStore' import * as DeliveryPickUpStoreApi from '@/api/mall/trade/delivery/pickUpStore'

View File

@ -351,7 +351,7 @@ const deliveryExpressList = ref<DeliveryExpressApi.DeliveryExpressVO[]>([]) //
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
await getList() await getList()
pickUpStoreList.value = await PickUpStoreApi.getListAllSimple() pickUpStoreList.value = await PickUpStoreApi.getSimpleDeliveryPickUpStoreList()
deliveryExpressList.value = await DeliveryExpressApi.getSimpleDeliveryExpressList() deliveryExpressList.value = await DeliveryExpressApi.getSimpleDeliveryExpressList()
}) })
</script> </script>

View File

@ -273,7 +273,7 @@ const openDetail = (id: number) => {
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
await getList() await getList()
pickUpStoreList.value = await PickUpStoreApi.getListAllSimple() pickUpStoreList.value = await PickUpStoreApi.getSimpleDeliveryPickUpStoreList()
deliveryExpressList.value = await DeliveryExpressApi.getSimpleDeliveryExpressList() deliveryExpressList.value = await DeliveryExpressApi.getSimpleDeliveryExpressList()
}) })
</script> </script>