vue 今天明天后天的时间设置

356 阅读3分钟

<template>
	<div id="contents">
		<div class="top">
			<div class="top_inline" style="margin-left: 20px;padding-top: 0">
				<p>&nbsp;</p>

				<el-button type="success"  width="40%" @click="holdAll">保存</el-button>
			</div>
		</div>
		<div class="content_table">
			<div class="btn_content">
				<el-table :data="tableData"  highlight-current-row border style="width: 100%" class="el-tb-edit" @current-change="handleCurrentChange" ref="demoTable">
					<el-table-column type="index" width="50" label="序号">
					</el-table-column>
					<el-table-column
                            prop="productNumber"
                            label="商品编号"
                            :resizable="resizable"
                            align="center"
                    >
                    </el-table-column>
                    
                    <el-table-column
                            prop="barCode"
                            label="商品条形码"
                            :resizable="resizable"
                            align="center"
                    >
                    </el-table-column>
                    
                    <el-table-column
                            prop="goodName"
                            label="货名"
                            :resizable="resizable"
                            align="center"
                    >
                    </el-table-column>
                    
                    <el-table-column
                            prop="buyCount"
                            label="数量"
                            :resizable="resizable"
                            align="center"
                            width="80"
                    >
                    </el-table-column>
					<el-table-column prop="buyPrice" label="采购价(元)">
						<template slot-scope="scope">
							<el-input type="number"  v-model="scope.row.buyPrice" placeholder="请输入内容" :min="1"></el-input>
						</template>
					</el-table-column>
					
					<el-table-column prop="supplierId" label="供应商"  width="300">
						<template slot-scope="scope">
			              	<el-select  v-model="scope.row.supplierId"  @change=""  placeholder="请选择" style="width: 280px;">
				                <el-option
					      			v-for="item in houselist"
					      			:key="item.id"
					      			:label="item.supplier_name"
					      			:value="item.id">
					    		</el-option>
			             	</el-select>
				        </template>
					</el-table-column>
					
					<el-table-column prop="arrivaltime" label="到店时间">
						<template slot-scope="scope">
							<el-select  v-model="scope.row.arrayTime"  @change=""  placeholder="请选择">
				                <el-option
					      			v-for="item in timelist"
					      			:key="item.id"
					      			:label="item.name"
					      			:value="item.id">
					    		</el-option>
			             	</el-select>
						</template>
					</el-table-column>
					
				</el-table>
			</div>
			<!--{{JSON.stringify(tableData)}}-->
		</div>

		<!--//弹出的部分------------------------------------------------------------------>
		
	</div>
