|
@@ -1,31 +1,46 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, reactive, nextTick } from 'vue'
|
|
|
-import Drawer from '@/components/Drawer/index.vue'
|
|
|
-import type { FormInstance, FormRules } from 'element-plus'
|
|
|
-import { Delete } from '@element-plus/icons-vue'
|
|
|
-import { GlobalStore } from '@/stores/index'
|
|
|
-import Upload from '@/components/Upload/index.vue'
|
|
|
import {
|
|
|
+ columns,
|
|
|
+ ContractFormType,
|
|
|
+ useTablePublic,
|
|
|
+ columnsRecoveries,
|
|
|
+ labelsRecoveries,
|
|
|
+ columnsInvoice,
|
|
|
+ labelsInvoice
|
|
|
+} from '@/hooks/useTablePublic'
|
|
|
+import {
|
|
|
+ Storehouse_Contract_Get,
|
|
|
Storehouse_Contract_Add,
|
|
|
Storehouse_Contract_Edit,
|
|
|
- Storehouse_Contract_Product_List,
|
|
|
Storehouse_Contract_Gen_Number
|
|
|
} from '@/api/storehouse/index'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
+import TableDetail from './TableDetail.vue'
|
|
|
+import { GlobalStore } from '@/stores/index'
|
|
|
+import { ref, reactive, nextTick } from 'vue'
|
|
|
+import Drawer from '@/components/Drawer/index.vue'
|
|
|
+import { Delete } from '@element-plus/icons-vue'
|
|
|
+import Upload from '@/components/Upload/index.vue'
|
|
|
import ImageCom from '@/components/Image/index.vue'
|
|
|
-import InStorageProduct from '@/views/storehouse/inventory/InStorageProduct.vue'
|
|
|
+import type { FormInstance, FormRules } from 'element-plus'
|
|
|
import ContractUser from '@/views/storehouse/outStock/receiveUser.vue'
|
|
|
+import InStorageProduct from '@/views/storehouse/inventory/InStorageProduct.vue'
|
|
|
|
|
|
+const isNew = ref(true)
|
|
|
const isProduct = ref(false)
|
|
|
+const tableData = ref<any[]>([])
|
|
|
let selectProductData: any[] = []
|
|
|
-const isNew = ref(true)
|
|
|
const globalStore = GlobalStore()
|
|
|
-const User_tokey = globalStore.GET_User_tokey
|
|
|
const formLabelWidth = ref('120px')
|
|
|
+const { resetForm } = useTablePublic()
|
|
|
const ruleFormRef = ref<FormInstance>()
|
|
|
+const contractNumberLoading = ref(false)
|
|
|
+const User_tokey = globalStore.GET_User_tokey
|
|
|
const drawerRef = ref<InstanceType<typeof Drawer> | null>(null)
|
|
|
const uploadRef = ref<InstanceType<typeof Upload> | null>(null)
|
|
|
const receiveUserdialog = ref<InstanceType<typeof ContractUser> | null>(null)
|
|
|
+const RecoveriesRef = ref<InstanceType<typeof TableDetail> | null>(null)
|
|
|
+const InvoiceRef = ref<InstanceType<typeof TableDetail> | null>(null)
|
|
|
|
|
|
const validate_T_product = (rule: any, value: any, callback: any) => {
|
|
|
if (value === '') {
|
|
@@ -38,56 +53,37 @@ const validate_T_product = (rule: any, value: any, callback: any) => {
|
|
|
}
|
|
|
|
|
|
const rules = reactive<FormRules>({
|
|
|
- T_number: [{ required: true, message: '请输入物联网卡号', trigger: 'blur' }],
|
|
|
+ T_number: [{ required: true, message: '请输入合同编号', trigger: 'blur' }],
|
|
|
T_customer: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
|
|
|
T_type: [{ required: true, message: '请选择合同类型', trigger: 'blur' }],
|
|
|
T_product: [{ validator: validate_T_product, trigger: 'blur' }],
|
|
|
T_money: [{ required: true, message: '请输入合同金额', trigger: 'blur' }],
|
|
|
- T_date: [{ required: true, message: '请选择业务日期', trigger: 'blur' }]
|
|
|
+ T_date: [{ required: true, message: '请选择签订时间', trigger: 'blur' }],
|
|
|
+ T_submit: [{ required: true, message: '请选择合同负责人', trigger: 'change' }],
|
|
|
+ T_submit_name: [{ required: true, message: '请输入项目名称', trigger: 'blur' }]
|
|
|
})
|
|
|
|
|
|
const callbackDrawer = (done: () => void) => {
|
|
|
- resetForm(ruleFormRef.value)
|
|
|
- isNew.value = true
|
|
|
- selectProductData = []
|
|
|
- drawerProductRef.value?.clearSelection()
|
|
|
- isProduct.value = false
|
|
|
+ closeCancle()
|
|
|
done()
|
|
|
}
|
|
|
|
|
|
-const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
- if (!formEl) return
|
|
|
- tableData.value = []
|
|
|
- formEl.resetFields()
|
|
|
-}
|
|
|
-
|
|
|
// 父级方法
|
|
|
const emit = defineEmits<{ (event: 'onTableList'): void }>()
|
|
|
|
|
|
-interface FormType {
|
|
|
- T_uuid: string
|
|
|
- T_number: string
|
|
|
- T_customer: string
|
|
|
- T_type: any
|
|
|
- T_product: any
|
|
|
- T_money: string
|
|
|
- T_date: string
|
|
|
- T_remark: string
|
|
|
- T_pdf: string
|
|
|
- T_submit: string
|
|
|
-}
|
|
|
-
|
|
|
-const form = reactive<FormType>({
|
|
|
+const form = reactive<ContractFormType>({
|
|
|
T_uuid: '',
|
|
|
T_number: '',
|
|
|
T_customer: '',
|
|
|
- T_type: '',
|
|
|
T_product: '',
|
|
|
T_money: '',
|
|
|
T_date: '',
|
|
|
T_remark: '',
|
|
|
T_pdf: '',
|
|
|
- T_submit: ''
|
|
|
+ T_submit: '',
|
|
|
+ T_recoveries: '',
|
|
|
+ T_invoice: '',
|
|
|
+ T_submit_name: ''
|
|
|
})
|
|
|
|
|
|
const openDrawer = (type: string, row?: any) => {
|
|
@@ -101,21 +97,23 @@ const openDrawer = (type: string, row?: any) => {
|
|
|
}
|
|
|
// edit data echo
|
|
|
const editDataEcho = async (row: any) => {
|
|
|
+ form.T_uuid = row.T_submit
|
|
|
form.T_pdf = row.T_pdf
|
|
|
form.T_date = row.T_date
|
|
|
- form.T_type = row.T_type
|
|
|
form.T_money = row.T_money
|
|
|
- form.T_remark = row.T_remark
|
|
|
+ form.T_submit = row.T_submit_name
|
|
|
form.T_number = row.T_number
|
|
|
form.T_customer = row.T_customer
|
|
|
|
|
|
- const res: any = await Storehouse_Contract_Product_List({
|
|
|
+ const res: any = await Storehouse_Contract_Get({
|
|
|
User_tokey,
|
|
|
T_number: row.T_number
|
|
|
})
|
|
|
if (res.Code === 200) {
|
|
|
- res.Data &&
|
|
|
- (tableData.value = res.Data.map((item: any) => {
|
|
|
+ const { T_Product, T_invoice, T_recoveries, T_remark } = res.Data
|
|
|
+ form.T_remark = T_remark
|
|
|
+ T_Product &&
|
|
|
+ (tableData.value = T_Product.map((item: any) => {
|
|
|
item.Id = item.T_product_id
|
|
|
item.T_img = item.T_product_img
|
|
|
item.T_name = item.T_product_name
|
|
@@ -127,6 +125,8 @@ const editDataEcho = async (row: any) => {
|
|
|
return item
|
|
|
}))
|
|
|
selectProductData = tableData.value
|
|
|
+ T_invoice && InvoiceRef.value?.setMoneyDeatil(T_invoice)
|
|
|
+ T_recoveries && RecoveriesRef.value?.setMoneyDeatil(T_recoveries)
|
|
|
blurHandle()
|
|
|
}
|
|
|
}
|
|
@@ -144,21 +144,35 @@ const deleteProduct = (row: any) => {
|
|
|
drawerProductRef.value?.selectTableChange(row)
|
|
|
}
|
|
|
|
|
|
+const getMontageStr = (arr: any[], value1: string, value2: string): string => {
|
|
|
+ let str = ''
|
|
|
+ arr.forEach(item => {
|
|
|
+ str += `${item[value1]},${item[value2]}|`
|
|
|
+ })
|
|
|
+ return str
|
|
|
+}
|
|
|
+
|
|
|
+const getFomrParams = () => {
|
|
|
+ const recoveriesData = RecoveriesRef.value?.getMoneyDeatil()
|
|
|
+ const invoiceData = InvoiceRef.value?.getMoneyDeatil()
|
|
|
+ if (recoveriesData?.length) form.T_recoveries = getMontageStr(recoveriesData, 'T_date', 'T_money')
|
|
|
+ if (invoiceData?.length) form.T_invoice = getMontageStr(invoiceData, 'T_date', 'T_money')
|
|
|
+ const product = getMontageStr(tableData.value, 'Id', 'count')
|
|
|
+ const params = {
|
|
|
+ ...form,
|
|
|
+ User_tokey,
|
|
|
+ T_submit: form.T_uuid,
|
|
|
+ T_product: product
|
|
|
+ }
|
|
|
+ return params
|
|
|
+}
|
|
|
+
|
|
|
const AddContract = (formEl: FormInstance | undefined) => {
|
|
|
if (!formEl) return
|
|
|
formEl.validate(async valid => {
|
|
|
if (valid) {
|
|
|
let res: any = {}
|
|
|
- let product = ''
|
|
|
- tableData.value.forEach(item => {
|
|
|
- product += `${item.Id},${item.count}|`
|
|
|
- })
|
|
|
- const params = {
|
|
|
- ...form,
|
|
|
- User_tokey,
|
|
|
- T_submit: form.T_uuid,
|
|
|
- T_product: product
|
|
|
- }
|
|
|
+ const params = getFomrParams()
|
|
|
if (isNew.value) {
|
|
|
res = await Storehouse_Contract_Add(params)
|
|
|
} else {
|
|
@@ -167,31 +181,14 @@ const AddContract = (formEl: FormInstance | undefined) => {
|
|
|
if (res.Code === 200) {
|
|
|
ElMessage.success(`${isNew.value ? '添加' : '修改'}合同成功!!`)
|
|
|
nextTick(() => {
|
|
|
- drawerRef.value?.closeDrawer()
|
|
|
+ closeCancle()
|
|
|
emit('onTableList')
|
|
|
- resetForm(ruleFormRef.value)
|
|
|
- isNew.value = true
|
|
|
})
|
|
|
}
|
|
|
- } else {
|
|
|
- return false
|
|
|
- }
|
|
|
+ } else false
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-const tableData = ref<any[]>([])
|
|
|
-const columns = [
|
|
|
- { type: 'index', label: '序号', width: 80, align: 'center ' },
|
|
|
- { label: '产品图片', prop: 'T_img', align: 'center ', name: 'T_img' },
|
|
|
- { label: '产品名称', prop: 'T_name', align: 'center ' },
|
|
|
- { label: '产品分类', prop: 'T_class_name', align: 'center ' },
|
|
|
- { label: '产品型号', prop: 'T_model', align: 'center ' },
|
|
|
- { label: '产品规格', prop: 'T_spec', align: 'center ' },
|
|
|
- { label: '是否关联SN', prop: 'T_relation_sn', align: 'center ', width: 120, name: 'T_relation_sn' },
|
|
|
- { label: '*数量', prop: 'count', align: 'center ', name: 'count' },
|
|
|
- { prop: 'operation', label: '操作', width: 80, fixed: 'right' }
|
|
|
-]
|
|
|
-
|
|
|
const drawerProductRef = ref<InstanceType<typeof InStorageProduct> | null>(null)
|
|
|
/**
|
|
|
* 添加产品
|
|
@@ -218,9 +215,18 @@ const ProductselectionChange = (row: any) => {
|
|
|
* 全选
|
|
|
*/
|
|
|
const ProductSelectionAllChange = (selection: any[]) => (tableData.value = selection)
|
|
|
+/**
|
|
|
+ * 生成合同编号
|
|
|
+ */
|
|
|
const getContractNumber = async () => {
|
|
|
- const res: any = await Storehouse_Contract_Gen_Number({ User_tokey })
|
|
|
- if (res.Code === 200) form.T_number = res.Data
|
|
|
+ contractNumberLoading.value = true
|
|
|
+ const res: any = await Storehouse_Contract_Gen_Number({ User_tokey }).catch(() => {
|
|
|
+ contractNumberLoading.value = false
|
|
|
+ })
|
|
|
+ if (res.Code === 200) {
|
|
|
+ contractNumberLoading.value = false
|
|
|
+ form.T_number = res.Data
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
* 合同负责人
|
|
@@ -230,6 +236,16 @@ const getReceiveInfo = ({ T_uuid, T_name }: { T_uuid: string; T_name: string })
|
|
|
form.T_submit = T_name
|
|
|
form.T_uuid = T_uuid
|
|
|
}
|
|
|
+const closeCancle = () => {
|
|
|
+ resetForm(ruleFormRef.value)
|
|
|
+ isNew.value = isProduct.value = false
|
|
|
+ tableData.value = []
|
|
|
+ selectProductData = []
|
|
|
+ drawerProductRef.value?.clearSelection()
|
|
|
+ RecoveriesRef.value?.clearDetail()
|
|
|
+ InvoiceRef.value?.clearDetail()
|
|
|
+ drawerRef.value?.closeDrawer()
|
|
|
+}
|
|
|
defineExpose({
|
|
|
openDrawer
|
|
|
})
|
|
@@ -242,11 +258,12 @@ defineExpose({
|
|
|
<h4 :id="params.titleId" :class="params.titleClass">{{ isNew ? '添加' : '编辑' }} - 合同</h4>
|
|
|
</template>
|
|
|
<el-form ref="ruleFormRef" :model="form" :rules="rules">
|
|
|
- <el-divider border-style="dashed" />
|
|
|
<el-form-item label="合同编号:" :label-width="formLabelWidth" prop="T_number">
|
|
|
<div>
|
|
|
<el-input v-model="form.T_number" :disabled="!isNew" placeholder="请输入合同编号" class="w-50" />
|
|
|
- <el-button type="primary" @click="getContractNumber">生成合同编号</el-button>
|
|
|
+ <el-button :loading="contractNumberLoading" :disabled="!isNew" type="primary" @click="getContractNumber"
|
|
|
+ >生成合同编号</el-button
|
|
|
+ >
|
|
|
</div>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="客户名称:" :label-width="formLabelWidth" prop="T_customer">
|
|
@@ -310,6 +327,9 @@ defineExpose({
|
|
|
<el-form-item label="合同负责人:" :label-width="formLabelWidth" prop="T_submit">
|
|
|
<el-input v-model="form.T_submit" placeholder="请选择合同负责人" class="w-50" @focus="selectApprover" />
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="项目:" :label-width="formLabelWidth" prop="T_submit_name">
|
|
|
+ <el-input v-model="form.T_submit_name" placeholder="请输入项目名称" class="w-50" />
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="合同备注:" :label-width="formLabelWidth" prop="T_remark">
|
|
|
<el-input
|
|
|
class="w-50"
|
|
@@ -334,15 +354,35 @@ defineExpose({
|
|
|
<template #tip> 只能上传pdf格式文件!!</template>
|
|
|
</Upload>
|
|
|
</el-form-item>
|
|
|
-
|
|
|
- <div class="btn">
|
|
|
- <el-divider>
|
|
|
- <el-button>取消</el-button>
|
|
|
+ <el-form-item label="回款明细:" :label-width="formLabelWidth" prop="T_recoveries">
|
|
|
+ <TableDetail ref="RecoveriesRef" :columns="columnsRecoveries" title="回款明细" :labels="labelsRecoveries">
|
|
|
+ <template #add="{ AddDetail }">
|
|
|
+ <el-button type="primary" @click="AddDetail">
|
|
|
+ <el-icon><Plus /></el-icon><span style="margin-left: 6px">添加</span>
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </TableDetail>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="开票明细:" :label-width="formLabelWidth" prop="T_invoice">
|
|
|
+ <TableDetail ref="InvoiceRef" :columns="columnsInvoice" title="开票明细" :labels="labelsInvoice">
|
|
|
+ <template #add="{ AddDetail }">
|
|
|
+ <el-button type="primary" @click="AddDetail">
|
|
|
+ <el-icon><Plus /></el-icon><span style="margin-left: 6px">添加</span>
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </TableDetail>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <div>
|
|
|
+ <el-divider border-style="dashed" />
|
|
|
+ <div class="btn">
|
|
|
+ <el-button @click="closeCancle">取消</el-button>
|
|
|
<el-button v-if="isNew" color="#626aef" @click="AddContract(ruleFormRef)">提交</el-button>
|
|
|
<el-button v-else color="#626aef" @click="AddContract(ruleFormRef)">修改</el-button>
|
|
|
- </el-divider>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </el-form>
|
|
|
+ </template>
|
|
|
</Drawer>
|
|
|
<ContractUser ref="receiveUserdialog" @onUserInfo="getReceiveInfo" title="合同负责人" />
|
|
|
<InStorageProduct
|