<template>
  <el-dialog
      class="client-data-dialog"
      :title="title"
      :visible.sync="dialogVisible"
      :before-close="handleClose">

    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm">
      <el-form-item label="反馈类型" prop="feedType">
        <el-select v-model="ruleForm.feedType" label="反馈类型" placeholder="请选择" style="width:80%">
          <el-option
              v-for="item in optionsFeedType"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="反馈描述" prop="feedContent">
        <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入反馈内容"
            v-model="ruleForm.feedContent" style="width:80%">
        </el-input>
      </el-form-item>

      <el-form-item label="反馈状态" prop="feedStatus">
        <el-select v-model="ruleForm.feedStatus" label="反馈状态" placeholder="请选择">
          <el-option
              v-for="item in optionsStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="创建人" prop="creater">
        <p>{{ this.ruleForm.creater }}</p>
      </el-form-item>
    </el-form>

    <div slot="footer" style="margin-right:30px">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')">新 增</el-button>
    </div>
  </el-dialog>
</template>

<script type="text/ecmascript-6">


export default {
  name: 'AddUserServiceDialog',
  props: {
    dialogVisible: {
      type: Boolean,
      required: true,
    },
    title: {
      type: String,
      required: true,
    },
    params: {
      type: Object,
      required: true
    },
  },
  data() {
    /*请选择功能点*/
    const validatefeedType = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请选择反馈类型'));
      }
    };
    /*请输入问题描述*/
    const validatefeedStatus = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请选择反馈结果'));
      }
    };
    const validatefeedContent = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请输入反馈问题描述'));
      }
    };
    return {
      ui: {
        submitLoading: false
      },
      visible: this.$props.dialogVisible,
      ruleForm: {
        feedType: '',
        feedStatus: '',
        feedContent: '',
        clientNo: '',
        creater: ''
      },
      rules: {
        feedType: [
          {required: true, message: "请选择反馈类型", trigger: 'blur'}
        ],
        feedStatus: [
          {required: true, message: '请选择反馈结果', trigger: 'blur'}
        ],
        feedContent: [
          {required: true, message: '请输入反馈问题描述', trigger: 'blur'}
        ]
      },
      optionsStatus: [
        {
          value: 'YES',
          label: '已解决'
        },
        {
          value: 'NO',
          label: '未解决'
        }
      ],
      optionsFeedType: [
        {
          value: '内部投诉',
          label: '内部投诉'
        },
        {
          value: '还款问题',
          label: '还款问题'
        },
        {
          value: '系统问题',
          label: '系统问题'
        },
        {
          value: '借款咨询',
          label: '借款咨询'
        },
        {
          value: '账户问题',
          label: '账户问题'
        },
        {
          value: '银行卡签约问题',
          label: '银行卡签约问题'
        },
        {
          value: '其它',
          label: '其它'
        }
      ],
    }
  },
  created() {
    const {clientNo} = this.params;
    this.ruleForm = {
      clientNo,
      creater: localStorage.getItem("userName"),
    }

  },
  methods: {
    /** 提交点击 */
    submitForm() {

      this.$refs['ruleForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.$$post('/feed/createClientFeed', {
          creater: localStorage.getItem("userName"),
          feedType: this.ruleForm.feedType,
          feedSource: 'CUSTOMER',
          feedStatus: this.ruleForm.feedStatus,
          feedContent: this.ruleForm.feedContent,
          clientNo: this.ruleForm.clientNo
        })
            .then(res => {
              if (res.data.code != 200) {
                this.$message.error(res.data.message);
                return
              }
              this.$message({message: '反馈问题新增成功', type: 'success'});
              this.handleClose();
            })
            .catch(err => {
              alert("error!")
            })

      })

    },


    /** 关闭处理 */
    handleClose() {
      this.$emit("handleClose");
      //this.visible = false;
      //setTimeout(() => {
      //  this.$emit('update:dialogVisible', false)
      //}, 300);
    }
  },


}
</script>

<style>

</style>
