<template>
  <div class="mod-user-userScoreLog">
    <avue-crud
      ref="crud"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="searchChange"
      @on-load="getDataList"
      @refresh-change="refreshChange"
    >
      <template slot-scope="scope" slot="menuLeft">
        <el-button
          v-if="isAuth('user:userScoreLog:save')"
          icon="el-icon-plus"
          type="primary"
          size="small"
          @click="addOrUpdateHandle()"
        >新增</el-button>
      </template>
      <template slot-scope="scope" slot="ioType">
        <el-tag v-if="scope.row.ioType === 0" size="small" type="info">支出</el-tag>
        <el-tag v-else size="small" type="primary">收入</el-tag>
      </template>
      <template slot-scope="scope" slot="source">
        <el-tag v-if="scope.row.source === 1" size="small" type="primary">订单</el-tag>
        <el-tag v-else-if="scope.row.source === 2" size="small" type="success">等级提升</el-tag>
        <el-tag v-else size="small" type="info">签到</el-tag>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          v-if="isAuth('user:userScoreLog:update')"
          icon="el-icon-edit"
          size="small"
          type="primary"
          @click="addOrUpdateHandle(scope.row.logId)"
        >修改</el-button>
        <el-button
          v-if="isAuth('user:userScoreLog:delete')"
          type="danger"
          icon="el-icon-delete"
          size="small"
          @click="deleteHandle(scope.row.logId)"
        >删除</el-button>
      </template>
    </avue-crud>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshChange"></add-or-update>
  </div>
</template>

<script>
import { tableOption } from '@/crud/user/userScoreLog'
import AddOrUpdate from './userScoreLog-add-or-update'
export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dataListLoading: false,
      tableOption: tableOption,
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  created () {
  },
  mounted () {
  },
  methods: {
    getDataList (page) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/user/userScoreLog/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('确定进行删除操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/user/userScoreLog/' + id),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.refreshChange()
            }
          })
        })
      }).catch(() => { })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.page = this.$refs.crud.$refs.tablePage.defaultPage
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.searchForm = params
      this.getDataList(this.page)
    }
  }
}
</script>
<style lang="scss">
.mod-user-userScoreLog {
}
</style>
