input 加减

 

 

 


<a-input class="input-center-met" v-model:value="form.name1"> <template #prefix> <div class="flex items-center"> <div class="number-btn auto" @click="addAndSubtract('name1', 2, 100)"> <PubSvgIcon name="minus-icon" size="1rem" />100 </div> <div class="number-btn auto ml-1" @click="addAndSubtract('name1', 2, 10)"> <PubSvgIcon name="minus-icon" size="1rem" />10 </div> <div class="number-btn auto ml-1" @click="addAndSubtract('name1', 2, 1)"> <PubSvgIcon name="minus-icon" size="1rem" />1 </div> </div> </template> <template #suffix> <div class="flex items-center"> <div class="number-btn auto" @click="addAndSubtract('name1', 1, 1)"> <PubSvgIcon name="add-icon" size="1rem" />1 </div> <div class="number-btn auto ml-1" @click="addAndSubtract('name1', 1, 10)"> <PubSvgIcon name="add-icon" size="1rem" />10 </div> <div class="number-btn auto ml-1" @click="addAndSubtract('name1', 1, 100)"> <PubSvgIcon name="add-icon" size="1rem" />100 </div> </div> </template> </a-input>
// 加减法(1加/2减)
function addAndSubtract(field: string, type: number, value: number = 1) {
  const fieldValue = Number(form.value[field]);
  if (type === 1) {
    if (value === 0.1) {
      form.value[field] = (fieldValue + value).toFixed(2);

    } else {
      form.value[field] = (fieldValue + value)
    }
  }
  else {
    if (value === 0.1) {
      form.value[field] = (fieldValue - value).toFixed(2);

    } else {
      form.value[field] = (fieldValue - value)
    }

  }
}

 

posted @ 2024-08-23 10:50  abcByme  阅读(5)  评论(0编辑  收藏  举报