<script lang="ts" setup>
import {
  expenseStrategy,
  unit,
} from '@/pages/gds/goods/constants.ts'
import VModel from '@/common/utils/v-model.ts'

const props = defineProps<{
  modelValue: {
    // 计费策略
    expenseStrategy?: string
    // 计量单位
    unit?: string
    // 税率
    taxRate?: number
    // 单价
    unitPrice?: number
    // 起步价
    initialPrice?: number
    // 起步量
    initialQuantity?: number
    // 每档的量
    everyQuantity?: number
  }
}>()
const emits = defineEmits([ 'update:modelValue' ])

const modelValueProxy = VModel<Pick<typeof props, 'modelValue'>>(props, 'modelValue', emits)


/*
 watch(
 () => props.modelValue.expenseStrategy,
 (n) => {
 switch (n) {
 case expenseStrategy.DanJia:
 rulesProxy.value?.unitPrice =
 break

 case expenseStrategy.GuDing:
 break

 case expenseStrategy.TanXing:
 break
 }
 },
 )
 */


</script>

<template>
  <ElFormItem label="计费策略" prop="expenseStrategy">
    <ElRadioGroup v-model="modelValueProxy.expenseStrategy">
      <ElRadio v-for="it in expenseStrategy" :key="'expenseStrategy'+it.val" :value="it.val" border>{{ it.txt }}</ElRadio>
    </ElRadioGroup>
  </ElFormItem>
  <ElFormItem label="计量单位" prop="unit">
    <ElSelect v-model="modelValueProxy.unit">
      <ElOption
        v-for="item in unit"
        :key="'unit'+item.val"
        :label="item.txt"
        :value="item.val"/>
    </ElSelect>
  </ElFormItem>
  <ElFormItem label="税率" prop="taxRate">
    <ElInputNumber v-model="modelValueProxy.taxRate" :max="100" :min="0" :precision="2" :step="0.01" controls-position="right"/>
  </ElFormItem>
  <ElFormItem v-if="modelValueProxy.expenseStrategy === expenseStrategy.TanXing" label="起步价" prop="initialPrice">
    <ElInputNumber v-model="modelValueProxy.initialPrice" :min="0" :precision="2" :step="1" controls-position="right"/>
  </ElFormItem>
  <ElFormItem v-if="modelValueProxy.expenseStrategy === expenseStrategy.TanXing" label="起步量" prop="initialQuantity">
    <ElInputNumber v-model="modelValueProxy.initialQuantity" :min="0" :step="1" controls-position="right"/>
  </ElFormItem>
  <ElFormItem
    v-if="modelValueProxy.expenseStrategy !== expenseStrategy.MianFei"
    :label="modelValueProxy.expenseStrategy === expenseStrategy.TanXing?'每档单价':(modelValueProxy.expenseStrategy === expenseStrategy.DanJia?'单价':'价格')"
    prop="unitPrice">
    <ElInputNumber v-model="modelValueProxy.unitPrice" :min="0" :precision="2" :step="1" controls-position="right"/>
  </ElFormItem>
  <ElFormItem v-if="modelValueProxy.expenseStrategy === expenseStrategy.TanXing" label="每档的量" prop="everyQuantity">
    <ElInputNumber v-model="modelValueProxy.everyQuantity" :min="0" :step="1" controls-position="right"/>
  </ElFormItem>
</template>

<style lang="stylus" scoped>

</style>
