<style scoped>
.user-panel {
  margin: 10px auto;
}
</style>
<template>
  <el-dialog
    :visible.sync="showDialog"
    :title="title"
    :modal-append-to-body="false"
    style="text-align: left"
    @close="closeDialog"
    :close-on-click-modal="false"
    width="1200px"
  >
    <div class="user-panel" v-loading="loading">
        <el-table
        :data="tableData"
        style="min-height:400px;"
        v-loading="loading"
        stripe
      >
            <el-table-column
            prop="num"
            label="流水号"
            ></el-table-column>
            <el-table-column
            prop="regUserName"
            label="爱心人士"
            ></el-table-column>
            <el-table-column
            prop="aspirationsName"
            label="交换礼物"
            ></el-table-column>
            <el-table-column
            prop="studentName"
            label="学生姓名"
            ></el-table-column>
            <el-table-column  prop="isSpot"  label="是否现场互换心愿">
                <template slot-scope="{row}">
                    <span v-if="row.isSpot">是</span>
                    <span v-else>否</span>
            </template>
            </el-table-column>
            <el-table-column  prop="status"  label="互换状态">
                <template slot-scope="{row}">
                    <span v-if="row.status=='0'">互换中</span>
                    <span v-else-if="row.status=='1'" style="color:#67C23A">已完成</span>
            </template>
            </el-table-column>
            <el-table-column
            prop="deliveryTime"
            label="发货时间"
            ></el-table-column>
            <el-table-column
            prop="completionTime"
            label="完成时间"
            ></el-table-column>
        </el-table>
        <el-pagination
            style="text-align:center"
            :current-page.sync="pageIndex"
            :total="totalElements"
            :page-sizes="pageSizeList"
            @current-change="changePage"
            @size-change="pageSizeChange"
            layout="total, sizes, prev, pager, next, jumper"
        ></el-pagination>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import Constant from "@/constant";
import wishInfoUserRecordApi from "@/api/base/wishInfoUserRecord";
import dataDictionaryApi from "@/api/sys/dataDictionary";

export default {
  props: ["businessKey", "title"],
  data() {
    return {
        showDialog: true,
        loading: false,
        submitting: false,
        typeList:[],
        tableData:[],
        pageIndex: 1,
        pageSize: 10,
        totalPages: 0,
        totalElements: 0,
        field: "",
        direction: "",
        pageSizeList: [10, 20, 30],
        multipleSelection: [],
    };
  },
  created() {
  },
  methods: {
    closeDialog() {
      this.$emit("close", false);
    },
    changePage(pageIndex) {
        var self = this;
  
        console.log(pageIndex);
  
        self.pageIndex = pageIndex;
        var formData = new FormData();
  
        formData.append("pageIndex", self.pageIndex);
        formData.append("pageSize", self.pageSize);

        formData.append("wishInfoId", self.businessKey);
        formData.append("status", "1");
  
        self.loading = true;
  
        wishInfoUserRecordApi.pageList(formData).then(function(response) {
          self.loading = false;
  
          var jsonData = response.data;
  
          if(jsonData.result){
            var pageInfo = jsonData.data;
  
            self.tableData = pageInfo.data;
            self.totalPages = pageInfo.totalPages;
            self.totalElements = pageInfo.recordsTotal;
          }
          else {
            self.$message({
                message: jsonData.message + "",
                type: "warning"
              });
          }
        }).catch((error)=>{
          self.loading = false;
        });
      },
      pageSizeChange(pageSize) {
        this.pageSize = pageSize;
      },
      sortChange(data) {
        this.field = data.column.field;
        this.direction = data.order == "ascending" ? "asc" : "desc";
  
        this.changePage(this.pageIndex);
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
  },
  async mounted() {
    var self = this;
    self.changePage(1);
  },
  components: {
    // "el-select-tree": SelectTree
  },
};
</script>