

<template>
  <el-dialog class="client-data-dialog" title="QA新增" :visible.sync="visible" :before-close="handleClose">
    <el-form :model="ruleForm"  :rules="rules" ref="ruleForm"  label-width="80px" class="demo-ruleForm">
    <el-form-item label="功能点" prop="pointCode">
        <el-select v-model="ruleForm.pointCode" label="功能点" placeholder="请选择" style="width:80%">
            <el-option
            v-for="item in operat"
            :key="item.code"
            :label="item.name"
            :value="item.code">
            </el-option>
        </el-select>
    </el-form-item >
     <el-form-item label="问题标题" prop="title">
        <el-col :span="20"><el-input v-model.number="ruleForm.title"></el-input></el-col>
      </el-form-item>  

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

      <el-form-item label="解决方式" prop="solve">
         <el-input
        type="textarea"
        :rows="2"
        placeholder="请输入内容"
        v-model="ruleForm.solve" style="width:60%">
        </el-input>
      </el-form-item>
    </el-form>

    <div slot="footer">
      <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
      },
    },
    data() {
      /*请选择功能点*/
      var validatepointFeatures = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择功能点'));
        }
      };
      /*请输入问题标题*/
      var validateqtitle = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入问题标题'));
        }
      };
      /*请输入问题描述*/
      var validateqdescription = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入问题描述'));
        }
      };
     
      var validatesolve = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入解决方式'));
        }
      };
      return {
        ui: {
          submitLoading: false
        },
        visible: this.$props.dialogVisible,

        ruleForm: {
          pointCode: '',
          title: '',
          questionDescribe:'',
          solve:'',
          creator:'',
        },
        rules: {
          pointCode: [
            { validator: validatepointFeatures, trigger: 'blur' }
          ],
          title: [
            { validator: validateqtitle, trigger: 'blur' }
          ],
          questionDescribe: [
            { validator: validateqdescription, trigger: 'blur' }
          ],
           solve: [
            { validator: validatesolve, trigger: 'blur' }
          ],
         
        },
        options: [{
            value: 'FOLLOWEDUP',
            label: '待跟进'
            },  {
            value: 'FOLLOWEDING',
            label: '跟进中'
          }, {
            value: 'FINISHED',
            label: '已解决'
          }],
        operat: [],
        }
    },
    methods: {
      /** 提交点击 */
      submitForm(formName) {


            if(!this.ruleForm.pointCode && !this.ruleForm.questionDescribe && !this.ruleForm.solve && !this.ruleForm.title){
               this.$message.error("参数不能为空");
            }
        
            this.$$post('/customer/addCustomerQa', {
              creator :  localStorage.getItem("loginName") ,
              pointCode:this.ruleForm.pointCode,
              questionDescribe:this.ruleForm.questionDescribe,
              solve:this.ruleForm.solve,
              title:this.ruleForm.title,
            })
              .then(res => {
                console.log(res.data)
                if (res.data.code < 1) {
                  this.$message.error(res.data.msg);
                  return
                }
                this.$message({message: '新增成功', type: 'success'});
                this.handleClose();
                window.location.reload();
              })
              .catch(err => {
                alert("error!")
              })
      },

      /** 关闭处理 */
      handleClose() {
        this.visible = false;
        setTimeout(() => {
          this.$emit('update:dialogVisible', false)
        }, 300);
      },
       /** 加载QA */
      loadOperate() {
        this.$$get('/customer/selectPointList')
          .then(res => {
            console.log(res.data)
            if (res.data.code == 1){
              this.operat = res.data.data;
            }else{
              this.$message({message: res.data.msg, type: 'error'});
            }
          })
          .catch(err => this.$$msg.err(err))
      },
    },
    mounted: function () {
      this.loadOperate();
    },
  }
</script>
