<template>
  <div class="app-container" ref="main">
    <div ref="search">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        class="search-container"
      >
        <el-form-item prop="name">
          <el-input
            v-model="queryParams.input"
            placeholder="请输入关键字"
            clearable
          >
            <div class="search-btn" slot="append">
              <i class="el-icon-search"></i>
            </div>
          </el-input>
        </el-form-item>
      </el-form>
    </div>

    <el-table
      v-loading="loading"
      :data="tableData"
      :height="tableHeigth + 'px'"
    >
      <el-table-column
        label="序号"
        align="center"
        type="index"
        prop="id"
        width="55"
      />
      <el-table-column label="证书名称" align="center" prop="certificateId" />
      <el-table-column label="志愿者" align="center" prop="userName" />
      <el-table-column label="兑换时间" align="center" prop="createTime" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          {{ scope.row.status == 1 ? "已发放" : "未发放" }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text">查看</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleFabu(scope.row)"
            v-if="scope.row.status != 1"
            >发放</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 发布对话框 -->
    <el-dialog :visible.sync="open" width="500px" append-to-body>
      <div slot="title" class="dialog-title">
        <span class="title-line"></span>
        {{ title }}
      </div>
      <div class="info-box">
        <div>
          <div class="info-form-title">
            <span></span>
            证书信息
          </div>
          <div class="info-item">
            <div class="item-lable">证书名称:</div>
            <div class="item-value">{{ form.certificateId }}</div>
          </div>
          <div class="info-item">
            <div class="item-lable">志愿者:</div>
            <div class="item-value">{{ form.userName }}</div>
          </div>
          <div class="info-item">
            <div class="item-lable">兑换时间:</div>
            <div class="item-value">{{ form.createTime }}</div>
          </div>
          <div class="info-item">
            <div class="item-lable">状态:</div>
            <div class="item-value">
              {{ form.status == 1 ? "已发放" : "未发放" }}
            </div>
          </div>
          <div class="info-form-title">
            <span></span>
            收货信息
          </div>
          <div class="info-item">
            <div class="item-lable">姓名:</div>
            <div class="item-value"></div>
          </div>
          <div class="info-item">
            <div class="item-lable">手机号:</div>
            <div class="item-value"></div>
          </div>
          <div class="info-item">
            <div class="item-lable">详细地址:</div>
            <div class="item-value"></div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
        <el-button type="warning" @click="submitPaper">发放纸质证书</el-button>
        <el-button type="primary" @click="submitElectron"
          >发放电子证书</el-button
        >
      </div>
    </el-dialog>
    <!-- 纸质证书 -->
    <el-dialog :visible.sync="infoOpen" width="500px" append-to-body>
      <div slot="title" class="dialog-title">
        <span class="title-line"></span>
        邮政信息
      </div>
      <!-- <Editor v-model="form.content" :min-height="192" /> -->
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="快递公司" prop="name">
          <el-input v-model="form.name" placeholder="请输入快递公司" />
        </el-form-item>
        <el-form-item label="快递单号" prop="serviceDuration">
          <el-input
            v-model="form.serviceDuration"
            placeholder="请输入快递公司"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">提 交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { dsbrecordsList } from "@/api/volunteer/gxhzs/hdzsff/index.js";
export default {
  data() {
    return {
      infoOpen: false,
      form: {},
      rules: {},
      open: false,
      title: "",
      tableHeigth: 0,
      queryParams: {},
      loading: false,
      tableData: [],
      total: 1,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
      },
    };
  },
  created() {
    // //给表格一个固定值
    this.$nextTick(() => {
      this.tableHeigth =
        this.$refs.main.offsetHeight - this.$refs.search.offsetHeight - 80;
      this.getList();
    });
  },
  methods: {
    /**纸质提交 */
    submitForm() {
      editData(this.form).then((res) => {
        this.submitElectron();
      });
    },
    /**纸质 */
    submitPaper() {
      this.infoOpen = true;
    },
    /**电子 */
    submitElectron() {
      let data = {
        activityId: this.form.activityId,
        uid: this.form.uid,
      };
      postElectron(data).then((res) => {
        this.infoOpen = false;
        this.open = false;
        this.$modal.msgSuccess("发放成功");
        this.getList();
      });
    },
    /**关闭 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /**重置 */
    reset() {
      this.form = {
        id: null,
        activityId: null,
        certificateId: null,
        uId: null,
        content: null,
        createId: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        userId: null,
        deptId: null,
        type: null,
      };
    },
    /** 查询发放记录列表 */
    getList() {
      this.loading = true;
      dsbrecordsList(this.queryParams).then((response) => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    handleFabu(row) {
      this.title = "发放查看";
      this.open = true;
      // this.reset();
      // let id = row.id;
      // getInfo(id).then((res) => {
      //   this.form = res.data;
      //   this.title = "发放查看";
      //   this.open = true;
      // });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/styles/myTable.scss";
.info-form-title {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  font-size: 17px;
  font-family: "Alibaba-PuHuiTi-Regular";
  font-weight: 500;
  color: #333;
  font-weight: bold;
  span {
    width: 5px;
    height: 17px;
    margin-right: 6px;
    background: #f8414d;
  }
}
</style>
