<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-form-item label="团队名称" label-width="70px">
          <el-input
            v-model="queryParams.teamName"
            placeholder="请输入团队名称"
            clearable
            style="width: 140px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="变动类型">
          <el-select
            v-model="queryParams.type"
            placeholder="变动类型"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in dict.type.accountDetails_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table ref="tables" v-loading="loading" :data="dataList" border>
        <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
        <el-table-column label="团队名称" align="center" prop="teamName" />
        <el-table-column label="变动类型" align="center" prop="type">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.accountDetails_type" :value="scope.row.type"/>
          </template>
        </el-table-column>
        <el-table-column label="变动金额(元)" align="center" prop="num" />
        <el-table-column label="操作描述" align="center" prop="remark" />
        <el-table-column label="变动凭证" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.voucherUrl" style="cursor: pointer;color: #1890ff;" @click="openShowViewer(scope.row)">查看</span>
            <span v-else>无</span>
          </template>
        </el-table-column>
        <el-table-column label="操作人" align="center" prop="updateBy" />
        <el-table-column label="账号余额" align="center" prop="total" />
        <el-table-column label="变动时间" align="center" prop="createTime" width="160" />
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <el-image-viewer :on-close="clearShowViewer" v-if="showViewer" :url-list="previewList" />
    </div>
  </template>
  
  <script>
  
  import { pageList } from '@/api/team/accountDetails'
  // 导入组件
  import ElImageViewer from 'element-ui/packages/image/src/image-viewer'

  export default {
    name: "agreement",
    dicts: ['accountDetails_type'],
    components: { ElImageViewer },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户表格数据
        dataList: null,
        // 弹出层标题
        title: "",
  
        // 是否显示弹出层
        open: false,
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          type: undefined
        },
        statusList: [
          {id: 1, name: '未发布', value: 0},
          {id: 2, name: '发布', value: 1},
          {id: 3, name: '下架', value: 2},
        ],
        visibleStatus: false,
        newObj: {},
        visibleType: '',
        showViewer: false,
        previewList: [],
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询列表 */
      getList() {
        this.loading = true;
        pageList(this.addDateRange({
          ...this.queryParams,
          balanceType: 1,
        }, this.dateRange))
        .then(response => {
            this.dataList = response.data.rows;
            this.dataList.forEach(item =>{
              item.switchValue = item.status;
            })
            this.total = response.data.total;
            this.loading = false;
          }
        );
      },
      // 取消按钮
      cancel() {
        this.open = false;
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.$set(this.queryParams, 'teamName', '');
        this.$set(this.queryParams, 'type', '');
        this.queryParams.pageNum = 1;
        this.handleQuery();
      },
      openShowViewer(row) {
        if(row.voucherUrl) {
          this.previewList = row.voucherUrl.split(',')
          console.log("this.previewList",this.previewList)
        }else {
          this.previewList = []
        }
        this.showViewer = true
      },
      clearShowViewer() {
        console.log("关闭")
        this.showViewer = false
      }
    }
  };
  </script>
  