<template>
  <el-dialog
    title="助力记录"
    :close-on-click-modal="false"
    top="5vh"
    width="80%"
    :visible.sync="visible"
    >
    <div class="mod-print-prodAssistRecord">
      <!-- 搜索相关区域 -->
      <!--<div class="search-bar">
        <el-button class="default-btn primary-btn" @click="searchChange">{{$t('crud.searchBtn')}}</el-button>
      </div>-->
      <!-- 列表相关区域 -->
      <div class="main-container">
        <!--<div class="operation-bar">
          <div class="default-btn primary-btn" @click="addOrUpdateHandle()">{{$t("crud.addTitle")}}</div>
        </div>-->
        <div class="table-con spec-table">
          <el-table
            ref="specListTable"
            :data="dataList"
            header-cell-class-name="table-header"
            row-class-name="table-row"
            style="width: 100%">
            <!-- 助力产品 -->
            <el-table-column label="助力产品" prop="assistName" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.assistName}}</span>
              </template>
            </el-table-column>
            <!-- 助力用户 -->
            <el-table-column label="用户昵称" prop="nickName" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.nickName}}</span>
              </template>
            </el-table-column>
            <!-- 助力电量 -->
            <el-table-column label="助力电量" prop="assistPower" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.assistPower}}</span>
              </template>
            </el-table-column>
            <!-- 助力时间 -->
            <el-table-column label="助力时间" prop="createTime" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.createTime}}</span>
              </template>
            </el-table-column>
            <!-- 助力时间 -->
            <el-table-column label="通知状态" prop="notify" align="center">
              <template slot-scope="scope">
                <el-tag type="success" v-if="scope.row.notify === 1">通知成功</el-tag>
                <el-tag type="error" v-if="scope.row.notify === 2">拒绝接收</el-tag>
                <el-tag type="danger" v-if="scope.row.notify === 0">未通知</el-tag>
              </template>
            </el-table-column>
            <!--<el-table-column align="center" fixed="right" :label="$t('publics.operating')" width="auto">
              <template slot-scope="scope">
                <div class="text-btn-con">
                  <div class="default-btn text-btn" @click="addOrUpdateHandle(scope.row.assistRecordId)"
                       v-if="isAuth('print:prodAssistRecord:update')">{{$t("crud.updateBtn")}}</div>
                  <div class="default-btn text-btn" @click.stop="deleteHandle(scope.row.assistRecordId)"
                       v-if="isAuth('print:prodAssistRecord:delete')">{{$t("text.delBtn")}}</div>
                </div>
              </template>
            </el-table-column>-->
          </el-table>
        </div>
        <el-pagination
          v-if="dataList.length"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </div>
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshChange"></add-or-update>
    </div>
  </el-dialog>
</template>

<script>
import AddOrUpdate from './prodAssistRecord-add-or-update'
export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      visible: false,
      searchForm: {}, // 搜索
      dataListLoading: false,
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  created () {

  },
  mounted () {
  },
  methods: {
    init(assistId){
      this.visible = true;
      this.$nextTick(() => {
        this.searchForm.assistId = assistId;
        this.getDataList(this.page)
      })
    },
    getDataList (page) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/assist/prodAssistRecord/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign({
            current: page == null ? this.page.currentPage : page.currentPage,
            size: page == null ? this.page.pageSize : page.pageSize
          },
            this.searchForm
          )
        )
      }).then(({data}) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    deleteHandle (id) {
      this.$confirm(this.$i18n.t('admin.isDeleOper') + '?', this.$i18n.t('text.tips'), {
        confirmButtonText: this.$i18n.t('crud.filter.submitBtn'),
        cancelButtonText: this.$i18n.t('crud.filter.cancelBtn'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/assist/prodAssistRecord/' + id),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.refreshChange()
            }
          })
        })
      }).catch(() => { })
    },
    // 刷新回调
    refreshChange () {
      this.page.currentPage = 1
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.searchForm = params
      this.getDataList(this.page)
    },
    handleSizeChange (val) {
      this.page.pageSize = val
      this.getDataList()
    },
    handleCurrentChange (val) {
      this.page.currentPage = val
      this.getDataList()
    }
  }
}
</script>
<style lang="scss">
.mod-print-prodAssistRecord {
}
</style>
