<template>
  <div id="card-1">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" style="margin: 0 0 10px 0">
          <el-col :span="2"><el-button type="primary" size="mini" @click="toBack()">返回</el-button></el-col>
        </el-col>
        <el-col :span="24" class="one">
          <el-col :span="24">
            <p>
              账户余额：<span>{{ info.total }}</span>
            </p>
          </el-col>
        </el-col>
        <el-col :span="24" class="two">
          <data-table :fields="fields" @query="search" :data="list" :total="total"> </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>
<script>
const _ = require('lodash');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('shopInBill');
const { mapActions: dictData } = createNamespacedHelpers('dictData');
export default {
  name: 'card-1',
  props: {
    id: { type: String },
  },
  components: {},
  data: function () {
    return {
      // 账户余额
      info: {},
      // 账户流水
      list: [],
      // 来源列表
      sourceList: [],
      fields: [
        {
          label: '来源',
          model: 'source',
          format: (i) => {
            let data = this.sourceList.find((f) => f.value == i);
            if (data) return data.label;
            else return '暂无';
          },
        },
        { label: '净金额', model: 'receipts' },
        { label: '总金额', model: 'total' },
        { label: '抽成比例(%)', model: 'cut' },
        { label: '时间', model: 'time' },
      ],
      total: 0,
    };
  },
  async created() {
    await this.searchOther();
    await this.search();
  },
  methods: {
    ...mapActions(['query', 'fetch', 'create', 'update', 'delete', 'bill']),
    ...dictData({ dictQuery: 'query' }),
    // 查询
    async search({ skip = 0, limit = this.$limit, ...info } = {}) {
      let arr = await this.bill(this.id);
      if (this.$checkRes(arr)) {
        this.$set(this, `info`, arr.data);
      }
      let res = await this.query({ skip, limit, ...info, shop: this.id });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 返回
    toBack() {
      this.$emit('toBack');
    },
    // 查询其他信息
    async searchOther() {
      let res = await this.dictQuery({ code: 'cashBack_source' });
      if (this.$checkRes(res)) this.$set(this, `sourceList`, res.data);
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  text-align: center;
}
.one {
  margin: 0 0 10px 0;
  p {
    font-size: 24px;
    font-weight: 700;
    span {
      color: red;
    }
  }
}
.two {
  span {
    color: red;
  }
  .sp1 {
    font-size: 18px;
    font-weight: 500;
  }
}
.title {
  text-align: center;
}
.el-col {
  margin: 10px 0;
}
</style>
