From 3539a3d350c9d5fa51871fa44a2745474c721410 Mon Sep 17 00:00:00 2001
From: yangan <yangan0921@163.com>
Date: 星期一, 02 十二月 2024 17:36:25 +0800
Subject: [PATCH] feat:电子提煤单下载

---
 api/globalApi.js                                                                 |    5 +
 api/request.js                                                                   |   54 +++++++++++++
 main.js                                                                          |    4 
 api/index.js                                                                     |    9 +
 pages/driver-page/driver-index/bill-of-lading-details/bill-of-lading-details.vue |  127 +++++++++++++++++++++++++++++++
 5 files changed, 193 insertions(+), 6 deletions(-)

diff --git a/api/globalApi.js b/api/globalApi.js
index 3d23a0c..87aed7b 100644
--- a/api/globalApi.js
+++ b/api/globalApi.js
@@ -569,6 +569,11 @@
 		url:'/wrzs/api/showQRCode',
 		method: 'GET'
 	},
+	//鐢靛瓙纾呭崟涓嬭浇
+	downLoadTm:{
+		url:'/wrzs/e-task',
+		method: 'GET'
+	}
 
 
 }
\ No newline at end of file
diff --git a/api/index.js b/api/index.js
index 55d48c4..ebcbdd2 100644
--- a/api/index.js
+++ b/api/index.js
@@ -1,4 +1,4 @@
-import { fetch } from '@/api/request.js'
+import { fetch ,fetchId} from '@/api/request.js'
 
 const typeObj = {
 	headerGET: { 'Content-type': 'application/x-www-from-urlencoded' },
@@ -33,7 +33,12 @@
 	opt.data = params
 	return fetch(url, opt)
 }
-
+export const reqGetId = (url, params, opt = {}) => {
+    opt.header = typeObj['headerGET']
+    opt.method = 'GET'
+    opt.data = params
+    return fetchId(url, opt)
+}
 // post璇锋眰
 // urlType鏄寚瀹氭嫾鎺ヨ矾寰勮繕鏄紶json鏍煎紡鍙傛暟
 export const reqPost = (url, params, urlType, opt = {}) => {
diff --git a/api/request.js b/api/request.js
index fc27ec4..bc646e6 100644
--- a/api/request.js
+++ b/api/request.js
@@ -169,6 +169,59 @@
 	})
 }
 
+const fetchId = (url, opt) => {
+    // 鏌ユ壘瀵瑰簲鍦板潃
+    let urls = (globalApi[opt.url]?.url || globalApi[url]?.url);
+    let params = opt.data ? ('/' +opt.data ):
+    '';
+    // #ifdef H5
+    opt.url = urls + params
+    // #endif
+    // #ifndef H5
+    opt.url = BaseUrl +urls + params
+    // #endif
+    opt.method = opt.method || "GET";
+    var header = {}
+    if (uni.getStorageSync('token')) {
+        header = {
+            "Authorization": "Bearer" + ' ' + uni.getStorageSync('token'),
+            "clientToc": "Y",
+            'CLIENT_TOC': 'Y',
+        }
+    }
+
+    opt.header = {
+        ...opt.header,
+        ...header
+    }
+
+    opt.data = opt.data || {};
+
+    return new Promise((resolve, reject) => {
+
+        let options = {}
+        if (opt.data) {
+            Object.keys(opt.data).map(key => {
+                if (opt.data[key] == '' || opt.data[key] == "") {
+                    opt.data[key] = null;
+                }
+            });
+        }
+
+        Object.keys(opt).map(key => {
+            if (key !== "params") {
+                return options[key] = opt[key]
+            }
+        })
+
+        uni.request(options)
+            .then(res => interceptorsRes(res, resolve, reject))
+            .catch(err => interceptorsErr(err, reject))
+    })
+}
+
+
+
 
 // 鍝嶅簲鎷︽埅
 const interceptorsRes = ([err, resp], resolve, reject) => {
@@ -194,6 +247,7 @@
 
 export {
 	fetch,
+	fetchId,
 	BaseUrl,
 	webSocketUrl
 }
diff --git a/main.js b/main.js
index e6ee9ed..48cd2e8 100644
--- a/main.js
+++ b/main.js
@@ -27,7 +27,8 @@
 	reqPost,
 	reqAllJson,
 	reqDelete,
-	reqPut
+	reqPut,
+	reqGetId
 } from '@/api/index.js'
 Vue.prototype.$reqAll = reqAll
 Vue.prototype.$reqAllJson = reqAllJson
