255 lines
6.2 KiB
Vue
255 lines
6.2 KiB
Vue
<!-- 编辑弹窗 -->
|
|
<template>
|
|
<ele-modal
|
|
:width="800"
|
|
:visible="visible"
|
|
:maskClosable="false"
|
|
:maxable="maxable"
|
|
title="生成IC卡"
|
|
:body-style="{ paddingBottom: '28px' }"
|
|
@update:visible="updateVisible"
|
|
@ok="save"
|
|
>
|
|
<a-form
|
|
ref="formRef"
|
|
:model="form"
|
|
:rules="rules"
|
|
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
|
|
:wrapper-col="
|
|
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
|
|
"
|
|
>
|
|
<a-form-item label="生成数量" name="makeNum">
|
|
<a-input-number
|
|
:min="1"
|
|
style="width: 300px;"
|
|
allow-clear
|
|
placeholder="请输入生成数量"
|
|
v-model:value="form.makeNum"
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="绑定用户">
|
|
<a-space v-if="form.phone">
|
|
<p>{{ form.username }}/{{ form.phone }}</p>
|
|
<a-button type="link" @click="clearBindCard">取消绑定</a-button>
|
|
</a-space>
|
|
<ThinkSelectUsers @done="changeBindCard" />
|
|
</a-form-item>
|
|
<a-form-item label="选择VIP卡" name="vid">
|
|
<a-select v-model:value="form.vid" show-search optionFilterProp="label">
|
|
<a-select-option v-for="(item, index) in vipList" :key="index" :value="item.id" :label="item.name">{{ item.name }}</a-select-option>
|
|
</a-select>
|
|
</a-form-item>
|
|
<a-form-item label="到期时间" name="expireTime">
|
|
<a-date-picker
|
|
placeholder="请选择到期时间"
|
|
value-format="YYYY-MM-DD"
|
|
v-model:value="expireTime"
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="凭证" name="expireTime">
|
|
<SelectFile
|
|
:placeholder="`请选择凭证`"
|
|
:limit="1"
|
|
:data="photo"
|
|
@done="chooseFile"
|
|
@del="onDeleteItem"
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="备注" name="remark">
|
|
<a-input
|
|
allow-clear
|
|
placeholder="请输入备注"
|
|
v-model:value="form.remark"
|
|
/>
|
|
</a-form-item>
|
|
</a-form>
|
|
</ele-modal>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref, reactive, watch } from "vue";
|
|
import { Form, message } from "ant-design-vue";
|
|
import { assignObject } from "ele-admin-pro";
|
|
import { makeThinkCard } from "@/api/think/thinkCard";
|
|
import { ThinkCard } from "@/api/think/thinkCard/model";
|
|
import { useThemeStore } from "@/store/modules/theme";
|
|
import { storeToRefs } from "pinia";
|
|
import { FormInstance } from "ant-design-vue/es/form";
|
|
import { ThinkVip } from "@/api/think/thinkVip/model";
|
|
import { listThinkVip } from "@/api/think/thinkVip";
|
|
import { FileRecord } from "@/api/system/file/model";
|
|
import { ItemType } from "ele-admin-pro/es/ele-image-upload/types";
|
|
import dayjs from "dayjs";
|
|
|
|
// 是否是修改
|
|
const isUpdate = ref(false);
|
|
const useForm = Form.useForm;
|
|
// 是否开启响应式布局
|
|
const themeStore = useThemeStore();
|
|
const { styleResponsive } = storeToRefs(themeStore);
|
|
|
|
const props = defineProps<{
|
|
// 弹窗是否打开
|
|
visible: boolean;
|
|
// 修改回显的数据
|
|
data?: ThinkCard | null;
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
(e: "done"): void;
|
|
(e: "update:visible", visible: boolean): void;
|
|
}>();
|
|
|
|
// 提交状态
|
|
const loading = ref(false);
|
|
// 是否显示最大化切换按钮
|
|
const maxable = ref(true);
|
|
// 表格选中数据
|
|
const formRef = ref<FormInstance | null>(null);
|
|
|
|
// 用户信息
|
|
const form = reactive<ThinkCard>({
|
|
id: undefined,
|
|
sid: undefined,
|
|
makeNum: undefined,
|
|
uid: 0,
|
|
vid: undefined,
|
|
aid: undefined,
|
|
wechatOrder: undefined,
|
|
code: undefined,
|
|
name: undefined,
|
|
username: "",
|
|
phone: "",
|
|
price: undefined,
|
|
desc: undefined,
|
|
info: undefined,
|
|
discount: undefined,
|
|
count: undefined,
|
|
eachMoney: undefined,
|
|
remainingMoney: undefined,
|
|
number: undefined,
|
|
num: undefined,
|
|
status: undefined,
|
|
term: undefined,
|
|
month: undefined,
|
|
type: undefined,
|
|
cardType: undefined,
|
|
vipType: undefined,
|
|
pic: undefined,
|
|
prices: undefined,
|
|
payType: undefined,
|
|
isIntegral: undefined,
|
|
isInvoice: undefined,
|
|
expireTime: undefined,
|
|
urgentName: undefined,
|
|
urgentPhone: undefined,
|
|
cardNum: undefined,
|
|
password: undefined,
|
|
useTime: undefined,
|
|
createTime: undefined,
|
|
updateTime: undefined,
|
|
remark: undefined
|
|
});
|
|
|
|
/* 更新visible */
|
|
const updateVisible = (value: boolean) => {
|
|
emit("update:visible", value);
|
|
};
|
|
|
|
const expireTime = ref<String>("");
|
|
// 表单验证规则
|
|
const rules = reactive({
|
|
vid: [
|
|
{ required: true, message: "请选择VIP卡", trigger: "blur" }
|
|
],
|
|
makeNum: [
|
|
{ required: true, message: "请输入生成数量", trigger: "blur" }
|
|
]
|
|
});
|
|
|
|
const { resetFields } = useForm(form, rules);
|
|
|
|
/* 保存编辑 */
|
|
const save = () => {
|
|
if (!formRef.value) {
|
|
return;
|
|
}
|
|
formRef.value
|
|
.validate()
|
|
.then(() => {
|
|
loading.value = true;
|
|
const formData = {
|
|
...form
|
|
};
|
|
if (!expireTime.value) {
|
|
return message.error("请选择到期时间");
|
|
}
|
|
formData.expireTime = dayjs(expireTime.value).unix()
|
|
makeThinkCard(formData)
|
|
.then((msg) => {
|
|
loading.value = false;
|
|
message.success(msg);
|
|
updateVisible(false);
|
|
emit("done");
|
|
})
|
|
.catch((e) => {
|
|
loading.value = false;
|
|
message.error(e.message);
|
|
});
|
|
})
|
|
.catch(() => {
|
|
});
|
|
};
|
|
|
|
const photo = ref<ItemType[]>([]);
|
|
const chooseFile = (data: FileRecord) => {
|
|
photo.value.push({
|
|
uid: data.id,
|
|
url: data.downloadUrl,
|
|
status: 'done'
|
|
});
|
|
form.pic = data.downloadUrl;
|
|
};
|
|
|
|
const onDeleteItem = (index: number) => {
|
|
photo.value.splice(index, 1);
|
|
form.pic = '';
|
|
};
|
|
|
|
const changeBindCard = (data: any) => {
|
|
form.uid = data.id;
|
|
form.username = data.username;
|
|
form.phone = data.phone;
|
|
};
|
|
|
|
const clearBindCard = () => {
|
|
form.uid = 0;
|
|
form.username = "";
|
|
form.phone = "";
|
|
};
|
|
|
|
const vipList = ref<ThinkVip[]>([]);
|
|
const getVipList = async () => {
|
|
vipList.value = await listThinkVip();
|
|
};
|
|
|
|
watch(
|
|
() => props.visible,
|
|
async (visible) => {
|
|
if (visible) {
|
|
await getVipList();
|
|
if (props.data) {
|
|
assignObject(form, props.data);
|
|
isUpdate.value = true;
|
|
} else {
|
|
isUpdate.value = false;
|
|
}
|
|
} else {
|
|
resetFields();
|
|
}
|
|
},
|
|
{ immediate: true }
|
|
);
|
|
</script>
|