<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="功能点">
        <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="18">
          <el-input v-model="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="submitClick('ruleForm')" :loading="ui.submitLoading">修改</el-button>
    </div>
  </el-dialog>
</template>

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

  export default {
    name: 'UpdateUserServiceDialog',
    props: {
      dialogVisible: {
        type: Boolean,
        required: true
      },
      pointCode: {
        type: String
      },
      title: {
        type: String
      },
      questionDescribe: {
        type: String
      },
      solve: {
        type: String
      },
      number: {
        type: String
      },
     
    },

    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('请输入解决方式'));
        }
      };
      var validatenumber = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('id不能为空'));
        }
      };
      return {
        ui: {
          submitLoading: false
        },
        visible: this.$props.dialogVisible,
        operat: [],
        ruleForm: {
          pointCode: '',
          title: '',
          questionDescribe:'',
          solve:'',
          creator:'',
          number:''
        },
        rules: {
          pointCode: [
            { validator: validatepointFeatures, trigger: 'blur' }
          ],
          title: [
            { validator: validateqtitle, trigger: 'blur' }
          ],
          questionDescribe: [
            { validator: validateqdescription, trigger: 'blur' }
          ],
           solve: [
            { validator: validatesolve, trigger: 'blur' }
          ],
          number: [
            { validator: validatenumber, trigger: 'blur' }
          ],
         
        },
      }
    },
    created() {
      //console.log(this)
      this.ruleForm = {
        dialogVisible: this.dialogVisible,
        pointCode: this.pointCode,
        title: this.title,
        questionDescribe: this.questionDescribe,
        solve: this.solve,
        number: this.number,
      }
    },
    methods: {
      /** 提交点击 */
      async submitClick(formName) {
            this.$$post('/customer/editCustomerQa', {
              dialogVisible: this.ruleForm.dialogVisible,
              number: this.ruleForm.number,
              pointCode: this.ruleForm.pointCode,
              title: this.ruleForm.title,
              solve: this.ruleForm.solve,
              questionDescribe: this.ruleForm.questionDescribe,
            })
              .then(res => {
                if (res.data.code < 1) {
                  this.$message.error(res.data.msg);
                  return
                }
                this.$message({message: '修改成功', type: 'success'});
                setTimeout(function () {
                  this.visible = false;
                  window.location.reload();
                }, 500)

              })
              .catch(err => {
                alert("error!")
              })
      },
        /** 加载QA */
      loadOperate() {
        this.$$get('/customer/selectPointList')
          .then(res => {
            console.log(565464564)
            console.log(res.data)
            console.log(565464564)
            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))
      },

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