<template>
    <div class="app-container">
<!--      <van-nav-bar-->
<!--        left-arrow-->
<!--        fixed-->
<!--        placeholder-->
<!--        @click-left="$router.back(-1)"-->
<!--        @click-right="goAdd()"-->
<!--      >-->
<!--        <template #title>-->
<!--          <p style="font-weight: bold;">银农付款账户列表</p>-->
<!--        </template>-->
<!--        <template #right>-->
<!--          <van-icon name="add" size="18"/>-->
<!--        </template>-->
<!--      </van-nav-bar>-->

      <div class="header_main">
        银农付款账户列表
        <div class="return_btn" @click="onClickLeft"></div>
        <div class="add_btn" @click="goAdd"></div>
      </div>

      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
        <van-swipe-cell v-for="(item,index) in applicationList" :key="index">
<!--          :to="{name:'paymentAccountDetail', query: {id:item.id,type:'modify'}}"-->
          <van-cell :title="item.accountType" center >
            <template #icon>
              <van-icon name="../../../../../static/images/onlineHome/icon_yn10.png" size="30" color="#539FFD" style="margin-right: 10px;" />
            </template>
            <template #label>
              <p><span><i>￥</i>{{item.balance}}</span></p>
            </template>
            <template #default>
              <p style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 1;word-break: break-all;overflow: hidden;">{{item.bankAccountNumber == null || item.bankAccountNumber == '' ? '&nbsp;':item.bankAccountNumber}}</p>
              <p style="font-size: 12px;font-weight: normal;color: #878787;display: flex;justify-content: space-between;">
                <span style="width: 60%;text-align:left;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 1;word-break: break-all;overflow: hidden;">{{item.accountName}}</span>
                <span :style="{color: item.status == '否' ? '#1D6FE9' : '#FF4646'}">{{item.status == '否' ? '未' : '已'}}停用</span>
              </p>
            </template>
          </van-cell>
          <template #right>
            <van-row>
              <van-col>
                <van-button square text="修改" type="info" :to="{name:'sunVillagePaymentAccountModify', query: {id:item.id}}" class="delete-button" />
              </van-col>
              <van-col>
                <van-button square text="删除" type="danger" @click="deleteList(item.id,index)" class="delete-button" />
              </van-col>
            </van-row>
          </template>
        </van-swipe-cell>
      </van-list>
    </div>
</template>

<script>
import { getList , delAccount } from "@/api/onlineHome/bankAgriculture/paymentAccount";
export default {
  name: "paymentAccountList",
  data() {
    return {
      applicationList:[],
      houseApplyStatus:[],
      // 账户类型 字典字典
      accountTypeOptions: [],
      // 是否停用 字典 sys_yes_no字典
      statusOptions: [],
      // 查询类型字典
      selectTypeOptions: [],
      // 来往账标识字典
      directionOptions: [],
      loading: false,
      finished: false,
      queryParams:{
        pageNum: 1,
        pageSize: 10,
      },
      statusColor:'#1D6FE9'
    };
  },
  created() {
    this.getDicts("account_type_cashier").then((response) => {
      this.accountTypeOptions = response.data;
    });
    this.getDicts("sys_yes_no").then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts("select_type").then((response) => {
      this.selectTypeOptions = response.data;
    });
    this.getDicts("direction").then(response => {
      this.directionOptions = response.data;
    });
  },
  methods: {
    goAdd(){
      window.location = 'paymentAccountAdd';
    },
    getList(){
      setTimeout(() => {
        getList(this.queryParams).then(response => {
          console.log(response)
          for (var i = 0; i < response.rows.length; i++) {
            response.rows[i].accountType = this.selectDictLabel(this.accountTypeOptions, response.rows[i].accountType);
            response.rows[i].status = this.selectDictLabel(this.statusOptions, response.rows[i].status);
            this.applicationList.push(response.rows[i]);
          }
          if(this.applicationList.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.queryParams.pageNum += 1 ;
          }
        });
      }, 1000);
    },
    deleteList(id,index){
      this.$dialog.confirm({
        message: '您确认删除账户信息？',
      })
      .then(() => {
        // on confirm
        this.applicationList.splice(index,1)
        delAccount(id).then(res => {
          if(res.code = 200){
            this.$toast.success('删除成功');
          }
        });
      })
      .catch(() => {
        // on cancel
      });
    }
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    .header_main{
      height: 116px;
      background: url('../../../../assets/images/sunVillage_info/list_head.png') no-repeat;
      background-size: 100% 100%;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      font-size: 36px;
      line-height: 116px;
      text-align: center;
      color: #fff;
      position: relative;
      .return_btn{
        width: 24px;
        height: 43.2px;
        background: url('../../../../assets/images/sunVillage_info/list_icon_5.png') center center no-repeat;
        background-size: 20px 36px;
        position: absolute;
        left: 38px;
        top: 36px;
      }
      .add_btn{
        width: 56.4px;
        height: 40.8px;
        background: url('../../../../assets/images/sunVillage_info/list_icon_9.png') center center no-repeat;
        background-size: 47px 34px;
        position: absolute;
        right: 38px;
        top: 36px;
      }
    }
  }
  /deep/.van-list{
    padding: 0.2rem 3%;
  }
  /deep/.van-cell__title{
    flex: 0.4;
  }
  /deep/.van-cell__title span{
    font-family: Arial;
    font-size: 0.4rem;
    font-weight: normal;

  }
  /deep/.van-cell__label span{
    color: #1D6FE9;
    font-weight: bold;
    i{
      font-size: 0.2rem;
    }
  }
  .van-cell__label{
    font-size: 14Px;
    font-weight: bold;
  }
  /deep/.van-cell__value{
    flex: 0.6;
    color: #333333;
  }
  /deep/.van-swipe-cell{
    margin-bottom: 0.2rem;
    border-radius: 0.2rem;
    overflow: hidden;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
  }
  /deep/van-ellipsis{
    font-weight: bold;
  }
  .van-row{
    height: 100%;
  }
  .van-col{
    height: 100%;
  }
  .delete-button {
    height: 100%;
  }
</style>
