<template>
	<el-dialog :model-value="props.showes" width="70%">
		<avue-crud
			ref="crudRef"
			:data="props.listData"
			:option="state.option"
		>
      <template #nowSendQty="{row}">
        <div style="display: flex;align-items: center;justify-content: center">
          <el-input-number v-model="row.nowSendQty" :min="1"/>
        </div>
      </template>
      <template #chengNuoJiaoQi="{row}">
        <div style="display: flex;align-items: center;justify-content: center">
          <el-date-picker v-model="row.chengNuoJiaoQi" type="date" size="large" style="width: 100%" format="YYYY/MM/DD"
                          value-format="YYYY-MM-DD" @change="chengNuoJiaoQiChange(row)"/>
        </div>
      </template>
      <template #newChengNuoJiaoQi="{row}">
        <div style="display: flex;align-items: center;justify-content: center">
          <el-date-picker v-model="row.newChengNuoJiaoQi" type="date" size="large" style="width: 100%" format="YYYY/MM/DD"
                          value-format="YYYY-MM-DD" @change="newChengNuoJiaoQiChange(row)"/>
        </div>
      </template>
    </avue-crud>
		<div class="btnList">
			<el-button type="primary" @click="batchAddInvoiceOrderFun">确定</el-button>
		</div>
	</el-dialog>
</template>
<script setup lang="ts">
import { defineProps, reactive, defineEmits, computed } from 'vue';
import { listApi } from '../../api/list/index'
const emits = defineEmits(['generateDocuments']);
import { useI18n } from 'vue-i18n';
import {ElMessage} from "element-plus";
const { t } = useI18n();
const props = defineProps({
	listData: {
		type: Array,
		default: () => [],
	},
	showes: {
		type: Boolean,
		default: false,
	},
});

const state = reactive({
	dialogVisible: true,
	data: [],
  show:true,
	formData: {},
	option: {
		tip: false,
		selection: false,
		index: true,
		menu: false,
		menuWidth: 150,
		border: true,
		delBtn: false,
		editBtn: false,
		align: 'center',
		searchLabelWidth: 140,
		searchMenuSpan: 6,
		addBtn: false,
		column: [
			{ label: 'PO号', prop: 'materialCode',  },
			{ label: '物料编码', prop: 'materialCode',  },
			{ label: '物料名称', prop: 'materialCode',  },
			{ label: '采购单位', prop: 'materialCode',  },
			{ label: '本次发货数量', prop: 'materialCode',  },
			{ label: '采购数量', prop: 'materialCode',  },
			{ label: '已发货数量', prop: 'materialCode',  },
			// { label: computed(() => t('message.list.MaterialName')), prop: 'materialName',  },
			// { label: computed(() => t('message.list.Specification')), prop: 'specificationModel',  },
			// { label: computed(() => t('message.list.PurchaseUnit')), prop: 'FUnitId',  },
      // { label: '采购数量', prop: 'qty',  },
      // { label: '处理中数量', prop: 'processingQty',  },
      // { label: '已发货数量', prop: 'sendedQty',  },
      // { label: '未发货数量', prop: 'notSendQty',  },
      // { label: '本次发货数量', prop: 'nowSendQty', ,fixed:true  },
			// { label: computed(() => t('message.list.UP')), prop: 'amount1',  },
			// { label: computed(() => t('message.list.TotalAmount')), prop: 'amount2',  },
			// { label: computed(() => t('message.list.AccumulatedReceiptQTY')), prop: 'FReceiveQty',  },
			// { label: computed(() => t('message.list.TaxAmount')), prop: 'taxAmount',  },
			// { label: computed(() => t('message.list.CommittedDeliveryDate')), prop: 'chengNuoJiaoQi',
      //   , type: 'datetime', searchSpan: 12, searchRange: true, searchLabelWidth: 150,fixed:true },
			// {
			// 	label: computed(() => t('message.list.LatestCommittedDeliveryDate')),
			// 	prop: 'newChengNuoJiaoQi',
			// 	,
			// 	type: 'datetime',
			// 	searchSpan: 12,
			// 	searchRange: true,
			// 	searchLabelWidth: 150,
      //   fixed:true
			// },
			// { label: computed(() => t('message.list.Comments2')), prop: 'remark',  },
		],
	},
	topId: '',
});
const chengNuoJiaoQiChange = (item:any) => {
  listApi().batchSetChengNuoJiaoQi([{
    id:item.id,
    newTime:item.chengNuoJiaoQi
  }]).then((res:any) => {
    if(res.resultCode === 0){
      ElMessage.success('操作成功');
    }
    if(res.resultCode === -1){
      ElMessage.success(res.errorMessage);
    }
  })
}
const newChengNuoJiaoQiChange = (item:any) => {
  listApi().batchSetNewChengNuoJiaoQi([{
    id:item.id,
    newTime:item.newChengNuoJiaoQi
  }]).then((res:any) => {
    if(res.resultCode === 0){
      ElMessage.success('操作成功');
    }
    if(res.resultCode === -1){
      ElMessage.success(res.errorMessage);
    }
  })
}
const batchAddInvoiceOrderFun = () => {
  console.log(props.listData)
  let arr:any = []
  props.listData.forEach((item:any) => {
    arr.push({
      id:item.id,
      qty:item.nowSendQty
    })
  })
  listApi().batchAddInvoiceOrder(arr).then((res:any) => {
    if(res.resultCode === 0){
      ElMessage.success('操作成功');
      emits('generateDocuments')
    }
    if(res.resultCode === -1){
      ElMessage.success(res.errorMessage);
    }
  })
}
</script>
<style scoped lang="scss">
.btnList {
	margin-top: 26px;
	display: flex;
	justify-content: center;
}
</style>
