jiuyiUniapp/jiuyi2/components/shop/order/express.vue

139 lines
2.8 KiB
Vue
Raw Normal View History

2025-01-23 21:29:16 +08:00
<script setup>
//
import {
ref,
reactive,
getCurrentInstance,
defineExpose,
2025-01-25 21:43:01 +08:00
defineEmits,
2025-01-23 22:26:04 +08:00
onMounted
2025-01-23 21:29:16 +08:00
} from 'vue'
// 工具库
import util from '@/common/js/util';
// api
import api from '@/api/index.js';
const {
proxy
} = getCurrentInstance()
2025-01-25 21:43:01 +08:00
//
const emit = defineEmits(['confirm'])
2025-01-23 21:29:16 +08:00
// 表单
const form = reactive({
// 物流公司名称
expressName: '',
// 运单号
trackingNumber: '',
})
2025-01-23 22:26:04 +08:00
// 物流公司列表
const expressList = reactive([])
// 物流公司列表
const expressIndex = ref('')
onMounted(() => {
// 获取物流公司列表
getExpressList()
})
2025-01-23 21:29:16 +08:00
// 获取物流公司列表
function getExpressList() {
api.getDict({
path: ['express_company'],
}).then(rs => {
if (rs.code == 200) {
2025-01-23 22:26:04 +08:00
Object.assign(expressList, rs.data)
2025-01-23 21:29:16 +08:00
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
})
}
2025-01-23 22:26:04 +08:00
/**
* 选择物流公司
* @param {Object} ev
*/
function handleExpressIndex(ev) {
const index = ev.detail.value
2025-01-25 21:43:01 +08:00
if (expressIndex.value === index) return
expressIndex.value = index
2025-01-23 22:26:04 +08:00
form.expressName = expressList[index].dictLabel
}
2025-01-23 21:29:16 +08:00
// 开启弹窗
function open() {
proxy.$refs.express.open()
}
// 关闭弹窗
function close() {
proxy.$refs.express.close()
2025-01-23 22:26:04 +08:00
//
setTimeout(() => {
2025-01-25 21:43:01 +08:00
expressIndex.value = ''
2025-01-23 22:26:04 +08:00
form.expressName = ''
form.trackingNumber = ''
2025-01-25 21:43:01 +08:00
}, 500)
}
// 保存
function handleSubmit() {
let data = {
...form
}
if (!data.expressName) {
util.alert('请选择快递公司')
return
}
if (!data.trackingNumber) {
util.alert('请输入快递单号')
return
}
emit('confirm', data)
close()
2025-01-23 21:29:16 +08:00
}
defineExpose({
open,
close
})
</script>
<template>
<uni-popup ref="express" type="center">
2025-01-23 22:26:04 +08:00
<view class="expressAlt popMid bfff">
<view class="header rows ptb20 plr20">
2025-01-23 21:29:16 +08:00
<view>填写快递单号</view>
2025-01-23 22:26:04 +08:00
<uni-icons type="closeempty" @click="close" />
2025-01-23 21:29:16 +08:00
</view>
2025-01-23 22:26:04 +08:00
<view class="form ooh mtb30 plr30 c333 f30">
<view class="line mtb30">
<picker :range="expressList" range-key="dictLabel" @change="handleExpressIndex">
<view class="rows">
<view class="mr20">快递公司</view>
2025-01-25 21:43:01 +08:00
<view class="f1">
<text v-if="form.expressName">{{form.expressName}}</text>
<text class="placeholderStyle" v-else>请选择</text>
</view>
<!-- <input type="text" placeholder="输入快递公司" /> -->
2025-01-23 22:26:04 +08:00
</view>
</picker>
2025-01-23 21:29:16 +08:00
</view>
<view class="line df aic">
2025-01-23 22:26:04 +08:00
<view class="mr20">快递单号</view>
2025-01-25 21:43:01 +08:00
<input type="text" v-model="form.trackingNumber" placeholder="输入快递公司"
placeholder-class="placeholderStyle" />
2025-01-23 21:29:16 +08:00
</view>
</view>
2025-01-23 22:26:04 +08:00
2025-01-25 21:43:01 +08:00
<view class="btn warm mtb30 mlr30" @click="handleSubmit">保存</view>
2025-01-23 21:29:16 +08:00
</view>
</uni-popup>
</template>
<style>
</style>