/**
* @Author: lizheng
*
*/

<template>
  <div id="system-registration">
    <br>

    <div class="top">
      <el-form :inline="true" :model="queryModel" class="demo-form-inline">
        <div class="btn">
          <el-button  @click="addUser" type="primary"><i
            class="el-icon-plus"></i>新增QA
          </el-button>
        </div>
      </el-form>
    </div>

    <!--用户信息列表-->
    <div>
      <div class="system-list">
        <el-table :data="records" stripe style="width: 100%">
          <!-- <el-table-column type="index" prop="id" width="60"></el-table-column> -->
          <el-table-column prop="id" sortable label="编号"></el-table-column>
          <el-table-column prop="pointName" sortable label="功能点"></el-table-column>
          <el-table-column prop="title" sortable label="问题标题"></el-table-column>
          <el-table-column prop="questionDescribe"  sortable label="问题描述"></el-table-column>
          <el-table-column prop="solve" sortable label="解决方式" ></el-table-column>
          <el-table-column label="操作">
            <template scope="scope">
              <el-button type="text" size="small" 
                         @click="updateUsers(scope.row)">编辑
              </el-button>
              <el-button type="text" size="small"  @click="deleteQuestion(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="page">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page.sync="page.current"
          :page-size="page.size"
          layout="prev, pager, next"
          :total="page.total">
        </el-pagination>
      </div>

    </div>

    <!--窗口组件-->
    <template>
      <!--新增窗口-->
      <addUserServiceDialog
        v-if="ui.addUserServiceDialog.visible"
        :dialogVisible.sync="ui.addUserServiceDialog.visible">
      </addUserServiceDialog>
    </template>


    <!--窗口组件-->
    <template>
      <!--修改窗口-->
      <updateUserServiceDialog
        v-if="ui.updateUserServiceDialog.visible"
        :pointCode="ui.updateUserServiceDialog.pointCode"
        :title="ui.updateUserServiceDialog.title"
        :number="ui.updateUserServiceDialog.number"
        :questionDescribe="ui.updateUserServiceDialog.questionDescribe"
        :solve="ui.updateUserServiceDialog.solve"
        :creator="ui.updateUserServiceDialog.creator"
        :dialogVisible.sync="ui.updateUserServiceDialog.visible">
      </updateUserServiceDialog>
    </template>


  </div>
</template>


<script>
  import * as moment from "moment";
  import addUserServiceDialog from "../user/addUserServiceDialog";
  import updateUserServiceDialog from "../user/UpdateUserServiceDialog";

  export default {
    name: "UserManagement",
    components: {
      addUserServiceDialog,
      updateUserServiceDialog,
    },
    data() {
      return {
        queryModel: {
          type: Object
        },
        search: "",
        records: [],
        page: {
          current: 1,
          size: 10,
          total: 0
        },
        record: "",
        ui: {
          addUserServiceDialog: {
            visible: false
          },
          updateUserServiceDialog: {
            visible: false,
            pointCode: '',
            title: '',
            questionDescribe:'',
            solve:'',
            creator:'',
            number:''
          },
         
        },
      }
    },


    mounted: function () {
      this.loadSearchData();
    },

    methods: {
      addUser() {
        this.ui.addUserServiceDialog = {
          visible: true,
        };
      },

      querySearchUser() {
        this.loadSearchData();
      },

      /** 加载搜索数据 */
      loadSearchData() {
        var url = '';
      
        url = `/customer/getCustomerQa/${this.page.current}`

         this.$$post('/customer/getCustomerQa', {
            current :this.page.current,
          })
            .then(res => {
              console.log(res.data)
              if (res.data.code < 1) {
                this.$message.error(res.data.msg);
                return
              }
              this.records = res.data.data;
              this.page.total = res.data.data.total
            })
            .catch(err => {
              alert("error!")
          })
      },
      /*重置密码*/
      resetPassword(record) {
        this.$$post('/user/resetPassword', {
          loginName: record.loginName,
          bindStatus: 'ENABLED'
        })
          .then(res => {
            if (res.data.code < 1) {
              this.$message.error(res.data.msg);
              return
            }
            this.$message({message: '重置成功', type: 'success'});
            this.loadSearchData();
          })
          .catch(err => {
            this.showErrorAlert(err)
          })
      },

      /*修改用户*/
      updateUsers(record) {
        this.ui.updateUserServiceDialog = {
          visible: true,
          pointCode: record.pointCode,
          title: record.title,
          questionDescribe: record.questionDescribe,
          solve: record.solve,
          creator: record.creator,
          number: record.number
        };
      },

      /*删除问题*/
      deleteQuestion(record) {
         this.commonGet(`/customer/removeCustomerQa/?number=` + record.number)
      },
      /** 处理分页操作*/
      handleCurrentChange() {
        this.loadSearchData();
      },

      statusFormat: function (row, column) {
        var status = row['status'];
        return this.$enumUtils.toMsg('UserStatusEnum', status);
      },
      commonGet(url) {
          this.$$get(url)
              .then(res => {
                  if (res.data.code < 1)
                      throw res.data.msg;
                  this.$message({message: '删除成功', type: 'success'});
                  this.loadSearchData()
              })
              .catch(err => this.$$msg.err(err))
      },

      dateFormat: function (row, column) {
        var date = row[column.property];
        if (date == undefined) {
          return "";
        }
        return moment(date).format("YYYY-MM-DD HH:mm:ss");
      }
    }
  }

</script>

