added kashkool
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
@info="info"
|
||||
@edit="edit"
|
||||
@delete="deleteItem"
|
||||
@add="add"
|
||||
@add="addGiftOrDiscount"
|
||||
@giftcardcodes="showGiftCardCodes"
|
||||
/>
|
||||
|
||||
@@ -17,6 +17,40 @@
|
||||
<!-- <BasicShowContext title="پروژه ها"> <Search /> </BasicShowContext>-->
|
||||
</div>
|
||||
</BasicMainCard>
|
||||
<BasicActionSheet
|
||||
v-model:visible="addDiscountVisible"
|
||||
:title="discountSheetTitle"
|
||||
modal-width="30rem"
|
||||
drawer-height="90vh"
|
||||
:loading="loading"
|
||||
:showButton="true"
|
||||
:showCancel="true"
|
||||
:showOk="true"
|
||||
ok-text="ثبت"
|
||||
cancel-text="انصراف"
|
||||
@ok="okDiscount"
|
||||
@close="closeDiscountSheet"
|
||||
@cancel="closeDiscountSheet"
|
||||
>
|
||||
<div v-if="isMobile" class="mb-3 text-base font-700">{{ discountSheetTitle }}</div>
|
||||
<a-form :model="discountForm" ref="discountFormRef" autocomplete="off" layout="vertical">
|
||||
<a-form-item label="نام پویش" name="name" :rules="inputRules()">
|
||||
<BasicInput v-model:value="discountForm.name" placeholder="نام پویش" />
|
||||
</a-form-item>
|
||||
<a-form-item label="درصد تخفیف" name="amount" :rules="inputRulesNumber()">
|
||||
<BasicInput v-model:value="discountForm.amount" type="tel" placeholder="مثلاً 10" addon-before="%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="تعداد کدها" name="count" :rules="inputRulesNumber()">
|
||||
<BasicInput v-model:value="discountForm.count" type="tel" />
|
||||
</a-form-item>
|
||||
<a-form-item label="تاریخ انقضا" name="expiry_date" :rules="inputRules()">
|
||||
<BaseDatePicker v-model:value="discountForm.expiry_date" format="YYYY-MM-DD" />
|
||||
</a-form-item>
|
||||
<a-form-item label="توضیحات" name="description">
|
||||
<BasicTextArea v-model:value="discountForm.description" place-holder="توضیحات اختیاری" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</BasicActionSheet>
|
||||
<BasicActionSheet
|
||||
v-model:visible="addGiftCardVisible"
|
||||
:title="giftCardSheetTitle"
|
||||
@@ -72,6 +106,11 @@ import type { Giftcard, Giftcardcode, GiftcardInput } from '@/model/giftCard'
|
||||
import { createGiftCard } from '@/api/giftCard'
|
||||
import dayjs from 'dayjs'
|
||||
import { isMobile } from '@core/utils/is'
|
||||
import { isStoreApp } from '@/utils/config'
|
||||
import { inputRules, inputRulesNumber } from '@/utils/inputRules'
|
||||
import BasicInput from '@core/components/BasicInput/src/BasicInput.vue'
|
||||
import BasicTextArea from '@core/components/BasicTextArea/src/BasicTextArea.vue'
|
||||
import BaseDatePicker from '@core/components/BaseDatePicker/src/BaseDatePicker.vue'
|
||||
|
||||
//loading
|
||||
const loading = ref<boolean>(false)
|
||||
@@ -89,6 +128,16 @@ const giftCardEditorRef = ref<{
|
||||
}>()
|
||||
|
||||
const giftCardSheetTitle = computed(() => `${editId ? 'ویرایش' : 'افزودن'} کارت هدیه`)
|
||||
const discountSheetTitle = computed(() => `${editId ? 'ویرایش' : 'افزودن'} کد تخفیف`)
|
||||
const addDiscountVisible = ref(false)
|
||||
const discountFormRef = ref<FormInstance>()
|
||||
const discountForm = ref({
|
||||
name: '',
|
||||
count: undefined as number | undefined,
|
||||
amount: undefined as number | undefined,
|
||||
expiry_date: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
function closeGiftCardSheet() {
|
||||
addGiftCardVisible.value = false
|
||||
@@ -125,7 +174,7 @@ function info(val: Giftcard) {
|
||||
},
|
||||
{
|
||||
key: 'نوع کارت هدیه',
|
||||
value: val.unit === 2 ? 'طلایی' : 'ریالی'
|
||||
value: val.unit === 3 ? 'تخفیف' : val.unit === 2 ? 'طلایی' : 'ریالی'
|
||||
},
|
||||
{
|
||||
key: 'تعداد کدها',
|
||||
@@ -194,9 +243,57 @@ async function edit(record: Giftcard) {
|
||||
}
|
||||
}
|
||||
|
||||
function closeDiscountSheet() {
|
||||
addDiscountVisible.value = false
|
||||
}
|
||||
|
||||
function resetDiscountData() {
|
||||
discountForm.value = {
|
||||
name: '',
|
||||
count: undefined,
|
||||
amount: undefined,
|
||||
expiry_date: '',
|
||||
description: ''
|
||||
}
|
||||
}
|
||||
|
||||
async function okDiscount() {
|
||||
await discountFormRef.value?.validateFields?.().then(async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const formData: any = {
|
||||
...discountForm.value,
|
||||
unit: '3',
|
||||
use_once: 0
|
||||
}
|
||||
if (formData.expiry_date) {
|
||||
formData.expiry_date = dayjs(formData.expiry_date)
|
||||
.calendar('gregory')
|
||||
.endOf('day')
|
||||
.format('YYYY-MM-DD HH:mm:ss')
|
||||
}
|
||||
await createGiftCard(formData)
|
||||
message.success('کد تخفیف با موفقیت ثبت شد')
|
||||
addDiscountVisible.value = false
|
||||
resetDiscountData()
|
||||
refreshTable()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
message.error('خطا در ثبت کد تخفیف')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//add
|
||||
async function add() {
|
||||
async function addGiftOrDiscount(type: 'gift' | 'discount' = 'gift') {
|
||||
editId = undefined
|
||||
if (type === 'discount' && isStoreApp()) {
|
||||
resetDiscountData()
|
||||
addDiscountVisible.value = true
|
||||
return
|
||||
}
|
||||
resetData()
|
||||
addGiftCardVisible.value = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user