<template>
	<view>
		<u-popup :show="show" closeOnClickOverlay mode="top" @close="closePopup">
			<view class="search_list">
				<u-form labelPosition="left" :model="form" labelWidth="180" labelAlign="left" class="baseForm">
					<u-form-item label="列表维度:" class="required-form" borderBottom prop="assetType">
						<zxz-uni-data-select :localdata="option.dimension" v-model="form.dimension" dataValue='type'
							dataKey="name" filterable format='{name}'></zxz-uni-data-select>
					</u-form-item>
					<u-form-item label="资产类型:" class="required-form" borderBottom prop="categoryLevelId">
						<zxz-uni-data-select :localdata="option.code" v-model="form.categoryLevelId" dataValue='id'
							dataKey="name" filterable format='{name}'></zxz-uni-data-select>
					</u-form-item>
					<u-form-item label="所属仓库:" class="required-form" borderBottom prop="warehouseId">
						<zxz-uni-data-select :localdata="option.warehouseId" v-model="form.warehouseId" dataValue='id'
							dataKey="name" filterable format='{name}'></zxz-uni-data-select>
					</u-form-item>
				</u-form>
			</view>
			<view class="operate_box rx-bc">
				<u-button size="small" class="u-reset-button" @click="reset">
					重置
				</u-button>
				<u-button type="success" size="small" class="u-reset-button" @click="submit">
					确定
				</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getWarehouseList,
		getProduceTreeByPid
	} from '@/api/warehouseManagement'
	import {
		post,
		get
	} from '@/utils/api.js'
	export default {
		components: {},
		props: ['dimension', 'categoryLevelId', 'warehouseId'],
		data() {
			return {
				infoData: '',
				show: false,
				form: {
					// 列表维度
					dimension: 1,
					/* 资产类型 */
					categoryLevelId: '',
					/* 所属仓库 */
					warehouseId: ''
				},
				option: {
					dimension: [{
							name: '物品维度',
							type: 1
						},
						{
							name: '批次维度',
							type: 2
						},
						{
							name: '包装维度',
							type: 3
						}
					],
					code: [],
					warehouseId: []
				}
			}
		},
		created() {
			this.getwarehouseList()
			this.getClassify()
		},
		methods: {
			open() {
				this.show = true
				for (let key of Object.keys(this.form)) {
					this.form[key] = this[key]
				}
			},
			closePopup() {
				this.show = false
			},
			reset() {
				this.form = {
					dimension: 1,
					categoryLevelId: '',
					warehouseId: ''
				}
				this.$emit('succeed', this.form)
				this.closePopup()
			},
			submit() {
				this.$emit('succeed', this.form)
				this.closePopup()
			},
			//获取仓库
			getwarehouseList() {
				getWarehouseList().then(res => {
					this.option.warehouseId = res.data
				})
				// post(this.apiUrl + '/warehouseGoodsshelves/select/warehouseList').then(
				//   res => {
				//     if (res.success) {
				//       this.option.warehouseId = res.data
				//         .filter(i => !i.isDelete && !!i.status)
				//         .map(n => {
				//           return {
				//             name: n.name,
				//             id: n.id
				//           }
				//         })
				//     }
				//   }
				// )
			},
			// 获取资产类型
			getClassify() {
				getProduceTreeByPid({
					type: 2
				}).then(res => {
					this.option.code = res
				})
				// get(this.apiUrl + '/classify/getClassify?id=0').then(res => {
				// 	if (res.success) {
				// 		this.option.code = res.data.map(n => {
				// 			return {
				// 				name: n.name,
				// 				type: n.type
				// 			}
				// 		})
				// 		this.form.code = this.option.code[0].type
				// 		this.submit()
				// 	}
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search_list {
		min-height: 100rpx;

		/deep/ .baseForm {
			padding: 0 20rpx;
		}
	}

	.operate_box {
		padding: 10rpx 32rpx;

		/deep/ .u-button {
			width: 40%;
		}
	}
</style>