wangyi
2026-01-19 7fb0a8f0ab16c149484bf043754cd10cfa94de2f
src/views/GyCustomer/CustomerEdit/index.vue
@@ -1,6 +1,6 @@
<template>
  <div class="customer-edit">
    <el-dialog
    <!-- <el-dialog
      :title="dialogTitle"
      :visible.sync="openEdit"
      width="1480px"
@@ -8,7 +8,7 @@
      class="customerBox"
      :before-close="handleClose"
      :close-on-click-modal="false"
    >
    > -->
      <div class="dialog-content">
        <el-card style="margin-bottom: 10px;">
          <div class="card-header">
@@ -23,15 +23,15 @@
        <el-card>
          <div class="card-body">
            <h1 style="text-align:center;margin-bottom:20px;"><b>客户资料</b></h1>
            <el-tabs v-model="activeTab" type="card">
              <el-tab-pane label="基本信息" name="basic">
                <el-form ref="form" :model="formData" label-width="100px" :rules="rules">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="客户代码" prop="HNumber">
                        <el-input
                          v-model="formData.HNumber"
                        <el-input
                          v-model="formData.HNumber"
                          placeholder="请输入客户代码"
                          :readonly="operationType === 3"
                        ></el-input>
@@ -78,8 +78,8 @@
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="创建组织" prop="HCreateOrgID">
                        <el-select
                          v-model="formData.HCreateOrgID"
                        <el-select
                          v-model="formData.HCreateOrgID"
                          placeholder="请选择创建组织"
                          :disabled="operationType !== 1"
                          style="width: 100%"
@@ -98,8 +98,8 @@
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="使用组织" prop="HUSEORGID">
                        <el-select
                          v-model="formData.HUSEORGID"
                        <el-select
                          v-model="formData.HUSEORGID"
                          placeholder="请选择使用组织"
                          :disabled="operationType !== 1"
                          style="width: 100%"
@@ -117,17 +117,17 @@
                </el-form>
              </el-tab-pane>
              <el-tab-pane label="其他信息" name="other">
                <el-form ref="formOther" :model="formData" label-width="100px">
                <el-form ref="formOther" :model="formData" :rules="rules" label-width="100px">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="联系人">
                      <el-form-item label="联系人" prop="HLinkMan">
                        <el-input v-model="formData.HLinkMan" placeholder="请输入联系人"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="联系电话">
                      <el-form-item label="联系电话" prop="HLinkPhone">
                        <el-input v-model="formData.HLinkPhone" placeholder="请输入联系电话"></el-input>
                      </el-form-item>
                    </el-col>
@@ -148,7 +148,7 @@
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="地址">
                      <el-form-item label="地址" prop="HAddress">
                        <el-input v-model="formData.HAddress" placeholder="请输入地址"></el-input>
                      </el-form-item>
                    </el-col>
@@ -220,17 +220,17 @@
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="地区">
                        <el-input
                          v-model="formData.HAreaName"
                      <el-form-item label="地区" prop="HAreaID">
                        <el-input
                          v-model="formData.HAreaName"
                          placeholder="请选择地区"
                          readonly
                          style="width: calc(100% - 50px)"
                        >
                        </el-input>
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                          style="margin-left: 10px;"
                          @click="openAreaDialog"
                        ></el-button>
@@ -242,16 +242,16 @@
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="默认货币">
                        <el-input
                          v-model="formData.HCurName"
                        <el-input
                          v-model="formData.HCurName"
                          placeholder="请选择默认货币"
                          readonly
                          style="width: calc(100% - 50px)"
                        >
                        </el-input>
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                          style="margin-left: 10px;"
                          @click="openCurrencyDialog"
                        ></el-button>
@@ -260,16 +260,16 @@
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="结算方式">
                        <el-input
                          v-model="formData.HSSName"
                        <el-input
                          v-model="formData.HSSName"
                          placeholder="请选择结算方式"
                          readonly
                          style="width: calc(100% - 50px)"
                        >
                        </el-input>
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                          style="margin-left: 10px;"
                          @click="openSettleStyleDialog"
                        ></el-button>
