123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- <template>
- <div class="tenant">
- <div class="content">
- <byTable
- :source="sourceList.data"
- :pagination="sourceList.pagination"
- :config="config"
- :loading="loading"
- :selectConfig="selectConfig"
- highlight-current-row
- :action-list="[
- {
- text: '添加客户',
- action: () => openModal('add'),
- },
- ]"
- @get-list="getList">
- <template #address="{ item }">
- <span>{{ item.countryName }}</span>
- <span v-if="item.provinceName"> ,{{ item.provinceName }}</span>
- <span v-if="item.cityName"> ,{{ item.cityName }}</span>
- </template>
- </byTable>
- </div>
- <el-dialog :title="modalType == 'add' ? '新增' : '编辑'" v-model="dialogVisible" width="800" v-loading="loadingOperation">
- <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
- <template #address>
- <el-row :gutter="10" style="width: 100%; margin-left: -15px">
- <el-col :span="8">
- <el-form-item prop="countryId">
- <el-select v-model="formData.data.countryId" placeholder="国家" @change="(val) => getCityData(val, '20', true)">
- <el-option v-for="item in countryData" :label="item.chineseName" :value="item.id"> </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="provinceId">
- <el-select v-model="formData.data.provinceId" placeholder="省/洲" @change="(val) => getCityData(val, '30', true)">
- <el-option v-for="item in provinceData" :label="item.name" :value="item.id"> </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="cityId">
- <el-select v-model="formData.data.cityId" placeholder="城市">
- <el-option v-for="item in cityData" :label="item.name" :value="item.id"> </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row style="margin-top: 20px; width: 100%; margin-left: -10px">
- <el-col :span="24">
- <el-form-item prop="address">
- <el-input v-model="formData.data.address" type="textarea"> </el-input>
- </el-form-item>
- </el-col>
- </el-row>
- </template>
- <template #person>
- <div>
- <el-button type="primary" @click="clickAddPerson"> 添加 </el-button>
- <byTable :source="formData.data.customerUserList" :config="configPerson" hideSearch hidePagination> </byTable>
- </div>
- </template>
- </byForm>
- <template #footer>
- <el-button @click="dialogVisible = false" size="large">取 消</el-button>
- <el-button type="primary" @click="submitForm('submit')" size="large" :loading="submitLoading"> 确 定 </el-button>
- </template>
- </el-dialog>
- <el-dialog title="添加联系人" v-model="openPerson" width="400" v-loading="openPerson">
- <byForm :formConfig="formConfigPerson" :formOption="formOption" v-model="formPerson.data" :rules="rulesPerson" ref="person"> </byForm>
- <template #footer>
- <el-button @click="openPerson = false" size="large">取 消</el-button>
- <el-button type="primary" @click="submitPerson('person')" size="large"> 确 定 </el-button>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup>
- import { ElMessage, ElMessageBox } from "element-plus";
- import byTable from "@/components/byTable/index";
- import byForm from "@/components/byForm/index";
- import { computed, ref } from "vue";
- import useUserStore from "@/store/modules/user";
- const { proxy } = getCurrentInstance();
- const loading = ref(false);
- const loadingOperation = ref(false);
- const submitLoading = ref(false);
- const openPerson = ref(false);
- const customerSource = ref([]);
- const customerStatus = ref([]);
- const userList = ref([]);
- const sourceList = ref({
- data: [],
- pagination: {
- total: 0,
- pageNum: 1,
- pageSize: 10,
- status: "",
- source: "",
- },
- });
- const selectConfig = computed(() => {
- return [
- {
- label: "客户来源",
- prop: "source",
- data: customerSource.value,
- },
- {
- label: "客户类型",
- prop: "status",
- data: customerStatus.value,
- },
- ];
- });
- const config = computed(() => {
- return [
- {
- attrs: {
- label: "客户名称",
- prop: "name",
- },
- },
- {
- attrs: {
- label: "所在城市",
- slot: "address",
- width: 200,
- },
- },
- {
- attrs: {
- label: "客户代码",
- prop: "customerCode",
- width: 140,
- },
- },
- {
- attrs: {
- label: "客户来源",
- prop: "source",
- width: 140,
- },
- render(type) {
- let data = customerSource.value.filter((item) => item.value == type);
- if (data && data.length > 0) {
- return data[0].label;
- } else {
- return "";
- }
- },
- },
- {
- attrs: {
- label: "客户类型",
- prop: "status",
- width: 140,
- },
- render(type) {
- let data = customerStatus.value.filter((item) => item.value == type);
- if (data && data.length > 0) {
- return data[0].label;
- } else {
- return "";
- }
- },
- },
- {
- attrs: {
- label: "操作",
- width: "100",
- align: "center",
- },
- renderHTML(row) {
- return [
- {
- attrs: {
- label: "退回公海",
- type: "primary",
- text: true,
- },
- el: "button",
- click() {
- ElMessageBox.confirm("是否确定将该客户退回公海?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- proxy
- .post("/customer/CustomerAllocation", {
- id: row.id,
- userId: "",
- })
- .then(() => {
- ElMessage({
- message: "退回成功",
- type: "success",
- });
- getList();
- });
- });
- },
- },
- ];
- },
- },
- ];
- });
- let modalType = ref("add");
- let dialogVisible = ref(false);
- let formData = reactive({
- data: {
- countryId: "China",
- },
- });
- let formPerson = reactive({
- data: {},
- });
- const formOption = reactive({
- inline: true,
- labelWidth: 100,
- itemWidth: 100,
- rules: [],
- });
- const formConfig = computed(() => {
- return [
- {
- type: "input",
- prop: "name",
- label: "客户名称",
- required: true,
- itemWidth: 100,
- itemType: "text",
- },
- {
- type: "slot",
- slotName: "address",
- label: "详细地址",
- },
- {
- type: "input",
- prop: "customerCode",
- label: "客户代码",
- required: true,
- itemWidth: 100,
- itemType: "text",
- },
- {
- type: "select",
- label: "客户来源",
- prop: "source",
- itemWidth: 50,
- isLoad: {
- url: "/dictTenantData/page",
- labelKey: "dictValue",
- labelVal: "dictKey",
- method: "post",
- req: {
- pageNum: 1,
- pageSize: 999,
- dictCode: "customer_source",
- tenantId: useUserStore().user.tenantId,
- },
- resUrl: "rows",
- },
- },
- {
- type: "select",
- label: "客户类型",
- prop: "status",
- itemWidth: 50,
- isLoad: {
- url: "/dictTenantData/page",
- labelKey: "dictValue",
- labelVal: "dictKey",
- method: "post",
- req: {
- pageNum: 1,
- pageSize: 999,
- dictCode: "customer_status",
- tenantId: useUserStore().user.tenantId,
- },
- resUrl: "rows",
- },
- },
- {
- type: "select",
- label: "业务员",
- prop: "userId",
- itemWidth: 100,
- isLoad: {
- url: "/tenantUser/list",
- labelKey: "nickName",
- labelVal: "userId",
- method: "get",
- resUrl: "rows",
- req: {
- pageNum: 1,
- pageSize: 10000,
- tenantId: useUserStore().user.tenantId,
- },
- },
- },
- {
- type: "slot",
- slotName: "person",
- label: "客户联系人",
- },
- ];
- });
- let rules = ref({
- name: [{ required: true, message: "请输入客户名称", trigger: "blur" }],
- countryId: [{ required: true, message: "请选择国家", trigger: "change" }],
- provinceId: [{ required: true, message: "请选择省/州", trigger: "change" }],
- // cityId: [{ required: true, message: "请选择城市", trigger: "change" }],
- source: [{ required: true, message: "请选择客户来源", trigger: "change" }],
- status: [{ required: true, message: "请选择类型", trigger: "change" }],
- });
- const formConfigPerson = computed(() => {
- return [
- {
- type: "input",
- prop: "name",
- label: "联系人名称",
- required: true,
- itemWidth: 100,
- itemType: "text",
- },
- {
- type: "input",
- prop: "phone",
- label: "联系人电话",
- required: true,
- itemWidth: 100,
- itemType: "text",
- },
- ];
- });
- const configPerson = computed(() => {
- return [
- {
- attrs: {
- label: "联系人名称",
- prop: "name",
- width: 150,
- },
- },
- {
- attrs: {
- label: "联系人电话",
- prop: "phone",
- width: 440,
- },
- },
- {
- attrs: {
- label: "操作",
- width: "100",
- align: "center",
- },
- renderHTML(row) {
- return [
- {
- attrs: {
- label: "删除",
- type: "primary",
- text: true,
- },
- el: "button",
- click() {
- formData.data.customerUserList.splice(row.$index, 1);
- },
- },
- ];
- },
- },
- ];
- });
- let rulesPerson = ref({
- name: [{ required: true, message: "请输入联系人名称", trigger: "blur" }],
- phone: [{ required: true, message: "请输入联系人电话", trigger: "blur" }],
- });
- const submit = ref(null);
- const person = ref(null);
- const getList = async (req) => {
- sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
- loading.value = true;
- proxy.post("/customer/privateSeaPage", sourceList.value.pagination).then((res) => {
- sourceList.value.data = res.rows;
- sourceList.value.pagination.total = res.total;
- setTimeout(() => {
- loading.value = false;
- }, 200);
- });
- };
- const openModal = () => {
- modalType.value = "add";
- formData.data = {
- countryId: "China",
- };
- getCityData(formData.data.countryId, "20");
- loadingOperation.value = false;
- dialogVisible.value = true;
- };
- const update = (row) => {
- modalType.value = "edit";
- loadingOperation.value = true;
- proxy.post("/customer/detail", { id: row.id }).then((res) => {
- res.customerUserList = res.customerUserList.map((item) => {
- return {
- name: item.name,
- phone: item.phone,
- customerId: item.customerId,
- };
- });
- formData.data = res;
- getCityData(formData.data.countryId, "20");
- getCityData(formData.data.provinceId, "30");
- loadingOperation.value = false;
- });
- dialogVisible.value = true;
- };
- const countryData = ref([]);
- const provinceData = ref([]);
- const cityData = ref([]);
- const getCityData = (id, type, isChange) => {
- proxy.post("/areaInfo/list", { parentId: id }).then((res) => {
- if (type === "20") {
- provinceData.value = res;
- if (isChange) {
- formData.data.provinceId = "";
- formData.data.cityId = "";
- }
- } else if (type === "30") {
- cityData.value = res;
- if (isChange) {
- formData.data.cityId = "";
- }
- } else {
- countryData.value = res;
- }
- });
- };
- getCityData("0");
- const clickAddPerson = () => {
- formPerson.data = {};
- openPerson.value = true;
- };
- const submitPerson = () => {
- person.value.handleSubmit(() => {
- if (formData.data.customerUserList && formData.data.customerUserList.length > 0) {
- formData.data.customerUserList.push({
- name: formPerson.data.name,
- phone: formPerson.data.phone,
- });
- } else {
- formData.data.customerUserList = [
- {
- name: formPerson.data.name,
- phone: formPerson.data.phone,
- },
- ];
- }
- openPerson.value = false;
- });
- };
- const submitForm = () => {
- submit.value.handleSubmit(() => {
- if (formData.data.customerUserList && formData.data.customerUserList.length > 0) {
- submitLoading.value = true;
- proxy.post("/customer/" + modalType.value, formData.data).then(
- () => {
- ElMessage({
- message: modalType.value == "add" ? "添加成功" : "编辑成功",
- type: "success",
- });
- dialogVisible.value = false;
- submitLoading.value = false;
- getList();
- },
- (err) => {
- console.log(err);
- submitLoading.value = false;
- }
- );
- } else {
- ElMessage("请添加客户联系人");
- }
- });
- };
- const getDict = () => {
- proxy
- .post("/dictTenantData/page", {
- pageNum: 1,
- pageSize: 999,
- dictCode: "customer_source",
- tenantId: useUserStore().user.tenantId,
- })
- .then((res) => {
- customerSource.value = res.rows.map((item) => {
- return {
- label: item.dictValue,
- value: item.dictKey,
- };
- });
- });
- proxy
- .post("/dictTenantData/page", {
- pageNum: 1,
- pageSize: 999,
- dictCode: "customer_status",
- tenantId: useUserStore().user.tenantId,
- })
- .then((res) => {
- customerStatus.value = res.rows.map((item) => {
- return {
- label: item.dictValue,
- value: item.dictKey,
- };
- });
- });
- proxy.get("/tenantUser/list", { pageNum: 1, pageSize: 10000, tenantId: useUserStore().user.tenantId }).then((res) => {
- userList.value = res.rows.map((item) => {
- return {
- label: item.nickName,
- value: item.userId,
- };
- });
- });
- };
- getDict();
- getList();
- </script>
- <style lang="scss" scoped>
- .tenant {
- padding: 20px;
- }
- </style>
|