jiang-youyi b105e4bec7 8.6
2023-08-06 20:17:26 +08:00

870 lines
25 KiB
Vue

<template>
<div class="edit-popup">
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
<!-- <div style="font-size: 1.2rem; margin: 10px 0">公司基本信息创建</div> -->
<el-col :span="24" class="el-card pt-6">
<div class="tit">公司基本信息创建</div>
<el-row>
<el-col :span="8">
<el-form-item label="公司名称" prop="company_name">
<el-input
v-model="formData.company_name"
placeholder="请输入公司名称"
clearable
:disabled="isDisabled"
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="社会代码" prop="organization_code">
<el-input
:disabled="isDisabled"
v-model="formData.organization_code"
placeholder="请输入社会代码"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="公司类型" prop="company_type">
<el-select
:disabled="isDisabled"
v-model="formData.company_type"
placeholder="请选择公司类型"
clearable
:style="{ width: '100%' }"
>
<el-option
v-for="(item, index) in datas.dictTypeLists"
:key="index"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="3">
<el-form-item label="省" prop="province">
<el-select
:disabled="isDisabled"
v-model="formData.province"
placeholder="请选择省"
clearable
@change="province_change"
:style="{ width: '100%' }"
>
<el-option
v-for="(item, index) in datas.provinceOptions"
:key="index"
:label="item.province_name"
:value="item.province_code"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="3">
<el-form-item label="市" prop="city">
<el-select
:disabled="isDisabled"
v-model="formData.city"
placeholder="请选择市"
clearable
@change="city_change"
:style="{ width: '100%' }"
>
<el-option
v-for="(item, index) in datas.cityOptions"
:key="index"
:label="item.city_name"
:value="item.city_code"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="3">
<el-form-item label="区" prop="area">
<el-select
:disabled="isDisabled"
v-model="formData.area"
placeholder="请选择区"
clearable
@change="area_change"
:style="{ width: '100%' }"
>
<el-option
v-for="(item, index) in datas.areaOptions"
:key="index"
:label="item.area_name"
:value="item.area_code"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="3">
<el-form-item label="镇" prop="street">
<el-select
:disabled="isDisabled"
v-model="formData.street"
placeholder="请选择镇"
clearable
@change="street_change"
:style="{ width: '100%' }"
>
<el-option
v-for="(item, index) in datas.streetOptions"
:key="index"
:label="item.street_name"
:value="item.street_code"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="地址" prop="address">
<el-input
:disabled="isDisabled"
v-model="formData.address"
placeholder="请输入地址"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
</el-row>
</el-col>
<el-col :span="24" class="el-card pt-6">
<div class="tit">主要联系人</div>
<el-row>
<el-col :span="12">
<el-form-item label="姓名" prop="master_name">
<el-input
:disabled="isDisabled"
v-model="formData.master_name"
placeholder="请输入姓名"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="职务" prop="master_position">
<el-input
:disabled="isDisabled"
v-model="formData.master_position"
placeholder="请输入职务"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="手机" prop="master_phone">
<el-input
:disabled="isDisabled"
v-model="formData.master_phone"
placeholder="请输入手机"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="邮箱">
<el-input
:disabled="isDisabled"
v-model="formData.master_email"
placeholder="请输入邮箱"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col v-if="show" :span="12">
<el-form-item label="管理人员" prop="admin_name">
<el-input
:disabled="isDisabled"
v-model="formData.admin_name"
placeholder="设置当前公司管理人员"
clearable
:style="{ width: '100%' }"
@click="isMan = true"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="片区经理" prop="area_manager_name">
<el-input
:disabled="isDisabled"
v-model="formData.area_manager_name"
placeholder="选择片区经理"
clearable
:style="{ width: '100%' }"
@click="isAreaManager = true"
></el-input>
</el-form-item>
</el-col>
</el-row>
</el-col>
<el-col :span="24" class="el-card pt-6">
<div class="tit">其他联系人</div>
<el-row>
<template v-for="(item, index) in formData.other_contacts" :key="index">
<el-col :span="12">
<el-form-item label="姓名" prop="field120">
<el-input
:disabled="isDisabled"
v-model="item.name"
placeholder="请输入姓名"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="职务" prop="field121">
<el-input
:disabled="isDisabled"
v-model="item.position"
placeholder="请输入职务"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="手机" prop="field122">
<el-input
:disabled="isDisabled"
v-model="item.phone"
placeholder="请输入手机"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="邮箱">
<el-input
:disabled="isDisabled"
v-model="item.email"
placeholder="请输入邮箱"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
</template>
<el-col :span="24">
<el-form-item label prop="field126">
<el-button type="primary" :disabled="isDisabled" size="medium" @click="other">其他联系人</el-button>
</el-form-item>
</el-col>
</el-row>
</el-col>
<!-- <div style="font-size: 1.2rem; margin: 10px 0">资质信息</div> -->
<el-col :span="24" class="el-card pt-6">
<div class="tit">资质信息</div>
<el-row>
<el-col :span="12">
<el-form-item label="公司资质" required>
<el-upload
:disabled="isDisabled"
v-model="formData.qualification.business_license"
class="avatar-uploader pl-3"
:data="{ cid: 1 }"
action="https://worker-task.lihaink.cn/api/upload/image"
:show-file-list="false"
:on-success="handleAvatarSuccess"
>
<img
v-if="formData.qualification.business_license"
:src="formData.qualification.business_license"
class="avatar"
/>
<el-icon v-else class="avatar-uploader-icon">
<Plus />
</el-icon>
</el-upload>
</el-form-item>
<el-form-item label="其他资质">
<div v-for="(v,i) in formData.qualification.bank_account" :key="i" class="otherimg" >
<img
:src="v"
/></div>
<el-upload v-if="imgflag"
:disabled="isDisabled"
class="avatar-uploader pl-3"
:data="{ cid: 1 }"
action="https://worker-task.lihaink.cn/api/upload/image"
:show-file-list="false"
:on-success="handleAvatarSuccess_two"
>
<el-icon class="avatar-uploader-icon">
<Plus />
</el-icon>
</el-upload>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label-width="120px" label="开户许可证" required>
<el-upload
:disabled="isDisabled"
v-model="formData.qualification.business_licenseB"
class="avatar-uploader pl-3"
:data="{ cid: 1 }"
action="https://worker-task.lihaink.cn/api/upload/image"
:show-file-list="false"
:on-success="handleAvatarSuccessB"
>
<img
v-if="formData.qualification.business_licenseB"
:src="formData.qualification.business_licenseB"
class="avatar"
/>
<el-icon v-else class="avatar-uploader-icon">
<Plus />
</el-icon>
</el-upload>
</el-form-item>
</el-col>
</el-row>
</el-col>
<!-- <div style="font-size: 1.2rem; margin: 10px 0">电子合同</div> -->
<el-col v-if="isshow" :span="24" class="el-card pt-6">
<div class="tit">电子合同</div>
<el-row>
<el-col :span="12">
<el-form-item label="签约方" prop="field130">
<el-input
v-model="formData.party_a_name"
placeholder="请选择签约方"
clearable
:style="{ width: '100%' }"
@click="openCompany"
:disabled="userStore.userInfo.root == 0 ? true : false"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label-width="100px" label="被签约公司" prop="field131">
<el-input
:disabled="true"
v-model="formData.company_name"
placeholder="请输入被签约公司"
clearable
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label-width="100px" label="合同类型" prop="contract_type">
<el-select
:disabled="isDisabled"
v-model="formData.contract.contract_type"
placeholder="请选择合同类型"
clearable
:style="{ width: '100%' }"
>
<el-option
v-for="(item, index) in datas.contract_type"
:key="index"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label-width="100px" label="合同编号" prop="field133">
<el-input
placeholder="系统自动生成"
v-model="formData.contract.contract_no"
clearable
:style="{ width: '100%' }"
:disabled="true"
></el-input>
</el-form-item>
</el-col>
</el-row>
</el-col>
<el-col v-if="isshow" :span="24" class="el-card pt-6">
<el-row >
<el-col :span="24">
<el-form-item label="合同上传" required>
<el-upload
:disabled="isDisabled"
v-model:file-list="fileList"
:headers="{ Token: userStore.token }"
class="upload-demo"
action="https://worker-task.lihaink.cn/adminapi/upload/file"
multiple
:limit="1"
:on-success="handleAvatarSuccess_three"
>
<el-button :disabled="isDisabled" type="primary">上传</el-button>
</el-upload>
</el-form-item>
</el-col>
</el-row>
</el-col>
<el-col :span="24" class="el-card pt-6">
<el-form-item label prop="field139">
<el-button v-if="isEdit" type="primary" size="medium" @click="create">修改</el-button>
<el-button v-else type="primary" :disabled="isDisabled" size="medium" @click="create">创建</el-button>
</el-form-item>
</el-col>
</el-form>
<el-dialog v-model="isCompany" title="选择签约方" width="60%">
<DialogIndex @customEvent="customEvent" />
</el-dialog>
<el-dialog v-model="isMan" title="选择管理人员" width="60%">
<DialogIndexMan @customEvent="customEventMan" />
</el-dialog>
<el-dialog v-model="isAreaManager" title="选择片区经理" width="60%">
<DialogIndexMan @customEvent="EventAreaManager" :type="8"/>
</el-dialog>
</div>
</template>
<script lang="ts" setup name="companyEdit">
import type {
FormInstance,
UploadProps,
ElMessage,
UploadUserFile,
} from "element-plus";
import Popup from "@/components/popup/index.vue";
import {
apiCompanyAdd,
apiCompanyEdit,
apiCompanyDetail,
apiCompanyLists,
} from "@/api/company";
import {
apiCityList,
apiAreaList,
apiStreetList,
apiProvinceList,
} from "@/api/common";
import { dictDataLists } from "@/api/setting/dict";
import { timeFormat } from "@/utils/util";
import DialogIndex from "./dialog_index.vue";
import DialogIndexMan from "./dialog_index_man.vue";
import type { PropType } from "vue";
import useMultipleTabs from "@/hooks/useMultipleTabs";
import useUserStore from "@/stores/modules/user";
const userStore = useUserStore();
const { removeTab } = useMultipleTabs();
const router = useRouter();
const route = useRoute();
let isshow=ref(true)
let imgflag=ref(true)
let isDisabled = ref(false);
if(route.query.flag){
isshow=false
}
if(route.query.isshow){
imgflag=false
isDisabled=true
}
let isEdit = ref(false);
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({}),
},
});
const emit = defineEmits(["success", "close"]);
const formRef = shallowRef<FormInstance>();
const popupRef = shallowRef<InstanceType<typeof Popup>>();
const mode = ref();
isDisabled = route.query.read;
isEdit = route.query.edit;
// 表单数据
const formData = reactive({
admin_id: "",
admin_name: "",
area_manager: "",
area_manager_name: "",
id: "",
// level_two: '',
// level_one: '',
company_name: "",
organization_code: "",
province: "",
city: "",
area: "",
street: "",
address: "",
company_type: "",
master_name: "",
master_position: "",
master_phone: "",
master_email: "",
other_contacts: [
// {
// name: "",
// position: "",
// phone: "",
// email: "",
// },
],
// area_manager: '',
// is_contract: '',
// account: '',
// password: '',
// deposit: '',
// deposit_time: '',
qualification: {
business_license: "",
business_licenseB: "",
bank_account:[],
bank_accountB: [],
},
contract: {
contract_type: "",
party_a: 0,
file: "",
contract_no: "系统自动生成",
type: 1,
},
//签约方
party_a_name: "",
file_image: "",
// status: ''
});
if (userStore.userInfo.root == 0) {
formData.contract.party_a = userStore.userInfo.company?.id;
formData.party_a_name = userStore.userInfo.company?.company_name;
}
const datas = reactive({
provinceOptions: [],
cityOptions: [],
areaOptions: [],
streetOptions: [],
dictTypeLists: [],
contract_type: [],
});
const fileList = ref<UploadUserFile[]>([]);
// 表单验证
const formRules = reactive<any>({
company_name: [
{
required: true,
message: "请输入公司名称",
trigger: ["blur"],
},
],
organization_code: [
{
required: true,
message: "请输入组织机构代码",
trigger: ["blur"],
},
],
master_name: [
{
required: true,
message: "请输入主联系人姓名",
trigger: ["blur"],
},
],
master_position: [
{
required: true,
message: "请输入主联系人职务",
trigger: ["blur"],
},
],
master_phone: [
{
required: true,
message: "请输入主联系人手机",
trigger: ["blur"],
},
],
account: [
{
required: true,
message: "请输入账号",
trigger: ["blur"],
},
],
password: [
{
required: true,
message: "请输入密码",
trigger: ["blur"],
},
],
});
const isCompany = ref(false);
const isMan = ref(false);
const isAreaManager = ref(false);
function customEvent(data: any) {
isCompany.value = false;
formData.contract.party_a = data.id;
formData.party_a_name = data.company_name;
}
function customEventMan(data: any) {
isMan.value = false;
formData.admin_name = data.name;
formData.admin_id = data.id;
}
//区域管理人员
function EventAreaManager(data: any) {
isAreaManager.value = false;
formData.area_manager_name = data.name;
formData.area_manager = data.id;
}
function openCompany() {
isCompany.value = true;
}
// 获取详情
const setFormData = async (data: Record<any, any>) => {
console.log(formData);
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key];
}
}
};
const getDetail = async (row: Record<string, any>) => {
const data = await apiCompanyDetail({
id: row.id,
});
setFormData(data);
};
//上传图片1
const handleAvatarSuccess: UploadProps["onSuccess"] = (
response,
uploadFile
) => {
if (response.code == 0) {
ElMessage.error(response.msg);
return;
}
formData.qualification.business_license = response.data.uri;
};
const handleAvatarSuccessB: UploadProps["onSuccess"] = (
response,
uploadFile
) => {
if (response.code == 0) {
ElMessage.error(response.msg);
return;
}
formData.qualification.business_licenseB = response.data.uri;
};
//上传图片2
const handleAvatarSuccess_two: UploadProps["onSuccess"] = (
response,
uploadFile
) => {
if (response.code == 0) {
ElMessage.error(response.msg);
return;
}
formData.qualification.bank_account.push(response.data.uri);
};
const handleAvatarSuccess_twoB: UploadProps["onSuccess"] = (
response,
uploadFile
) => {
if (response.code == 0) {
ElMessage.error(response.msg);
return;
}
formData.qualification.bank_accountB = response.data.uri;
};
//上传文件3
const handleAvatarSuccess_three: UploadProps["onSuccess"] = (
response,
uploadFile
) => {
if (response.code == 0) {
ElMessage.error(response.msg);
return;
}
formData.file_image = response.data.uri;
formData.contract.file = response.data.uri;
fileList.value[0].url = response.data.uri;
fileList.value[0].name = "合同文件";
};
//增加其他联系人
function other() {
formData.other_contacts.push({
name: "",
position: "",
phone: "",
email: "",
});
}
//获取省份
function province_change(value: string) {
getCityList();
}
function city_change(value: string) {
getAreaList();
}
function area_change(value: string) {
getStreetList();
}
function street_change(value: string) {
formData.street = value;
}
const getProvinceList = async () => {
const data = await apiProvinceList({});
datas["provinceOptions"] = data;
};
const getCityList = async () => {
const data = await apiCityList({ city: formData.province });
datas["cityOptions"] = data;
};
const getAreaList = async () => {
const data = await apiAreaList({ area: formData.city });
datas["areaOptions"] = data;
};
const getStreetList = async () => {
const data = await apiStreetList({ street: formData.area });
datas["streetOptions"] = data;
};
getProvinceList();
const getcontract_type = async () => {
const data = await dictDataLists({ type_id: 7 });
datas["contract_type"] = data["lists"];
};
const getdictTypeLists = async () => {
const data = await dictDataLists({ type_id: 6 });
datas["dictTypeLists"] = data["lists"];
};
const getDetails = async () => {
const data = await apiCompanyDetail({
id: route.query.id,
});
Object.keys(formData).forEach((key) => {
const stringArr = ["province", "city", "area", "street"];
if (data[key] != null && data[key] != undefined) {
formData[key] = data[key];
if(key=='qualification'&&formData.qualification.bank_account){
try {
if(Array.isArray(JSON.parse(formData.qualification.bank_account))){
formData.qualification.bank_account = JSON.parse(formData.qualification.bank_account);
}else {
let str = formData.qualification.bank_account;
formData.qualification.bank_account = [];
formData.qualification.bank_account.push(str);
}
} catch (error) {
let str = formData.qualification.bank_account;
formData.qualification.bank_account = [];
formData.qualification.bank_account.push(str);
}
}
}
if (stringArr.includes(key)) formData[key] = formData[key].toString();
});
await getCityList();
await getAreaList();
await getStreetList();
formData["party_a_name"] = data.contract?.party_a_name;
formData["file_image"] = data.contract?.file;
if (data.contract?.file) {
fileList.value[0].url = data.contract?.file;
fileList.value[0].name = "合同文件";
}
};
getdictTypeLists();
getcontract_type();
const create = async () => {
await formRef.value?.validate();
const data = JSON.parse(JSON.stringify({...formData}));
data.qualification.bank_account=JSON.stringify(data.qualification.bank_account)
if (route.query.id) {
await apiCompanyEdit(data);
} else {
await apiCompanyAdd(data);
}
removeTab();
router.back();
};
route.query.id && getDetails();
defineExpose({
open,
setFormData,
getDetail,
});
</script>
<style lang="scss">
.tit {
font-size: 1.2rem;
translate: 1vw -1vw;
}
.avatar-uploader .el-upload {
width: 10vw;
height: 6.3vw;
background-color: #fff;
border: 1px dashed var(--el-border-color);
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
transition: var(--el-transition-duration-fast);
}
.avatar-uploader .el-upload:hover {
border-color: var(--el-color-primary);
}
.el-icon.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
text-align: center;
}
.el-icon.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
text-align: center;
}
.otherimg{
img{
width: 10vw;
height: 6.3vw;
border-radius: 5px;
margin-left: 12px;
}
}
</style>