<!--检斤管理-->
<template>
	<div>
		<BaseHeaderLayout :leftSpan="12">
			<template slot="left">
				<ws-button type="primary" @click="weighing(3)">添加</ws-button>
			</template>
			<!-- <template slot="left"> </template> -->
			<template slot="right">
				<ws-select v-model="warehouseName" placeholder="" @change="warehouseNameChange" :value="searchType">
					<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;
              left: -8px;
            " src="../../../public/img/sousuo.png" alt="" /></ws-button>
			</template>
		</BaseHeaderLayout>
		<el-table :data="weighingList" style="width: 100%; margin-top: 20px" ref="weighingList" border height="780">
			<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="contractNo" width="120" label="合同编号"></el-table-column>
			<el-table-column prop="goodsName" label="货名"></el-table-column>
			<el-table-column prop="carNumber" label="车牌号"></el-table-column>
			<el-table-column prop="grossWeight" label="毛重（公斤）"></el-table-column>
			<el-table-column prop="tare" label="皮重（公斤）"></el-table-column>
			<el-table-column prop="netWeight" label="净重（公斤）"></el-table-column>
			<el-table-column prop="binNumber" label="仓位号"></el-table-column>
			<el-table-column prop="storageNumber" label="囤位号"></el-table-column>
			<el-table-column prop="secretaryWeigher" label="司称员"></el-table-column>
			<el-table-column prop="grossDate" label="称重时间">
				<template slot-scope="scope">
				{{scope.row.grossDate}}
				<span v-if="scope.row.grossDate == null">
            		{{scope.row.tareDate}}
          		</span>
				</template>
			</el-table-column>
			<el-table-column prop="addressUrl" label="附件">
				<template slot-scope="scope">
					<img width="18" height="20" style="vertical-align: text-top; position: relative; top: -1px"
						src="../../../public/img/fujian.png" @click="fujian(scope.row)" alt="" />
					<span v-if="scope.row.addressUrlArray != null">
						{{scope.row.addressUrlArray.length == 0? '': scope.row.addressUrlArray.length}}
					</span>
				</template>
			</el-table-column>
			<el-table-column prop="status" label="状态"></el-table-column>
			<el-table-column width="300" prop="contractNo1" label="操作">
				<template slot-scope="scope">
					<el-button @click="weighing(scope.row, 1)" v-if="scope.row.status != '已质检'">毛重</el-button>
					<el-button @click="weighing(scope.row, 2)" v-if="scope.row.status == '已称皮重'">皮重</el-button>
					<el-button @click="del(scope.row)" v-if="scope.row.status == '已称皮重'">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div style="text-align: center">
			<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>
		<WinseaContentModal v-model="accessoryTFs" :title="$t('system.noticeCircular.information')"
			@on-cancel="handleClose">
			<p>查看附件</p>
			<div style="display: inline-block; margin: 5px" v-for="item in appendixIdss">
				<img width="100" height="100" :src="item" alt="" />
			</div>
		</WinseaContentModal>
	</div>
