This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
<!-- 右侧商品列表 -->
|
||||
<scroll-view scroll-y class="product-scroll">
|
||||
<view class="product-list">
|
||||
<view v-for="item in productList" :key="item.productId" class="product-item" @click="openProductDetail(item)">
|
||||
<view v-for="item in productList" :key="item.productId" class="product-item" @click="selectProduct(item)">
|
||||
<view class="product-info">
|
||||
<text class="product-name">{{ item.name }}</text>
|
||||
<view class="product-row">
|
||||
@@ -50,37 +50,6 @@
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 商品详情/选择弹窗 -->
|
||||
<view class="modal-mask" v-if="showModal" @click="closeModal">
|
||||
<view class="modal-content" @click.stop>
|
||||
<view class="modal-header">
|
||||
<text class="modal-title">{{ selectedProduct.name }}</text>
|
||||
<text class="modal-close" @click="closeModal">×</text>
|
||||
</view>
|
||||
<view class="modal-body">
|
||||
<view class="size-row">
|
||||
<view class="size-item">
|
||||
<text class="size-label">长度(cm)</text>
|
||||
<input class="size-input" type="digit" v-model="selectedProduct.length" placeholder="非必填" />
|
||||
</view>
|
||||
<view class="size-item">
|
||||
<text class="size-label">宽度(cm)</text>
|
||||
<input class="size-input" type="digit" v-model="selectedProduct.width" placeholder="非必填" />
|
||||
</view>
|
||||
<view class="size-item">
|
||||
<text class="size-label">面积(m²)</text>
|
||||
<input class="size-input" type="digit" v-model="selectedProduct.area" disabled />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<button class="cancel-btn" @click="closeModal">取消</button>
|
||||
<button class="confirm-btn" @click="confirmProduct">确认</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -95,26 +64,7 @@ export default {
|
||||
productList: [],
|
||||
page: 1,
|
||||
pageSize: 50,
|
||||
loading: false,
|
||||
showModal: false,
|
||||
selectedProduct: {
|
||||
productId: '',
|
||||
name: '',
|
||||
spec: '',
|
||||
unit: '',
|
||||
price: 0,
|
||||
length: '',
|
||||
width: '',
|
||||
area: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'selectedProduct.length'(val) {
|
||||
this.calcArea()
|
||||
},
|
||||
'selectedProduct.width'(val) {
|
||||
this.calcArea()
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
@@ -122,12 +72,6 @@ export default {
|
||||
this.getProducts()
|
||||
},
|
||||
methods: {
|
||||
calcArea() {
|
||||
const length = parseFloat(this.selectedProduct.length) || 0
|
||||
const width = parseFloat(this.selectedProduct.width) || 0
|
||||
// 长度(cm) * 宽度(cm) / 10000 = 面积(m²)
|
||||
this.selectedProduct.area = length && width ? (length * width / 10000).toFixed(2) : ''
|
||||
},
|
||||
async loadCategories() {
|
||||
try {
|
||||
const categories = await productApi.getCategories()
|
||||
@@ -161,31 +105,10 @@ export default {
|
||||
this.page = 1
|
||||
this.getProducts()
|
||||
},
|
||||
openProductDetail(item) {
|
||||
this.selectedProduct = {
|
||||
productId: item.productId,
|
||||
name: item.name,
|
||||
spec: item.spec,
|
||||
unit: item.unit,
|
||||
price: item.price,
|
||||
length: '',
|
||||
width: '',
|
||||
area: ''
|
||||
}
|
||||
this.showModal = true
|
||||
},
|
||||
closeModal() {
|
||||
this.showModal = false
|
||||
},
|
||||
confirmProduct() {
|
||||
selectProduct(item) {
|
||||
const pages = getCurrentPages()
|
||||
const prevPage = pages[pages.length - 2]
|
||||
prevPage.$vm.addProduct({
|
||||
...this.selectedProduct,
|
||||
length: this.selectedProduct.length,
|
||||
width: this.selectedProduct.width,
|
||||
area: this.selectedProduct.area
|
||||
})
|
||||
prevPage.$vm.addProduct(item)
|
||||
uni.navigateBack()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user