sen
2026-01-29 fea2d693c33fdbcb4c8304a96a4e584829cb437b
ui/admin-ui3/src/views/cwgl/customerManagement/index.vue
@@ -1,163 +1,413 @@
<template>
  <basicContainer >
    <avue-crud
        :option="option"
        :table-loading="pageF.loading"
        :data="tableData"
        :page="page"
        :permission="permissionList"
        :before-open="beforeOpen"
        v-model="form"
        ref="crudRef"
        @row-update="rowUpdate"
        @row-save="rowSave"
        @refresh-change="refreshChange"
        @row-del="rowDel"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @on-load="onLoad"
    >
  <basicContainer>
    <avue-crud :option="option" :table-loading="pageF.loading" :data="tableData" :page="page"
      :permission="permissionList" :before-open="beforeOpen" v-model="form" ref="crudRef" @row-update="rowUpdate"
      @row-save="rowSave" @refresh-change="refreshChange" @row-del="rowDel" @search-change="searchChange"
      @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange"
      @size-change="sizeChange" @on-load="onLoad">
      <template #menu-left>
        <el-button
            type="success"
            icon="Edit"
            :disabled="pageF.single"
            v-hasPermi="['cwgl:customerManagement:edit']"
            @click="handleUpdate">修改
        <!-- <el-button type="success" icon="Edit" :disabled="pageF.single" v-hasPermi="['cwgl:customerManagement:edit']"
          @click="handleUpdate">修改
        </el-button>
        <el-button
            type="danger"
            icon="Delete"
            :disabled="pageF.multiple"
            @click="handleDelete"
            v-hasPermi="['cwgl:customerManagement:remove']"
        >删除
        <el-button type="danger" icon="Delete" :disabled="pageF.multiple" @click="handleDelete"
          v-hasPermi="['cwgl:customerManagement:remove']">删除
        </el-button> -->
        <el-button type="primary" icon="Plus" v-hasPermi="['cwgl:customerManagement:add']" @click="handleAdd">新增
        </el-button>
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['cwgl:customerManagement:export']"
        >导出
        <el-button type="warning" plain icon="Download" @click="handleExport"
          v-hasPermi="['cwgl:customerManagement:export']">导出
        </el-button>
      </template>
      <template #menu="{ size, row, index }">
        <el-link class="link-btn" type="primary" :underline="false" plain :size="size" icon="Edit"
          @click="handleFy(row)" v-hasPermi="['cwgl:dispatchOrder:query']"> 编辑
        </el-link>
      </template>
    </avue-crud>
  </basicContainer>
  <!-- 新增客户弹窗 -->
  <el-dialog v-model="dialogVisible" title="新增" width="70%" destroy-on-close @close="handleClose">
    <!-- 表单 -->
    <el-form ref="customerFormRef" :model="formData" :rules="formRules" label-width="140px" size="default">
      <!-- 基本信息折叠面板 -->
      <el-collapse v-model="activePanels">
        <!-- 基本信息面板 -->
        <el-collapse-item title="基本信息" name="basic">
          <el-row :gutter="20">
            <!-- 客户类型 -->
                   <!-- 客户简称 -->
            <el-col :span="12">
              <el-form-item label="客户编码" prop="customerCode">
                <el-input v-model="formData.customerCode" placeholder="请输入客户编码" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户类型" prop="customerType">
                <el-select v-model="form.customerType" placeholder="请选择客户类型" clearable>
                  <el-option v-for="dict in customer_type" :key="dict.value" :label="dict.label"
                    :value="parseInt(dict.value)" />
                </el-select>
              </el-form-item>
            </el-col>
            <!-- 客户简称 -->
            <el-col :span="12">
              <el-form-item label="客户简称" prop="customerShortName">
                <el-input v-model="formData.customerShortName" placeholder="请输入客户简称" />
              </el-form-item>
            </el-col>
            <!-- 客户全称 -->
            <el-col :span="12">
              <el-form-item label="客户全称" prop="customerFullName">
                <el-input v-model="formData.customerFullName" placeholder="请输入客户全称" />
              </el-form-item>
            </el-col>
            <!-- 经营登记证件号码 -->
            <el-col :span="12">
              <el-form-item label="经营登记证件号码" prop="licenseNumber">
                <el-input v-model="formData.licenseNumber" placeholder="请输入经营登记证件号码" />
              </el-form-item>
            </el-col>
            <!-- 地址 -->
            <el-col :span="24">
              <el-form-item label="地址" prop="address">
                <el-input v-model="formData.address" placeholder="请输入地址" type="textarea" :rows="2" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <!-- 联系人信息面板 -->
        <el-collapse-item title="联系人信息" name="contact">
          <el-row :gutter="20">
            <!-- 联系人姓名 -->
            <el-col :span="12">
              <el-form-item label="联系人姓名" prop="contactName">
                <el-input v-model="formData.contactName" placeholder="请输入联系人姓名" />
              </el-form-item>
            </el-col>
            <!-- 联系人电话 -->
            <el-col :span="12">
              <el-form-item label="联系人电话" prop="contactPhone">
                <el-input v-model="formData.contactPhone" placeholder="请输入联系人电话" />
              </el-form-item>
            </el-col>
            <!-- 联系人邮箱 -->
            <el-col :span="24">
              <el-form-item label="联系人邮箱" prop="contactEmail">
                <el-input v-model="formData.contactEmail" placeholder="请输入联系人邮箱" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <!-- 其他信息面板 -->
        <el-collapse-item title="其他信息" name="other">
          <el-row :gutter="20">
            <!-- 备注 -->
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="formData.remark" placeholder="请输入备注" type="textarea" :rows="2" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
      </el-collapse>
    </el-form>
    <!-- 底部按钮 -->
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleSubmit">保存</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup name="customerManagement" lang="ts">
  import {CustomerManagementI,addCustomerManagement, delCustomerManagement, exportCustomerManagement, getCustomerManagement, listCustomerManagement, updateCustomerManagement} from "@/api/cwgl/customerManagement";
  import useCurrentInstance from "@/utils/useCurrentInstance";
  import {computed,reactive, ref, toRefs} from "vue";
  import {PagesInterface, PageQueryInterface} from "@/utils/globalInterface";
  import {usePagePlus} from "@/hooks/usePagePlus";
  import {hasPermission} from "@/utils/permissionUtils";
