<template>
  <div v-loading="loading">
    <div class="white-box">
      <leo-filter :filter="handleFilter" :dateRangePickerDisplay="false" :dateMonthPickerDisplay="true"></leo-filter>
      <el-table class="withdraw-table" ref="multipleTable" :data="tableData" stripe style="width: 100%;">
        <el-table-column label="会员编号">
          <template slot-scope="scope">
            {{scope.row.USER_NAME}}
          </template>
        </el-table-column>
        <el-table-column label="会员姓名">
          <template slot-scope="scope">
            {{scope.row.REAL_NAME}}
          </template>
        </el-table-column>
        <el-table-column label="提现方式">
          <template slot-scope="scope">
            {{scope.row.IS_AUTO_WITHDRAW==='1'?'自动提现':'手动提现'}}
          </template>
        </el-table-column>
        <el-table-column label="提现金额" prop="AMOUNT"></el-table-column>
        <el-table-column label="手续费" prop="FEES"></el-table-column>
        <el-table-column label="实际到账金额" prop="REAL_AMOUNT"></el-table-column>
        <el-table-column label="提现时间" width="180">
          <template slot-scope="scope">
            {{tool.formatDate(scope.row.CREATED_AT)}}
          </template>
        </el-table-column>
        <el-table-column label="提现状态" width="120">
          <template slot-scope="scope">
            <el-tag :type="tool.statusType(scope.row.AUDIT_STATUS)">{{scope.row.STATUS_NAME}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="备注" width="120">
          <template slot-scope="scope">
            <el-tag :type="tool.statusType(scope.row.REMARK)">{{scope.row.REMARK}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="提现退回备注" width="120">
          <template slot-scope="scope">
            <el-tag :type="tool.statusType(scope.row.BACK_REMARK)">{{scope.row.BACK_REMARK}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="付款时间" width="180">
          <template slot-scope="scope">
            {{tool.formatDate(scope.row.PAID_AT)}}
          </template>
        </el-table-column>
        <!--<el-table-column label="付款类型">-->
          <!--<template slot-scope="scope">-->
            <!--{{scope.row.PAY_TYPE==='1'?'见票付款':'无票付款'}}-->
          <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="发票金额">-->
          <!--<template slot-scope="scope">-->
            <!--{{scope.row.INVOICE_AMOUNT}}-->
          <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="发票状态">-->
          <!--<template slot-scope="scope">-->
            <!--{{scope.row.INVOICE_STATUS_NAME}}-->
          <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="发票信息" width="200">-->
          <!--<template slot-scope="scope">-->
            <!--<el-button type="primary" size="small" @click="handleAddInvoiceShow(scope.row)"-->
                       <!--v-if="scope.row.AUDIT_STATUS==='0'" icon="el-icon-upload">上传发票-->
            <!--</el-button>-->
            <!--<el-button type="warning" size="small" @click="handleAddInvoiceShow(scope.row)"-->
                       <!--v-if="scope.row.AUDIT_STATUS==='1'" icon="el-icon-upload">重传发票-->
            <!--</el-button>-->
            <!--<el-button type="success" size="small" @click="handleInvoiceShow(scope.row)"-->
                       <!--v-if="scope.row.AUDIT_STATUS!=='0'&&scope.row.UPLOAD_ID" icon="el-icon-view">查看发票-->
            <!--</el-button>-->
          <!--</template>-->
        <!--</el-table-column>-->
        <el-table-column label="付款失败原因" width="120">
          <template slot-scope="scope">
            {{scope.row.PAID_FAIL_REMARK}}
          </template>
        </el-table-column>
<!--        <el-table-column label="操作" width="120">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button type="primary" size="small" @click="handleReturn(scope.row)"-->
<!--                       v-if="scope.row.AUDIT_STATUS==='0'||scope.row.AUDIT_STATUS==='1'" icon="el-icon-sold-out">提现退回-->
<!--            </el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <div class="white-box-footer">
        <el-button type="primary" size="small" @click="handleAdd">我要提现</el-button>
        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
      </div>
    </div>
    <el-dialog title="上传发票" :visible.sync="dialogAddInvoiceVisible">
      <div v-loading="dialogAddInvoiceLoading">
        <el-alert type="warning" :closable="false">
          <slot name="title">
            <pre v-html="addInvoiceTips"></pre>
          </slot>
        </el-alert>

        <leo-uploader :requestRoute.sync="requestRoute" :defaultImageUrl="defaultImageUrl" width="480px" height="320px"
                      :uploaderSuccessCanChange="false" @on-success="handleSuccess"></leo-uploader>
      </div>
    </el-dialog>

    <el-dialog title="查看发票" :visible.sync="dialogInvoiceVisible">
      <div v-loading="dialogInvoiceLoading">
        <a :href="invoiceUrl" target="_blank"><img :src="invoiceUrl" alt="" style="max-width: 100%"></a>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogInvoiceVisible = false">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import Vue from 'vue'
  import network from './../../utils/network'
  import tool from '@/utils/tool'
  import store from '@/utils/vuexStore'
  import LeoFilter from '@/components/Filter'
  import LeoUploader from '@/components/Uploader'
  import Pagination from '@/components/Pagination'

  export default {
    name: 'finance_withdraw',
    components: {LeoFilter, LeoUploader,Pagination},
    mounted() {
      this.getData()
    },
    data() {
      return {
        tableData: null,
        loading: true,
        currentPage: 1,
        totalPages: 1,
        totalCount: 1,
        pageSize: 20,
        tool: tool,
        filterData: null,
        auditId: null,
        invoiceId: null,
        dialogAddInvoiceVisible: false,
        dialogAddInvoiceLoading: false,
        dialogInvoiceVisible: false,
        dialogInvoiceLoading: false,
        defaultImageUrl: null,
        addInvoiceTips: '',
        requestRoute: '',
        uploadId: null,
        invoiceUrl: '',
      }
    },
    methods: {
      handleCurrentChange(page) {
        this.getData(page, this.pageSize)
      },
      handleSizeChange(pageSize) {
        this.getData(this.currentPage, pageSize)
      },
      handleFilter(model) {
        this.filterData = model
        this.getData(1, this.pageSize)
      },
      handleAdd() {
        this.$router.push({path: `/finance/withdraw-add`})
      },
      getData(page, pageSize) {
        network.getPageData(this, 'finance/withdraw', page, pageSize, this.filterData, function (response) {

        })
      },
      handleAddInvoiceShow(row) {
        this.dialogAddInvoiceLoading = true
        this.auditId = row.ID
        this.requestRoute = 'finance/invoice-add/' + this.auditId
        this.dialogAddInvoiceVisible = true
        let vueObj = this
        network.getData('finance/invoice-before-add', {id: this.auditId}).then(response => {
          vueObj.dialogAddInvoiceLoading = false
          vueObj.addInvoiceTips = response.addInvoiceTips
        })
      },
      handleSuccess(response, file) {
        this.getData()
        this.$message({
          message: '上传发票完成，请尽快邮寄纸质发票！',
          type: 'success'
        })
        //this.form.image = imageUrl;
      },
      handleInvoiceShow(row) {
        this.dialogInvoiceLoading = true
        this.uploadId = row.UPLOAD_ID
        this.dialogInvoiceVisible = true
        let vueObj = this
        network.getData('finance/invoice-show', {id: this.uploadId}).then(response => {
          vueObj.dialogInvoiceLoading = false
          vueObj.invoiceUrl = response
        })
      },
      // handleReturn(row){
      //   this.$prompt('确定要提现退回？请填写退回备注', '提示', {
      /*    confirmButtonText: '确定',*/
      /*    cancelButtonText: '取消',*/
      /*    inputPlaceholder: '请填写退回备注',*/
      /*  }).then(({value}) => {*/
      /*    this.$message({*/
      /*      message: '正在提交',*/
      /*      type: 'info'*/
      /*    })*/
      /*    return network.postData(`finance/withdraw-back`, {*/
      //       id: row.ID,
      //       createRemark: value
      //     }).then(response => {
      //       this.$message({
      //         message: response,
      //         type: 'success'
      //       })
      //       this.getData()
      //     }).catch(() => {
      //     })
      //   }).catch((response) => {
      //   })
      // }
    }
  }
</script>

<style scoped>
  .el-button {
    margin: 3px;
  }
</style>