</template>
<script>
	import pages from '../../component/pagination/pagination'
	import FileSaver from 'file-saver'
	import XLSX from 'xlsx'
	import { API } from '../../lib/api'
	import { LINK } from '../../lib/api'
	import Qs from 'qs'
	export default {
		data() {
			return {
				houselist:[],
				tableData: [],
				currentRow: null,
				restaurants: [],
				formLabelWidth: '80px',
				showFlag: false,
				resizable: false,
				input9: '',
				value5: '',
				value1: "请选择",
				value2: '2',
				value3: '1',
				input: '',
				htmlTitle: '表格数据',
				searchValue: '',
				total: null,
				value4: '',
				excelData: [],
				value: '',
				cont:{},
				contB:{},
				contC:{},
				build:'',
				showcode:false,
				showid:1,
				timelist:[
					{
      					name: '今天',
		          		label: '今天',
		          		id:0,
			        },{
			          	name: '明天',
			          	label: '明天',
			          	id:1,
			        },{
			          	name: '后天',
			          	label: '后天',
			          	id:2,
			        }
				],
				arrivaltime:{
		          	name: '后天',
		          	label: '后天',
		          	id:2,
		        },
			}
		},
		created() {
			this.axios({
                method:'POST',
                url: `${LINK}/sku/purchase-order/supplier/query-all/do`,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
            }).then(res=>{
            	this.houselist = res.data.data;
            });
			this.databuild();
			var todaydata = this.getDay(0, '-');
			var mingdata = this.getDay(1, '-');
			var houdata = this.getDay(2, '-');
			console.log("时间")
			console.log(todaydata);
			//修改今天明天的时间的
				this.timelist.map((item) => {
            		var todaynum="";
            		var mingtian="";
            		var houtian="";
            		if(item.id ==0){
            			this.$set(item, 'Actualtime', todaydata)
            		}
            		if(item.id ==1){
            			this.$set(item, 'Actualtime', mingdata)
            		}
            		if(item.id ==2){
            			this.$set(item, 'Actualtime', houdata)
            		}
//          		this.$set(item, 'buyPrice', buyPrice)
//          		this.$set(item, 'supplier', supplier)
//          		this.$set(item, 'arrivaltime', 0)
//        			console.log(item.pushdata)
		        });
		        console.log(this.timelist)
			
			
		},
		components: {
			pages
		},
		methods: {
		 	getDay(num, str) {
			    var today = new Date();
			    var nowTime = today.getTime();
			    var ms = 24*3600*1000*num;
			    today.setTime(parseInt(nowTime + ms));
			    var oYear = today.getFullYear();
			    var oMoth = (today.getMonth() + 1).toString();
			    if (oMoth.length <= 1) oMoth = '0' + oMoth;
			    var oDay = today.getDate().toString();
			    if (oDay.length <= 1) oDay = '0' + oDay;
			    return oYear + str + oMoth + str + oDay;
			},
			databuild(){
				//传递两个参数 其中一个参数判断是不是编辑或者新增
				this.build = this.$route.query.id;
				let formData = new FormData()
    			formData.append('uuid', localStorage.getItem('uuid'))
    			formData.append('prId', this.$route.query.id)
				this.axios({
					method: 'POST',
					url: `${LINK}/sku/purchas/requisition/product/list`,
					data:formData,
					headers: {
	                	'Content-Type': 'multipart/form-data'
	            	},
				}).then( res=>{
					console.log("编辑时候得到的数据")
					console.log(res.data.data.prpsList)
					this.tableData = res.data.data.prpsList
					
					//res.data.data.prpsList.map((item) => {
            		//var buyPrice="";
            		//var supplier="";
            		//var arrivaltime="";
            		//this.$set(item, 'buyPrice', buyPrice)
            		//this.$set(item, 'supplier', supplier)
            		//this.$set(item, 'arrivaltime', 0)
//          		console.log(item.pushdata)
		        //});
//          	console.log("变更后的数据")
//          	console.log(res.data.data.prpsList)
//          	this.tableData = res.data.data.prpsList
//          	console.log("变更后得到的数据是这个样子的啊")
//          	console.log(this.tableData)
	           	})
			},
			//保存事件
			holdAll() {
				console.log("原始数据是多少")
				console.log(this.tableData)
					let setDATA =[];  //0为编辑   1为新增
	    			this.tableData.map((item)=> {
						setDATA.push({
							"prpId":item.id,
							"skuId":item.skuId,
							"buyCount":item.buyCount,
							"arrayTime":item.arrayTime,
							"supperId":item.supplierId,
							"buyPrice":item.buyPrice
						})
					})
	    			console.log(this.tableData)
	    			
	    			
	    			var nopass = false;
			    	for (var i = 0; i < this.tableData.length; i++) {
				            if (this.tableData[i].buyPrice == 0 ){nopass = true; break;}
				        if (nopass) break;
			    	}
	    			if(nopass){
				    	this.$message({
	                        type: 'error',
	                        message: "采购价必须大于0,再次提交!"
	                    });
	                    return false;
			    	}
	    			
	    			var findsame = false;
			    	for (var i = 0; i < this.tableData.length; i++) {
			            if (this.tableData[i].buyPrice ==""||this.tableData[i].supplierId ==""||this.tableData[i].arrayTime ==""){findsame = true; }else{
			            	findsame = false;
			            }
			    	}
	    			if(findsame){
				    	this.$message({
	                        type: 'error',
	                        message: "请填写完整信息后再次提交!"
	                    });
	                    return false;
			    	}
	    			if(this.tableData.length === 0){
				    	this.$message({
	                        type: 'error',
	                        message: "商品不可为空!"
	                    });
	                    return false;
	    			}
	    			let formData = new FormData()
	    			formData.append('uuid', localStorage.getItem('uuid'))
	    			formData.append('prId', this.$route.query.id)
					formData.append('jsonArray', JSON.stringify(setDATA))// 权限类型 系统  模块 菜单选择
					this.axios({
	                    method: 'POST',
	                    url:`${LINK}/sku/purchas/requisition/skuProduct/update/do`,
	                    data:formData,
	                    headers: {
	                        'Content-Type': 'application/x-www-form-urlencoded'
	                    },
	               	}).then( res=>{
	               		if(res.data.code==200){
                            this.$message({
		                        type: 'success',
		                        message: res.data.msg
		                    });
                            setTimeout(() => {
			      				this.$router.push({
				            		path: 'buyList', 
				            		name: 'buyList',
				        		})
			    			}, 1500);
	               		}else{
	               			this.$message({
		                        type: 'error',
		                        //message: "请填写完整信息后,再次保存",
		                       message: res.data.msg,
		                    });
	               			return false;
	               		}
	               	}).catch((err)=>{
			  	});
			},
			handleIconClick(ev) {
				//console.log(ev);
			},
			handleCurrentChange(val) {
				this.currentRow = val;
			},
			handleEdit(index, row) {
				//console.log(index, row);
			},
			del(index) {
				this.formData.splice(index, 1)
			},
			handleEdit() {
				this.dialogFormVisible = true
			},
			update() {
				this.dialogFormVisible = false
			},
			cancel() {
				this.dialogFormVisible = false
			},
			radioEvent() {
				this.showFlag = false;
			},
			changepages(a) {
			},
			reset() {
				this.value1 = -1
				this.input = ''
			},
			printContent() {
				let wpt = document.getElementById('mytable');
				let newContent = wpt.innerHTML;
				let oldContent = document.body.innerHTML;
				document.body.innerHTML = newContent;
				window.print(); //打印方法
				window.localtion.reload();
				document.body.innerHTML = oldContent
			},
		},
		computed: {
			tableDatas: function() {
				var search = this.searchValue;
				if(search) {
					return this.excelData.filter(function(product) {
						return Object.keys(product).some(function(key) {
							return String(product[key]).toLowerCase().indexOf(search) > -1
						})
					})
				}
				return this.excelData;
			}
		},
		watch: {
		},
		mounted() {
		}
	}
</script>

<style scoped="">
	.el-table td,
	.el-table th {
		text-align: center!important;
	}
	
	.deleach i {
		margin: 22px 2px;
		display: inline-block;
		color: #f56c6c;
	}
	
	.deleach {
		cursor: pointer;
	}
	
	/*.el-tb-edit .el-autocomplete,
	.el-tb-edit .el-input .input,
	.el-tb-edit .el-input,
	.el-tb-edit .el-input-number,
	.el-tb-edit .el-select {
		display: none;
		width: 100%;
	}
	
	.el-tb-edit .current-row .el-input,
	.el-tb-edit .current-row .el-autocomplete,
	
	.el-tb-edit .current-row .el-input-number,
	.el-tb-edit .current-row .el-select {
		display: inherit;
	}
	
	.el-tb-edit .current-row .el-autocomplete+span,
	.el-tb-edit .current-row .el-input+span,
	.el-tb-edit .current-row .el-input-number+span,
	.el-tb-edit .current-row .el-select+span {
		display: none;
	}*/
	
	
</style>