<!--
 * @Author: micky
 * @Date: 2024-08-20 10:05:01
 * @LastEditors: micky
 * @LastEditTime: 2024-10-29 22:41:55
 * @FilePath: \chargingpile-uniapp\src\bundle\pages\contract\contract-view\download.vue
-->
<template>
    <view class="contract-download">
        <view class="contract-template">
            <ContractTemplate :image-list="imageList" />
        </view>
        <TFooterBtn text="下载合同" @handle-btn-click="handleDownloadContract" />
    </view>
</template>

<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app'
import ContractTemplate from '@/pages/salesman/contract/components/contract-template.vue'
import { shallowRef } from 'vue'
import contractTemplate1 from '@/static/images/contract-template1.png'
import contractTemplate2 from '@/static/images/contract-template1.png'
import contractTemplate3 from '@/static/images/contract-template1.png'

const imageList = shallowRef([
    { src: contractTemplate1 },
    { src: contractTemplate2 },
    { src: contractTemplate3 }
])
const handleDownloadContract = () => {
    uni.downloadFile({
        url: '',
        success: res => {
            if (res.statusCode === 200) {
                // 预览pdf文件
                uni.openDocument({
                    filePath: res.tempFilePath,
                    showMenu: true, // 右上角菜单，可以进行分享保存pdf
                    success: function (file) {
                        console.log('file-success', file)
                    }
                })
            }
        }
    })
}
onLoad(e => {
    uni.setNavigationBarTitle({
        title: e.name!
    })
})
</script>

<style lang="scss" scoped>
.contract-download {
    width: 100vw;
    height: 100vh;
    @include flex-direction;
    background-color: $gray-1;
    .contract-template {
        flex: 1;
        overflow-y: auto;
        padding: 20rpx 0;
    }
}
</style>