@@ -280,7 +280,7 @@
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="客户状态">
                      <el-form-item label="客户状态" prop="HCusStatus">
                        <el-select v-model="formData.HCusStatus" placeholder="请选择客户状态" style="width: 100%">
                          <el-option label="潜在" value="101"></el-option>
                          <el-option label="合格" value="102"></el-option>
@@ -292,16 +292,16 @@
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="客户分类">
                        <el-input
                          v-model="formData.HCusTypeName"
                        <el-input
                          v-model="formData.HCusTypeName"
                          placeholder="请选择客户分类"
                          readonly
                          style="width: calc(100% - 50px)"
                        >
                        </el-input>
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                          style="margin-left: 10px;"
                          @click="openCustomerTypeDialog"
                        ></el-button>
@@ -372,32 +372,32 @@
        </el-card>
      </div>
    <!-- 地区tanchuang -->
    <AreaDialog
    <AreaDialog
      :visible.sync="areaDialogVisible"
      @selected="handleAreaSelected"
    />
    <!-- 货币tanchuang -->
    <CurrencyDialog
    <CurrencyDialog
      :visible.sync="currencyDialogVisible"
      @selected="handleCurrencySelected"
    />
    <!-- 结算方式tanchuang -->
    <SettleStyleDialog
    <SettleStyleDialog
      :visible.sync="settleStyleDialogVisible"
      @selected="handleSettleStyleSelected"
    />
      <!-- 客户分类tanchuang -->
    <CustomerTypeDialog
    <CustomerTypeDialog
      :visible.sync="customerTypeDialogVisible"
      @selected="handleCustomerTypeSelected"
    />
    </el-dialog>
    <!-- </el-dialog> -->
  </div>
</template>
@@ -442,7 +442,7 @@
    return {
      openEdit: true,
      activeTab: 'basic',
      // 表单数据
      formData: {
        HNumber: '',
@@ -454,7 +454,7 @@
        HMateOutEmp: '',
        HCreateOrgID: '',
        HUSEORGID: '',
        // 其他信息
        HLinkMan: '',
        HLinkPhone: '',
@@ -480,7 +480,7 @@
        HCusStatus: '',
        HCusTypeName: '',
        HCusTypeID: '0',
        // 系统信息
        HCreator: '',
        HCreateDate: '',
@@ -491,7 +491,7 @@
        HDeleteMan: '',
        HDeleteDate: ''
      },
      // 验证
      rules: {
        HNumber: [
@@ -507,19 +507,19 @@
          { required: true, message: '请选择使用组织', trigger: 'change' }
        ]
      },
      organizationList: [],
      areaDialogVisible: false,
      currencyDialogVisible: false,
      settleStyleDialogVisible: false,
      customerTypeDialogVisible: false,
      saveDisabled: false,
      auditDisabled: false,
      baseURL: process.env.VUE_APP_BASE_URL || 'http://47.96.97.237/API/',
      baseURL: process.env.VUE_APP_BASE_API || 'http://47.96.97.237/API/',
      user: 'admin'
    }
  },
