<template>
  <div :class="'app-container'">
    <div class="filter-container">
      <el-select
        v-model="listQuery.sysOrigin"
        :placeholder="$t('pages.userBankDiamondWithdrawGoldApply.filter.system')"
        style="width: 120px"
        class="filter-item"
        @change="handleSearch"
      >
        <el-option
          v-for="item in permissionsSysOriginPlatforms"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
          <span style="float: left;">
            <sys-origin-icon :icon="item.value" :desc="item.value"
          /></span>
          <span style="float: left;margin-left:10px">{{ item.label }}</span>
        </el-option>
      </el-select>
      <div class="filter-item">
        <account-input
          v-model="listQuery.submitUserId"
          :sys-origin="listQuery.sysOrigin"
          :placeholder="$t('pages.userBankDiamondWithdrawGoldApply.filter.submitUserId')"
        />
      </div>
      <div class="filter-item">
        <account-input
          v-model="listQuery.acceptUserId"
          :sys-origin="listQuery.sysOrigin"
          :placeholder="$t('pages.userBankDiamondWithdrawGoldApply.filter.acceptUserId')"
        />
      </div>
      <el-select
        v-model="listQuery.acceptAccount"
        :placeholder="$t('pages.userBankDiamondWithdrawGoldApply.filter.acceptAccount')"
        style="width: 120px"
        class="filter-item"
        clearable
        @change="handleSearch"
      >
        <el-option :label="$t('pages.userBankDiamondWithdrawGoldApply.acceptAccount.GOLD')" :value="'GOLD'" />
        <el-option :label="$t('pages.userBankDiamondWithdrawGoldApply.acceptAccount.FREIGHT')" :value="'FREIGHT'" />
      </el-select>

      <div class="filter-item">
        <el-date-picker
          v-model="rangeDate"
          value-format="timestamp"
          type="datetimerange"
          :picker-options="pickerOptions"
          :range-separator="$t('pages.userBankDiamondWithdrawGoldApply.date.rangeSeparator')"
          :start-placeholder="$t('pages.userBankDiamondWithdrawGoldApply.date.start')"
          :end-placeholder="$t('pages.userBankDiamondWithdrawGoldApply.date.end')"
        />
      </div>
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        :disabled="searchDisabled"
        @click="handleSearch"
      >
        {{ $t('pages.userBankDiamondWithdrawGoldApply.action.search') }}
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      fit
      highlight-current-row
    >
      <el-table-column :label="$t('pages.userBankDiamondWithdrawGoldApply.table.system')" prop="sysOrigin" align="center" width="80">
        <template slot-scope="scope">
          <sys-origin-icon
            :icon="scope.row.sysOrigin"
            :desc="scope.row.sysOrigin"
          />
        </template>
      </el-table-column>
      <el-table-column :label="$t('pages.userBankDiamondWithdrawGoldApply.table.submitUser')" align="center" min-width="80">
        <template slot-scope="scope">
          <user-table-exhibit
            :user-profile="scope.row.submitUser"
            :query-details="true"
          />
        </template>
      </el-table-column>
      <el-table-column :label="$t('pages.userBankDiamondWithdrawGoldApply.table.acceptUser')" align="center" min-width="80">
        <template slot-scope="scope">
          <user-table-exhibit
            :user-profile="scope.row.acceptUser"
            :query-details="true"
          />
        </template>
      </el-table-column>
      <el-table-column
        prop="acceptAccountName"
        :label="$t('pages.userBankDiamondWithdrawGoldApply.table.acceptAccount')"
        align="center"
        width="100"
      />
      <el-table-column
        prop="amount"
        :label="$t('pages.userBankDiamondWithdrawGoldApply.table.amount')"
        align="center"
        min-width="80"
      />
      <el-table-column
        prop="exchangeRate"
        :label="$t('pages.userBankDiamondWithdrawGoldApply.table.exchangeRate')"
        align="center"
        min-width="80"
      />
      <el-table-column
        prop="goldQuantity"
        :label="$t('pages.userBankDiamondWithdrawGoldApply.table.goldQuantity')"
        align="center"
        min-width="80"
      />
      <el-table-column
        prop="createTime"
        :label="$t('pages.userBankDiamondWithdrawGoldApply.table.createTime')"
        align="center"
        width="160"
      >
        <template slot-scope="scope">
          {{ $t('pages.userBankDiamondWithdrawGoldApply.table.createDate') }}: {{ scope.row.createTime | dateFormat }}
        </template>
      </el-table-column>
    </el-table>
    <div v-if="listQuery.lastId" class="load-more">
      <span v-if="notData">{{ $t('pages.userBankDiamondWithdrawGoldApply.action.allLoaded') }}</span>
      <el-button
        v-else
        size="mini"
        :disabled="loadMoreLoading"
        :loading="loadMoreLoading"
        @click="clickLoadMore"
        >{{ $t('pages.userBankDiamondWithdrawGoldApply.action.loadMore') }}</el-button
      >
    </div>
  </div>
