<script lang="ts" setup>
import { ref } from "vue"
import { useVModel } from "@vueuse/core"
import { ElMessage } from "element-plus"
import { httpUpdate } from "/@/api/serviceParam/terrace";

const props = defineProps<{ visible: boolean, data: any }>()
const emit = defineEmits(['refresh'])
const visible = useVModel(props,'visible')
const data = useVModel(props, 'data')
const loading = ref(false)

async function onSubmit() {
  try {
    const { id, platform_name, platform_type, use_type, is_select_pay_rate, pay_list, desc } = data.value;
    const parameter = { id, platform_name, platform_type, use_type, is_select_pay_rate, pay_list, desc }
    loading.value = true
    const res = await httpUpdate(parameter)
    loading.value = false
    if (res.code === 0) {
      visible.value = false
      ElMessage.success(`修改平台排序权重成功`)
      emit('refresh')
    } else {
      ElMessage.warning(`修改平台排序权重失败`)
    }
  } catch (err) {
    console.log(err);
  }
}

</script>


<template>
  <ElDialog v-model="visible" title="修改平台排序权重" center>
    <ElForm>
      <ElFormItem label="排序权重" required>
        <ElInputNumber :min="0" v-model="data.desc" style="width:100%" />
      </ElFormItem>
    </ElForm>

    <div class="flex justify-end">
      <ElButton type="primary" :loading="loading" @click="onSubmit">保存</ElButton>
    </div>
  </ElDialog>
</template>
