<!--
 * @Descripttion: 财务管理 - 在线支付明细
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="main">
      <el-form
        ref="select"
        :model="select"
        style="background-color: #fff"
        label-width="100px"
      >
        <el-row>
          <!-- 一层 -->
          <el-col :span="4">
            <el-form-item :label="'会员编号'">
              <el-input
                v-model="select.memberCode"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员姓名'">
              <el-input
                v-model="select.memberName"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'交易金额'">
              <el-input
                v-model="select.businessMoney"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'交易类型'">
              <el-select
                v-model="select.businessType"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in tradeTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'支付渠道'">
              <el-select
                v-model="select.payChannel"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in channelList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'支付方式'">
              <el-select
                v-model="select.payType"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in peyTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'支付状态'">
              <el-select
                v-model="select.payStatus"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in statusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'单据编号'">
              <el-input
                v-model="select.businessCode"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'下单日期'">
              <el-date-picker
                v-model="select.creationTime"
                value-format="yyyy-MM-dd"
                type="daterange"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'支付日期'">
              <el-date-picker
                v-model="select.payTime"
                value-format="yyyy-MM-dd"
                type="daterange"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                @change="changeTime1"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button
              class="my_search"
              style="margin-left: 30px"
              @click="getDataList"
            > {{ '搜索' }}</el-button>
            <el-button class="my_reset" @click="reset"> {{ '重置' }}</el-button>
          </el-col>
        </el-row>
      </el-form>
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            v-has-buttons="['OnlinePayDetailsExport']"
            size="small"
            class="thebtn2"
            @click="handleExport"
          > {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          height="640px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            width="55"
          />
          <el-table-column
            align="center"
            prop="memberCode"
            :label="'会员编号'"
            width="150"
          />
          <el-table-column
            align="center"
            prop="memberName"
            :label="'会员姓名'"
          />
          <el-table-column
            align="center"
            prop="businessTypeVal"
            :label="'交易类型'"
          />
          <el-table-column
            align="center"
            prop="businessMoney"
            :formatter="stateFormat"
            :label="'交易金额'+`(${isLocalSymbol()})`"
            width="150"
          />
          <el-table-column
            align="center"
            prop="payMoney"
            :formatter="stateFormat"
            label="实际支付金额(¥)"
            width="150"
          />
          <!-- <el-table-column align="center"
                           prop="payMoney"
                           :formatter="stateFormat"
                            :label="'交易金额'+`(${isLocals()})`" width="150">
          </el-table-column>
          <el-table-column align="center"
                           :formatter="stateFormat"
                           prop="settleTradeBalance"
                           label="实际支付金额($)" width="150">
          </el-table-column>
          <el-table-column align="center"
                           prop="exchangeRate"
                            :label="'汇率'">
          </el-table-column> -->

          <el-table-column
            align="center"
            prop="payChannelVal"
            :label="'支付渠道'"
          />
          <el-table-column
            align="center"
            prop="payTypeVal"
            :label="'支付方式'"
          />
          <el-table-column
            align="center"
            prop="payStatusVal"
            :label="'支付状态'"
          />
          <el-table-column
            align="center"
            prop="creationTime"
            :label="'下单日期'"
            width="200"
          />
          <el-table-column
            align="center"
            prop="payTime"
            :label="'支付日期'"
            width="200"
          />
          <el-table-column
            align="center"
            prop="businessCode"
            min-width="180px"
            :label="'单据编号'"
          />
          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                style="color: #ffad41"
                type="text"
                size="small"
                @click="toFixed(scope.row.pkId)"
              >
                {{ '导出' }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/financialCase.js'
import { userCountryList } from '@/api/user'

export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  filters: {
    isAgree(val) {
      if (!val) {
        return '允许'
      } else {
        return '禁止'
      }
    }
  },
  data() {
    return {
      creationTime: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      total: 0,
      dialogVisible: false,
      tableData: [],
      statusList: [],
      channelList: [],
      payTime: [],
      peyTypeList: [
        {
          value: '1',
          label: '支付宝'
        },
        {
          value: '2',
          label: '微信'
        },
        {
          value: '3',
          label: '银行卡'
        }
      ],
      tradeTypeList: [],
      moren: 'onlinePayDetails',
      topList: [
        {
          name: '在线支付明细',
          path: 'onlinePayDetails'
        }
      ],
      countryList: []
    }
  },
  mounted() {
    this.getCountry()
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
  },
  methods: {
    getData() {
      api.payChannel().then((res) => {
        this.channelList = res.data
      })
      api.payStatus().then((res) => {
        this.statusList = res.data
      })
      api.businessType().then((res) => {
        this.tradeTypeList = res.data
      })
    },
    changeTime(val) {
      // this.select.startDate = val[0]
      // this.select.endDate = val[1]
    },
    changeTime1(val) {
      // this.select.startDate = val[0]
      // this.select.endDate = val[1]
    },
    reset() {
      this.select = {}
      this.getDataList()
    },
    // 点击修改
    toFixed(id) {},
    getCountry() {
      userCountryList().then((res) => {
        this.countryList = res.data
      })
    },
    getDataList() {
      api
        .onlineList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          res.rows.forEach((item) => {
            this.countryList.forEach((child) => {
              if (item.pkCountry == child.pkCountry) {
                item.pkCountryName = child.name
                item.pkCountryIcon = child.nationalFlag2
              }
            })
          })
          this.tableData = res.rows
          this.total = res.total
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/pay/manage/online-payment/export',
          Object.assign({}, this.queryParams, this.select),
          `${'在线支付明细'}${new Date().getTime()}.xlsx`
        )
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    }
  }
}
</script>
<style scoped lang="scss">
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .maintop {
      display: flex;
      padding: 0px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
          width: 68px;
          height: 32px;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .tem {
    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
  .bgImg {
    width: 48px;
    height: 48px;
  }
}
.openClose {
  text-align: right;
  margin-right: 10px;
  color: #3181e5;
}
</style>