</template>
<script>
	import {
		getweighingList,
		selectWarehouseSelf,
		delelteWeighing,
	} from '@/model/outboundManagement/index'
	import {
		EventBus
	} from 'base-core-lib'
	import WsUpload from '@/components/WsUpload'
	export default {
		components: {
			WsUpload,
		},
		data() {
			return {
				//分页
				dialogViewSpareMoney: false,
				currentPage: 1,
				pageSize: 10,
				deptCircularPage: {},
				deptBudgetTotal: 0,
				paymentForm: false,
				paymentForm1: false,
				weighingList: [],
				searchKeyWord: '',
				searchType: [],
				warehouseName: '',
				value1: '', //选择时间
				warehouseList: [],
				warehouseId: '',
				accessoryTFs: false,
				appendixIdss: [],
				addressUrls: [],
				compId: sessionStorage.getItem('ws-pf_compId'),
			}
		},
		activated() {
			this.selectWarehouse()
			this.showType = this.isShow
		},
		methods: {
			warehouseNameChange(e) {
				// this.warehouseName = e
				console.log(this.warehouseList)
				for (let i = 0; i < this.warehouseList.length; i++) {
					if (this.warehouseList[i].value == e) {
						this.warehouseId = this.warehouseList[i].warehouseId
					}
				}
			},
			weighing(row, num) {
				console.log
				this.$router.push({
					path: 'weighing',
					query: {
						typeNo: num,
						id: row.id,
						number: row.number,
						binNumber: row.binNumber,
						customer: row.customer,
						storageNumber: row.storageNumber,
						carNumber: row.carNumber,
						goodsName: row.goodsName,
						grossWeight: row.grossWeight,
						tare: row.tare,
						netWeight: row.netWeight,
						relationId: row.relationId,
						warehouseId: this.warehouseId,
						warehouseName: this.warehouseName,
					},
				})
			},
			// Reacquire() {
			//   //重新获取
			// },
			find() {
				this.getList()
			},
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`)
				this.pageSize = val
				this.getList()
			},
			handleCurrentChange(val) {
				this.currentPage = val
				console.log(`当前页: ${val}`)
				this.getList()
			},
			del(row) {
				this.$confirm(`检斤信息删除后不可恢复，是否确定删除？`, {
						cancelButtonText: '取消',
						confirmButtonText: '确定',
						type: 'warning',
					})
					.then(() => {
						delelteWeighing({
								id: row.id
							})
							.toPromise()
							.then((response) => {
								this.$notify.success({
									title: '成功',
									message: '删除成功',
								})
								this.getList()
							})
							.catch((response) => {})
					})
					.catch(() => {
						return false
					})
			},
			selectWarehouse() {
				selectWarehouseSelf({
						compId: sessionStorage.getItem('ws-pf_compId'),
						personCharge: sessionStorage.getItem('ws-pf_staffName'),
					})
					.toPromise()
					.then((response) => {
						this.warehouseList = []
						for (let i = 0; i < response.length; i++) {
							this.warehouseList.push({
								value: response[i].warehouseName,
								warehouseId: response[i].id,
							})
						}
						this.warehouseName = this.warehouseList[0].value
						this.warehouseId = this.warehouseList[0].warehouseId
						this.purchasePriceList = this.warehouseList[0].warehouseList
						this.getList()
					})
			},
			getList() {
				getweighingList({
						compId: sessionStorage.getItem('ws-pf_compId'),
						currentPage: this.currentPage,
						pageSize: this.pageSize,
						searchKeyWord: this.searchKeyWord,
						warehouseName: this.warehouseName,
						managementType: 3,
					})
					.toPromise()
					.then((response) => {
						this.weighingList = response.records
						this.deptBudgetTotal = response.total
						for (var i = 0; i < response.records.length; i++) {
							if (response.records[i].addressUrl != null) {
								if (response.records[i].addressUrl) {
									response.records[i].addressUrlArray = response.records[i].addressUrl.split(',')
								}
							} else {
								response.records[i].addressUrlArray = []
							}
						}
						for (var i = 0; i < response.records.length; i++) {
							var arr = new Array()
							this.addressUrls[i] = new Array()
							if (this.weighingList.records[i].addressUrl !=
								null) {
								arr = this.weighingList.records[i].addressUrl.split(',')
								this.addressUrls[i] = arr
							}
						}
					})
					.catch((response) => {

					})
			},
			//附件
			fujian(row) {
				if (row.addressUrl === null || row.addressUrl === '') {
					EventBus.$emit(
						'warning',
						this.$t('system.noticeCircular.NoInformation')
					)
				} else {
					this.accessoryTFs = true
				}
				this.appendixIdss = row.addressUrlArray
			},
			handleClose() {
				this.dialogViewSpareMoney = false
			},
		},
	}
</script>
<style lang="scss" scoped>
	.title {
		font-size: 20px;
		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;
	}

	.formItem {
		width: 51% !important;
	}
</style>
