<template>
	<view class="mainBox">
		<uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back"
			title="配件申请记录" @clickLeft="back">
		</uni-nav-bar>
		<view class="top-wrapper">
			<uni-section>
				<uni-easyinput prefixIcon="search" style="width: 460rpx" v-model="searchVal" placeholder="名称">
				</uni-easyinput>
			</uni-section>
			<button class="search_btn" @click="doSearch">搜索</button>
			<image class="menu_icon" src="~@/static/pda/menu.svg"></image>
		</view>
		<view class="wrapper">
			<u-list @scrolltolower="scrolltolower" class="listContent" style="height: auto;">
				<view v-for="(item, index) in tableList" :key="index" style="position: relative;">
					<myCard :columns="columns" :btnList="btnList" :item="item" @details="add(item,'view')"
						@edit="add(item,'edit')">
					</myCard>
				</view>
			</u-list>
		</view>
		<view class="add" @click="add('','add')">
			<u-icon name="plus" color="#fff"></u-icon>
		</view>
	</view>
</template>

<script>
	import {
		accessoryPage,
	} from '@/api/salesServiceManagement/accessory/index.js';
	import myCard from '@/pages/saleManage/components/myCard.vue';
	export default {
		components: {
			myCard
		},
		data() {
			return {
				columns: [
					[{
						label: '编号：',
						prop: 'code',
						type: 'title',
						className: 'perce100',
					}],
					[{
						label: '工单编码：',
						prop: 'orderCode'
					}],
					[{
						label: '物品分类：',
						prop: 'categoryLevelName',
						formatter: (row) => {
							if (!row.details) return '';
							let str = '';
							row.details.map((el, idx) => {
								if (idx + 1 == row.details.length) {
									str += el.categoryLevelName;
								} else {
									str = el.categoryLevelName ?
										str + '' + el.categoryLevelName + ',' :
										str + '';
								}
							});
							return str;
						}
					}],
					[{
						label: '物品名称：',
						prop: 'categoryName',
						formatter: (row) => {
							if (!row.details) return '';
							let str = '';
							row.details.map((el, idx) => {
								if (idx + 1 == row.details.length) {
									str += el.categoryName;
								} else {
									str = str + '' + el.categoryName + ',';
								}
							});
							return str;
						}
					}],
					[{
						label: '领用部门：',
						prop: 'receivingDeptName',
					}, {
						label: '领用人：',
						prop: 'recipientName',
					}],
					[{
						label: '客户名称：',
						prop: 'contactName'
					}],
					[{
						label: '设备名称：',
						prop: 'categoryName',
						formatter: (row) => {
							if (!row.deviceDetails) return '';
							let str = '';
							row.deviceDetails.map((el, idx) => {
								if (idx + 1 == row.deviceDetails.length) {
									str += el.categoryName;
								} else {
									str = str + '' + el.categoryName + ',';
								}
							});
							return str;
						}
					}],
					[{
						label: '创建时间：',
						prop: 'createTime'
					}, {
						label: '使用时间：',
						prop: 'usageTime',
					}],
					[{
						label: '操作：',
						prop: 'action',
						type: 'action',
						className: 'perce100',
					}],
				],
				btnList: [{
					name: '详情',
					apiName: 'details',
					btnType: 'primary',
					type: '2',
					pageUrl: '',

				}, {
					name: '修改',
					apiName: 'edit',
					btnType: 'primary',
					type: '2',
					pageUrl: '',
					judge: [{
						authorities: '',
					}, {
						key: 'source',
						value: [0],

					}],
				}],
				page: 1,
				size: 10,
				isEnd: false,
				tableList: [],
				searchVal: ''
			}
		},
		created() {
			
		},
		onShow() {
			this.doSearch();
		},
		methods: {
			doSearch() {
				this.isEnd = false;
				this.page = 1;
				this.getList();
			},
			//获取列表信息
			getList() {
				if (this.isEnd) {
					return;
				}
				uni.showLoading({
					title: '加载中'
				})
				let data = {
					pageNum: this.page,
					size: this.size,
				}
				accessoryPage(data).then(res => {
					if (this.page === 1) {
						this.tableList = res.list;
					} else {
						this.tableList.push(...res.list);
					}
					this.page += 1
					this.isEnd = this.tableList.length >= res.count;
					uni.hideLoading();
				}).catch((e) => {
					uni.hideLoading();
				})
			},
			scrolltolower() {
				if (this.isEnd) {
					return;
				}
				this.getList();
			},
			add(item, type) {
				console.log(item, 'item ---')
				uni.navigateTo({
					url: `/pages/salesServiceManagement/accessory/accessoryAdd?type=${type}&id=${item.id}`
				})
			},
			
		}
	}
</script>

<style scoped lang="scss">
	.top-wrapper {
		background-color: #fff;
		display: flex;
		width: 750rpx;
		height: 88rpx;
		padding: 16rpx 32rpx;
		align-items: center;
		gap: 16rpx;

		/deep/.uni-section {
			margin-top: 0px;
		}

		/deep/.uni-section-header {
			padding: 0px;

		}

		.search_btn {
			width: 120rpx;
			height: 70rpx;
			line-height: 70rpx;
			padding: 0 24rpx;
			background: $theme-color;
			font-size: 32rpx;
			color: #fff;
			margin: 0;
			margin-left: 26rpx;
		}

		.menu_icon {
			width: 44rpx;
			height: 44rpx;
			margin-left: 14rpx;
		}
	}

	.add {
		width: 96rpx;
		height: 96rpx;
		border-radius: 48rpx;
		background: #3c9cff;
		position: fixed;
		bottom: 100rpx;
		right: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>