<script setup>
import {apiProductsConfig} from '@/api/products'
const show = defineModel('show', { type: Boolean, default: false })
const props = defineProps({
  productInfo:{
    type:Object,
    default:{}
  },
})
const emits = defineEmits(["close"])

async function handleSubmitForm() {
  if(!props.productInfo.Price) return ElMessage.warning('请输入商品价格')
  const res=await apiProductsConfig.postEditProduct({
    SourceId:props.productInfo.SourceId,
    Type:props.productInfo.ProductType === '报告'?'report':props.productInfo.ProductType === '音频' ? 'audio' : 'video',
    Price:props.productInfo.Price,
    ProductId:props.productInfo.Id,
  })
  if(res.Ret!==200) return
  ElMessage.success('保存成功')
  handleClose()
}
function handleClose() {
  emits("close")
}
</script>

<template>
  <el-dialog
    v-model="show"
    :close-on-click-modal="false"
    :modal-append-to-body="false"
    width="30%"
    title="编辑"
  >
    <div class="dialog-content">
      <el-form label-width="150px">
        <el-form-item label="产品名称">
          <span>{{ props.productInfo.ProductName }}</span>
        </el-form-item>
        <el-form-item label="商品价格(元)" prop="depart">
          <el-input v-model="props.productInfo.Price" placeholder="请输入商品价格" />
        </el-form-item>
        <el-form-item label="风险等级">
          <span>{{ props.productInfo.RiskLevel }}</span>
        </el-form-item>
      </el-form>
      <div class="tips">
        提示：修改价格和有效时长不影响历史已支付订单，仅对未来订单生效！
      </div>
    </div>
    <template #footer>
      <div class="btn-content">
        <el-button style="width: 80px" @click="handleClose()">取消</el-button>
        <el-button
          type="primary"
          style="width: 80px; margin-right: 24px"
          @click="handleSubmitForm"
          >保存</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<style scoped lang="scss">
.tips {
  line-height: 22px;
  padding-left: 50px;
  color: #909399;
}

.btn-content {
  text-align: center;
  padding-bottom: 20px;
}
</style>
