<template>
  <div class="exp-form">
    <van-collapse v-model="activeNames">
      <van-collapse-item title="基础信息" name="1">
        <van-field v-model="form.prepaymentNo" label="收款编号" readonly />
        <van-field v-model="form.tradePartnerName" label="客户名称" readonly />
        <van-field v-model="form.prepaymentAmt" label="收款金额" readonly />
        <van-field v-model="form.prepaymentDt" label="收款日期" readonly />
        <van-field v-model="form.payMth" label="收款类型" readonly  :formatter="formatter"/>
        <van-field v-model="form.billNoteNo" label="承兑编号" readonly />
        <van-field v-model="form.billNoteNum" label="票据张数" readonly />
        <van-field v-model="form.remarks" label="备注" readonly />
      </van-collapse-item>
      <van-collapse-item title="文件信息" name="2">
        <div v-for="(item,index) in tableDataFile" style="color: #323233">

          <p>文件名：{{ item.fileName }}</p>

          <div class="padd" style="display: flex;justify-content: space-between;">
            <span>文件类型：{{ item.fileType }}</span>
            <van-button icon="search" type="default" size="small" plain @click="fileClick(item.id)"/>
          </div>
          <span>文件大小：{{ item.fileSize }}</span>
          <van-divider />
        </div>

      </van-collapse-item>
    </van-collapse>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, getCurrentInstance } from 'vue';
import { useRouter, useRoute } from 'vue-router'
const { proxy } = getCurrentInstance();
const route = useRoute()
import {
  useWorkflowStore
} from '@/stores/workflow';

import { AddressList, PickerGroup, Button   , showNotify ,showToast ,showFailToast   } from 'vant';

const workflow = useWorkflowStore();

onMounted(() => {
  workflow.setWorkId(route.query.workId);
  getTableData();
  dictData();
});

const activeNames = ref(['1']);

const form = ref({
  id: '',
  signReqNm: '',
  signDt: '',
  otherInformation: '',
  estProfit: null,
  ProcessInstanceSts: '',

  addDeptName: '',
  addTime: '',
  workModel: {
    flowStatusName: ''
  }
});

const getTableData = () => {
  var url = 'sal/PrepayErp/queryByWorkId';
  var param = {
    workId: workflow.workId
  };

  proxy.$axios.get(url, param).then((response: any) => {
    if (response.data.code == '0') {
      form.value = response.data.data;
      form.value.payMthStr = response.data.data.payMth
      getTableDataFile(response.data.data.id);
    } else {
      // showNotify('操作失败！' + response.data.msg);
      // showNotify({ type: 'danger', message: '操作失败！' + response.data.msg });
      showFailToast('操作失败！' + response.data.msg);
    }
  });
};

const tableDataMx = ref([]);
const tableDataFile = ref([]);



const dictList = ref({});
const dictData = () => {
  var url = 'framework/Common/querySelectorList';
  var param = {
    type: JSON.stringify(['MEASURING_UNIT' , 'COM_PAY_MTH'])
  };
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      dictList.value = response.data.data;
    } else {
      showFailToast('操作失败！' + response.data.msg);
    }
  });
};

const getTableDataFile = (fId) => {
  var url = 'framework/Common/queryFile';
  var param = {
    fId: fId
  };
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == 0) {
      tableDataFile.value = response.data.data;
    } else {
      showFailToast('操作失败！' + response.data.msg);
    }
  });
};

const fileClick = (id) =>{
  location.href = import.meta.env.VITE_BASE_API + '/framework/Common/downloadFileFtp?id=' + id
}
const formatter = () => {
  var re = ''
  if (dictList.value.COM_PAY_MTH){
    for (var i =0 ; i < dictList.value.COM_PAY_MTH.length ; i++){
      if (form.value.payMth == dictList.value.COM_PAY_MTH[i].dicCode){
        re =  dictList.value.COM_PAY_MTH[i].dicName
        form.value.payMthStr = re
        break;
      }
    }
  }
  return form.value.payMthStr
}

</script>

<style lang="scss" scoped>
.exp-form {
  background: #f7f8fa;
  padding-bottom: 20px;
}

.padd {
  padding: 3px;
}

.van-collapse-item {
  padding: 10px;
  border-radius: 45px !important;

  .van-cell--clickable {
    border-radius: 10px 10px 0 0;
  }
}

:deep .van-cell {
  border-radius: 10px 10px 0 0;
}

:deep .van-collapse-item__wrapper {
  border-radius: 0 0 10px 10px;
}

</style>
