<!--质检管理-->
<template>
	<div>
		<BaseHeaderLayout :leftSpan="16">
			<template slot="left">
				<ws-button type="primary" @click="inspectInfo(1)"
					v-hasPermission="`acquisitionManagement.acquisitionQuality.add`">添加</ws-button>
			</template>
			<template slot="right">
				<ws-select v-model="warehouseName" placeholder="" @change="warehouseNameChange" :value="searchType"
					style="margin: 0 10px">
					<ws-option v-for="item in warehouseList" :key="item.value" :label="item.value" :value="item.value"
						style="color: #8890b1" />
				</ws-select>
				<div></div>
				<ws-input v-model="searchKeyWord" placeholder="可按编号、客户名、车牌号查找" clearable maxlength="500" type="input">
				</ws-input>
				<ws-button class="find" type="primary" @click="find()"><img width="16" height="16" style="
              vertical-align: text-top;
              position: relative;
              top: 0px;
              
            " src="../../../public/img/sousuo.png" alt="" /></ws-button>
			</template>
		</BaseHeaderLayout>
		<!-- <div style="height:calc(100vh - 600px)"> -->
		<el-table :data="inspect" style="width: 100%; margin-top: 20px" ref="inspect" border height="600">
			<el-table-column type="index" label="序号" width="50">
				<template scope="scope">
					<span v-if="scope.$index < 9">0{{ scope.$index + 1 }}</span>
					<span v-else>{{ scope.$index + 1 }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="qualityNo" width="100" label="编号"></el-table-column>
			<el-table-column prop="customerName" label="客户"></el-table-column>
			<el-table-column prop="carNumber" label="车牌号"></el-table-column>
			<el-table-column prop="goodsName" label="货名"></el-table-column>
			<el-table-column prop="waterContent" label="水分（%）" width="120">
				<template scope="scope">
					<span class="water-left">{{scope.row.waterContent}}</span>
					<span class="water-line">|</span>
					<span class="water-right">{{scope.row.reWaterContent ? scope.row.reWaterContent : '未复检' }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="buckleMiscellaneous" label="扣杂" width="120">
				<template scope="scope">
					<div v-if="scope.row.paramType == 1">
						<span class="water-left">{{scope.row.buckleMiscellaneous}} </span>
						<span class="water-line">|</span>
						<span
							class="water-right">{{scope.row.reBuckleMiscellaneous ? scope.row.reBuckleMiscellaneous : '未复检'}}</span>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="type" label="类型"></el-table-column>
			<el-table-column prop="tidalGrainPrice" label="单价（元/公斤）" width="120px">
				<template scope="scope">
					<span v-if="scope.row.type == '潮粮'">{{ scope.row.tidalGrainPrice }}</span>
					<span v-else>{{ scope.row.dryGrainPrice }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="binNumber" label="仓位号"></el-table-column>
			<el-table-column prop="storageTagNo" label="囤位号"></el-table-column>
			<el-table-column prop="qualityInspector" label="质检员" width="120px">
				<template scope="scope">
					<span>{{scope.row.qualityInspector}}</span>
					<span
						v-if="scope.row.reInspector && scope.row.qualityInspector != scope.row.reInspector">,{{scope.row.reInspector}}</span>
				</template>
			</el-table-column>
			<el-table-column prop="updateDate" label="质检时间" width="90px"></el-table-column>
			<el-table-column prop="status" label="状态">
				<template slot-scope="scope">
					<span v-if='scope.row.confirm=="1"'>
						已确认
					</span>
					<span v-else>
						{{scope.row.status}}
					</span>
				</template>
			</el-table-column>
			<el-table-column width="410" label="操作">
				<template slot-scope="scope">
					<el-button @click="inspectInfo(scope.row, 2)"
						v-hasPermission="`acquisitionManagement.acquisitionQuality.view`">查看</el-button>
					<el-button @click="inspectInfo(scope.row, 3)"
						v-if="scope.row.status=='已初检'&& scope.row.confirm!='1'"
						v-hasPermission="`acquisitionManagement.acquisitionQuality.initial`">初检</el-button>
					<div v-show="scope.row.confirm !='1' && scope.row.status == '已复检'" style="display: inline-block;">
						<el-button @click="inspectInfo(scope.row, 5)"
							v-hasPermission="`acquisitionManagement.acquisitionQuality.con`">确认</el-button>
					</div>
					<el-button @click="inspectInfo(scope.row, 4)" v-if="scope.row.confirm !='1'"
						v-hasPermission="`acquisitionManagement.acquisitionQuality.again`">复检</el-button>
					<div style="display: inline-block;"
						v-if="scope.row.weighingManagement&&scope.row.weighingManagement.status=='已质检'">
						<el-button @click="del(scope.row)" type="danger"
							v-hasPermission="`acquisitionManagement.acquisitionQuality.delete`">删除</el-button>
					</div>
					<el-button @click="print(scope.row)"
						v-hasPermission="`acquisitionManagement.acquisitionQuality.print`">打印</el-button>
				</template>
			</el-table-column>
		</el-table>
		
		 <el-dialog width="70%" class="table-content" center :visible.sync="isShowPrint" title="粮食质检单">
			<!-- <inspectInfoPrint :printData="printData"></inspectInfoPrint> -->
			<inspectInfoPrint :printData="printData" ref="saveImg"></inspectInfoPrint>
			<div style="text-align:center">
				<el-button type="primary" @click="closePrint">关闭</el-button>
				<el-button type="primary" @click="printSmall">打印小票</el-button>
				<el-button type="primary" @click="printBig">打印单据</el-button>
			</div>
		</el-dialog>
		<div style="text-align: center;margin-top:20px">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="currentPage" :page-size="deptCircularPage.pageSize"
				layout="total, sizes, prev, pager, next, jumper" :total="deptBudgetTotal">
			</el-pagination>
		</div>
		<!-- </div> -->
	</div>
</template>
<script>
	import {
		selectWarehouseSelf,
		getinspectList,
		getinspectDelete,
		getinspectLook,
	} from '@/model/houseSelfCollect/index'
	import inspectInfoPrint from './component/inspectInfoPrint.vue'
	export default {
		components: {
			inspectInfoPrint
		},
		watch: {},
		data() {
			return {
				//分页
				currentPage: 1,
				pageSize: 10,
				deptCircularPage: {},
				deptBudgetTotal: 0,

				searchKeyWord: '',
				taskTypeList: [],
				searchType: 0,
				warehouseName: '',
				inspect: [],
				warehouseList1: [],
				warehouseList: [],
				cangid: '', //仓库id
				warehouseCount: '',
				warehouseNo: '',
				isShowPrint: false,
				printData: {},
				deductWeight: '', //扣重比
				saleLimit: '',
				allowEdit:'0'
			}
		},
		activated() {
			this.selectWarehouse()
		},
		methods: {
			printSmall() {
				window.open('../../../static/inspection.html?type=1&dataList=' + JSON.stringify(this.printData))
			},
			printBig() {
				window.open('../../../static/inspection.html?type=2&dataList=' + JSON.stringify(this.printData))
			},
			closePrint() {
				this.isShowPrint = false
				this.$router.push({
					path: 'inspectionManagement'
				})
			},
			find() {
				this.getList()
			},
			inspectInfo(row, index) {
				for (let i = 0; i < this.warehouseList.length; i++) {
					if (this.warehouseName == this.warehouseList[i].value) {
						// console.log(this.warehouseList[i])
						this.cangid = this.warehouseList[i].id
					}
				}
				// console.log(this.cangid)
				//添加,编辑，查看
				this.$router.push({
					path: 'inspectInfo',
					query: {
						type: index,
						cangid: this.cangid,
						id: row.id,
						warehouseName: this.warehouseName,
						count: this.warehouseCount,
						warehouseNo: this.warehouseNo,
						allowEdit:this.allowEdit
					},
				})
			},
			warehouseNameChange(e) {
				// console.log(e)
				for (let i = 0; i < this.warehouseList.length; i++) {
					if (this.warehouseList[i].value == e) {
						this.warehouseName = this.warehouseList[i].value
						this.warehouseCount = this.warehouseList[i].count
						this.warehouseNo = this.warehouseList[i].No
						this.cangid = this.warehouseList[i].id
						this.allowEdit = this.warehouseList[i].allowEdit
						this.WAREHOUSE[1].payname = this.warehouseList[i].value
						localStorage.setItem('houseSelfCollect_house1', JSON.stringify(this.warehouseList[i]))
					}
				}
				this.getList()
			},
			del(row) {
				//删除
				this.$confirm('确定删除质检信息？', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning',
					})
					.then(() => {
						getinspectDelete({
								id: row.id,
							})
							.toPromise()
							.then((response) => {
								this.$notify.success({
									title: '成功',
									message: '删除成功',
								})
								this.getList()
							})
							.catch((response) => {
								// EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
							})
					})
					.catch(() => {
						return false
					})
			},
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`)
				this.pageSize = val
				this.getList()
			},
			handleCurrentChange(val) {
				this.currentPage = val
				console.log(`当前页: ${val}`)
				this.getList()
			},
			selectWarehouse() {
				selectWarehouseSelf({
						compId: localStorage.getItem('ws-pf_compId'),
					})
					.toPromise()
					.then((response) => {
						this.warehouseList1 = response
						this.warehouseList = []
						let _wareHouse = localStorage.getItem('houseSelfCollect_house1')
						_wareHouse = JSON.parse(_wareHouse)
						if (_wareHouse) {
								this.cangid = _wareHouse.warehouseId
								this.warehouseName = _wareHouse.value
								this.warehouseNo = _wareHouse.No
								this.warehouseCount = _wareHouse.count
								this.allowEdit = _wareHouse.allowEdit
							} 
						for (let i = 0; i < response.length; i++) {
							if(_wareHouse && response[i].warehouseName==_wareHouse.value){
								this.warehouseCount = response[i].count
								this.allowEdit = response[i].allowEdit
							}
							this.warehouseList.push({
								value: response[i].warehouseName,
								id: response[i].id,
								count: response[i].count,
								No: response[i].commonWarehouseNo,
								allowEdit:response[i].allowEdit
							})
							if (!_wareHouse) {
								if (this.cangid && this.cangid == response[i].id) {
									this.warehouseName = response[i].warehouseName
									this.warehouseCount = response[i].count
									this.warehouseNo = response[i].commonWarehouseNo
									this.allowEdit =  response[i].allowEdit
								}
								if (this.warehouseList.length > 0 && !this.cangid) {
									this.warehouseName = this.warehouseList[0].value
									this.warehouseCount = this.warehouseList[0].count
									this.warehouseNo = this.warehouseList[0].No
									this.cangid = this.warehouseList[0].id
									this.allowEdit = this.warehouseList[0].allowEdit
									this.WAREHOUSE[1].payname = this.warehouseList[0].value
								}
							}
						}
						this.getList()
					})
			},
			getList() {
				getinspectList({
						compId: localStorage.getItem('ws-pf_compId'),
						currentPage: this.currentPage,
						pageSize: this.pageSize,
						searchKeyWord: (this.searchKeyWord).toUpperCase(),
						warehouseName: this.warehouseName,
						managementType: 1
					})
					.toPromise()
					.then((response) => {
						console.log(response)
						this.inspect = response.records
						this.deptBudgetTotal = response.total
						// this.$forceUpdate();
					})
			},
			print(row) {

				getinspectLook({
						id: row.id,
					})
					.toPromise()
					.then((response) => {
						this.isShowPrint = true
						this.printData = response
						// window.location.href="../../../static/inspection.html?dataList="+JSON.stringify(response)
					})
			},
		},
	}
</script>
<style lang="scss" scoped>
	/deep/.el-dialog__header {
		text-align: center !important;
		padding: 10px 0 !important;
		height: auto !important;
	}

	/deep/.el-dialog__title {
		font-size: 24px !important;
	}

	.title {
		font-size: 20px;
		font-weight: 600;
		margin: 20px 0 0 20px;
	}

	.tit {
		font-size: 16px;
		font-weight: 600;
		margin: 20px;
	}

	.ws-info-table {
		border: none;
	}

	.ws-info-table .el-form-item {
		width: 50%;
		border: none;
	}

	/deep/.ws-info-table .el-form-item .el-form-item__label {
		width: 30%;
		text-align: center;
		background: #ffffff;
		color: #8890b1;
	}

	/deep/.ws-info-table .el-form-item .el-form-item__content {
		border: none;
	}

	/deep/.el-table .el-table__header .cell,
	.el-table .el-table__body .cell {
		text-align: center;
	}

	/deep/.el-table--enable-row-transition .el-table__body td {
		text-align: center;
	}

	/deep/.el-dialog__body {
		padding: 20px !important;
	}

	.water-left,
	.water-right {
		width: 45%;
		display: inline-block;
	}
// 	/deep/.el-table--border{
//   height: calc(100vh - 600px) !important;
// }
</style>
