From 1f478b4b033d518f6de21f931d828d2a175b2a3e Mon Sep 17 00:00:00 2001
From: wzp <2880584989@qq.com>
Date: 星期二, 08 三月 2022 13:40:51 +0800
Subject: [PATCH] 最新版本,修复bug

---
 assetMgtH5/pages/assets/scrapped.vue |  283 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 279 insertions(+), 4 deletions(-)

diff --git a/assetMgtH5/pages/assets/scrapped.vue b/assetMgtH5/pages/assets/scrapped.vue
index 6ddd6fc..7acfe21 100644
--- a/assetMgtH5/pages/assets/scrapped.vue
+++ b/assetMgtH5/pages/assets/scrapped.vue
@@ -1,4 +1,3 @@
-<!-- 璧勪骇鎶ュ簾 -->
 <template>
 	<view>
 		<view class="">
@@ -7,6 +6,41 @@
 			    <block slot="content">璧勪骇鎶ュ簾</block>
 			</cu-custom>
 		</view>
+		
+		<view class="contentBox">
+			<u--form labelPosition="left">
+				<u-form-item label="璧勪骇鍚嶇О:" labelWidth="80"  borderBottom>
+					<u--input v-model="model1.devInfo.name" border="none"></u--input>
+				</u-form-item>
+				
+				<u-form-item label="璧勪骇缂栧彿:" labelWidth="80"  borderBottom >
+					<u--input v-model="model1.devInfo.serialNumber" border="none"></u--input>
+				</u-form-item>
+				
+			</u--form>
+			
+			<view class="margin-top">
+				<view>鎷嶇収涓婁紶</view>
+				<u-upload
+				    :fileList="fileList"
+				    @afterRead="afterRead"
+				    @delete="deletePic"
+				    multiple
+				    :maxCount="3"
+				></u-upload>
+			</view>
+			
+			<view class="margin-top">
+				鎶ュ簾鍘熷洜(蹇呭~)
+				<u--textarea v-model="reason" placeholder="璇疯緭鍏ュ唴瀹�" ></u--textarea>
+			</view>
+			
+			<view class="flex margin-top btnBox">
+				<u-button type="primary" size="small" class="btn" @click="submit" text="鎶ュ簾鐢宠"></u-button>
+				
+			</view>
+		</view>
+		<u-toast ref="uToast"></u-toast>
 	</view>
 </template>
 
