<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="btnList">
				</myCard>
			</view>
		</u-list>
		<view class="add" @click="add('add')">
			<u-icon name="plus" color="#fff"></u-icon>
		</view>
	</view>
</template>

<script>
	import myCard from '@/pages/saleManage/components/myCard.vue'
	export default {
		components: {
			myCard
		},
		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: 'details',
						btnType: 'primary',
						type: '2',
						pageUrl: '',
					},
					{
						name: '修改',
						apiName: 'edit',
						btnType: 'primary',
						type: '2',
						pageUrl: '',
					}
				],
				tableList: []
			}
		},
		computed: {},
		created() {
			uni.$off('updateInfo');
			uni.$on('updateInfo', (data) => {
				if(data.index || data.index == 0){
					let index = data.index;
					delete data.index;
					this.$set(this.tableList,index,data);
				}else{
					this.tableList.push(data);
				}
				console.log(data, 'data 接收的数据')
			})
		},
		onShow() {

		},
		methods: {
			add(type, item = {}, index) {
				if (type == 'edit') {
					item.index = index;
				}
				let data = JSON.stringify(item);
				uni.navigateTo({
					url: `/pages/salesServiceManagement/toDoList/components/schemeAdd?obtain=仓库&type=${type}&data=${data}`
				})
			},

		}
	}
</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>