<template>
	<view class="">123</view>
</template>

<script>
	import { getBusinessOpportunityDetailAPI, businessOpportunityUpdateAPI } from '@/api/wt/index.js'
	export default {
		props: {
			businessId: {
				default: ''
			},
			taskDefinitionKey: {
				default: ''
			}
		},
		data() {
			return {
				form: {},
				calendarShow: false,
				tableField: [
					{
						label: '名称',
						field: 'productName'
					},
					{
						label: '编码',
						field: 'productCode'
					},
					{
						label: '类型',
						field: 'productCategoryName'
					},
					{
						label: '单价',
						field: 'singlePrice'
					},
					{
						label: '数量',
						field: 'totalCount'
					},
					{
						label: '合计',
						field: 'totalPrice'
					},
					{
						label: '生产交付交期',
						field: 'produceDeliveryDeadline',
						type: 'date',
						disabled: !['productionSupervisorApprove1', 'productionSupervisorApprove2'].includes(this.taskDefinitionKey)
					}
				],
				list: ['基本信息', '产品清单'],
				totalPrice: 0,
				curNow: 0,
				curIndex: null,
				rules: {
					produceDeliveryDeadline: {
						type: 'string',
						required: true,
						message: '请选择生产交付日期',
						trigger: ['blur', 'change']
					}
				}
			}
		},
		methods: {
			sectionChange(index) {
				this.curNow = index
			},
			async getDetailData(id) {
				const data = await getBusinessOpportunityDetailAPI(id)
				if (data) {
					this.form = data
					console.log(this.form.productList)
					this.totalPrice = this.form.productList.reduce((num, row) => (num += row.totalPrice), 0)
				}
			},
			openCalendar(e, index) {
				this.calendarShow = true
				this.curIndex = index
			},
			confirm(e) {
				this.$set(this.form.productList[this.curIndex], 'produceDeliveryDeadline', ...e)
				this.calendarShow = false
			},
			//
			getTableValue() {
				let validField = ['produceDeliveryDeadline']
				let valid = false
				for (var i = 0; i < validField.length; i++) {
					valid = this.form.productList.some(item => !!item[validField[i]] == false)
					if (valid) break
				}
				return new Promise(async (resolve, reject) => {
					valid ? reject(uni.$u.toast('请完善产品清单信息')) : resolve(this.form)
				})
			}
		}
	}
</script>

<style></style>
