<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.memberLevelInput" class="form_select" placeholder="优惠券">
          <el-option label="普通会员" value="0"></el-option>
          <el-option label="高级会员" value="1"></el-option>
          <el-option label="尊贵会员" value="2"></el-option>
          <el-option label="黄金会员" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注">
        <el-input
          type="textarea"
          :rows="4"
          placeholder="备注"
          v-model="ruleForm.textarea">
        </el-input>
      </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: 'MemberLevel',
  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: '',
        memberLevelInput: '', // 会员等级
      },
      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>