<template>
	<view class="scheme">
		<u-list class="listContent">
			<view v-for="(item, index) in tableList" :key="index" style="position: relative;">
				<myCard :item="item" @details="add('view',item)" @edit="add('edit',item,index)" :index="index+1"
					:columns="columns" :btnList="btnData">
				</myCard>
			</view>
		</u-list>
		<view class="add" @click="add('add')" v-if="type != 'view'">
			<u-icon name="plus" color="#fff"></u-icon>
		</view>
	</view>
</template>

<script>
	import myCard from '@/pages/saleManage/components/myCard.vue'
	export default {
		components: {
			myCard
		},
		props: {
			type: {
				type: String,
				default: 'edit'
			},
			itemList: {
				type: Array,
				default: () => []
			},
		},
		watch: {
			itemList: {
				handler(newVal) {
					let list = JSON.parse(JSON.stringify(newVal));
					this.tableList = list
				},
				deep: true,
				immediate: true
			}
		},
		data() {
			return {
				columns: [
					[{
						label: '名称：',
						prop: 'name',
						type: 'title',
						className: 'perce100',
					}],
					[{
						label: '项目：',
						prop: 'typeId',
						formatter: (row) => {
							let typeId = row.typeId;
							return typeId == 1 ?
								'工时' :
								typeId == 2 ?
								'零配件' :
								typeId == 3 ?
								'差旅费' : ''
						}
					}],
					[{
						label: '编码：',
						prop: 'code'
					}, ],
					[{
						label: '型号：',
						prop: 'categoryModel'
					}, {
						label: '规格：',
						prop: 'specification',
					}],
					[{
						label: '仓库：',
						prop: 'warehouseName'
					}],
					[{
						label: '库存：',
						prop: 'warehouseNum',
					}, {
						label: '单位：',
						prop: 'measureUnit'
					}],
					[{
						label: '数量：',
						prop: 'totalCount',
					}, {
						label: '单价：',
						prop: 'singlePrice'
					}],
					[{
						label: '合计：',
						prop: 'settlementPrice',
					}],
					[{
						label: '详细内容：',
						prop: 'content'
					}],
					[{
						label: '操作：',
						prop: 'action',
						type: 'action',
						className: 'perce100',
					}],
				],
				btnList: [{
					name: '修改',
					apiName: 'edit',
					btnType: 'primary',
					type: '2',
					pageUrl: '',
					juge: [{
						authorities: '',
					}, {
						key: 'customize',
						value: ['5'],

					}]
				}],
				tableList: []
			}
		},
		computed: {
			btnData() {
				if (this.type == 'view') {
					return [];
				}
				return this.btnList;
			}
		},
		created() {
			uni.$off('updateInfo');
			uni.$on('updateInfo', (data) => {
				console.log(data,'data ----')
				data.customize = '5';
				if (data.index || data.index == 0) {
					let index = data.index;
					delete data.index;
					this.$set(this.tableList, index, data);
					return
				}
				this.tableList.push(data);
			})
		},
		onShow() {

		},
		methods: {
			add(type, item = {}, index) {
				if (type == 'edit') {
					item.index = index;
				}
				let data = JSON.stringify(item);
				uni.navigateTo({
					url: `/pages/salesServiceManagement/workOrder/components/schemeAdd?obtain=仓库&type=${type}&data=${data}`
				})
			},
			getTabData() {
				return this.tableList || [];
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import url('@/pages/salesServiceManagement/demandList/components/invoice.scss');

	.scheme {
		padding: 10rpx 20rpx;
	}

	.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>