@@ -36,6 +37,7 @@
 Vue.prototype.$reqDelete = reqDelete
 Vue.prototype.$reqPut = reqPut
 Vue.prototype.$store = store
+Vue.prototype.$reqGetId = reqGetId
 // 鐢变簬寰俊灏忕▼搴忕殑杩愯鏈哄埗闂锛岄渶澹版槑濡備笅涓�琛岋紝H5鍜孉PP闈炲繀濉�
 const app = new Vue({
 	store,
diff --git a/pages/driver-page/driver-index/bill-of-lading-details/bill-of-lading-details.vue b/pages/driver-page/driver-index/bill-of-lading-details/bill-of-lading-details.vue
index fa97382..5a89d06 100644
--- a/pages/driver-page/driver-index/bill-of-lading-details/bill-of-lading-details.vue
+++ b/pages/driver-page/driver-index/bill-of-lading-details/bill-of-lading-details.vue
@@ -219,7 +219,7 @@
 			</view>
 			<view class="weigh-button"
 				v-show="ablePrintOut">
-				<u-button text="鎵撳嵃鍑洪棬璇�"
+				<u-button :text=" isXiaBang ? '涓嬬' : '鎵撳嵃鍑洪棬璇�'"
 					@click="printBefore('out')"
 					type="primary"
 					shape="circle"
@@ -228,6 +228,11 @@
 			</view>
 			<view class="weigh-button"><u-button text="灞曠ず鎻愮叅鍗�"
 					@click="showCaolPickUpBill"
+					type="primary"
+					shape="circle"></u-button></view>
+					<!-- 鐢靛瓙纾呭崟涓嬭浇 -->
+					<view class="weigh-button"><u-button text="涓嬭浇鐢靛瓙纾呭崟"
+					@click="downloadFileFun"
 					type="primary"
 					shape="circle"></u-button></view>
 					<!-- 鏌ョ湅璺嚎鎸囧紩 -->
@@ -268,7 +273,7 @@
 				@change="radioChange"
 				>
 				<u-radio label="鐓ゅ満" :name="'鐓ゅ満'" :labelSize="30" :size="30"></u-radio>
-				<u-radio label="鍗曚綅"  :name="'鍗曚綅'":labelSize="30" :size="30"></u-radio>
+				<u-radio label="鍗曚綅"  :name="'鍗曚綅'" :labelSize="30" :size="30"></u-radio>
 			</u-radio-group>
 
             <div class="guidebox">
@@ -359,6 +364,7 @@
 				currentNum:0,
 				guideLineshow:false,
 				yyId: null,
+				isXiaBang:false, // 鍒ゆ柇鏄笉鏄┈澶存礂閫夊巶 鏄殑璇濓紝鎵撳嵃2瀛楁敼涓嬬
 				dayRZ: [],
 				activeText:'',
 				activeObj:{
@@ -602,6 +608,7 @@
 						this.originInfoForm.coalContactSkin = this.coalDetailsData.skinTwo;
 						this.originInfoForm.coalContactHair = this.coalDetailsData.hairTwo;
 						this.originInfoForm.contactPicture = this.coalDetailsData.contactPicture
+						this.isXiaBang = (this.coalDetailsData.deptId == '1765926490588897282' ? true : false);
 						if (this.coalDetailsData.contactPicture) {
 							this.fileList1 = this.coalDetailsData.contactPicture.split(',').map(v => {
 								return {
@@ -1066,8 +1073,122 @@
 					this.$refs.swiperAlbum.onPreviewTap();
 					this.$refs.swiperAlbum.openPage();
 				})
+			},
+			downloadFileFun(){
+				wx.getSetting({
+								success: (res) => {
+									//妫�鏌ユ槸鍚︽湁璁块棶鐩稿唽鐨勬潈闄愶紝濡傛灉娌℃湁鍒欓�氳繃wx.authorize鏂规硶鎺堟潈
+									if (!res.authSetting['scope.writePhotosAlbum']) {
+										console.log('娌℃湁鑾峰彇鎺堟潈');
+										wx.authorize({
+											scope: 'scope.writePhotosAlbum',
+											success: (res) => {
+												//鐢ㄦ埛鐐瑰嚮鍏佽鑾峰彇鐩稿唽淇℃伅鍚庤繘鍏ヤ笅杞戒繚瀛橀�昏緫
+												this.downloadTmFile()
+											}
+										})
 
-			}
+									} else {
+										console.log('宸茶幏鍙栨巿鏉�');
+										this.downloadTmFile()
+
+									}
+
+								}
+
+								});
+			},
+			//涓嬭浇鐢靛瓙纾呭崟
+			downloadTmFile(){
+				uni.showLoading({
+					title: '鍔犺浇涓�'
+				});
+				this.$reqGetId('downLoadTm',this.coalDetailsData.id).then(res=>{
+					console.log(res,'result')
+					this.$u.toast('涓嬭浇鎴愬姛锛�')
+					uni.hideLoading();
+					const result =    res.data.url;
+					let that = this;
+					const fileExtName = ".pdf";
+					const randfile = new Date().getTime() +res.data.fileExtName;
+					const newPath = `${wx.env.USER_DATA_PATH}/${randfile}`;
+					if(result){
+								wx.downloadFile({
+								url: `${BaseUrl}${result}`,
+								filePath:newPath,
+								header: {
+									Authorization: 'Bearer' + ' ' + uni.getStorageSync('token'),
+									CLIENT_TOC: 'Y'
+								},
+								success(res){
+									const filePath = res.tempFilePath;
+									wx.openDocument({
+									filePath: newPath,
+									showMenu: true,
+									fileType: 'pdf',
+									success: function (res) {}
+									})
+									//鍏堟鏌ョ浉鍐岃闂巿鏉冩儏鍐�
+									// try {
+									// 	setTimeout(() => {
+									// 		wx.getFileSystemManager().saveFile({
+									// 	tempFilePath:data,
+									// 	// filePath: data,
+									// 	success(res2) {
+									// 		console.log('瑙﹀彂res2save',res2)
+									// 		//鑾峰彇浜嗙浉鍐岀殑璁块棶鏉冮檺锛屼娇鐢� wx.saveImageToPhotosAlbum 灏嗗浘鐗囦繚瀛樺埌鐩稿唽涓�
+
+									// 		wx.saveImageToPhotosAlbum({
+									// 		filePath: res2.savedFilePath,
+									// 		success: (res) => {
+									// 			console.log('淇濆瓨鍒扮浉鍐�>>>>>>',res)
+									// 			//淇濆瓨鎴愬姛寮瑰嚭鎻愮ず锛屽憡鐭ヤ竴涓嬬敤鎴�
+									// 			wx.showModal({
+									// 				title: '鏂囦欢宸蹭繚瀛樺埌鎵嬫満鐩稿唽',
+									// 				content: '浣嶄簬tencent/MicroMsg/WeiXin涓� \r\n灏嗕繚瀛樼殑鏂囦欢閲嶅懡鍚嶆敼涓篬 .pdf ]鍚庣紑鍗冲彲',
+									// 				confirmColor: '#0bc183',
+									// 				confirmText: '鐭ラ亾浜�',
+									// 				showCancel: false
+									// 			})
+									// 		},
+									// 		fail(res) {
+									// 			console.log('瑙﹀彂澶辫触save',res)
+
+									// 		}
+									// 		})
+									// 	},
+									// 	fail(err){
+									// 		console.log(err,'淇濆瓨澶辫触')
+
+									// 	}
+										
+									// })
+									// 	}, 2000);
+									
+									// } catch (error) {
+									// 	console.log(error,'resoor')
+										
+									// }
+
+									
+									
+									// wx.openDocument({
+									// filePath: data,
+									// fileType: 'pdf',
+									// showMenu: true  //琛ㄧず鍙充笂瑙掓槸鍚︽湁杞彂鎸夐挳
+									// })
+									uni.hideLoading();
+
+								},
+								fail(err){
+									console.log(err,'涓嬭浇鏂囦欢澶辫触')
+								}
+					})
+							}
+
+				})
+			},
+			
 		}
 	};
 </script>

--
Gitblit v1.9.1