<template>
    <div class="app-container">
      <van-nav-bar
        left-arrow
        fixed
        placeholder
        @click-left="$router.back(-1)"
      >
        <template #title>
          <p style="font-weight: bold;">银农交易明细列表</p>
        </template>
      </van-nav-bar>
      <div class="main_box">
        <!--      <van-field label="付款方" v-model="form.payer" placeholder="请输入付款方" input-align="right" label-width="auto"/>-->
        <van-field
          readonly
          clickable
          label="付款方"
          placeholder="请选择付款方"
          v-model="payer"
          @click="showpayer = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto"
          required
          :rules="[{ required: true , message:'请选择付款方' }]"
        />
        <van-popup v-model="showpayer" position="bottom">
          <van-picker
            show-toolbar
            :columns="payerOptions"
            @confirm="onConfirmPayer($event)"
            @cancel="showpayer = false"
          />
        </van-popup>
      </div>
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
        <van-swipe-cell v-for="(item,index) in applicationList" :key="index">
          <van-cell :title="item.txnamt" center  :to="{name:'recordDetailDetail', query: {id:item.id}}">
            <template #icon>
              <van-icon v-if="item.direction=='1'" name="../../../../../static/images/onlineHome/icon_yn9.png" size="30" color="#539FFD" style="margin-right: 10px;" />
              <van-icon v-if="item.direction=='2'" name="../../../../../static/images/onlineHome/icon_yn10.png" size="30" color="#539FFD" style="margin-right: 10px;" />
            </template>
            <template #label>
              <p style="font-size: 12px;font-weight: normal;color: #878787;display: flex;justify-content: space-between;">
                <span style="width: 100%;text-align:left;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 1;word-break: 
                break-all;overflow: hidden;">{{item.payeeToname}}</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.actacn}}</p>
              <p style="font-size: 12px;font-weight: normal;color: #878787;display: flex;justify-content: space-between;">
                <span style="width: 100%;text-align:right;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 1;word-break: 
                break-all;overflow: hidden;">{{item.payeeActacn}}</span>
              </p>
            </template>
          </van-cell>
        </van-swipe-cell>
      </van-list>
    </div>
</template>

<script>
import { listRecordDetail, getRecordDetail,getDianzihuidan} from "@/api/onlineHome/bankAgriculture/recordDetail";  
import { getAccount} from "@/api/onlineHome/bankAgriculture/paymentApproval";
export default {
  name: "recordDetailList",
  data() {
    return {
      applicationList:[],
      houseApplyStatus:[],
      payerOptions:[],
      // 账户类型 字典字典
      accountTypeOptions: [],
      // 是否停用 字典 sys_yes_no字典
      statusOptions: [],
      // 查询类型字典
      selectTypeOptions: [],
      // 来往账标识字典
      directionOptions: [],
      loading: false,
      finished: false,
      showpayer:false,
      payer:"",
      queryParams:{
        pageNum: 1,
        pageSize: 10,
        actacn: null,
      },
      statusColor:'#1D6FE9'
    };
  },
  created() {
    this.getAccountList();
    this.getList();
  },
  methods: {
    getList(){
      // if(this.queryParams.actacn ==null && this.payerOptions != null && this.payerOptions != [] && this.payerOptions.length>0){
      //   this.queryParams.actacn = this.payerOptions[0].bankAccountNumber;
      //   this.payer = this.payerOptions[0].accountName;
      // }
      listRecordDetail(this.queryParams).then(response => {
        for (var i = 0; i < response.rows.length; i++) {
          this.applicationList.push(response.rows[i]);
        }
        if(this.applicationList != null && this.applicationList != [] && this.applicationList.length>0){
          if(this.applicationList.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.queryParams.pageNum += 1 ;
          }
        }
      });
    },
    getAccountList(){
      let params1={
        accountType: "102",
        status: "N",
      }
      getAccount(params1).then((response) => {
        this.payerOptions = response.rows;
        response.rows.map((res,index) => {
          this.payerOptions[index].text = res.accountName;
          this.payerOptions[index].value = res.bankAccountNumber;
        })
      });
    },
    onConfirmPayer(data){
      this.showpayer = false;
      this.payer = data.text;
      this.selectChange(data.value)
    },
    selectChange(select) {
      this.applicationList = [];
      this.queryParams.actacn = select;
      listRecordDetail(this.queryParams).then(response => {
        for (var i = 0; i < response.rows.length; i++) {
          this.applicationList.push(response.rows[i]);
        }
        if(this.applicationList != null && this.applicationList != [] && this.applicationList.length>0){
          if(this.applicationList.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.queryParams.pageNum += 1 ;
          }
        }
      });
    }
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    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>
