<template>
  <div class="app-container">
    <!-- <div class="filter-container">
      <el-form
        :model="filter"
        v-bind:inline="true"
        label-position="left"
        label-width="100px"
        style="width: 100%;">
        <el-row :gutter="20">
          <el-col :span="7">
            <el-form-item
              label=""
              class="flex-item">
              <el-input
                v-model="filter.criteria"
                placeholder="Search by Provider Name/Address/Contact"
                @keyup.enter.native="handleFilter" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="handleFilter">
              Search
            </el-button>
          </el-col>
          <el-col :span="6" :offset="3" style="text-align: right;">
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-plus"
              @click="addProvider">
                Add Provider
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </div> -->
    <el-table
      v-loading="listLoading"
      :data="tableList"
      fit
      :row-class-name="({row})=>'read'+row.readStatus"
      style="width: 100%;">
      <el-table-column
        label="ID"
        align="center"
        class-name="fixed-width">
          <template slot-scope="{row}">
            <a class="link-detail" href="javascript:void(0);" @click="viewFeedback(row)">{{ row.feedbackPk }}</a>
          </template>
      </el-table-column>
      <el-table-column
        label="Type of Feedback"
        align="center"
        class-name="fixed-width">
          <template slot-scope="{row}">
            <span>{{ row.typeOfFeedback }}</span>
          </template>
      </el-table-column>
      <el-table-column
        label="Feedback"
        align="center"
        class-name="fixed-width">
          <template slot-scope="{row}">
            <span>{{ row.feedback }}</span>
          </template>
      </el-table-column>
      <el-table-column
        label="Status"
        align="center"
        class-name="fixed-width">
          <template slot-scope="{row}">
            <span :class="{readYes: row.readStatus}">{{ row.readStatus ? "Read" : "Unread" }}</span>
          </template>
      </el-table-column>
      <el-table-column
        label="Reply Count"
        align="center"
        class-name="fixed-width">
          <template slot-scope="{row}">
            <span>{{ "0" }}</span>
          </template>
      </el-table-column>
      <el-table-column
        label="Feedback Time"
        align="center"
        class-name="fixed-width">
          <template slot-scope="{row}">
            <span>{{ row.feedbackTime }}</span>
          </template>
      </el-table-column>
      <el-table-column
        label="Action"
        align="center"
        class-name="fixed-width">
          <template slot-scope="{row}">
            <TableAction
              :showEdit="false"
              @delete="deleteFeedback(row)"/>
          </template>
      </el-table-column>
    </el-table>
    <div class="right">
      <Pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.pageNo"
        :limit.sync="listQuery.pageSize"
        @pagination="handlePageChange" />
    </div>
  </div>
</template>

<script>
  import Pagination from '@/components/Pagination'
  import TableAction from '@/components/TableAction.vue'
  import feedback from '../../http/api/feedback'
  export default {
    components: { Pagination, TableAction },
    data() {
      return {
        listLoading: false,
        tableList: [],
        total: 0,
        listQuery: {
          pageNo: 1,
          pageSize: 10,
          pageVo: {
            criteria: ""
          }
        },
      }
    },
    created() {
      this.getList();
    },
    methods: {
      handleFilter() {
        this.listLoading = true;
        this.listQuery.page = 1;
        this.getList();
      },
      handlePageChange() {
        this.listLoading = true;
        this.getList();
      },
      getList() {
        feedback.getFeedbackPages(this.listQuery).then(res => {
          this.listLoading = false;
          this.total = res.total;
          this.tableList = res.data
        }).catch(err => {
          this.listLoading = false;
        })
      },
      viewFeedback(row) {
        //this.$store.commit('provider/SET_Feedback', row)
        this.$router.push({path: '/support-management/feedback/'+row.feedbackPk})
      },
      deleteFeedback(row) {
        this.$confirm('Are you sure you want to delete this feedback?', 'Delete', {
          confirmButtonText: 'OK',
          cancelButtonText: 'Cancel',
          type: 'warning'
        }).then(res => {
          this.handleDeleteFeedback(row.feedbackPk)
        })
      },
      handleDeleteFeedback(id) {
        feedback.deleteFeedback(id).then(res => {
          this.$message({
            message: 'Delete feedback successfully',
            type: 'success'
          });
          this.listLoading = true;
          this.getList();
        }).catch(err => {
          this.$message({
            message: err,
            type: 'error'
          })
        })
      }
    }
  }
</script>

<style lang="scss" scoped="scoped">
  @import '../../styles/variables.scss';
  .readYes {
    color: $panGreen;
  }
</style>