<template>
  <div class="mod-config">
    <!-- <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item >
        <el-input v-model="dataForm.key" placeholder="参数名" clearable>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>    -->
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column type="selection" header-align="center" align="center" width="50">
      </el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" label="操作时间">
      </el-table-column>
      <el-table-column prop="userName" header-align="center" align="center" label="用户">
      </el-table-column>
      <el-table-column prop="orderType" header-align="center" align="center" label="充值 支付 赠送优惠券.....">
      </el-table-column>
      <el-table-column prop="changeAmount" header-align="center" align="center" label="变动金额">
        <template slot-scope="scope">
          <span v-if="scope.row.changeAmount > 0" style="color: red;">{{scope.row.changeAmount}}</span>
          <span v-if="scope.row.changeAmount < 0" style="color: #54a966;">{{scope.row.changeAmount}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="relationId"
        header-align="center"
        align="center"
        label="关联id">
      </el-table-column> -->
      <el-table-column prop="remark" header-align="center" align="center" label="备注">
      </el-table-column>
      <el-table-column prop="userBalance" header-align="center" align="center" label="余额">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">明细</el-button>
          <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row.transactionId)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <el-dialog title="充/扣天医币明细" :close-on-click-modal="false" :visible.sync="memoryDetail" append-to-body width="30%">
      <el-form :model="mdetail" label-width="100px" ref="pointForm">

        <el-form-item label="充/扣主题：">
          <!-- <el-input v-model="pointForm.remark"></el-input> -->
          <span>{{mdetail.remark}}</span>
        </el-form-item>
        <el-form-item label="操作时间：">
          <!-- <el-input v-model="pointForm.remark"></el-input> -->
          <span>{{mdetail.createTime}}</span>
        </el-form-item>
        <el-form-item label="充值类型：">
          <el-tag type="danger" v-if="mdetail.changeAmount > 0">充值天医币</el-tag>
          <el-tag type="success" v-else>扣除天医币</el-tag>
        </el-form-item>
        <el-form-item label="金额：">
          <!-- <el-input-number v-model="mdetail.pointAmount" :placeholder="mdetail.peanutCoin+'可用'">
  </el-input-number>           -->
          <span>{{mdetail.changeAmount}}</span>
        </el-form-item>

        <el-form-item label="充扣明细：">
          <span>{{mdetail.note}}</span>
          <!-- <el-input type="textarea" rows="5" v-model="mdetail.note" placeholder="操作说明">
  </el-input> -->
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDia">关 闭</el-button>
        <!-- <el-button type="primary" @click="huaSheng">确 定</el-button> -->
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    memoryUsage
  } from 'process';

  export default {
    data() {
      return {
        dataForm: {
          key: ''
        },
        memoryDetail: false,
        headers: [{
            prop: 'remark',
            label: '充/扣主题',
          },
          {
            prop: 'createTime',
            label: '操作时间',
          },
          {
            prop: 'changeAmount',
            label: '充值类型',
          },
          {
            prop: 'changeAmount',
            label: '充值类型',
          },
        ],
        query: {
          id: 0,
          tel: ''
        },
        mdetail: {}, //
        dataListLoading: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,


      }
    },
    created() {
      // this.getDataList()
    },
    activated() {
      this.query.id = this.$route.query.id;
      this.query.tel = this.$route.query.tel;
      // console.log(this.$route.query.orderId)
      this.getDataList()
    },

    methods: {
      closeDia() {
        this.memoryDetail = false
        this.mdetail = {}
      },
      huaSheng() {
        this.$http({
          url: this.$http.adornUrl(`/book/user/pointChange?&note=${this.mdetail.note}&id=${this.mdetail.id}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.$message.success('操作成功')
            this.getDataList()
            this.closeDia()
          }
        })
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true

        this.$http({
          url: this.$http.adornUrl('/book/transactiondetails/getTransactionList'),
          method: "POST", // POST、GET、PUT、DELETE，具体说明查看官方文档
          data: {
            'page': 1,
            'limit': 200,
            'userId': this.query.id
          },
          header: { //默认 无 说明：请求头
            'Content-Type': 'application/json'
          },
        }).then(res => {
            if (res.data.code === 0) {
              this.dataList = res.data.page.records
              this.totalPage = res.data.page.total
              this.dataListLoading = false
            }
        })

        // this.$http({
        //   url: this.$http.adornUrl('/book/transactiondetails/getTransactionList'),
        //   method: 'post',
        //   params: this.$http.adornParams({
        //     'page': 1,
        //     'limit': 200,
        //     'userId': this.query.id
        //   })
        // }).then(({
        //   data
        // }) => {
        //   if (data && data.code === 0) {
        //     this.dataList = data.page.list
        //     this.totalPage = data.page.totalCount
        //     this.dataListLoading = false
        //   }
        // })
      },
      // 新增 / 修改
      addOrUpdateHandle(row) {
        this.memoryDetail = true
        this.mdetail = row
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },

    }

  }
</script>
<style lang="less" scoped>
  /deep/ .el-form-item {
    margin-bottom: 1px solid #eee;
    margin-bottom: 10px;
  }
</style>
