新建公共样式文件夹

master
qiuhongwu 9 months ago
parent 9dcd15c783
commit 0a84a97b79

@ -0,0 +1,269 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="1500">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="模具类型" prop="name">
<el-input v-model="formData.name" placeholder="请输入模具类型" />
</el-form-item>
<el-form-item label="启用状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.HELI_COMMON_STATUS)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-row>
<el-col>
<el-card>
<el-table
:data="formData.productBomItemDOList"
class="xy-table"
@cell-click="handleCellClick"
@cell-blur="handleCellBlur"
>
<el-table-column prop="projectName" label="项目名称">
<template #default="scope">
<el-input v-model="scope.row.projectName" :disabled="!scope.row.editable" />
</template>
</el-table-column>
<el-table-column prop="name" label="商品名称">
<template #default="scope">
<el-input
v-model="scope.row.name"
@click="openshoopname(scope.$index)"
:disabled="!scope.row.editable"
/>
</template>
</el-table-column>
<el-table-column prop="inventoryType" label="存货类型">
<template #default="scope">
<dict-tag
:type="DICT_TYPE.PRODUCT_SAVE_TYPE"
:value="scope.row.inventoryType"
/>
</template>
</el-table-column>
<el-table-column prop="spec" label="规格" />
<el-table-column prop="inventoryUnitId" label="库存单位">
<template #default="scope">
<dict-tag
:type="DICT_TYPE.PRODUCT_INVENTORY_UNIT_ID"
:value="scope.row.inventoryUnitId"
/>
</template>
</el-table-column>
<el-table-column prop="barCode" label="条码" />
<el-table-column prop="unit" width="120" label="操作单位">
<template #default="scope">
<el-select v-model="scope.row.unit" placeholder="" style="width: 100%">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.PRODUCT_INVENTORY_UNIT_ID)"
:key="dict.value"
:label="dict.label"
:value="dict.value.toString()"
/>
</el-select>
</template>
</el-table-column>
<el-table-column prop="proportionNum" width="120" label="比例数量">
<template #default="scope">
<el-input v-model="scope.row.proportionNum" :disabled="!scope.row.editable">
<template #append>{{ scope.row.unit }}</template>
</el-input>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="240">
<template #default="scope">
<el-button
v-if="!scope.row.editable"
type="primary"
size="small"
@click="handleEdit(scope.$index)"
>
编辑
</el-button>
<el-button v-else type="success" size="small" @click="handleSave(scope.$index)">
保存
</el-button>
<el-button class="xy-addbutton" @click="handlefuke(scope.$index,scope.row)"></el-button>
<el-button
link
type="primary"
size="small"
@click.prevent="handleDelete2(scope.$index)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<el-button class="xy-addbutton" @click="onAddItem"></el-button>
</el-card>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import * as MouldTypeApi from '@/api/heli/mouldtype'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
name: undefined,
status: 1,
productBomItemDOList:[
]
})
const formRules = reactive({
name: [{ required: true, message: '模具类型不能为空', trigger: 'blur' }],
status: [{ required: true, message: '启用状态不能为空', trigger: 'blur' }],
})
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
formLoading.value = true
try {
formData.value = await MouldTypeApi.getMouldType(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
await formRef.value.validate()
//
formLoading.value = true
try {
const data = formData.value as unknown as MouldTypeApi.MouldTypeVO
if (formType.value === 'create') {
await MouldTypeApi.createMouldType(data)
message.success(t('common.createSuccess'))
} else {
await MouldTypeApi.updateMouldType(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
name: undefined,
status: 1,
productBomItemDOList:[]
}
formRef.value?.resetFields()
}
const onAddItem = () => {
const newData = {
//
projectName: '--',
name: '--',
productStatus: '--',
spec: '--',
inventoryUnitId: '--',
inventoryType: '--',
barCode: '--',
productTypeId: '--',
unit: [],
editable: true,
productBomItemValueDOList: []
}
formData.value.productBomItemDOList.push(newData)
}
//
const handlefuke = (index,item) => {
const data = formData.value.productBomItemDOList[index]
console.log(index,item);
//
const newData = {
...data,
projectName: item.projectName,
name: item.name,
productStatus: item.productStatus,
spec: item.spec,
inventoryUnitId: item.inventoryUnitId,
inventoryType:item.spec,
barCode: item.spec,
productTypeId: item.spec,
unit: [],
editable: true,
productBomItemValueDOList: [],
}
//
formData.value.productBomItemDOList.push(newData)
}
// / input
const handleEdit = (index) => {
formData.value.productBomItemDOList[index].editable = true
}
const handleSave = (index) => {
formData.value.productBomItemDOList[index].editable = false
}
const handleCellClick = (row, column, event) => {
if (row.editable) {
column.el.querySelector('input').focus()
}
}
const handleCellBlur = (row, column, event) => {
if (row.editable) {
column.el.querySelector('input').blur()
}
}
//
const handleDelete2 = (index: number) => {
formData.value.productBomItemDOList.splice(index, 1)
}
</script>
Loading…
Cancel
Save