<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
	<member-base :show="false"><view class="div distributor-bank-list">
		<view class="div common-header-wrap">
			<view :style="'height:'+navHeight+'px'"></view>
			<view class="common-header-holder"></view>
			<view class="common-header-fixed">
			<title-header />
			<uni-nav-bar title="提现账户" class="common-header" left-icon="back" @clickLeft="goBack">
			</uni-nav-bar>
		</view>
		</view>
		<view class="div pb-30" v-if="bank_list.length>0">
			<view class="div mb-5" v-for="(item,index) in bank_list" :key="index">
				<view class="div container" v-if="item.memberbank_id > 0">
					<view class="div top-wrapper">
						<view class="div title-wrapper">
							<label class="title">{{ item.memberbank_name }}</label>
							<label class="title">{{ item.memberbank_truename }}</label>
						</view>
						<label class="desc bank-text">{{memberbankTypeText(item.memberbank_type)}}&nbsp;{{item.memberbank_no}}</label>
						<view class="div bottom-line"></view>
					</view>
					<view class="div bottom-wrapper">
						<view class="div bottom-right-wrapper">
							<view class="div edit-wrapper" @click="onEdit(item.memberbank_id)">
								<view class="div common-btn btn-2 mr-5">编辑</view>
							</view>
							<view class="div edit-wrapper delete-wrapper" @click="onDelete(item.memberbank_id)">
								<view class="div common-btn btn-1">删除</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="div"  v-else>
			<empty-record></empty-record>
		</view>
		<view class='common-add-btn-wrapper'><view class="div common-btn common-add-btn"  @click="goAdd">新增</view></view>
	</view>
<uni-popup background-color="#fff" ref="confirm" type="dialog">
    <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content" :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
</uni-popup>
</member-base>
</template>

<script>
import {getFontSize} from '@/util/common'

import TitleHeader from '../../TitleHeader'

import { urlencode } from '@/util/common'

import MemberBase from '../MemberBase'
import EmptyRecord from '../../EmptyRecord'
import { getBankList, delBank } from '../../../api/memberBank'
export default {
  components:{
    TitleHeader,
    MemberBase,
    EmptyRecord
  },
  name:'MemberBankList',
  mounted(){
  // #ifdef  MP-WEIXIN
  this.navHeight = uni.getMenuButtonBoundingClientRect().top
  // #endif
  },
  data(){
    return {
      navHeight: 0,
      dialog:{},
      bank_list: []
    }
  },
  computed:{
    fontSize(){
      return getFontSize()
    },
    memberbankTypeText () {
      return function (memberbankType) {
        if (memberbankType === 'bank') {
          return '银行'
        } else if (memberbankType === 'alipay') {
          return '支付宝'
        } else {
          return '账户类型错误'
        }
      }
    }
  },
  onShow: function () {
    this.getBankList()
  },
  methods:{
    closeDialog(){
    },
    confirmDialog(value){
        uni.showLoading({ title: '加载中' })
        delBank(this.dialog.data).then(
          (response) => {
            this.getBankList()
            uni.hideLoading()
          }, (error) => {
            uni.hideLoading()
            uni.showToast({icon:'none',title: error.message})
          })
    },
    goBack () {
      uni.navigateBack({delta:1})
    },
    goAdd () {
      uni.navigateTo({ url: '/pages/member/bank/BankForm'+'?'+urlencode( { action: 'add' } )})
    },
    onEdit (memberbankId) {
      uni.navigateTo({ url: '/pages/member/bank/BankForm'+'?'+urlencode( { memberbank_id: memberbankId } )})
    },
    onDelete (memberbankId) {
      this.dialog={content:'确定要删除该提现账户吗？',data:memberbankId}
      this.$refs.confirm.open()

    },
    getBankList () {
      getBankList().then(res => {
        this.bank_list = res.result.bank_list
      }).catch(function (error) {
        uni.showToast({icon:'none',title: error.message})
      })
    }
  }
}
</script>
<style  lang="scss" scoped>
	.distributor-bank-list {
		.common-header{
			.btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
		}
		.container {
			display: flex;
			flex-direction: column;
			justify-content: flex-start;
			align-items: stretch;
			background-color: #fff;
		}
		.btn-1{border:1px solid $primaryColor;color:$primaryColor;min-width: 2rem}
		.btn-2{border:1px solid #333;color:#333;min-width: 2rem}
		.top-wrapper {
			position: relative;
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: flex-start;
			align-items: stretch;
		}
		.title-wrapper {
			height:1rem;
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: center;
			margin-top:0.5rem;
			margin-left:0.5rem;
		}
		.title {
			font-size:$h3;
			color: #333;
			font-weight: 700;
			margin-left:0.5rem;
		}
		.default {
			width:1.4rem;
			margin-left:0.5rem;
			margin-right:0.5rem;
			border: 1px solid $primaryColor;
			color: $primaryColor;
			font-size:$h6;
			text-align: center;
			border-radius:0.1rem;
		}
		.desc {
			color:$descTextColor;
			font-size:$subFontSize;
		}
		.bank-text {
			margin-top:0.5rem;
			margin-bottom:0.5rem;
			margin-left:1rem;
			margin-right:0.5rem;
		}
		.bottom-line {
			position: absolute;
			left:0.5rem;
			bottom: 0;
			right:0.5rem;
			border-bottom:1px dashed #eee
		}
		.bottom-wrapper {
			height:2.5rem;
			display: flex;
			flex-direction: row;
			justify-content: space-around;
			align-items: stretch;
		}
		.bottom-right-wrapper {
			flex: 1;
			display: flex;
			flex-direction: row;
			justify-content: flex-end;
			align-items: stretch;
		}
		.edit-wrapper {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: center;
		}
		.delete-wrapper {
			margin-right:0.5rem;
		}
		.indicator {
			width:1rem;
			height:1rem;
			margin-left:0.75rem;
			margin-right:0.5rem;
			font-size:$subFontSize;
		}
		.icon {
			width:0.9rem;
			height:0.9rem;
			margin-left:0.5rem;
		}
		.subtitle {
			font-size:$subFontSize;
			color: #7c7f88;
			margin-top:0.5rem;
			margin-bottom:0.5rem;
			margin-left: 1rem;
			margin-right:0.5rem;
		}
		.subtitle .i{font-size:$h2;margin-right:.5rem;}
	}

</style>