@@ -548,15 +548,16 @@
    this.initData()
    this.loadOrganizations()
    this.handleOperationType()
    this.setConditionalRules()
  },
  methods: {
    initData() {
      this.formData.HCreator = this.user
      this.formData.HCreateDate = new Date().toLocaleString()
    },
    loadOrganizations() {
      axios.get(`${this.baseURL}/Web/GetOrganizations`)
      axios.get(`${this.$baseUrl}/Web/GetOrganizations`)
        .then(response => {
          if (response.data.count === 1) {
            this.organizationList = response.data.data
@@ -571,7 +572,7 @@
          this.$modal.msgError('加载组织数据失败!')
        })
    },
    handleOperationType() {
      switch (this.operationType) {
        case 1: // 新增
@@ -588,13 +589,13 @@
          break
      }
    },
    handleAddNew() {
      this.auditDisabled = true
      this.getMaxBillID()
    },
    handleSerialAdd() {
      this.formData.HCusTypeName = this.HCusClsName
@@ -602,21 +603,21 @@
      this.setHNumber(this.HCusTypeID)
      this.auditDisabled = true
    },
    handleEdit() {
      this.loadEditData(this.linterid)
    },
    handleCopy() {
      this.loadEditData(this.linterid)
      this.auditDisabled = true
    },
    getMaxBillID() {
      axios.get(`${this.baseURL}/Gy_Customer/GetMAXBillID`)
      axios.get(`${this.$baseUrl}/Gy_Customer/GetMAXBillID`)
        .then(response => {
          console.log('Max Bill ID:', response.data)
        })
@@ -624,10 +625,10 @@
          console.error('获取最大单据ID失败:', error)
        })
    },
    // 设置流水号
    setHNumber(typeID) {
      axios.get(`${this.baseURL}/Gy_Customer/getMaxNum`, {
      axios.get(`${this.$baseUrl}/Gy_Customer/getMaxNum`, {
        params: {
          HCusTypeID: typeID,
          user: this.user,
@@ -643,16 +644,16 @@
          this.$modal.msgError('获取流水号失败!')
        })
    },
    loadEditData(interId) {
      axios.get(`${this.baseURL}/Gy_Customer/xg_extendCheckEmp`, {
      axios.get(`${this.$baseUrl}/Gy_Customer/xg_extendCheckEmp`, {
        params: { HInterID: interId }
      })
        .then(response => {
          if (response.data.data && response.data.data.length > 0) {
            const data = response.data.data[0]
            this.populateFormData(data)
            if (data.审核人 && data.审核人 !== '') {
              this.saveDisabled = true
              this.auditDisabled = true
@@ -663,8 +664,8 @@
          this.$modal.msgError('加载客户数据失败!')
        })
    },
    populateFormData(data) {
      this.formData = {
        ...this.formData,
@@ -702,64 +703,115 @@
        HChecker: data.审核人 || '',
        HCheckDate: data.审核日期 || ''
      }
      this.formData.HUpDater = this.user
      this.formData.HUpDateDate = new Date().toLocaleString()
    },
    // 保存
    handleSave() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (!this.validateForm()) {
            return
          }
          const formData = { ...this.formData }
          formData.HStopflag = formData.HStopflag ? 'true' : 'false'
          let url = `${this.baseURL}/Gy_Customer/AddBill`
          let params = { oMain: JSON.stringify(formData) + ';' + this.user }
          if (this.operationType === 3) {
            // 编辑保存
            url = `${this.baseURL}/Gy_Customer/AddBill1`
            params = {
              oMain: JSON.stringify(formData) + ';' + this.linterid + ';' + this.user + ';Gy_Customer_Edit'
            }
          }
          axios.post(url, params)
            .then(response => {
              if (response.data.count === 1) {
                this.$modal.msgSuccess(response.data.Message)
                this.saveDisabled = true
                this.saveConfig()
                this.openEdit = false
                this.$emit('editClose', true)
              } else {
                this.$modal.msgError(response.data.Message)
              }
            })
            .catch(error => {
              this.$modal.msgError('保存失败!')
            })
        }
    async handleSave() {
      const validMain = await new Promise(resolve => {
        this.$refs.form.validate(valid => resolve(valid))
      })
      let validOther = true
      if (this.$refs.formOther) {
        validOther = await new Promise(resolve => {
          this.$refs.formOther.validate(valid => resolve(valid))
        })
      }
      if (validMain && validOther) {
        if (!this.validateForm()) {
          return
        }
        const formData = { ...this.formData }
        formData.HStopflag = formData.HStopflag ? 'true' : 'false'
        let url = `${this.$baseUrl}/Gy_Customer/AddBill`
        let params = { oMain: JSON.stringify(formData) + ';' + this.user }
        if (this.operationType === 3) {
          // 编辑保存
          url = `${this.$baseUrl}/Gy_Customer/AddBill1`
          params = {
            oMain: JSON.stringify(formData) + ';' + this.linterid + ';' + this.user + ';Gy_Customer_Edit'
          }
        }
        axios.post(url, params)
          .then(response => {
            if (response.data.count === 1) {
              this.$modal.msgSuccess(response.data.Message)
              this.saveDisabled = true
              this.saveConfig()
              this.openEdit = false
              this.$emit('editClose', true)
            } else {
              this.$modal.msgError(response.data.Message)
            }
          })
          .catch(error => {
            this.$modal.msgError('保存失败!')
          })
      }
    },
    setConditionalRules() {
      this.rules.HLinkMan = [
        { validator: this.validateRequiredIfAdd, trigger: 'blur', message: '请输入联系人' }
      ]
      this.rules.HLinkPhone = [
        { validator: this.validateRequiredIfAdd, trigger: 'blur', message: '请输入联系电话' }
      ]
      this.rules.HAddress = [
        { validator: this.validateRequiredIfAdd, trigger: 'blur', message: '请输入地址' }
      ]
      this.rules.HAreaID = [
        { validator: this.validateRequiredIfAdd, trigger: 'change', message: '请选择地区' }
      ]
      this.rules.HCusStatus = [
        { validator: this.validateRequiredIfAdd, trigger: 'change', message: '请选择客户状态' }
      ]
    },
    validateRequiredIfAdd(rule, value, callback) {
      if (this.operationType !== 1) {
        return callback()
      }
      if (value === null || value === undefined) {
        return callback(new Error(rule.message || '该项为必填'))
      }
      if (typeof value === 'string' && value.trim() === '') {
        return callback(new Error(rule.message || '该项为必填'))
      }
      if (value === '0') {
        return callback(new Error(rule.message || '该项为必填'))
      }
      return callback()
    },
    // 表单验证
    validateForm() {
      if (!this.formData.HNumber) {
        this.$modal.msgWarning('请输入客户代码!')
        return false
      }
      if (!this.formData.HName) {
        this.$modal.msgWarning('请输入客户名称!')
        return false
      }
      // 增值税率验证
      const taxRate = this.formData.HTaxRate
      // if (taxRate && taxRate.substring(taxRate.length - 1) === '.') {
@@ -771,13 +823,13 @@
        this.$modal.msgWarning('增值税率请输入正确数字!')
        return false
      }
      return true
    },
    // 审核
    handleAudit() {
      axios.get(`${this.baseURL}/Gy_Customer/AuditGy_Customer`, {
      axios.get(`${this.$baseUrl}/Gy_Customer/AuditGy_Customer`, {
        params: {
          HInterID: this.linterid,
          IsAudit: 0,
@@ -797,13 +849,13 @@
          this.$modal.msgError('审核失败!')
        })
    },
    // 退出
    handleExit() {
      this.openEdit = false
      this.$emit('editClose', false)
    },
    // 关闭对话框
    handleClose(done) {
      this.$confirm('确认关闭?')
@@ -813,7 +865,7 @@
        })
        .catch(_ => {})
    },
    // 保存配置
    saveConfig() {
      const config = {
@@ -824,40 +876,40 @@
      }
      localStorage.setItem('Gy_Customer_Edit', JSON.stringify(config))
    },
    // 打开对话框方法
    openAreaDialog() {
      this.areaDialogVisible = true
    },
    openCurrencyDialog() {
      this.currencyDialogVisible = true
    },
    openSettleStyleDialog() {
      this.settleStyleDialogVisible = true
    },
    openCustomerTypeDialog() {
      this.customerTypeDialogVisible = true
    },
    // 对话框选择回调
    handleAreaSelected(data) {
      this.formData.HAreaName = data.地区名称
      this.formData.HAreaID = data.HItemID
    },
    handleCurrencySelected(data) {
      this.formData.HCurName = data.货币名称
      this.formData.HCurID = data.HItemID
    },
    handleSettleStyleSelected(data) {
      this.formData.HSSName = data.结算方式名称
      this.formData.HSSID = data.HItemID
    },
    handleCustomerTypeSelected(data) {
      this.formData.HCusTypeName = data.客户分类名称
      this.formData.HCusTypeID = data.HItemID
@@ -895,4 +947,4 @@
.el-button-group {
  margin-bottom: 10px;
}
</style>
</style>