<template>
  <div class="exp-form">
    <van-collapse v-model="activeNames">
      <van-collapse-item title="基础信息" name="1">
        <van-field v-model="form.pricNo" label="定价编号" readonly />
        <van-field v-model="form.addName" label="录入人" readonly />
        <van-field v-model="form.addTime" label="录入时间" readonly />
        <van-field v-model="form.remark" label="备注" readonly />
      </van-collapse-item>
      <van-collapse-item title="行信息" name="2">
        <div v-for="(item,index) in tableDataMx" style="color: #323233">
          <div class="padd" style="display: flex;justify-content: space-between;">
            <span>物料名称：{{ item.itemNm }}</span>
            <span>物料编码：{{ item.itemCd }}</span>
          </div>
          <div class="padd" style="display: flex;justify-content: space-between;">
            <span>现汇价格：{{ item.priceCash }}</span>
            <span>承兑价格：{{ item.priceBill }}</span>
          </div>
          <div class="padd">
            <span>开始执行时间：{{ item.startDt }}</span>
          </div>
          <div class="padd">
            <span>规格(品位)%：{{ item.transTasteSci }}</span>
          </div>

          <van-divider />
        </div>

      </van-collapse-item>
      <van-collapse-item title="文件信息" name="3">
        <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'
import { showToast, showDialog, showLoadingToast, showSuccessToast, closeToast } from 'vant'
const { proxy } = getCurrentInstance();
const route = useRoute()
import {
  useWorkflowStore
} from '@/stores/workflow';

import { AddressList, PickerGroup, Button ,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/UpriceHead/queryByWorkId';
  var param = {
    id: workflow.workId
  };

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

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

const getTableLine = (id) => {
  var url = 'sal/UpriceLine/queryAll';
  var param = {
    params: JSON.stringify({ id: id })
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      tableDataMx.value = response.data.data.records;
    } else {
      showFailToast('操作失败！' + response.data.msg);
    }
  });
};


const dictList = ref({});
const dictData = () => {
  var url = 'framework/Common/querySelectorList';
  var param = {
    type: JSON.stringify(['MEASURING_UNIT'])
  };
  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
}


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