Files

261 lines
7.6 KiB
Vue
Raw Normal View History

2022-09-20 17:31:39 +08:00
<template>
<div class="app-container">
<el-card shadow="always" style="width: 55%; margin: 0 auto">
<el-form
ref="formRef"
:model="form"
:rules="rules"
:label-width="labelWidth + 'px'"
>
2023-07-11 17:21:34 +08:00
<p>
<b> {{ t("admin.form.basicInfo") }}</b>
</p>
2022-09-20 17:31:39 +08:00
2022-11-17 17:29:47 +08:00
<!-- <el-row>
2022-09-20 17:31:39 +08:00
<el-col :span="24">
2023-07-17 15:47:45 +08:00
<el-form-item :label="t('admin.form.name', {type:t('admin.common.demand')})" prop="title">
2022-09-20 17:31:39 +08:00
<el-input v-model="form.title"></el-input>
</el-form-item>
</el-col>
2022-11-17 17:29:47 +08:00
</el-row> -->
2022-09-20 17:31:39 +08:00
<el-row>
<el-col :span="24">
2023-07-11 17:21:34 +08:00
<el-form-item
:label="
t('admin.form.category', { type: t('admin.common.demand') })
"
>
2022-09-20 17:31:39 +08:00
<el-checkbox-group v-model="form.kinds">
<el-checkbox
v-for="item in checkList"
:key="item.id"
:label="item.name"
2023-07-17 15:47:45 +08:00
>{{ item.name }}
</el-checkbox>
2022-09-20 17:31:39 +08:00
<!-- <el-checkbox label="0" @change="handleCheck">其他</el-checkbox> -->
</el-checkbox-group>
<el-row :gutter="20">
<el-col :span="20">
<el-input
v-model="checkInput"
placeholder="请输入需求类别"
></el-input>
</el-col>
<el-col :span="4">
<el-button type="primary" @click="addCheck">添加</el-button>
</el-col>
</el-row>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
2023-07-17 15:47:45 +08:00
<el-form-item
:label="t('webSearch.demandDescription')"
prop="description"
>
2022-09-20 17:31:39 +08:00
<!-- <Editor v-model="form.description" :minHeight="150" /> -->
2023-07-27 17:31:39 +08:00
<!-- <wangEditor
v-model="form.description"
width="100%"
min-height="150px"
@blur="formRef.validateField(`description`)"
></wangEditor>-->
<el-input
type="textarea"
2022-09-20 17:31:39 +08:00
v-model="form.description"
2023-07-27 17:31:39 +08:00
:autosize="{ minRows: 6, maxRows: 8 }"
:placeholder="
t('admin.form.placeholder', {
type: t('webSearch.demandDescription'),
})
"
></el-input>
2022-09-20 17:31:39 +08:00
</el-form-item>
</el-col>
</el-row>
2022-11-17 17:29:47 +08:00
<!-- <CityOptions
2022-09-20 17:31:39 +08:00
v-model="form"
:labelWidth="labelWidth"
ref="cityFormRef"
2022-11-17 17:29:47 +08:00
/> -->
2022-09-20 17:31:39 +08:00
<el-row>
<el-col :span="12">
2023-07-17 15:47:45 +08:00
<el-form-item :label="t('admin.form.demandContact')" prop="name">
2022-09-20 17:31:39 +08:00
<el-input
v-model="form.name"
placeholder="请输入需求联系人"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
2023-07-17 15:47:45 +08:00
<el-form-item :label="t('admin.form.contactPhone')" prop="mobile">
2022-09-20 17:31:39 +08:00
<el-input
v-model="form.mobile"
placeholder="请输入联系人手机号"
></el-input>
</el-form-item>
</el-col>
</el-row>
2022-11-17 17:29:47 +08:00
2022-09-20 17:31:39 +08:00
<el-row>
<el-col :span="12">
<el-form-item label="需求提交人:" prop="commitUserName">
<el-input
v-model="form.commitUserName"
placeholder="请输入需求提交人"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="需求提交人手机号:" prop="commitPhone">
<el-input
v-model="form.commitPhone"
placeholder="需求提交人手机号"
></el-input>
</el-form-item>
</el-col>
2022-11-17 17:29:47 +08:00
</el-row>
2022-09-20 17:31:39 +08:00
</el-form>
<div :style="{ marginLeft: labelWidth + 'px' }">
2023-07-17 15:47:45 +08:00
<el-button @click="backToList"
>{{ t("admin.common.cancel") }}
</el-button>
<el-button type="primary" @click="submitForm"
>{{ t("admin.common.submit") }}
</el-button>
2022-09-20 17:31:39 +08:00
</div>
</el-card>
</div>
</template>
<script setup>
2022-10-27 13:39:36 +08:00
// import { insertDemand } from "@/api/admin/enterprise";
2022-11-22 17:31:02 +08:00
import tab from "@/plugins/tab";
2022-10-27 13:39:36 +08:00
import {
insertDemand,
getDemand,
updateDemand,
} from "@/api/admin/enterprise/demand";
2022-11-17 17:29:47 +08:00
// import CityOptions from "@/views/components/CityOptions";
2022-09-20 17:31:39 +08:00
import { ElMessage } from "element-plus";
2023-07-17 15:47:45 +08:00
import { onActivated, onMounted, reactive, toRefs } from "vue";
2022-11-25 17:30:39 +08:00
import { demandCategoryList } from "@/utils/parameter";
2022-11-17 17:29:47 +08:00
// import { onActivated } from "vue";
2022-10-27 13:39:36 +08:00
import { useRoute, useRouter } from "vue-router";
2023-07-17 15:47:45 +08:00
import { updateCount } from "@/api/admin/count";
import { useI18n } from "vue-i18n";
2022-09-20 17:31:39 +08:00
2023-07-17 15:47:45 +08:00
const { t } = useI18n();
2022-09-20 17:31:39 +08:00
const router = useRouter();
2022-10-27 13:39:36 +08:00
const route = useRoute();
2022-09-20 17:31:39 +08:00
const data = reactive({
form: {
check: [],
status: 1,
2022-09-20 17:31:39 +08:00
},
queryParams: {
pageNum: 1,
pageSize: 10,
postCode: undefined,
},
rules: {
title: [{ required: true, message: "需求名称不能为空", trigger: "blur" }],
description: [
{ required: true, message: "需求描述不能为空", trigger: "blur" },
],
name: [{ required: true, message: "需求联系人不能为空", trigger: "blur" }],
mobile: [
{ required: true, message: "联系人手机号不能为空", trigger: "blur" },
],
username: [
2023-07-27 17:31:39 +08:00
{
required: true,
message: computed(() => t("webContact.demandSubmit")),
trigger: "blur",
},
2022-09-20 17:31:39 +08:00
],
userPhone: [{ required: true, message: "手机号不能为空", trigger: "blur" }],
},
});
const { form, rules } = toRefs(data);
const labelWidth = 140;
2022-11-25 17:30:39 +08:00
const checkList = reactive([...demandCategoryList]);
2022-09-20 17:31:39 +08:00
const checkInput = ref("");
2022-11-22 17:31:02 +08:00
// const cityFormRef = ref();
2022-09-20 17:31:39 +08:00
const formRef = ref();
const submitForm = () => {
formRef.value.validate(async (valid) => {
2022-11-22 17:31:02 +08:00
// const cityFormValid = cityFormRef.value.validateForm(); // 城市
if (valid) {
2022-09-20 17:31:39 +08:00
if (form.value.id != undefined) {
2022-10-27 13:39:36 +08:00
await updateDemand(form.value);
2023-07-19 09:22:11 +08:00
ElMessage.success(t("admin.common.editSuccess"));
2022-11-22 17:31:02 +08:00
// router.back();
2022-09-20 17:31:39 +08:00
} else {
await insertDemand(form.value);
ElMessage.success("新增服务需求成功");
2022-11-22 17:31:02 +08:00
// router.back();
updateCount("service");
2022-09-20 17:31:39 +08:00
}
2022-11-22 17:31:02 +08:00
backToList();
2022-09-20 17:31:39 +08:00
}
});
};
2022-11-17 17:29:47 +08:00
// 返回服务需求列表
const backToList = () => {
tab.closeOpenPage({ path: "/demand/serviceDemand" });
};
2023-07-17 15:47:45 +08:00
2022-09-20 17:31:39 +08:00
// 添加需求类别时验证
function addCheck() {
if (!checkInput.value.trim().length) return ElMessage.error("请输入");
const flag = checkList.some((item) => {
return item.name.trim() == checkInput.value.trim();
});
if (!flag) {
checkList.push({
id: checkList.length + 1,
name: checkInput.value,
});
checkInput.value = "";
}
}
2022-10-31 17:46:09 +08:00
onMounted(() => {
formRef.value.resetFields();
2022-10-27 13:39:36 +08:00
if (route.query.id) {
2022-11-25 17:30:39 +08:00
const obj = Object.assign({}, route, { title: "修改服务需求" });
tab.updatePage(obj);
2022-10-27 13:39:36 +08:00
getDemand({ id: route.query.id }).then((resp) => {
2022-10-31 17:46:09 +08:00
if (resp.data.kinds) {
resp.data.kinds.forEach((el, index) => {
if (!checkList.find((item) => item.name == el)) {
checkList.push({
id: index,
name: el,
});
}
});
}
2022-10-27 13:39:36 +08:00
form.value = resp.data;
});
2022-11-17 17:29:47 +08:00
} else {
form.value = {
check: [],
2022-11-22 17:31:02 +08:00
status: 0,
2022-11-17 17:29:47 +08:00
};
if (formRef.value) {
formRef.value.resetFields();
}
2022-10-27 13:39:36 +08:00
}
});
2022-09-20 17:31:39 +08:00
</script>