|
|
@@ -1,6 +1,6 @@
|
|
|
<script setup lang="ts">
|
|
|
import {useRouter} from "vue-router";
|
|
|
-import {ref, onMounted} from "vue";
|
|
|
+import {ref, onMounted, computed} from "vue";
|
|
|
import {addStock, getProductById} from "../../api/product.ts";
|
|
|
import {Back, RefreshRight} from "@element-plus/icons-vue";
|
|
|
import {ElTable} from "element-plus";
|
|
|
@@ -35,25 +35,28 @@ let orderDialogVisible = ref(false)
|
|
|
const orderId = ref()
|
|
|
const couponId = ref(0)
|
|
|
|
|
|
-getProductDetail()
|
|
|
-
|
|
|
-function getProductDetail() {
|
|
|
- getProductById(productId).then(res => {
|
|
|
- productVO.value = res.result
|
|
|
- storeId.value = productVO.value.storeId
|
|
|
- name.value = productVO.value.name
|
|
|
- photoUrlList.value = productVO.value.photoUrlList
|
|
|
- rating.value = productVO.value.rating
|
|
|
- number.value = productVO.value.number
|
|
|
- salesAmount.value = productVO.value.salesAmount
|
|
|
- stock.value = productVO.value.stock
|
|
|
- category.value = productVO.value.category
|
|
|
- price.value = productVO.value.price
|
|
|
-
|
|
|
- photoUrl.value = photoUrlList.value[0]
|
|
|
- totalPrice.value = price.value
|
|
|
- })
|
|
|
-}
|
|
|
+const hasTypeInput = computed(() => type.value != '')
|
|
|
+const typeLegal = hasTypeInput
|
|
|
+
|
|
|
+const createDisabled = computed(() => {
|
|
|
+ return !(nameLegal.value && locationLegal.value && imageFileList.value);
|
|
|
+})
|
|
|
+
|
|
|
+getProductById(productId).then(res => {
|
|
|
+ productVO.value = res.result
|
|
|
+ storeId.value = productVO.value.storeId
|
|
|
+ name.value = productVO.value.name
|
|
|
+ photoUrlList.value = productVO.value.photoUrlList
|
|
|
+ rating.value = productVO.value.rating
|
|
|
+ number.value = productVO.value.number
|
|
|
+ salesAmount.value = productVO.value.salesAmount
|
|
|
+ stock.value = productVO.value.stock
|
|
|
+ category.value = productVO.value.category
|
|
|
+ price.value = productVO.value.price
|
|
|
+
|
|
|
+ photoUrl.value = photoUrlList.value[0]
|
|
|
+ totalPrice.value = price.value
|
|
|
+})
|
|
|
|
|
|
function parseCategory(category) {
|
|
|
if (category === 'FOOD') {
|
|
|
@@ -135,26 +138,19 @@ const isLoading = ref(false)
|
|
|
const refreshButtonVisible = ref(false)
|
|
|
|
|
|
function handleConfirmOrder() {
|
|
|
- isLoading.value = true
|
|
|
- refreshButtonVisible.value = true
|
|
|
payOrder(orderId.value, couponId.value).then(res => {
|
|
|
- const paymentWindow = window.open('', '_blank');
|
|
|
- paymentWindow.document.write(res);
|
|
|
- paymentWindow.document.forms[0].submit(); // 提交表单
|
|
|
- showForm.value = false; // 隐藏表单
|
|
|
if (res.code === '000') {
|
|
|
ElMessage({
|
|
|
- message: '订单支付成功!',
|
|
|
+ message: '订单提交成功!',
|
|
|
type: 'success',
|
|
|
center: true,
|
|
|
})
|
|
|
- orderDialogVisible.value = false
|
|
|
- amount.value = 1
|
|
|
- type.value = ''
|
|
|
- totalPrice.value = price.value
|
|
|
- couponId.value = 0
|
|
|
- isLoading.value = false
|
|
|
- refreshButtonVisible.value = false
|
|
|
+ isLoading.value = true
|
|
|
+ refreshButtonVisible.value = true
|
|
|
+ const paymentWindow = window.open('', '_blank');
|
|
|
+ paymentWindow.document.write(res.result);
|
|
|
+ paymentWindow.document.forms[0].submit(); // 提交表单
|
|
|
+ showForm.value = false; // 隐藏表单
|
|
|
} else if (res.code === '400') {
|
|
|
ElMessage({
|
|
|
message: res.msg,
|
|
|
@@ -281,23 +277,14 @@ function toBackPage() {
|
|
|
{{ stock }} 件
|
|
|
</el-descriptions-item>
|
|
|
</el-descriptions>
|
|
|
-
|
|
|
- <el-input class="add-stock-number-input" v-if="role === 'STAFF'"
|
|
|
- v-model="addStockNumber" placeholder="请输入添加库存数"/>
|
|
|
- <el-button class="add-stock-button" @click="AddStock" v-if="role === 'STAFF'"
|
|
|
- type="primary" plain>
|
|
|
- 新增库存
|
|
|
- </el-button>
|
|
|
</div>
|
|
|
</el-aside>
|
|
|
|
|
|
- <el-main>
|
|
|
+ <el-main v-if="role === 'CUSTOMER'">
|
|
|
<div>
|
|
|
- <span class="buy-product-title">购买商品</span>
|
|
|
+ <span class="main-title">购买商品</span>
|
|
|
</div>
|
|
|
- <el-form ref="form" v-if="showForm">
|
|
|
- </el-form>
|
|
|
- <el-form class="buy-form-main">
|
|
|
+ <el-form class="buy-form">
|
|
|
<el-form-item>
|
|
|
<label for="amount">购买数量:</label>
|
|
|
<el-input-number v-model="amount" :min="1" :max="stock + 10" @change="handleChange"/>
|
|
|
@@ -317,68 +304,84 @@ function toBackPage() {
|
|
|
{{ totalPrice }} 元
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
- <el-button class="buy-button"
|
|
|
- @click="handleCreateOrder">创建订单
|
|
|
+ <el-button @click="handleCreateOrder" :disabled="createDisabled"
|
|
|
+ class="buy-button" type="primary" plain>创建订单
|
|
|
</el-button>
|
|
|
+ </el-main>
|
|
|
|
|
|
- <el-dialog v-model="orderDialogVisible" :before-close="handlePayDialogClose">
|
|
|
- <el-row>
|
|
|
- <span class="pay-dialog-title">订单支付</span>
|
|
|
- <el-button v-if="refreshButtonVisible" @click="refreshPage()"
|
|
|
- type="primary" plain class="pay-dialog-refresh-button">
|
|
|
- 已完成支付,刷新界面
|
|
|
- <el-icon>
|
|
|
- <RefreshRight/>
|
|
|
- </el-icon>
|
|
|
- </el-button>
|
|
|
- </el-row>
|
|
|
-
|
|
|
- <div v-loading="isLoading">
|
|
|
- <el-form>
|
|
|
- <el-form-item>
|
|
|
- <label for="amount">购买数量:</label>
|
|
|
- {{ amount }} 件
|
|
|
- </el-form-item>
|
|
|
- <el-form-item>
|
|
|
- <label for="discountPrice">折扣前总价:</label>
|
|
|
- {{ totalPrice }} 元
|
|
|
- </el-form-item>
|
|
|
- <el-form-item>
|
|
|
- <label for="type">提货方式:</label>
|
|
|
- {{ parseOrderType(type) }}
|
|
|
- </el-form-item>
|
|
|
- <el-form-item>
|
|
|
- <label for="type">优惠券:</label>
|
|
|
- <el-button @click="setCurrent()">不使用优惠券</el-button>
|
|
|
- <el-table
|
|
|
- ref="singleTableRef"
|
|
|
- :data="availableCouponList"
|
|
|
- highlight-current-row
|
|
|
- style="width: 100%"
|
|
|
- @current-change="handleCurrentChange"
|
|
|
- >
|
|
|
- <el-table-column type="index" width="50"/>
|
|
|
- <el-table-column prop="type" label="类型" width="180">
|
|
|
- <template #default="scope">
|
|
|
- {{ handleCouponType(scope.row.type) }}
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column prop="satisfaction" label="满(元)" width="180"/>
|
|
|
- <el-table-column prop="minus" label="减(元)" width="180"/>
|
|
|
- </el-table>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item>
|
|
|
- <label>折扣后金额:</label>
|
|
|
- {{ discountPrice }} 元
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
-
|
|
|
- <el-button @click="handleConfirmOrder" type="primary" plain>确认支付</el-button>
|
|
|
- </div>
|
|
|
-
|
|
|
- </el-dialog>
|
|
|
+ <el-main v-if="role === 'STAFF'">
|
|
|
+ <div>
|
|
|
+ <span class="main-title">添加库存</span>
|
|
|
+ </div>
|
|
|
+ <div class="add-stock-main">
|
|
|
+ <el-input class="add-stock-number-input"
|
|
|
+ v-model="addStockNumber" placeholder="请输入添加库存数">
|
|
|
+ <template #append>件</template>
|
|
|
+ </el-input>
|
|
|
+ <br>
|
|
|
+ <el-button @click="AddStock"
|
|
|
+ class="add-stock-button" type="primary" plain>
|
|
|
+ 新增库存
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
</el-main>
|
|
|
+
|
|
|
+ <el-dialog v-model="orderDialogVisible" :before-close="handlePayDialogClose">
|
|
|
+ <el-row>
|
|
|
+ <span class="pay-dialog-title">订单支付</span>
|
|
|
+ <el-button v-if="refreshButtonVisible" @click="refreshPage()"
|
|
|
+ type="primary" plain class="pay-dialog-refresh-button">
|
|
|
+ 已完成支付,刷新界面
|
|
|
+ <el-icon>
|
|
|
+ <RefreshRight/>
|
|
|
+ </el-icon>
|
|
|
+ </el-button>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <div v-loading="isLoading">
|
|
|
+ <el-form>
|
|
|
+ <el-form-item>
|
|
|
+ <label for="amount">购买数量:</label>
|
|
|
+ {{ amount }} 件
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <label for="type">提货方式:</label>
|
|
|
+ {{ parseOrderType(type) }}
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <label for="discountPrice">折扣前总价:</label>
|
|
|
+ {{ totalPrice }} 元
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <label for="type">优惠券:</label>
|
|
|
+ <el-button @click="setCurrent()">不使用优惠券</el-button>
|
|
|
+ <el-table
|
|
|
+ ref="singleTableRef"
|
|
|
+ :data="availableCouponList"
|
|
|
+ highlight-current-row
|
|
|
+ style="width: 100%"
|
|
|
+ @current-change="handleCurrentChange"
|
|
|
+ >
|
|
|
+ <el-table-column type="index" width="50"/>
|
|
|
+ <el-table-column prop="type" label="类型" width="180">
|
|
|
+ <template #default="scope">
|
|
|
+ {{ handleCouponType(scope.row.type) }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="satisfaction" label="满(元)" width="180"/>
|
|
|
+ <el-table-column prop="minus" label="减(元)" width="180"/>
|
|
|
+ </el-table>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <label>折扣后金额:</label>
|
|
|
+ {{ discountPrice }} 元
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <el-button @click="handleConfirmOrder" type="primary" plain>确认支付</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
</el-container>
|
|
|
</template>
|
|
|
|
|
|
@@ -410,22 +413,27 @@ function toBackPage() {
|
|
|
}
|
|
|
|
|
|
.add-stock-number-input {
|
|
|
- margin-top: 15px;
|
|
|
- margin-bottom: 10px;
|
|
|
+ width: 300px;
|
|
|
+ margin-bottom: 20px;
|
|
|
}
|
|
|
|
|
|
.add-stock-button {
|
|
|
margin-bottom: 40px;
|
|
|
}
|
|
|
|
|
|
-.buy-product-title {
|
|
|
+.main-title {
|
|
|
font-size: 30px;
|
|
|
margin-top: 20px;
|
|
|
margin-bottom: 20px;
|
|
|
margin-left: 20px;
|
|
|
}
|
|
|
|
|
|
-.buy-form-main {
|
|
|
+.buy-form {
|
|
|
+ margin-top: 20px;
|
|
|
+ margin-left: 30px;
|
|
|
+}
|
|
|
+
|
|
|
+.add-stock-main {
|
|
|
margin-top: 20px;
|
|
|
margin-left: 30px;
|
|
|
}
|