封装钱包规则下拉框
This commit is contained in:
1 parent
c23f369a77
commit
7da1bb9a05
12 files changed
+194
-79
No files matched your search
@@ -0,0 +1,105 @@
|
||||
<template>
|
||||
<el-select
|
||||
style="width: 100%"
|
||||
v-model="state.selectId"
|
||||
:placeholder="props.placeholder"
|
||||
clearable
|
||||
remote-show-suffix
|
||||
filterable
|
||||
remote
|
||||
:remote-method="remoteSearch"
|
||||
:loading="state.loading"
|
||||
@visible-change="(e: boolean) => e && getOptions()"
|
||||
>
|
||||
<el-option v-for="v in state.options" :key="v.id" :label="getDictById(v.rulePriceType, v)" :value="v.rulePriceType">
|
||||
<div class="flex items-center">
|
||||
<div class="flex items-center ml5">
|
||||
<dict-tag :options="state.walletRulePriceType" :value="v.rulePriceType" />
|
||||
<div class="ml-2">
|
||||
<span>超过</span>
|
||||
<span class="color-success">{{ displayPrice(v.basePrice) }}</span>
|
||||
<span>额外支付</span>
|
||||
<span class="color-danger">{{ v.multiple }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="select-mch-rule">
|
||||
import { reactive } from "vue"
|
||||
import * as mchRulePriceConfigApi from "/@/api/wallet/mch-rule-price-config"
|
||||
import { displayPrice } from "/@/utils/formatMoney"
|
||||
import { useDict } from "/@/hooks/dict"
|
||||
|
||||
const selectId = defineModel()
|
||||
|
||||
export type Props = {
|
||||
placeholder?: string
|
||||
apiParams?: any
|
||||
}
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
placeholder: "请选择",
|
||||
apiParams: {},
|
||||
})
|
||||
|
||||
const queryForm = reactive<any>({
|
||||
name: null,
|
||||
current: 1,
|
||||
size: 10,
|
||||
})
|
||||
|
||||
const state = reactive<any>({
|
||||
loading: true,
|
||||
selectId: selectId,
|
||||
options: [],
|
||||
walletRulePriceType: [],
|
||||
})
|
||||
|
||||
watch(
|
||||
selectId,
|
||||
(newVal, oldValue) => {
|
||||
if (newVal == oldValue) return
|
||||
state.selectId = newVal
|
||||
getOptions()
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
async function getOptions() {
|
||||
try {
|
||||
state.loading = true
|
||||
const _pa = {
|
||||
...queryForm,
|
||||
...props.apiParams,
|
||||
}
|
||||
const { data } = await mchRulePriceConfigApi.pageSelect(_pa)
|
||||
state.options = data.records ?? []
|
||||
|
||||
const { wallet_rule_price_type } = useDict("wallet_rule_price_type")
|
||||
state.walletRulePriceType = wallet_rule_price_type
|
||||
} finally {
|
||||
setTimeout(() => (state.loading = false), 500)
|
||||
}
|
||||
}
|
||||
|
||||
function remoteSearch(params: string) {
|
||||
if (params != queryForm.name) {
|
||||
queryForm.name = params
|
||||
getOptions()
|
||||
}
|
||||
}
|
||||
|
||||
function getDictById(value: any, v) {
|
||||
if (!value) return ""
|
||||
const target = state.walletRulePriceType.find((v: any) => v.value == value)
|
||||
if (!target) return ""
|
||||
return `${target.label} 超过${displayPrice(v.basePrice)},额外支付${v.multiple}%`
|
||||
}
|
||||
|
||||
function clear() {
|
||||
state.selectId = null
|
||||
getOptions()
|
||||
}
|
||||
</script>
|
||||
@@ -24,6 +24,7 @@ import SelectCtcgol from "/@/components/Select/SelectCtcgol.vue"
|
||||
import SelectHardGroup from "/@/components/Select/selectHardGroup.vue"
|
||||
import SelectHandlerUser from "/@/components/Select/SelectHandlerUser.vue"
|
||||
import SelectSupplier from "/@/components/Select/SelectSupplier.vue"
|
||||
import SelectMchRule from "/@/components/Select/SelectMchRule.vue"
|
||||
|
||||
// 第三方组件
|
||||
import ElementPlus from "element-plus"
|
||||
@@ -70,6 +71,7 @@ export default {
|
||||
app.component("SelectHardGroup", SelectHardGroup)
|
||||
app.component("SelectHandlerUser", SelectHandlerUser)
|
||||
app.component("SelectSupplier", SelectSupplier)
|
||||
app.component("SelectMchRule", SelectMchRule)
|
||||
|
||||
// 导入全部的elmenet-plus的图标
|
||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
|
||||
Reference in new issue
Block a user