<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>

      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
        <van-swipe-cell v-for="(item,index) in applicationList" :key="index">
          <van-cell center :to="{name:'collectionDetail', query: {id:item.id}}">
            <template #icon>
              <van-icon name="../../../../../static/images/onlineHome/icon_yn9.png" size="30" color="#539FFD" style="margin-right: 10px;" />
            </template>
            <template #label>
              <p>{{item.payeeAccount}}</p>
            </template>
            <template #title>
              <p class="van-ellipsis">{{item.payee}}</p>
            </template>
            <template #default>
              <p>{{item.accountType}}</p>
              <p style="font-size: 12px;font-weight: normal;color: #878787;">{{item.bankType}}</p>
            </template>
          </van-cell>
          <template #right>
            <van-row>
              <van-col>
                <van-button square text="修改" type="info" :to="{name:'collectionModify', 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 { listPayee , delPayee } from "@/api/onlineHome/bankAgriculture/collectionAccount";
export default {
  name: "collectionList",
  data() {
    return {
      applicationList:[],
      loading: false,
      finished: false,
      queryParams:{
        pageNum:1,
        pageSize:10,
      }
    };
  },
  created() {
    this.getDicts("bank_type").then(response => {
      this.bankTypeOptions = response.data;
    });
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("bank_account_type").then(response => {
      this.accountTypeOptions = response.data;
    });
    this.getDicts("payee_type").then(response => {
      this.payeeTypeOptions = response.data;
    });
  },
  methods: {
    goAdd(){
      window.location = 'collectionAdd';
    },
    getList(){
      setTimeout(() => {
        listPayee(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].bankType = this.selectDictLabel(this.bankTypeOptions, response.rows[i].bankType);

            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)
        delPayee(id).then(res => {
          if(res.code = 200){
            this.$toast.success('删除成功');
          }
        });
      })
      .catch(() => {
        // on cancel
      });
    }
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    padding: 0.2rem 3%;
  }
  /deep/.van-cell__title{
    flex: 0.7;
    width: 70%;
  }
  /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{
    color: #333333;
    font-size: 14Px;
  }
  /deep/.van-cell__value{
    flex: 0.3;
    color: #1D6FE9;
    font-weight: bold;
  }
  /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>
