Component({
	properties: {
		list: Array,
		deleteItem: Function,
		changeProduct: Function, //修改队列
		disabled: Boolean
	},
	options: {
		addGlobalClass: true
	},
	methods: {
		toProductDetail(e) {
			const {
				item
			} = e.currentTarget.dataset;
			console.log(item)
		},
		onBlur(e) {
			let {
				data
			} = e.currentTarget.dataset;
			let i = this.data.list.findIndex(v => v.sa_orderitemsid == data.sa_orderitemsid)
			if (e.detail.value > data.uninvoiceamount) {
				e.detail.value = data.uninvoiceamount;
				wx.showToast({
					title: `最大开票金额${data.uninvoiceamount}元`,
					icon: "none"
				});
				if (i != -1) this.setData({
					[`list[${i}].invoiceamount`]: data.uninvoiceamount,
					[`list[${i}].invoiceaqty`]: data.uninvoiceamount / data.price,
				})
			} else if (e.detail.value == 0) {
				wx.showToast({
					title: `开票金额不可为0`,
					icon: "none"
				});
				if (i != -1) return this.setData({
					[`list[${i}].invoiceamount`]: this.data.list[i].invoiceamount,
					[`list[${i}].invoiceaqty`]: this.data.list[i].invoiceaqty,
				})
			}
			if (e.detail.value != data.invoiceamount) this.triggerEvent("changeProduct", {
				"sa_invoiceapply_orderid": data.sa_invoiceapply_orderid,
				"saorderid": data.sa_orderid,
				"sa_orderitemsid": data.sa_orderitemsid,
				"price": data.price,
				"invoiceamount": e.detail.value - 0,
				"invoiceaqty": (e.detail.value - 0) / data.price
			})
		},
		deleteProduct(e) {
			let {
				item
			} = e.currentTarget.dataset;
			this.triggerEvent("deleteItem", item)
		},
		isEdit() {
			if (this.data.disabled) wx.showToast({
				title: '当前状态不可编辑！',
				icon: "none"
			})
		}
	}
})