@@ -14,15 +48,256 @@
 	export default {
 		data() {
 			return {
-				
+				fileList:[],
+				listMediaId:[],
+				number:"",
+				model1: {
+					devInfo: {
+						id:'',
+						name: '',
+						serialNumber:"",
+						brand:'',//鍝佺墝
+						type:'',//绫诲瀷
+						category:'',//绫诲埆
+						quantity:0
+					},
+				},
+				templateId:'',//妯℃澘ID
+				reason:'',//鎶ヤ慨鎻忚堪
+				approvalAssetsId:'',//闈炲繀浼� 鎴戠殑璧勪骇鎶ヤ慨銆佹姤搴熴�佸綊杩樻椂濉啓  瀹℃壒璧勪骇ID
+				productCode: "" //闈炲繀浼� 鎶ヤ慨鎶ュ簾鏃� 濉啓
 			}
 		},
+		onLoad(options) {
+			this.number= options.number;
+			this.getAssetsData();
+			this.initTemplateData();
+		},
 		methods: {
+			submit() {
+				this.isDisabled = true;
+				if (this.reason.length <= 0) {
+					this.isDisabled = false;
+					this.$refs.uToast.show({
+						type: 'error',
+						message: "璇峰~鍐欐姤淇弿杩�"
+					});
+					return;
+				}
+				if(this.fileList.length<=0){
+					this.isDisabled = false;
+					this.$refs.uToast.show({
+						type: 'error',
+						message: "璇锋媿鐓т笂浼犲浘鐗囷紒"
+					});
+					return;
+				}
+		
+				this.submitApply();
+			},
 			
+			submitApply() {
+				let assets = [];
+				assets.push({
+					"id": this.model1.devInfo.id,
+					"name": this.model1.devInfo.name,
+					"serialNumber": this.model1.devInfo.serialNumber,
+					"quantity": this.model1.devInfo.quantity
+				})
+			
+				// console.log(assets);
+				let data = {
+					"assets": assets,
+					"templateId": this.templateId,
+					"reason": this.reason
+				}
+			
+				this.$http.post('/assets/approval/submit', data)
+					.then(res => {
+						// debugger;
+						if (res.data.code === 0) {
+							console.log("鎴愬姛浜�");
+							this.reason="";
+							this.$refs.uToast.show({
+								type: 'success',
+								message: "鎻愪氦鎴愬姛"
+							});
+						} else {
+							this.$refs.uToast.show({
+								type: 'error',
+								message: res.data.msg
+							});
+						}
+						this.isDisabled = false;
+			
+					}).catch(err => {
+						this.isDisabled = false;
+						console.log(err.data)
+					})
+			},
+			
+			getAssetsData(){
+				this.$http.get('/assets/approval/assetDeatail',{params:{serialNumber:this.number}})
+					.then(res => {
+						// debugger;
+						if (res.data.code === 0) {
+							let data = res.data.data;
+							this.model1.devInfo.name=data.name;
+							this.model1.devInfo.serialNumber =data.serialNumber;
+							this.model1.devInfo.brand= data.brand;
+							this.model1.devInfo.type =data.typeName;
+							this.model1.devInfo.category = data.categoryName;
+							this.model1.devInfo.quantity =data.quantity;
+							this.model1.devInfo.id =data.id;
+							
+							if(data["approvalAssets"])
+							{
+								this.approvalAssetsId=data.approvalAssets.id;
+							}
+							if(data["product"])
+							{
+								this.productCode=data.product.productCode;
+							}
+						}
+					}).catch(err => {
+						console.log(err)
+					})
+			},
+			
+			
+			// 鍒犻櫎鍥剧墖
+			deletePic(event) {
+				this[`fileList`].splice(event.index, 1);
+				this.listMediaId.splice(event.index,1);
+				console.log(this.listMediaId.length)
+			},
+			
+			// 鏂板鍥剧墖
+			async afterRead(event) {
+				console.log(event)
+				// 褰撹缃� mutiple 涓� true 鏃�, file 涓烘暟缁勬牸寮忥紝鍚﹀垯涓哄璞℃牸寮�
+				let lists = [].concat(event.file)
+				let fileListLen = this[`fileList`].length
+				lists.map((item) => {
+					this[`fileList`].push({
+						...item,
+						status: 'uploading',
+						message: '涓婁紶涓�'
+					})
+				})
+				for (let i = 0; i < lists.length; i++) {
+					// const result = await this.uploadFilePromise(lists[i].url)
+					const result = await this.uploadFile(lists[i].url)
+					let item = this[`fileList`][fileListLen]
+					this[`fileList`].splice(fileListLen, 1, Object.assign(item, {
+						status: 'success',
+						message: '',
+						url: result
+					}))
+					fileListLen++
+				}
+			},
+			
+			//浣滃簾鍜�
+			uploadFilePromise(url) {
+				return new Promise((resolve, reject) => {
+					let a = uni.uploadFile({
+						url: '', // 浠呬负绀轰緥锛岄潪鐪熷疄鐨勬帴鍙e湴鍧�
+						filePath: url,
+						name: 'file',
+						formData: {
+							user: 'test'
+						},
+						success: (res) => {
+							setTimeout(() => {
+								resolve(res.data.data)
+							}, 1000)
+						}
+					});
+				})
+			},
+			
+			//涓婁紶鏂囦欢
+			async uploadFile(url){
+				this.$http.upload('/assets/approval/upload', {
+				    params: {}, /* 浼氬姞鍦╱rl涓� */
+				    // #ifdef APP-PLUS || H5
+				    files: [], // 闇�瑕佷笂浼犵殑鏂囦欢鍒楄〃銆備娇鐢� files 鏃讹紝filePath 鍜� name 涓嶇敓鏁堛�侫pp銆丠5锛� 2.6.15+锛�
+				    // #endif
+				    // #ifdef MP-ALIPAY
+				    fileType: 'image', // 浠呮敮浠樺疂灏忕▼搴忥紝涓斿繀濉��
+				    // #endif
+				    filePath: url, // 瑕佷笂浼犳枃浠惰祫婧愮殑璺緞銆�
+				    // 娉細濡傛灉灞�閮╟ustom涓庡叏灞�custom鏈夊悓鍚嶅睘鎬э紝鍒欏悗闈㈢殑灞炴�т細瑕嗙洊鍓嶉潰鐨勫睘鎬э紝鐩稿綋浜嶰bject.assign(鍏ㄥ眬锛屽眬閮�)
+				    custom: {auth: true}, // 鍙互鍔犱竴浜涜嚜瀹氫箟鍙傛暟锛屽湪鎷︽埅鍣ㄧ瓑鍦版柟浣跨敤銆傛瘮濡傝繖閲屾垜鍔犱簡涓�涓猘uth锛屽彲鍦ㄦ嫤鎴櫒閲屾嬁鍒帮紝濡傛灉true灏变紶token
+				    name: 'file', // 鏂囦欢瀵瑰簲鐨� key , 寮�鍙戣�呭湪鏈嶅姟鍣ㄧ閫氳繃杩欎釜 key 鍙互鑾峰彇鍒版枃浠朵簩杩涘埗鍐呭
+				    // #ifdef H5 || APP-PLUS
+				    timeout: 60000, // H5(HBuilderX 2.9.9+)銆丄PP(HBuilderX 2.9.9+)
+				    // #endif
+				    header: {},  /* 浼氫笌鍏ㄥ眬header鍚堝苟锛屽鏈夊悓鍚嶅睘鎬э紝灞�閮ㄨ鐩栧叏灞� */
+				    formData: {}, // HTTP 璇锋眰涓叾浠栭澶栫殑 form data
+				    // 杩斿洖褰撳墠璇锋眰鐨則ask, options銆傝鍕垮湪姝ゅ淇敼options銆傞潪蹇呭~
+				    getTask: (task, options) => {
+				      // task.Update((res) => {
+				      //   console.log('涓婁紶杩涘害' + res.progress);
+				      //   console.log('宸茬粡涓婁紶鐨勬暟鎹暱搴�' + res.totalBytesSent);
+				      //   console.log('棰勬湡闇�瑕佷笂浼犵殑鏁版嵁鎬婚暱搴�' + res.totalBytesExpectedToSend);
+				      //
+				      //   // 娴嬭瘯鏉′欢锛屽彇娑堜笂浼犱换鍔°��
+				      //   if (res.progress > 50) {
+				      //     uploadTask.abort();
+				      //   }
+				      // });
+				    }
+				  }).then(res => {
+					  // debugger;
+				    // 杩斿洖鐨剅es.data 宸茬粡杩涜JSON.parse
+					if(res.data.code===0){
+						console.log("mediaid="+res.data.data.media_id);
+						this.listMediaId.push(res.data.data.media_id);
+					}
+				  }).catch(err => {
+				
+				  })
+			},
+			
+			//鑾峰彇鎶ュ簾鐨勬ā鏉�
+			initTemplateData() {
+				this.$http.get('/assets/approval/getTemplate')
+					.then(res => {
+						// debugger;
+			
+						if (res.data.code === 0) {
+							let data = res.data.data;
+							//鑾峰彇棰嗙敤鐨勬ā鏉縄D
+							for (let i = 0; i < data.length; i++) {
+								if (data[i].type === 5) {
+									this.templateId = data[i].templateId;
+									break;
+								}
+							}
+							console.log('妯℃澘ID=' + this.templateId)
+						}
+			
+			
+					}).catch(err => {
+			
+						console.log(err.data)
+					})
+			},
 		}
 	}
 </script>
 
-<style>
-
+<style lang="scss">
+.contentBox {
+		padding: 15px 15px 40px 15px;
+	}
+	
+	.btnBox{
+		padding: 20px 0 0 0;
+		.btn{
+			width: 25%;
+		}
+	}
 </style>

--
Gitblit v1.9.1