
<template>
  <div class="index">
    <!-- <el-form ref="searchFrom" :model="searchFrom" label-width="80px" inline>
          <el-form-item label="用户ID">
            <el-input v-model="searchFrom.user_id" 
                     ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" plain  @click="initPage">
              搜索
            </el-button>
          </el-form-item>
    </el-form> -->
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="nickname"
        label="用户">
      </el-table-column>
      <el-table-column
        prop="mobile"
        label="手机号">
      </el-table-column>
       <el-table-column
        prop="integral"
        label="积分">
      </el-table-column>
      <el-table-column
        prop="desc"
        label="备注">
      </el-table-column>
      <el-table-column
        label="操作"
        min-width="150"
        v-if="!$store.state.readonly">
        <template slot-scope="scope">
          <el-button
            @click="editComment(scope.row.id, scope.row.integral)"
            type="text"
            plain
            size="mini">
            修改积分
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <page :total="total" :limit="limit" @pageChange="onPageChange" @sizeChange="onSizeChange"/>
    <!-- 修改积分 -->
    <el-dialog
      title="修改积分"
      center
      append-to-body
      :visible.sync="showCommentDialog"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      width="600px">
      <div>
        <el-form ref="commentFrom" :model="commentForm" inline>
             <el-form-item label="积分">
              <el-input-number v-model="commentForm.integral" :min="0"></el-input-number>
            </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
            <el-button @click="showCommentDialog = false">取 消</el-button>
            <el-button type="primary" @click="saveComment(commentForm.integral)">确 定</el-button>
          </span>
    </el-dialog>
  </div>
</template>

<script>
  import page from '../framework/page'
  import {} from "../../service/api";
  export default {
    name: "index",
    components:{
      page
    },
    data(){
      return {
        total:0,
        nowPage:1,
        limit: 10,
        searchFrom: {
          source:''
        },
        tableData:[1,2],
        commentForm: {
            integral:0,
        },
        showCommentDialog: false
      }
    },
    created(){
      this.initPage()
    },
    methods:{
      initPage(){
        let json = {
          limit: this.limit,
          page: this.nowPage
        }
        // if (this.searchFrom.user_id) {
        //   json.user_id = this.searchFrom.user_id
        // }
        // getAdsInnerListApi(json).then((res)=>{
        //   this.tableData = res.list;
        //   this.total = res.total
        // })

      },
      onPageChange(val){
        this.nowPage = val
        this.initPage()
      },
      onSizeChange(val){
        this.nowPage = 1
        this.limit = val
        this.initPage()
      },
      saveComment(data){
             this.$confirm('确定修改?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(()=>{
                let json={
                    integral:data,
                }
            //   Api(id).then(res=>{
                this.$message({
                  type: 'success',
                  message: '修改成功'
                });
                this.showCommentDialog = false;
                this.initPage();
              });
            // });
      },
      editComment(id, integral) {
        this.showCommentDialog = true;
        this.commentForm = {
          id: id,
          integral: integral
        };
      },
    }
  }
</script>

<style scoped lang="less">
  .index {
    padding: 20px 0;
  }
</style>