import { CustomerManagementI, addCustomerManagement, delCustomerManagement, exportCustomerManagement, getCustomerManagement, listCustomerManagement, updateCustomerManagement } from "@/api/cwgl/customerManagement";
import useCurrentInstance from "@/utils/useCurrentInstance";
import { computed, reactive, ref, toRefs } from "vue";
import { PagesInterface, PageQueryInterface } from "@/utils/globalInterface";
import { usePagePlus } from "@/hooks/usePagePlus";
import { hasPermission } from "@/utils/permissionUtils";
import router from "@/router";
const { proxy } = useCurrentInstance();
  const { proxy } = useCurrentInstance();
  const crudRef = ref();
const {
  customer_type, sys_invoice_type, sys_currency, sys_account_type
  const permissionList = computed(()=>{
    return {
      addBtn: hasPermission(["cwgl:customerManagement:add"]),
      delBtn: hasPermission(["cwgl:customerManagement:remove"]),
      editBtn: hasPermission(["cwgl:customerManagement:edit"]),
      viewBtn: hasPermission(["cwgl:customerManagement:query"]),
    }
  })
  const data = reactive({
    form:<CustomerManagementI>{},
    queryParams:<CustomerManagementI&PageQueryInterface>{},
    page: <PagesInterface>{
      pageSize: 10,
      total: 0,
      currentPage: 1,
} =
  proxy.useDict(
    'customer_type', 'sys_invoice_type', 'sys_currency', 'sys_account_type'
  );
const crudRef = ref();
const permissionList = computed(() => {
  return {
    addBtn: hasPermission(["cwgl:customerManagement:add"]),
    delBtn: hasPermission(["cwgl:customerManagement:remove"]),
    editBtn: hasPermission(["cwgl:customerManagement:edit"]),
    viewBtn: hasPermission(["cwgl:customerManagement:query"]),
  }
})
const data = reactive({
  form: <CustomerManagementI>{},
  queryParams: <CustomerManagementI & PageQueryInterface>{},
  page: <PagesInterface>{
    pageSize: 10,
    total: 0,
    currentPage: 1,
  },
  selectionList: [],
  formData: <CustomerManagementI>{},
  formRules: {
    customerType: [
      { required: true, message: '请选择客户类型', trigger: 'change' }
    ],
    customerShortName: [
      { required: true, message: '请输入客户简称', trigger: 'blur' }
    ],
    customerFullName: [
      { required: true, message: '请输入客户全称', trigger: 'blur' }
    ],
    licenseNumber: [
      { required: true, message: '请输入经营登记证件号码', trigger: 'blur' }
    ],
    contactName: [
      { required: true, message: '请输入联系人姓名', trigger: 'blur' }
    ]
  }
})
const { queryParams, form, page, selectionList, formData } = toRefs(data);
const option = ref({
  pageKey: 'CustomerManagement',
  rowKey: 'id',
  searchSpan: 5,
  addBtn: false,
  //  editBtn: false,
  searchLabelWidth: 100,
  column: {
    // id: {
    //   label: 'ID',
    // },
    customerCode: {
      label: '客户编码',
      minWidth: 120,
      search: true,
    },
    selectionList:[],
  })
  const {queryParams,form,page,selectionList} = toRefs(data);
  const option = ref({
    pageKey: 'CustomerManagement',
    rowKey: 'id',
    column: {
                                id: {
          label: 'ID',
                            },
                                customerFullName: {
          label: '客户全称',
                                rules: [
              {
                required: true,
                message: "客户全称不能为空", trigger: "blur" }
            ],                  },
                                customerShortName: {
          label: '客户简称',
                            },
                                customerType: {
          label: '客户类型',
                            },
                                contactPerson: {
          label: '联系人姓名',
                            },
                                address: {
          label: '地址',
                      type: 'textarea', minRows: 3, maxRows: 5,
                            },
                                contactPhone: {
          label: '联系人电话',
                            },
                                customerCode: {
          label: '客户编码',
                            },
                                status: {
          label: '状态',
                            },
                                remark: {
          label: '备注',
                      type: 'textarea', minRows: 3, maxRows: 5,
                            },
                                createBy: {
          label: '创建人',
                            },
                                updateBy: {
          label: '更新人',
                            },
                                createTime: {
          label: '创建时间',
                            },
                                updateTime: {
          label: '更新时间',
                            },
                                deleted: {
          label: '删除标记(0:正常;1:删除)',
                            },
          }
  })
    customerType: {
      label: '客户类型', minWidth: 120,
      type: 'select', dataType: 'string', dicUrl: '/system/dict/data/type/customer_type',
      addDisplay: true,
      editDisplay: true, value: '1',
      viewDisplay: true,
      hide: false,
      search: true,
      rules: [
        {
          required: true,
          message: "客户类型不能为空", trigger: "change"
        }
      ],
    },
    customerFullName: {
      label: '客户全称',
      addDisplay: true,
      editDisplay: true,
      viewDisplay: true,
      hide: true,
      search: true,
      rules: [
        {
          required: true,
          message: "客户全称不能为空", trigger: "blur"
        }
      ],
    },
    customerShortName: {
      label: '客户简称',
      addDisplay: true, minWidth: 130,
      editDisplay: true,
      viewDisplay: true,
      hide: false,
      search: true,
      rules: [
        {
          required: true,
          message: "客户简称不能为空", trigger: "blur"
        }
      ],
    },
  const { tableData,pageF,rowSave,rowUpdate,rowDel,beforeOpen,searchChange,
    searchReset,selectionChange,onLoad,currentChange,sizeChange,handleDelete,handleExport,handleUpdate,refreshChange} = usePagePlus({
    form:form,
    option:option,
    queryParams:queryParams,
    idKey:'id',
    page:page.value,
    getListApi:listCustomerManagement,
    getDetailApi:getCustomerManagement,
    exportApi:exportCustomerManagement,
    deleteApi:delCustomerManagement,
    addApi:addCustomerManagement,
    updateApi:updateCustomerManagement,
    handleUpdateFunc:()=>{
    contactPerson: {
      label: '联系人姓名',
      search: true,
      minWidth: 180,
    },
    contactPhone: {
      label: '联系人电话',
      minWidth: 180,
    },
    // address: {
    //   label: '地址',
    //   type: 'textarea', minRows: 3, maxRows: 5,
    // },
    status: {
      label: '状态',
    },
    // remark: {
    //   label: '备注',
    //   type: 'textarea', minRows: 3, maxRows: 5,
    // },
    createBy: {
      label: '创建人',
      minWidth: 180,
    },
    createTime: {
      label: '创建时间',
      minWidth: 180,
    },
    createdTimeArray: {
      label: '创建时间',
      search: true,
      searchRange: true,
      type: 'daterange',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
      valueFormat: 'YYYY-MM-DD',
      hide: true
    },
    updateBy: {
      label: '更新人',
      minWidth: 180,
    },
    updateTime: {
      label: '更新时间',
      addDisplay: false, minWidth: 180,
      editDisplay: false,
      viewDisplay: true,
      hide: false,
      search: false,
      rules: [
        {
          required: true,
          message: "更新时间不能为空", trigger: "blur"
        }
      ],
    },
    updateTimeArray: {
      label: '更新时间',
      search: true,
      searchRange: true,
      type: 'daterange',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
      valueFormat: 'YYYY-MM-DD',
      hide: true
    },
    // deleted: {
    //   label: '删除标记(0:正常;1:删除)',
    // },
  }
})
const { tableData, pageF, rowSave, rowUpdate, rowDel, beforeOpen, searchChange,
  searchReset, selectionChange, onLoad, currentChange, sizeChange, handleDelete, handleExport, handleUpdate, refreshChange } = usePagePlus({
    form: form,
    option: option,
    queryParams: queryParams,
    idKey: 'id',
    page: page.value,
    getListApi: listCustomerManagement,
    getDetailApi: getCustomerManagement,
    exportApi: exportCustomerManagement,
    deleteApi: delCustomerManagement,
    addApi: addCustomerManagement,
    updateApi: updateCustomerManagement,
    handleUpdateFunc: () => {
      crudRef.value.rowEdit(selectionList.value[0]);
    },
    handleSelectionChangeFunc:(selection:any)=>{
    handleSelectionChangeFunc: (selection: any) => {
      selectionList.value = selection;
    },
    getBeginListFunc: (params = {}) => {
      // 创建新参数对象
      let newParams = { ...params };
      newParams = proxy.addDateRangeNew(newParams, newParams?.createdTimeArray, 'createTime') || [];
      newParams = proxy.addDateRangeNew(newParams, newParams?.updateTimeArray, 'updateTime') || [];
      delete newParams.createdTimeArray;
      delete newParams.updateTimeArray;
      queryParams.value = newParams;
      return newParams;
    }
  })
const handleAdd = () => {
  router.push('/customer/customerManagement-info')
  // crudRef.value.rowAdd();
}
// 弹窗显示状态
const dialogVisible = ref(false);
// 折叠面板默认展开项
const activePanels = ref(['basic', 'contact', 'other']);
// 表单实例
const customerFormRef = ref<FormInstance>();
// 表单数据
// 打开弹窗(供父组件调用)
const handleFy = () => {
  dialogVisible.value = true;
  // 重置表单
  customerFormRef.value?.resetFields();
};
// 关闭弹窗
const handleClose = () => {
  dialogVisible.value = false;
  customerFormRef.value?.resetFields();
};
// 提交表单
const handleSubmit = async () => {
  if (!customerFormRef.value) return;
  try {
    // 表单校验
    await customerFormRef.value.validate();
    // 这里可以写提交接口的逻辑
    console.log('表单数据:', form);
    ElMessage.success('保存成功!');
    // 关闭弹窗
    dialogVisible.value = false;
    // 重置表单
    customerFormRef.value.resetFields();
  } catch (error) {
    ElMessage.warning('请完善必填项后提交');
  }
};
</script>