<template>
  <div>
    <el-form
      inline
      :model="form"
      :rules="rules"
      ref="form"
      class="form-wrap dialog-info"
      label-width="100px">
      <el-form-item
        label="分销商类型"
        prop="type">
        <el-select
          v-model="form.type"
          placeholder="请选择分销商类型">
          <el-option
            label="普通分销商"
            :value="0" />
          <el-option
            label="商户"
            :value="1" />
          <el-option
            label="总代"
            :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item
        label="分销商编码"
        prop="otaSourceCode"
        verify>
        <el-input
          v-model="form.otaSourceCode"
          placeholder="请输入分销商编码" />
      </el-form-item>
      <el-form-item
        label="分销商名称"
        prop="otaSourceName"
        verify>
        <el-input
          v-model="form.otaSourceName"
          placeholder="请输入分销商名称" />
      </el-form-item>
      <el-form-item
        label="分销商描述"
        prop="otaSourceDesc">
        <el-input
          v-model="form.otaSourceDesc"
          placeholder="请输入分销商描述" />
      </el-form-item>
      <el-form-item
        label="分销商参数"
        prop="param">
        <el-input
          v-model="form.param" />
      </el-form-item>
      <el-form-item
        label="下单回调地址"
        prop="createCallbackUrl">
        <el-input
          v-model="form.createCallbackUrl"
          placeholder="请输入下单回调地址" />
      </el-form-item>
      <el-form-item
        label="核销回调地址"
        prop="checkCallbackUrl">
        <el-input
          v-model="form.checkCallbackUrl"
          placeholder="请输入核销回调地址" />
      </el-form-item>
      <el-form-item
        label="退单回调地址"
        prop="cancelCallbackUrl">
        <el-input
          v-model="form.cancelCallbackUrl"
          placeholder="请输入退单回调地址" />
      </el-form-item>
    </el-form>

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

</template>

<script>
import { addOtaSource } from '@/api/platform'

export default {
  data () {
    return {
      visible: false,
      form: {
        type: 0,
        otaSourceCode: '',
        otaSourceName: '',
        param: '',
        otaSourceDesc: '',
        createCallbackUrl: '',
        checkCallbackUrl: '',
        cancelCallbackUrl: ''
      },
      rules: {}
    }
  },
  methods: {
    handleClose () {
      this.$parent.handleClose()
    },
    reset () {
      this.$refs.form.resetFields()
    },
    submit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.addOtaSource()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    addOtaSource () {
      addOtaSource(this.form).then(res => {
        this.$message.success('添加成功')
        this.reset()
        this.handleClose()
        this.$emit('updateList')
      })
    }
  },
  watch: {
    visible (val) {
      // 获取角色列表
      val && this.getRoleList()
      // 重置表单
      this.reset()
    }
  }
}
</script>
<style scoped>
.btn-wrap{
  padding-right: 20px;
}
</style>
