Browse Source

要花计划--创建供应商申请页面

master_hella_20240701
yufei0306 7 months ago
parent
commit
37b23d781d
  1. 330
      src/views/wms/purchasereceiptManage/supplierdeliver/supplierdeliverRequestMain/supplierdeliverBasicForm.vue

330
src/views/wms/purchasereceiptManage/supplierdeliver/supplierdeliverRequestMain/supplierdeliverBasicForm.vue

@ -0,0 +1,330 @@
<template>
<!-- 表单弹窗添加/修改 -->
<!-- 供应商发货申请 -->
<BasicForm
ref="formRef"
:isOpenSearchTable="true"
:indexTableColumn="0"
@success="getList"
:rules="SupplierdeliverRequestMainRules"
:formAllSchemas="SupplierdeliverRequestMain.allSchemas"
:tableAllSchemas="SupplierdeliverRequestDetail.allSchemas"
:tableFormRules="SupplierdeliverRequestDetailRules"
:tableData="tableData"
:apiUpdate="SupplierdeliverRequestMainApi.updateSupplierdeliverRequestMain"
:apiCreate="SupplierdeliverRequestMainApi.createSupplierdeliverRequestMain"
:isBusiness="true"
@handleAddTable="handleAddTable"
@handleDeleteTable="handleDeleteTable"
@searchTableSuccess="searchTableSuccess"
@submitForm="submitForm"
@formFormDateChange="formFormDateChange"
@onEnter="onEnter"
>
<template v-slot="{row}">
<el-date-picker v-bind:modelValue="row['expireTime']?addDay(row['produceDate'],row['expireTime']).format('YYYY-MM-DD'):'2099-12-31'"
:clearable="true"
style="width: 100%"
:disabled="true"
placeholder="选择日期"/>
</template>
</BasicForm>
</template>
<script setup lang="ts">
import {
SupplierdeliverRequestMain,
SupplierdeliverRequestMainRules,
SupplierdeliverRequestDetail,
SupplierdeliverRequestDetailRules,
SupplierdeliverRequestDetailLabel,
SupplierdeliverRequestPackage
} from './supplierdeliverRequestMain.data'
import { Supplier } from '@/views/wms/basicDataManage/supplierManage/supplier/supplier.data'
import * as SupplierdeliverRequestMainApi from '@/api/wms/supplierdeliverRequestMain'
import * as PurchasePlanDetailApi from '@/api/wms/purchasePlanDetail'
import * as SupplierApi from '@/api/wms/supplier'
import * as ItembasicApi from '@/api/wms/itembasic'
import { addDay } from '@/utils/formatTime'
import { PurchasePlanDetail } from '../purchasePlanMain/purchasePlanMain.data'
import { formatDate } from '@/utils/formatTime'
const emit = defineEmits(['getList'])
const getList = () =>{
emit('getList')
}
const message = useMessage() //
const { t } = useI18n() //
const planArriveTimeStr = ref()
///
const formRef = ref()
const tableData = ref([])
const tableFormKeys = {}
SupplierdeliverRequestDetail.allSchemas.tableFormColumns.forEach((item) => {
tableFormKeys[item.field] = item.default ? item.default : ''
})
//
const handleAddTable = () => {
tableData.value.push(JSON.parse(JSON.stringify(tableFormKeys)))
}
//
const handleDeleteTable = (item, index) => {
tableData.value.splice(index, 1)
}
const openFormByCreate = async ( data ) => {
SupplierdeliverRequestMain.allSchemas.formSchema.forEach((item) => {
if(item.field == 'supplierCode'){
item.componentProps.isSearchList = true
}
if(item.field == 'ppNumber'){
item.componentProps.isSearchList = true
}
if(item.field == 'asnNumber'){
item.componentProps.disabled = false
}
if(item.field == 'planArriveTime'){
item.componentProps.disabled = false
}
})
const setV = {}
//
setV['supplierCode'] = data['supplierCode'] //
setV['ppNumber'] = data['number'] //
searchPage: SupplierApi.getSupplierPage
//--
getSearchTableData(data['number'],'ppNumber','number')
//
let beginTime = data['endTime']
let deliveryDate = formatDate(data['deliveryDate'],'YYYY-MM-DD')
planArriveTimeStr.value = deliveryDate + ' '+ beginTime+":00"
setV['planArriveTime']= new Date(planArriveTimeStr.value).valueOf();
formRef.value.open('create', null)
//
const {tableObject ,tableMethods} = useTable({
defaultParams:{code:data['supplierCode']},
getListApi: SupplierApi.getSupplierPage //
})
const { getList } = tableMethods
await getList()
if(tableObject.tableList.length>0){
setV['contactName'] = tableObject.tableList[0]['contacts'] //
setV['contactPhone'] = tableObject.tableList[0]['phone'] //
setV['contactEmail'] = tableObject.tableList[0]['email'] //
}
nextTick(() => {
console.log('formRef.value.formRef',formRef.value.formRef)
formRef.value.formRef.setValues(setV)
})
}
const openForm = async (type: string, row?: number) => {
if(type == "update"){
SupplierdeliverRequestMain.allSchemas.formSchema.forEach((item) => {
if(item.field == 'supplierCode'){
item.componentProps.isSearchList = false
item.componentProps.disabled = true
}
if(item.field == 'ppNumber'){
item.componentProps.isSearchList = false
item.componentProps.disabled = true
}
if(item.field == 'asnNumber'){
item.componentProps.disabled = true
}
if(item.field == 'planArriveTime'){
item.componentProps.disabled = true
}
})
}else {
SupplierdeliverRequestMain.allSchemas.formSchema.forEach((item) => {
if(item.field == 'supplierCode'){
item.componentProps.isSearchList = true
}
if(item.field == 'ppNumber'){
item.componentProps.isSearchList = true
}
if(item.field == 'asnNumber'){
item.componentProps.disabled = false
}
if(item.field == 'planArriveTime'){
item.componentProps.disabled = false
}
})
}
tableData.value = [] //
formRef.value.open(type, row)
}
//
const searchTableSuccess = (formField, searchField, val, formRef, type, row) => {
nextTick(() => {
console.log("type:",type)
console.log("formField:",formField)
console.log(formField, searchField, val, formRef, type, row)
if (type == 'tableForm') {
//
// row[formField] = val[0][searchField]
// if (formField == 'poNumber') {
// row['poNumber'] = val[0]['poNumber']
// row['itemCode'] = val[0]['itemCode']
// row['poLine'] = val[0]['poLine']
// row['orderQty'] = val[0]['orderQty']
// row['uom'] = val[0]['uom']
// }
//--
const itemCodes = []
val.forEach(item=>{
if(tableData.value.find(item1=>item1['id'] == item['id'])) return
const newRow = {...row}
newRow[formField] = item[searchField]
newRow['poNumber'] = item['poNumber']
newRow['itemCode'] = item['itemCode']
newRow['poLine'] = item['poLine']
newRow['orderQty'] = item['orderQty']
newRow['uom'] = item['uom']
itemCodes.push(item['itemCode'])
tableData.value.push(newRow)
})
//
ItembasicApi.getItembasicPage({
code:itemCodes.join(',')
}).then((res)=>{
res.list.forEach((item,index)=>{
const findItem = tableData.value.find(item1=>item1['itemCode']==item['code'])
findItem['expireTime'] = findItem['expireTime']
})
})
} else {
const setV = {}
setV[formField] = val[0][searchField]
if(formField == 'ppNumber'){
//--
getSearchTableData(val[0]['number'],formField,searchField)
//
let beginTime = val[0]['endTime']
let deliveryDate = formatDate(val[0]['deliveryDate'],'YYYY-MM-DD')
planArriveTimeStr.value = deliveryDate + ' '+ beginTime+":00"
setV['planArriveTime']= new Date(planArriveTimeStr.value).valueOf();
//
tableData.value = []
}
if(formField == 'supplierCode'){
setV['contactName'] = val[0]['contacts']
setV['contactPhone'] = val[0]['phone']
setV['contactEmail'] = val[0]['email']
}
formRef.setValues(setV)
}
})
}
const getSearchTableData = async (number,formField,searchField)=>{
const {tableObject ,tableMethods} = useTable({
defaultParams:{number},
getListApi: PurchasePlanDetailApi.getPurchasePlanDetailPage //
})
//
const { getList:getList1 } = tableMethods
await getList1()
const tableColumns = PurchasePlanDetail.allSchemas.tableFormColumns
tableColumns.forEach((item) => {
item.width = item.table?.width || 150
})
tableData.value = []
const itemCodes = []
tableObject.tableList.forEach(row=>{
const newRow = JSON.parse(JSON.stringify({...tableFormKeys,...row}))
newRow[formField] = row[searchField]
newRow['poNumber'] = row['poNumber']
newRow['itemCode'] = row['itemCode']
newRow['poLine'] = row['poLine']
newRow['orderQty'] = row['orderQty']
newRow['uom'] = row['uom']
tableData.value.push(newRow)
itemCodes.push(row['itemCode'])
})
//
ItembasicApi.getItembasicPage({
code:itemCodes.join(',')
}).then((res)=>{
res.list.forEach((item,index)=>{
const findItem = tableData.value.find(item1=>item1['itemCode']==item['code'])
findItem['expireTime'] = findItem['expireTime']
})
})
}
//
const submitForm = async (formType, data) => {
data.subList = tableData.value //
let isHave = data.subList.some((item) => {
console.log("CCCCC",item.expireDate)
if(item.expireDate != null){
item.produceDate > item.expireDate
}
})
if (isHave) {
message.error('生产日期不可以大于过期日期')
formRef.value.formLoading = false
return
}
try {
if (formType === 'create') {
let planArriveStr = formatDate(data.planArriveTime);
if(planArriveStr > planArriveTimeStr.value){
let confirmFlag = false;
await message.confirm("计划到货时间大于要货计划送达日期是否继续?").then(() => {
console.log("选择了OK")
//OK
}).catch(() => {
//
console.log("选择了cancel")
confirmFlag = true;
formRef.value.formLoading = false
return;
})
if(confirmFlag){
return;
}
}
if(tableData.value.length <= 0){
message.warning(`子表明细不能为空!`)
formRef.value.formLoading = false
return;
}
await SupplierdeliverRequestMainApi.createSupplierdeliverRequestMain(data)
message.success(t('common.createSuccess'))
} else {
await SupplierdeliverRequestMainApi.updateSupplierdeliverRequestMain(data)
message.success(t('common.updateSuccess'))
}
formRef.value.dialogVisible = false
//
getList()
} finally {
formRef.value.formLoading = false
}
}
const formFormDateChange = (field, val,row, index) => {
if(field == 'produceDate'){
let produceDateStr = formatDate(val,'YYYYMMDD');
row.batch = produceDateStr
row.supplierBatch = produceDateStr
}
}
//
const onEnter = async (field,value)=>{
console.log(field,value)
formRef.value.opensearchTable('supplierCode', 'code', '供应商信息', Supplier.allSchemas, SupplierApi.getSupplierPage,[{
key:'code',
value:value
}])
}
defineExpose({ openForm , openFormByCreate}) // open
</script>
<style lang="scss" scoped></style>
Loading…
Cancel
Save