</template>

<script>
import { pageBankWithdrawGoldApply } from "@/api/app-user-bank-balance";
import { pickerOptions } from "@/constant/el-const";
import { mapGetters } from "vuex";
export default {
  name: "UserBankDiamondWithdrawGoldApply",
  data() {
    return {
      rangeDate: [],
      thatSelectedUserId: "",
      thatSelectedAcceptUserId: "",
      searchDisabled: false,
      pickerOptions,
      listQuery: {
        limit: 20,
        acceptUserId: "",
        submitUserId: "",
        sysOrigin: "HALAR",
        acceptAccount: "",
        lastId: "",
        startTime: "",
        endTime: "",
      amountType:"SALARY_DIAMOND"
      },
      listLoading: false,
      list: [],
      notData: false,
      loadMoreLoading: false
    };
  },
  computed: {
    ...mapGetters(["permissionsSysOriginPlatforms"])
  },
  watch: {
    rangeDate: {
      immediate: true,
      deep: true,
      handler(newVal) {
        if (newVal && newVal.length > 0) {
          this.listQuery.startTime = newVal[0];
          this.listQuery.endTime = newVal[1];
          return;
        }
        this.listQuery.startTime = "";
        this.listQuery.endTime = "";
      }
    }
  },
  created() {
    const that = this;
    const querySystem = this.permissionsSysOriginPlatforms[0];
    if (!querySystem) {
      return;
    }
    that.listQuery.sysOrigin = querySystem.value;
    that.renderData();
  },
  methods: {
    renderData(isReset) {
      const that = this;
      if (!that.listQuery.sysOrigin) {
        return;
      }
      if (isReset === true) {
        that.list = [];
        that.notData = false;
        that.listQuery.lastId = "";
      }
      that.listLoading = true;
      pageBankWithdrawGoldApply(that.listQuery)
        .then(res => {
          that.listLoading = false;
          that.loadMoreLoading = false;
          const { body } = res;
          const list = body || [];
          that.notData = list.length <= 0;
          if (!that.notData) {
            that.list = that.list.concat(list);
            that.listQuery.lastId = that.list[that.list.length - 1].id;
          }
        })
        .catch(er => {
          that.listLoading = false;
          that.loadMoreLoading = false;
        });
    },
    handleSearch() {
      this.renderData(true);
    },
    clickLoadMore() {
      const that = this;
      that.loadMoreLoading = true;
      that.renderData();
    }
  }
};
</script>
<style scoped lang="scss">
.user-css {
  display: flex;
  align-items: center;
  color: #909399;
  font-size: 0.15rem;
  line-height: 0.3rem;
  padding: 0.02rem;
  border-radius: 0.04rem;
}
.load-more {
  padding: 20px;
  text-align: center;
}
</style>
