|
@@ -0,0 +1,92 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <el-table ref="productTableRef" :data="productTable" border :row-class-name="tableRowClassName"
|
|
|
+ @row-click="tableRowItem" style="width: 100%;height: 200px">
|
|
|
+ <el-table-column label="序号" width="80">
|
|
|
+ <template #default="scope">
|
|
|
+ <span>{{ scope.$index + 1 }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="productName" label="产品名称" width="180">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-select v-model="productTable[scope.$index].productName" placeholder="请选择"
|
|
|
+ v-if="productTableIndex == scope.$index" clearable @clear="clearTableItem(scope.$index)"
|
|
|
+ @change="selectChange(scope.$index, productTable[scope.$index].productName)">
|
|
|
+ <el-option v-for="item in productArrar" :key="item.id" :label="item.productName" :value="item.id" />
|
|
|
+ </el-select>
|
|
|
+ <span v-else>{{ productTable[scope.$index].productName }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="productType" label="产品类型" width="180"></el-table-column>
|
|
|
+ <el-table-column prop="unit" label="单位" width="80"></el-table-column>
|
|
|
+ <el-table-column prop="price" label="标准价格" width="120"></el-table-column>
|
|
|
+ <el-table-column prop="stock" label="库存" width="80"></el-table-column>
|
|
|
+ <el-table-column prop="sellingPrice" label="售价" width="180">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-input-number v-model="productTable[scope.$index].sellingPrice" class="mx-4" :min="0" :max="100000000" controls-position="right" v-if="productTableIndex == scope.$index" />
|
|
|
+ <span v-else>{{ productTable[scope.$index].sellingPrice }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="quantity" label="数量" width="180">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-input-number v-model="productTable[scope.$index].quantity" class="mx-4" :min="0" :max="100000000" controls-position="right" v-if="productTableIndex == scope.$index" />
|
|
|
+ <span v-else>{{ productTable[scope.$index].quantity }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="discount" label="折扣(%)" width="180">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-input-number v-model="productTable[scope.$index].discount" class="mx-4" :min="0" :max="100" controls-position="right" v-if="productTableIndex == scope.$index" />
|
|
|
+ <span v-else>{{ productTable[scope.$index].discount }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="total" label="合计" width="180"></el-table-column>
|
|
|
+ <el-table-column label="操作" fixed="right" width="120">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-button link type="primary" size="large" @click.stop="addTableItem(scope.$index)">添加</el-button>
|
|
|
+ <el-button link type="danger" size="large" v-if="productTable.length > 1"
|
|
|
+ @click.stop="deteleTableItem(scope.$index)">删除</el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import { ref, reactive, onMounted, inject } from "vue";
|
|
|
+
|
|
|
+const productTable: any = ref([{}])
|
|
|
+const productTableIndex = ref(0) // 可以编辑索引
|
|
|
+const productArrar = ref([
|
|
|
+ { id: 1, productName: '产品1', productType: '类别1', unit: '台', price: '1122', stock: '100', sellingPrice: 0, quantity: 0, discount: 0, total: '' },
|
|
|
+ { id: 2, productName: '产品2', productType: '类别2', unit: '台', price: '2211', stock: '300', sellingPrice: 0, quantity: 0, discount: 0, total: '' },
|
|
|
+])
|
|
|
+
|
|
|
+function selectChange(index: number, val: number | string) {
|
|
|
+ let newObj = productArrar.value.find((item: any) => item.id == val)
|
|
|
+ console.log(newObj)
|
|
|
+ productTable.value.splice(index, 1, newObj)
|
|
|
+}
|
|
|
+
|
|
|
+function tableRowItem(row: any) {
|
|
|
+ productTableIndex.value = row.index
|
|
|
+}
|
|
|
+
|
|
|
+function tableRowClassName({ row, rowIndex, }: { row: any, rowIndex: number }) {
|
|
|
+ row.index = rowIndex
|
|
|
+ return ''
|
|
|
+}
|
|
|
+
|
|
|
+function addTableItem(index: number) {
|
|
|
+ productTable.value.splice(index + 1, 0, {})
|
|
|
+}
|
|
|
+
|
|
|
+function clearTableItem(index: number) {
|
|
|
+ productTable.value.splice(index, 0, {})
|
|
|
+}
|
|
|
+
|
|
|
+function deteleTableItem(index: number) {
|
|
|
+ productTable.value.splice(index, 1)
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped></style>
|