|
@@ -3,24 +3,22 @@ import { ref, reactive, nextTick } from 'vue'
|
|
|
import Drawer from '@/components/Drawer/index.vue'
|
|
|
import Dialog from '@/components/dialog/Dialog.vue'
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
|
|
-// import type { TableColumnCtx } from 'element-plus'
|
|
|
import { Delete } from '@element-plus/icons-vue'
|
|
|
import { GlobalStore } from '@/stores/index'
|
|
|
-import TableBase from '@/components/TableBase/index.vue'
|
|
|
import Upload from '@/components/Upload/index.vue'
|
|
|
import {
|
|
|
Storehouse_Contract_Add,
|
|
|
Storehouse_Product_List,
|
|
|
- Storehouse_IotCard_Edit,
|
|
|
+ Storehouse_Contract_Edit,
|
|
|
Storehouse_ProductClass_List,
|
|
|
Storehouse_Product_Model_List,
|
|
|
- Storehouse_Product_Name_List
|
|
|
+ Storehouse_Product_Name_List,
|
|
|
+ Storehouse_Contract_Product_List
|
|
|
} from '@/api/storehouse/index'
|
|
|
-import { debounce } from '@/utils/common'
|
|
|
-import { ElMessageBox, ElMessage } from 'element-plus'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
import { default as vElTableInfiniteScroll } from 'el-table-infinite-scroll'
|
|
|
-import { log } from 'console'
|
|
|
|
|
|
+let selectProductData: any[] = []
|
|
|
const isNew = ref(true)
|
|
|
const globalStore = GlobalStore()
|
|
|
const formLabelWidth = ref('120px')
|
|
@@ -52,12 +50,14 @@ const rules = reactive<FormRules>({
|
|
|
|
|
|
const callbackDrawer = (done: Fn) => {
|
|
|
resetForm(ruleFormRef.value)
|
|
|
+ isNew.value = true
|
|
|
done()
|
|
|
}
|
|
|
const callbackProductDrawer = (done: Fn) => done()
|
|
|
|
|
|
const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
if (!formEl) return
|
|
|
+ tableData.value = []
|
|
|
formEl.resetFields()
|
|
|
}
|
|
|
|
|
@@ -66,7 +66,7 @@ const emit = defineEmits<{ (event: 'onTableList'): void }>()
|
|
|
|
|
|
// 添加仓库名称
|
|
|
interface FormType {
|
|
|
- T_id: string
|
|
|
+ // T_id: string
|
|
|
T_number: string
|
|
|
T_customer: string
|
|
|
T_type: any
|
|
@@ -78,7 +78,7 @@ interface FormType {
|
|
|
}
|
|
|
type Fn = () => void
|
|
|
const form = reactive<FormType>({
|
|
|
- T_id: '',
|
|
|
+ // T_id: '',
|
|
|
T_number: '',
|
|
|
T_customer: '',
|
|
|
T_type: '',
|
|
@@ -90,17 +90,46 @@ const form = reactive<FormType>({
|
|
|
})
|
|
|
|
|
|
const openDrawer = (type: string, row?: any) => {
|
|
|
- console.log(type, row)
|
|
|
isNew.value = type === 'new' ? true : false
|
|
|
- // nextTick(() => {
|
|
|
- // form.T_id = row.Id
|
|
|
- // form.T_sn = row.T_sn
|
|
|
- // form.T_type = row.T_type
|
|
|
- // form.T_state = row.T_State
|
|
|
- // form.T_iccid = row.T_iccid
|
|
|
- // })
|
|
|
+ if (!isNew.value) {
|
|
|
+ nextTick(() => {
|
|
|
+ editDataEcho(row)
|
|
|
+ })
|
|
|
+ }
|
|
|
drawerRef.value?.openDrawer()
|
|
|
}
|
|
|
+// edit data echo
|
|
|
+const editDataEcho = async (row: any) => {
|
|
|
+ // console.log(row)
|
|
|
+ // form.T_id = row.Id
|
|
|
+ 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_number = row.T_number
|
|
|
+ form.T_customer = row.T_customer
|
|
|
+
|
|
|
+ const res: any = await Storehouse_Contract_Product_List({
|
|
|
+ User_tokey: globalStore.GET_User_tokey,
|
|
|
+ T_number: row.T_number
|
|
|
+ })
|
|
|
+ if (res.Code === 200) {
|
|
|
+ res.Data &&
|
|
|
+ (tableData.value = res.Data.map((item: any) => {
|
|
|
+ item.Id = item.T_product_id
|
|
|
+ item.T_img = item.T_product_img
|
|
|
+ item.T_name = item.T_product_name
|
|
|
+ item.T_class_name = item.T_product_class_name
|
|
|
+ item.T_model = item.T_product_model
|
|
|
+ item.T_spec = item.T_product_spec
|
|
|
+ item.T_relation_sn = item.T_product_relation_sn
|
|
|
+ item.count = item.T_product_total
|
|
|
+ return item
|
|
|
+ }))
|
|
|
+ selectProductData = tableData.value
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
const blurHandle = () => {
|
|
|
form.T_product = tableData.value.map(item => {
|
|
@@ -108,34 +137,33 @@ const blurHandle = () => {
|
|
|
return `${item.Id},${item.count}`
|
|
|
})
|
|
|
}
|
|
|
-const deleteProduct = (id: number) => {
|
|
|
- tableData.value = tableData.value.filter(item => item.Id !== id)
|
|
|
- console.log(id)
|
|
|
+const deleteProduct = (row: any) => {
|
|
|
+ tableData.value = tableData.value.filter(item => item.Id !== row.Id)
|
|
|
|
|
|
- selectTable.value?.toggleRowSelection([tableData.value[1]])
|
|
|
+ // 设置产品的选中
|
|
|
+ selectTable.value?.toggleRowSelection(row, false)
|
|
|
}
|
|
|
|
|
|
const AddContract = (formEl: FormInstance | undefined) => {
|
|
|
if (!formEl) return
|
|
|
- // form.T_product = tableData.value.map(item => {
|
|
|
- // if (!item.count) return undefined
|
|
|
- // return `${item.Id},${item.count}`
|
|
|
- // })
|
|
|
-
|
|
|
formEl.validate(async valid => {
|
|
|
if (valid) {
|
|
|
let res: any = {}
|
|
|
+ let product = ''
|
|
|
+ tableData.value.forEach(item => {
|
|
|
+ product += `${item.Id},${item.count}|`
|
|
|
+ })
|
|
|
if (isNew.value) {
|
|
|
- console.log(form)
|
|
|
res = await Storehouse_Contract_Add({
|
|
|
...form,
|
|
|
User_tokey: globalStore.GET_User_tokey,
|
|
|
- T_product: form.T_product.toString()
|
|
|
+ T_product: product
|
|
|
})
|
|
|
} else {
|
|
|
- res = await Storehouse_IotCard_Edit({
|
|
|
- User_tokey: globalStore.GET_User_tokey,
|
|
|
- ...form
|
|
|
+ res = await Storehouse_Contract_Edit({
|
|
|
+ ...form,
|
|
|
+ T_product: product,
|
|
|
+ User_tokey: globalStore.GET_User_tokey
|
|
|
})
|
|
|
}
|
|
|
if (res.Code === 200) {
|
|
@@ -199,7 +227,14 @@ const getRowKey = (row: any) => {
|
|
|
}
|
|
|
// 选中的产品
|
|
|
const ProductselectionChange = (row: any[]) => {
|
|
|
- tableData.value = row
|
|
|
+ if (!isNew.value) {
|
|
|
+ const newProduct = row.find(
|
|
|
+ (product: any) => tableData.value.findIndex((item: any) => item.Id === product.Id) === -1
|
|
|
+ )
|
|
|
+ newProduct && tableData.value.push({ ...newProduct })
|
|
|
+ } else {
|
|
|
+ tableData.value = row
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 加载第二个抽屉数据
|
|
@@ -215,9 +250,16 @@ let total = 0
|
|
|
const tableProductData = ref<any[]>([])
|
|
|
const getProductList = async () => {
|
|
|
const res: any = await Storehouse_Product_List({ ...initParam, T_name: autoSelect.value })
|
|
|
- console.log(res)
|
|
|
tableProductData.value.push(...res.Data.Data)
|
|
|
total = res.Data.Num
|
|
|
+ if (!isNew.value) {
|
|
|
+ // 设置产品的选中
|
|
|
+ tableProductData.value.forEach((row: any) => {
|
|
|
+ const matchedIndex = selectProductData.findIndex((item: any) => item.Id == row.Id)
|
|
|
+
|
|
|
+ selectTable.value?.toggleRowSelection(row, matchedIndex != -1)
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const tableData = ref<any[]>([])
|
|
@@ -230,7 +272,6 @@ const columns = [
|
|
|
{ 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' },
|
|
|
- { label: '备注', prop: 'T_remark', align: 'center ' },
|
|
|
{ prop: 'operation', label: '操作', width: 80, fixed: 'right' }
|
|
|
]
|
|
|
|
|
@@ -291,16 +332,23 @@ defineExpose({
|
|
|
<el-input
|
|
|
v-model="form.T_number"
|
|
|
type="text"
|
|
|
+ :disabled="!isNew"
|
|
|
autocomplete="off"
|
|
|
- placeholder="请输入物联网卡号"
|
|
|
+ placeholder="请输入合同编号"
|
|
|
class="w-50"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="客户名称:" :label-width="formLabelWidth" prop="T_customer">
|
|
|
- <el-input v-model="form.T_customer" type="text" autocomplete="off" placeholder="请输入型号" class="w-50" />
|
|
|
+ <el-input
|
|
|
+ v-model="form.T_customer"
|
|
|
+ type="text"
|
|
|
+ autocomplete="off"
|
|
|
+ placeholder="请输入客户名称"
|
|
|
+ class="w-50"
|
|
|
+ />
|
|
|
</el-form-item>
|
|
|
<el-form-item label="合同类型:" :label-width="formLabelWidth" prop="T_type">
|
|
|
- <el-select v-model="form.T_type" class="w-50" clearable placeholder="请选择~">
|
|
|
+ <el-select v-model="form.T_type" class="w-50" clearable :disabled="!isNew" placeholder="请选择合同类型~">
|
|
|
<el-option label="销售合同" :value="1" />
|
|
|
<el-option label="验证合同" :value="2" />
|
|
|
</el-select>
|
|
@@ -339,9 +387,7 @@ defineExpose({
|
|
|
</el-table-column>
|
|
|
<el-table-column v-bind="item" v-if="item.fixed === 'right'">
|
|
|
<template #default="{ row }">
|
|
|
- <el-button link type="danger" size="small" :icon="Delete" @click="deleteProduct(row.Id)"
|
|
|
- >删除</el-button
|
|
|
- >
|
|
|
+ <el-button link type="danger" size="small" :icon="Delete" @click="deleteProduct(row)">删除</el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</template>
|
|
@@ -395,14 +441,14 @@ defineExpose({
|
|
|
<el-divider>
|
|
|
<el-button>取消</el-button>
|
|
|
<el-button v-if="isNew" color="#626aef" @click="AddContract(ruleFormRef)">提交</el-button>
|
|
|
- <el-button v-else color="#626aef">修改</el-button>
|
|
|
+ <el-button v-else color="#626aef" @click="AddContract(ruleFormRef)">修改</el-button>
|
|
|
</el-divider>
|
|
|
</div>
|
|
|
<Drawer ref="drawerProductRef" :handleClose="callbackProductDrawer" size="70%">
|
|
|
<template #header="{ params }">
|
|
|
<h4 :id="params.titleId" :class="params.titleClass">选择产品</h4>
|
|
|
</template>
|
|
|
- <el-card class="box-card">
|
|
|
+ <el-card class="box-card" shadow="never">
|
|
|
<template #header>
|
|
|
<div class="input-suffix">
|
|
|
<el-row :gutter="20" style="margin-bottom: 0">
|
|
@@ -441,7 +487,6 @@ defineExpose({
|
|
|
</template>
|
|
|
<el-table
|
|
|
ref="selectTable"
|
|
|
- border
|
|
|
:row-key="getRowKey"
|
|
|
:data="tableProductData"
|
|
|
style="width: 100%; height: 99%"
|