<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width=“110px“ >
      <el-form-item label="发起方用户编号" prop="sponsorUsercode">
        <el-input
            v-model="queryParams.sponsorUsercode"
            placeholder="请输入发起方用户编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发起方用户昵称" prop="sponsorNickname">
        <el-input
            v-model="queryParams.sponsorNickname"
            placeholder="请输入发起方用户昵称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发起方用户手机" prop="sponsorMobile">
        <el-input
            v-model="queryParams.sponsorMobile"
            placeholder="请输入发起方用户手机"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="接收方用户编号" prop="receiveUsercode">
        <el-input
            v-model="queryParams.receiveUsercode"
            placeholder="请输入接收方用户编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="接收方用户昵称" prop="receiveNickname">
        <el-input
            v-model="queryParams.receiveNickname"
            placeholder="请输入接收方用户昵称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="接收方用户手机" prop="receiveMobile">
        <el-input
            v-model="queryParams.receiveMobile"
            placeholder="请输入接收方用户手机"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" clearable size="small">
          <el-option
              v-for="dict in wxTransDataStatusList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
              @keyup.enter.native="handleQuery"
          />
        </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-table v-loading="loading" :data="wxTransDataList" @selection-change="handleSelectionChange">
      <el-table-column label="状态" align="center" prop="status" >
        <template v-slot="scope">
          <cai-dict-tag :options="wxTransDataStatusList" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="发起方" align="center" prop="sponsor">
        <el-table-column label="用户编号" align="center" prop="sponsorUsercode" />
        <el-table-column label="昵称" align="center" prop="sponsorNickname" />
        <el-table-column label="手机号" align="center" prop="sponsorMobile" />
        <el-table-column label="头像" align="center" prop="sponsorAvatar" >
          <template v-slot="scope">
            <image-avatar :src="scope.row.sponsorAvatar"/>
          </template>
        </el-table-column>
        <el-table-column label="微信号" align="center" prop="sponsorWx" />
      </el-table-column>
      <el-table-column label="接受方" align="center" prop="receive">
        <el-table-column label="用户编号" align="center" prop="receiveUsercode" />
        <el-table-column label="昵称" align="center" prop="receiveNickname" />
        <el-table-column label="手机号" align="center" prop="receiveMobile" />
        <el-table-column label="头像" align="center" prop="receiveAvatar" >
          <template v-slot="scope">
            <image-avatar :src="scope.row.receiveAvatar"/>
          </template>
        </el-table-column>
        <el-table-column label="微信号" align="center" prop="receiveWx" />
      </el-table-column>
      <el-table-column label="后台操作" align="center" prop="isAdmin" >
        <template v-slot="scope">
          <cai-dict-tag :options="yesOrNoList" :value="scope.row.isAdmin"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.status === 0"
            @click="handleAllow(scope.row)"
            v-hasPermi="['xq:wxTransData:edit']"
          >接受</el-button>
          <el-button
              size="mini"
              type="text"
              v-if="scope.row.status === 0"
              @click="handleNotAllow(scope.row)"
              v-hasPermi="['xq:wxTransData:edit']"
          >拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { allowWxTransData, listWxTransData, notAllowWxTransData } from '@/api/xq/wxTransData'
import { wxTransDataStatusList, yesOrNoList } from '@/constant/statusMap'

export default {
  name: "WxTransData",
  data() {
    return {
      yesOrNoList,wxTransDataStatusList,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 微信交换数据表格数据
      wxTransDataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sponsorUsercode: undefined,
        sponsorNickname: undefined,
        sponsorMobile: undefined,
        receiveUsercode: undefined,
        receiveNickname: undefined,
        receiveMobile: undefined,
        status: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询微信交换数据列表 */
    getList() {
      this.loading = true;
      listWxTransData(this.queryParams).then(response => {
        this.wxTransDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleAllow(row){
      this.$modal.confirm('是否要帮助用户"' + row.receiveNickname + '"的接受微信邀请项？').then(() => {
        this.loading = true;
        return allowWxTransData({"id":row.id});
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("接受成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    handleNotAllow(row){
      this.$modal.confirm('是否要帮助用户"' + row.receiveNickname + '"的拒绝微信邀请项？').then(() => {
        this.loading = true;
        return notAllowWxTransData({"id":row.id});
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("拒绝成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    }
  }
};
</script>
