<template>
  <div v-loading="loading">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="150px" class="order_form">
      <el-form-item label="付费会员类型">
        <el-select v-model="ruleForm.paidMemberType" class="form_select" placeholder="付费会员类型">
          <el-option label="一般付费" value="0"></el-option>
          <el-option label="超级付费" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="延期条件">
        <el-select v-model="ruleForm.extensionCondition" class="form_select" placeholder="延期条件">
          <el-option label="指定会员或指定条件" value="0"></el-option>
          <el-option label="付费会员已失效" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="延期天数" prop="deferredDays">
        <el-input v-model="ruleForm.deferredDays" placeholder="请输入延期天数"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getProviceCity, getDictionary } from '@/api/commonAPI'
import { getOrder, addOrder } from '@/api/memberManagement/memberList'
import { validateTel } from '@/utils/validate'
import { filterContent } from '@/utils'

export default {
  name: 'MemberExtension',
  props: {
    rowid: {
      type: String,
      default: ''
    },
    callid: {
      type: Number,
      default: 0
    },
    layerid: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      props: { // 自定义省市下拉数据的key值
        value: 'code',
        label: 'name',
        children: 'entityJson'
      },
      sourceOptions: [], // 工单来源下拉数据
      ruleForm: {
        unique_id: '', //		否	string	callid
        ordercode: '', 
        paidMemberType: '', // 付费会员类型 
        extensionCondition: '', // 延期条件
        deferredDays: '', // 延期天数
      },
      rules: {
      },
      loading: false
    }
  },
  created() {
    if (this.callid) {
      this.ruleForm.unique_id = this.callid
    }
    Promise.all([])
      .then(() => {
        if (this.rowid) {
          this.ruleForm.ordercode = this.rowid
        }
      })
  },
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.ruleForm.content = filterContent.delHtmlTag(this.ruleForm.content)// 保存内容时去掉 html 标签
          this.loading = true
          addOrder(this.ruleForm).then(response => {
            this.loading = false
            if (response.state.toLowerCase() === 'success') {
              this.$parent.$layer.close(this.layerid)
              this.$parent.getList() // 重新加载父级数据
              this.$message.success('恭喜你，添加成功!')
            }
          }).catch(() => {
            this.loading = false
          })
          return
        } else {
          this.$message.error('请输入有效的必填项信息!')
          return false
        }
      })
    },
    resetForm() {
      this.$refs.ruleForm.resetFields()
    },
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.order_form .form_select{
	width: 100%;
}
</style>