106 lines
2.4 KiB
Vue
106 lines
2.4 KiB
Vue
<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>
|