<template>
  <el-dialog
    width="700px"
    title="修改分销商预付类型"
    :before-close="handleClose"
    :visible.sync="visible"
  >
    <el-form
      inline
      :model="form"
      ref="form"
      label-width="180px">
      <div class="dialog-info">
        <el-form-item
          verify
          prop="paymentType"
          label="预付类型"
          style="width:100%">
          <el-select v-model="form.paymentType">
            <el-option
              label="OTA平台付款"
              :value="1"></el-option>
            <el-option
              label="平台充值余额支付"
              :value="2"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item
          v-if="form.paymentType ===2"
          prop="prePaymentLimit"
          label="挂账额度(￥)"
          style="width:100%"
        >
          <el-input-number
            :disabled="dialogType === 'edit'"
            :min="0"
            :step="0.01"
            :precision="2"
            v-model="form.prePaymentLimit"></el-input-number>
        </el-form-item> -->
      </div>

      <div class="dialog-btn-wrap">
        <el-button
          @click="submit"
          type="primary">保存</el-button>
      </div>
    </el-form>
  </el-dialog>
</template>

<script>
import { updateOtaProject } from '@/api/ota'
export default {
  data () {
    return {
      visible: false,
      form: {
        id: '',
        paymentType: 1 // 默认值为1，OTA平台付款
      }
    }
  },
  methods: {
    show (data) {
      this.visible = true
      let formData = JSON.parse(JSON.stringify(data))
      this.form.id = formData.id
      this.form.paymentType = formData.paymentType || 1 // 默认值为1，OTA平台付款
    },
    setotaSourceCodeById (id) {
      let item = this.publicOtaList.find(ota => ota.id === id)
      this.form.otaSourceCode = item.otaSourceCode
      this.form.otaSourceName = item.publicotaSourceName
    },
    handleClose () {
      this.visible = false
    },
    submit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          updateOtaProject(this.form).then(res => {
            this.$message.success('修改成功')
            this.handleClose()
            this.$emit('update')
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
