<template>
  <div class="protocol" v-loading="loading">
    <el-form :model="form" :rules="rules" ref="ruleFormRef" label-width="180">
      <el-form-item label="解锁单条信息费用" prop="itemUnlockFee">
        <el-input-number :min="0" v-model="form.itemUnlockFee" style="width: 300px" placeholder="请输入解锁单条信息费用" />
      </el-form-item>
      <el-form-item label="每公斤服务费" prop="shopFeePerKg">
        <el-input-number :min="0" v-model="form.shopFeePerKg" style="width: 300px" placeholder="请输入每公斤服务费" />
      </el-form-item>
      <!-- <el-form-item label="协议内容" prop="agreeUnlockInfo">
        <BasicEditor ref="editotTool"></BasicEditor>
      </el-form-item> -->
      <el-form-item>
        <div style="width: 80%; text-align: left">
          <!-- <el-button style="margin-right: 3rem" @click="$router.go(-1)">返回</el-button> -->
          <el-button type="primary" @click="submitForm(ruleFormRef)" :loading="loading"> 更新费用 </el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { Message } from 'view-ui-plus'
import { ref, reactive, onMounted } from 'vue'
import BasicEditor from '@/components/wangEditor/BasicEditor.vue'
import { cow } from '@/request/api'
import { useRouter } from 'vue-router'
const router = useRouter()

const loading = ref(false)
const ruleFormRef = ref()
const form = ref({})

const getServiceFee = async () => {
  loading.value = true
  await cow.getServiceFee().then(res => {
    if (res.code == 101 && res.data) {
      form.value = res.data
    }
  })
  loading.value = false
}

onMounted(() => {
  getServiceFee()
})

const rules = reactive({
  itemUnlockFee: [{ required: true, message: '请输入信息费用', trigger: 'blur' }],
  shopFeePerKg: [{ required: true, message: '请输入每公斤服务费', trigger: 'blur' }],
  // agreeUnlockInfo: [{ required: true, message: '请输入协议内容', trigger: 'blur' }],
})

const submitForm = async formEl => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      loading.value = true
      cow
        .updateServiceFee(form.value)
        .then(res => {
          loading.value = false
          Message.success('更新成功')
          getServiceFee()
        })
        .catch(err => {
          loading.value = false
        })
    } else {
      console.log('error submit!', fields)
    }
  })
}
</script>

<style lang="scss" scoped>
.protocol {
  padding: 20px;
}
</style>
