فهرست منبع

客户信息表制单增加必填校验

cgp 1 هفته پیش
والد
کامیت
589e8c5782
1فایلهای تغییر یافته به همراه298 افزوده شده و 289 حذف شده
  1. 298 289
      src/views/qw/companyCustomer/index.vue

+ 298 - 289
src/views/qw/companyCustomer/index.vue

@@ -294,18 +294,19 @@
       </div>
     </el-dialog>
 
-    <el-dialog :title="createOrder.title" v-if="createOrder.open" :visible.sync="createOrder.open" width="1000px" append-to-body :close-on-click-modal ="false">
+    <!-- 制单弹窗 - 全部字段必填 -->
+    <el-dialog :title="createOrder.title" :visible.sync="createOrder.open" width="1000px" append-to-body :close-on-click-modal="false" @close="createOrderCancel">
       <el-form ref="createOrderForm" :model="createOrderForm" :rules="createOrderRules" label-width="120px">
-        <el-form-item label="收货人姓名" prop="realName">
+        <el-form-item label="收货人姓名" prop="realName" required>
           <el-input v-model="createOrderForm.realName" placeholder="请输入收货人姓名" />
         </el-form-item>
-        <el-form-item label="收货人电话" prop="phone">
+        <el-form-item label="收货人电话" prop="phone" required>
           <el-input v-model="createOrderForm.phone" placeholder="请输入收货人电话" />
         </el-form-item>
-        <el-form-item label="收货地址" prop="district">
+        <el-form-item label="收货地址" prop="district" required>
           <el-row :gutter="20">
-          <el-col :span="6">
-             <el-select @change="provinceChange" v-model="createOrderForm.province" placeholder="请选择">
+            <el-col :span="6">
+              <el-select @change="provinceChange" v-model="createOrderForm.provinceId" placeholder="请选择" clearable>
                 <el-option
                   v-for="item in province"
                   :key="item.cityId"
@@ -313,9 +314,9 @@
                   :value="item.cityId">
                 </el-option>
               </el-select>
-          </el-col>
-          <el-col :span="6">
-            <el-select @change="cityChange" v-model="createOrderForm.city" placeholder="请选择">
+            </el-col>
+            <el-col :span="6">
+              <el-select @change="cityChange" v-model="createOrderForm.cityId" placeholder="请选择市" clearable :disabled="!createOrderForm.provinceId">
                 <el-option
                   v-for="item in city"
                   :key="item.cityId"
@@ -323,9 +324,9 @@
                   :value="item.cityId">
                 </el-option>
               </el-select>
-          </el-col>
-          <el-col :span="6">
-             <el-select @change="districtChange" v-model="createOrderForm.district" placeholder="请选择">
+            </el-col>
+            <el-col :span="6">
+              <el-select @change="districtChange" v-model="createOrderForm.districtId" placeholder="请选择区" clearable :disabled="!createOrderForm.cityId">
                 <el-option
                   v-for="item in district"
                   :key="item.cityId"
@@ -333,13 +334,13 @@
                   :value="item.cityId">
                 </el-option>
               </el-select>
-          </el-col>
-        </el-row>
+            </el-col>
+          </el-row>
         </el-form-item>
-        <el-form-item label="详细地址" prop="detail">
+        <el-form-item label="详细地址" prop="detail" required>
           <el-input v-model="createOrderForm.detail" placeholder="请输入收货人详细地址" />
         </el-form-item>
-        <el-form-item label="商品列表" >
+        <el-form-item label="商品列表" prop="products" required>
           <el-select
             v-model="createOrderForm.erpType"
             placeholder="请选择ERP类型"
@@ -361,25 +362,16 @@
               type="primary"
               icon="el-icon-plus"
               @click="handleAddProduct"
-              >添加商品</el-button
+            >添加商品</el-button
             >
           </div>
-          <!-- <el-row  >
-            <el-col >
-              <el-button plain  type="primary" icon="el-icon-plus" @click="handleAddProduct">添加商品</el-button>
-            </el-col>
-          </el-row> -->
-          <el-table border :key = "tablekey" width="100%" style="margin-top:5px;"  :data="products">
+          <el-table border :key="tablekey" width="100%" style="margin-top:5px;" :data="products">
             <el-table-column label="商品编号" align="center" prop="barCode" />
             <el-table-column label="商品图片" align="center" width="100">
               <template slot-scope="scope">
-                <el-popover
-                  placement="right"
-                  itle=""
-                  trigger="hover"
-                >
-                <img slot="reference" :src="scope.row.image" width="50">
-                <img :src="scope.row.image" style="max-width: 50px;">
+                <el-popover placement="right" title="" trigger="hover">
+                  <img slot="reference" :src="scope.row.image" width="50">
+                  <img :src="scope.row.image" style="max-width: 50px;">
                 </el-popover>
               </template>
             </el-table-column>
@@ -387,21 +379,21 @@
             <el-table-column label="商品规格" align="center" prop="sku" />
             <el-table-column label="库存" align="center" prop="stock" />
             <el-table-column label="单价" align="center" prop="price" />
-            <el-table-column label="数量" align="center"  prop="count" width="200px" :key="tablekey">
+            <el-table-column label="数量" align="center" prop="count" width="200px">
               <template slot-scope="scope">
                 <div>
-                  <el-input-number v-model="scope.row.count"  @change="handleProductCountChange(scope.row)"  size="mini" :min="1" :max="scope.row.stock"  ></el-input-number>
+                  <el-input-number v-model="scope.row.count" @change="handleProductCountChange(scope.row)" size="mini" :min="1" :max="scope.row.stock"></el-input-number>
                 </div>
               </template>
             </el-table-column>
-            <el-table-column label="小计" align="center" prop="money"   />
-            <el-table-column label="操作" align="center" width="100px" >
+            <el-table-column label="小计" align="center" prop="money" />
+            <el-table-column label="操作" align="center" width="100px">
               <template slot-scope="scope">
                 <el-button
                   size="mini"
                   type="text"
                   icon="el-icon-delete"
-                  @click="handleDelete(scope.row)"
+                  @click="removeProduct(scope.row)"
                 >删除</el-button>
               </template>
             </el-table-column>
@@ -413,28 +405,23 @@
           </el-row>
         </el-form-item>
 
-        <el-form-item label="赠品列表" >
-          
+        <el-form-item label="赠品列表">
           <div style="float: right">
             <el-button
               plain
               type="primary"
               icon="el-icon-plus"
               @click="handleAddGiftProduct"
-              >添加商品</el-button
+            >添加赠品</el-button
             >
           </div>
-          <el-table border  width="100%" style="margin-top:5px;"  :data="giftProducts">
+          <el-table border width="100%" style="margin-top:5px;" :data="giftProducts">
             <el-table-column label="商品编号" align="center" prop="barCode" />
             <el-table-column label="商品图片" align="center" width="100">
               <template slot-scope="scope">
-                <el-popover
-                  placement="right"
-                  itle=""
-                  trigger="hover"
-                >
-                <img slot="reference" :src="scope.row.image" width="50">
-                <img :src="scope.row.image" style="max-width: 50px;">
+                <el-popover placement="right" title="" trigger="hover">
+                  <img slot="reference" :src="scope.row.image" width="50">
+                  <img :src="scope.row.image" style="max-width: 50px;">
                 </el-popover>
               </template>
             </el-table-column>
@@ -442,38 +429,38 @@
             <el-table-column label="商品规格" align="center" prop="sku" />
             <el-table-column label="库存" align="center" prop="stock" />
             <el-table-column label="单价" align="center" prop="price" />
-            <el-table-column label="数量" align="center"  prop="count" width="200px" :key="tablekey">
+            <el-table-column label="数量" align="center" prop="count" width="200px">
               <template slot-scope="scope">
                 <div>
-                  <el-input-number v-model="scope.row.count"  @change="handleProductCountChange(scope.row)"  size="mini" :min="1" :max="scope.row.stock"  ></el-input-number>
+                  <el-input-number v-model="scope.row.count" @change="handleGiftProductCountChange(scope.row)" size="mini" :min="1" :max="scope.row.stock"></el-input-number>
                 </div>
               </template>
             </el-table-column>
-            <el-table-column label="小计" align="center" prop="money"   />
-            <el-table-column label="操作" align="center" width="100px" >
+            <el-table-column label="小计" align="center" prop="money" />
+            <el-table-column label="操作" align="center" width="100px">
               <template slot-scope="scope">
                 <el-button
                   size="mini"
                   type="text"
                   icon="el-icon-delete"
-                  @click="handleDelete(scope.row)"
+                  @click="removeGiftProduct(scope.row)"
                 >删除</el-button>
               </template>
             </el-table-column>
           </el-table>
         </el-form-item>
-        <el-form-item label="支付方式" prop="payType">
-          <el-select   v-model="createOrderForm.payType" placeholder="请选择支付方式" clearable size="small" >
+        <el-form-item label="支付方式" prop="payType" required>
+          <el-select v-model="createOrderForm.payType" placeholder="请选择支付方式" clearable size="small">
             <el-option
               v-for="item in payTypeOptions"
               :key="item.dictValue"
               :label="item.dictLabel"
               :value="item.dictValue"
-              />
+            />
           </el-select>
         </el-form-item>
-        <el-form-item label="抵扣金额" prop="reduceAmount">
-          <el-input-number  v-model="createOrderForm.reduceAmount" placeholder="抵扣金额" size="medium" :precision="2" :min=0.01 :step="0.1" />
+        <el-form-item label="抵扣金额" prop="reduceAmount" required>
+          <el-input-number v-model="createOrderForm.reduceAmount" placeholder="抵扣金额" size="medium" :precision="2" :min="0" :step="0.1" />
         </el-form-item>
       </el-form>
       <div slot="footer" class="dialog-footer">
@@ -482,31 +469,31 @@
       </div>
     </el-dialog>
 
-    <el-dialog :title="product.title" v-if="product.open"  :visible.sync="product.open" width="1000px" append-to-body>
-        <product-select ref="Details"  @selectProduct="selectProduct" />
+    <el-dialog :title="product.title" :visible.sync="product.open" width="1000px" append-to-body>
+      <product-select ref="Details" @selectProduct="selectProduct" />
     </el-dialog>
 
-    <el-dialog :title="giftProduct.title" v-if="giftProduct.open"  :visible.sync="giftProduct.open" width="1000px" append-to-body>
-        <product-select ref="GiftDetails"  @selectProduct="selectGiftProduct" />
+    <el-dialog :title="giftProduct.title" :visible.sync="giftProduct.open" width="1000px" append-to-body>
+      <product-select ref="GiftDetails" @selectProduct="selectGiftProduct" />
     </el-dialog>
-    
   </div>
 </template>
 
 <script>
 import {
   listCustomer, getCustomer, addCustomer, updateCustomer, delCustomer, exportCustomer,
-  getCompanyUserAndDoctor, getPrescribeListByIdAndPhone, claimCustomer,getCustomerLogList
+  getCompanyUserAndDoctor, getPrescribeListByIdAndPhone, claimCustomer, getCustomerLogList, createUserOrder
 } from '@/api/qw/companyCustomer'
-import {parseTime} from '@/utils/common'
-import {getCitys} from "@/api/hisStore/city";
+import { parseTime } from '@/utils/common'
+import { getCitys } from "@/api/hisStore/city";
 import CollectionInfoDialog from './CollectionInfoDialog.vue'
 import productSelect from "../../hisStore/components/erpProductSelect";
 
 export default {
   name: "Customer",
-  components: {CollectionInfoDialog, productSelect},
+  components: { CollectionInfoDialog, productSelect },
   data() {
+    // 自定义校验:手机号
     const validatePhone = (rule, value, callback) => {
       if (!value) {
         callback(new Error('电话号码不能为空'));
@@ -519,6 +506,7 @@ export default {
       }
       callback();
     };
+    // 自定义校验:年龄
     const validateAge = (rule, value, callback) => {
       if (value === null || value === undefined || value === '') {
         callback(new Error('年龄不能为空'));
@@ -528,7 +516,7 @@ export default {
         callback();
       }
     };
-    // 认领号码校验(必填,11位手机号格式)
+    // 认领号码校验
     const validateClaimNumber = (rule, value, callback) => {
       if (!value) {
         callback(new Error('请输入认领号码'));
@@ -541,6 +529,25 @@ export default {
       }
       callback();
     };
+    // 制单必填项校验:商品列表不能为空
+    const validateProducts = (rule, value, callback) => {
+      if (!this.products || this.products.length === 0) {
+        callback(new Error('请至少添加一个商品'));
+      } else {
+        callback();
+      }
+    };
+    // 收货地址联动校验
+    const validateAddress = (rule, value, callback) => {
+      if (!this.createOrderForm.provinceId || !this.createOrderForm.cityId || !this.createOrderForm.districtId) {
+        callback(new Error('请完整选择省/市/区'));
+      } else if (!this.createOrderForm.detail) {
+        callback(new Error('请填写详细地址'));
+      } else {
+        callback();
+      }
+    };
+
     return {
       loading: true,
       ids: [],
@@ -559,37 +566,37 @@ export default {
         customerName: null,
         phone: null,
         companyUserName: null,
-        claimStatus: null,    // 认领状态筛选
-        completeStatus: null, // 完善状态筛选
+        claimStatus: null,
+        completeStatus: null,
         purchased: false,
         minBuyCount: null,
         maxBuyCount: null
       },
       form: {},
       rules: {
-        customerName: [{required: true, message: "客户姓名不能为空", trigger: "blur"}],
-        sex: [{required: true, message: "请选择性别", trigger: "change"}],
+        customerName: [{ required: true, message: "客户姓名不能为空", trigger: "blur" }],
+        sex: [{ required: true, message: "请选择性别", trigger: "change" }],
         age: [
-          {required: true, message: "年龄不能为空", trigger: "blur"},
-          {validator: validateAge, trigger: "blur"}
+          { required: true, message: "年龄不能为空", trigger: "blur" },
+          { validator: validateAge, trigger: "blur" }
         ],
         phone: [
-          {required: true, message: "电话不能为空", trigger: "blur"},
-          {validator: validatePhone, trigger: "blur"}
+          { required: true, message: "电话不能为空", trigger: "blur" },
+          { validator: validatePhone, trigger: "blur" }
         ],
-        address: [{required: true, message: "地址不能为空", trigger: "blur"}],
-        companyUserName: [{required: true, message: "客服姓名不能为空", trigger: "blur"}],
-        doctorName: [{required: true, message: "负责医生不能为空", trigger: "blur"}],
+        address: [{ required: true, message: "地址不能为空", trigger: "blur" }],
+        companyUserName: [{ required: true, message: "客服姓名不能为空", trigger: "blur" }],
+        doctorName: [{ required: true, message: "负责医生不能为空", trigger: "blur" }],
       },
       sexOptions: [
-        {label: '女', value: '0'},
-        {label: '男', value: '1'},
-        {label: '未知', value: '2'}
+        { label: '女', value: '0' },
+        { label: '男', value: '1' },
+        { label: '未知', value: '2' }
       ],
-      erpList:[
-        {dictLabel: '聚水潭', dictValue: '1'},
-        {dictLabel: '兔灵', dictValue: '2'},
-        {dictLabel: '京东云仓', dictValue: '3'}
+      erpList: [
+        { dictLabel: '聚水潭', dictValue: '1' },
+        { dictLabel: '兔灵', dictValue: '2' },
+        { dictLabel: '京东云仓', dictValue: '3' }
       ],
       // 处方相关
       prescribeOpen: false,
@@ -603,32 +610,28 @@ export default {
         pageSize: 10
       },
       doctorConfirmOptions: [
-        {dictValue: '0', dictLabel: "未确认"},
-        {dictValue: '1', dictLabel: "已确认"}
+        { dictValue: '0', dictLabel: "未确认" },
+        { dictValue: '1', dictLabel: "已确认" }
       ],
       prescribeTypeOptions: [
-        {dictValue: '1', dictLabel: "西药"},
-        {dictValue: '2', dictLabel: "中药"},
-        {dictValue: '3', dictLabel: "OTC"}
+        { dictValue: '1', dictLabel: "西药" },
+        { dictValue: '2', dictLabel: "中药" },
+        { dictValue: '3', dictLabel: "OTC" }
       ],
-      // 控制信息采集弹窗的变量
       collectionVisible: false,
-      // 详情弹窗只读模式
       isDetail: false,
-      // 独立认领弹窗相关
+      // 认领弹窗
       claimDialogVisible: false,
       claimSubmitLoading: false,
       currentClaimRow: null,
-      claimForm: {
-        claimNumber: ''
-      },
+      claimForm: { claimNumber: '' },
       claimRules: {
         claimNumber: [
           { required: true, message: '请输入认领号码', trigger: 'blur' },
           { validator: validateClaimNumber, trigger: 'blur' }
         ]
       },
-      // 认领记录弹窗相关
+      // 认领记录
       claimLogDialogVisible: false,
       claimLogLoading: false,
       claimLogList: [],
@@ -636,38 +639,50 @@ export default {
       claimLogQueryParams: {
         pageNum: 1,
         pageSize: 10,
-        companyCustomerId: null   // 当前查看的客户ID
+        companyCustomerId: null
       },
-      createOrder:{
+      // 制单相关
+      createOrder: {
         open: false,
         title: '创建订单',
       },
       createOrderForm: {
-
+        realName: '',
+        phone: '',
+        provinceId: null,
+        cityId: null,
+        districtId: null,
+        province: '',
+        city: '',
+        district: '',
+        detail: '',
+        erpType: '',
+        payType: '',
+        reduceAmount: 0,
       },
-      createOrderRules: { 
-      },
-
-      citys:[],
-      province:[],
-      city:[],
-      district:[],
-
-      products:[],
-      product:{
-        open:false,
-        title:"商品选择"
-      },
-
-      giftProducts:[],
-      giftProduct:{
-        open:false,
-        title:"赠品选择"
+      createOrderRules: {
+        realName: [{ required: true, message: '收货人姓名不能为空', trigger: 'blur' }],
+        phone: [
+          { required: true, message: '收货人电话不能为空', trigger: 'blur' },
+          { validator: validatePhone, trigger: 'blur' }
+        ],
+        detail: [{ required: true, message: '详细地址不能为空', trigger: 'blur' }],
+        payType: [{ required: true, message: '请选择支付方式', trigger: 'change' }],
+        reduceAmount: [{ required: true, message: '抵扣金额不能为空', trigger: 'blur' }],
+        products: [{ validator: validateProducts, trigger: 'change' }],
+        address: [{ validator: validateAddress, trigger: 'change' }]
       },
-      tablekey:false,
-      totalMoney:0.00,
-
-      payTypeOptions:[],
+      citys: [],
+      province: [],
+      city: [],
+      district: [],
+      products: [],
+      product: { open: false, title: "商品选择" },
+      giftProducts: [],
+      giftProduct: { open: false, title: "赠品选择" },
+      tablekey: false,
+      totalMoney: 0.00,
+      payTypeOptions: [],
     }
   },
   created() {
@@ -678,156 +693,182 @@ export default {
     });
   },
   methods: {
-    createOrderSubmitForm(){
-      
+    // ========== 制单相关方法 ==========
+    createOrderSubmitForm() {
       this.$refs["createOrderForm"].validate(valid => {
-        if(this.products.length==0){
-          this.msgError("请选择商品");
+        // 手动校验地址联动
+        if (!this.createOrderForm.provinceId || !this.createOrderForm.cityId || !this.createOrderForm.districtId) {
+          this.$message.error('请完整选择省/市/区');
           return;
         }
-        this.createOrderForm.products=this.products;
-        if(this.giftProducts.length > 0) {
-          this.createOrderForm.giftProducts=this.giftProducts;
+        if (this.products.length === 0) {
+          this.$message.error('请至少添加一个商品');
+          return;
         }
-        console.log(this.createOrderForm);
-        return;
         if (valid) {
-          createUserOrder(this.createOrderForm).then(response => {
+          const params = {
+            ...this.createOrderForm,
+            products: this.products,
+            giftProducts: this.giftProducts,
+            province: this.createOrderForm.province,
+            city: this.createOrderForm.city,
+            district: this.createOrderForm.district,
+            totalAmount: this.totalMoney
+          };
+          createUserOrder(params).then(response => {
             if (response.code === 200) {
               this.msgSuccess("创建成功");
-              this.open = false;
+              this.createOrder.open = false;
+              this.createOrderReset();
               this.getList();
             }
+          }).catch(err => {
+            this.$message.error(err.message || '创建订单失败');
           });
-
         }
-      })
+      });
     },
-        // 取消按钮
     createOrderCancel() {
-      this.open = false;
+      this.createOrder.open = false;
       this.createOrderReset();
     },
-    // 表单重置
     createOrderReset() {
       this.createOrderForm = {
-        products:null,
-        giftProducts:null,
+        realName: '',
+        phone: '',
+        provinceId: null,
+        cityId: null,
+        districtId: null,
+        province: '',
+        city: '',
+        district: '',
+        detail: '',
+        erpType: '',
+        payType: '',
+        reduceAmount: 0,
       };
-      this.resetForm("createOrderForm");
+      this.products = [];
+      this.giftProducts = [];
+      this.totalMoney = 0;
+      this.city = [];
+      this.district = [];
+      if (this.$refs.createOrderForm) {
+        this.$refs.createOrderForm.clearValidate();
+      }
     },
     handleAddGiftProduct() {
-      if (this.createOrderForm.erpType== null || this.createOrderForm.erpType== '') {
-        return this.$message({
-          message: "请先选择ERP",
-          type: "warning",
-        });
-      } else {
-        setTimeout(() => {
-          this.$refs.GiftDetails.getDetails(this.createOrderForm.erpType,1);
-        }, 1);
-        this.giftProduct.open = true;
+      if (!this.createOrderForm.erpType) {
+        this.$message.warning("请先选择ERP");
+        return;
       }
-    },
-
-    selectGiftProduct(row){
-      for(var i=0;i<this.products.length;i++){
-        if(this.products[i].id==row.id){
-          return;
+      setTimeout(() => {
+        if (this.$refs.GiftDetails) {
+          this.$refs.GiftDetails.getDetails(this.createOrderForm.erpType, 1);
         }
+      }, 1);
+      this.giftProduct.open = true;
+    },
+    selectGiftProduct(row) {
+      for (let i = 0; i < this.giftProducts.length; i++) {
+        if (this.giftProducts[i].id === row.id) return;
       }
-      row.count=1;
-      row.money=row.count*row.price;
-      this.products.push(row);
-      this.$message.success("商品"+ row.productName + "添加成功")
-      this.compute();
+      const newRow = { ...row, count: 1, money: row.price };
+      this.giftProducts.push(newRow);
+      this.$message.success("赠品 " + row.productName + " 添加成功");
     },
-
-    changeErp(){
+    changeErp() {
       this.products = [];
-      this.giftProducts=[];
+      this.giftProducts = [];
+      this.totalMoney = 0;
     },
-    /** 删除按钮操作 */
-    handleDelete(row) {
-       this.products.splice(this.products.findIndex(item => item.id === row.id), 1)
-       this.compute();
-
+    removeProduct(row) {
+      const index = this.products.findIndex(item => item.id === row.id);
+      if (index !== -1) this.products.splice(index, 1);
+      this.computeTotalMoney();
     },
-    handleAddProduct(){
-      if(this.createOrderForm.erpType== null || this.createOrderForm.erpType== '') {
-        return this.$message({
-          message: "请先选择ERP",
-          type: "warning",
-        });
-      } else{
-        setTimeout(() => {
-          this.$refs.Details.getDetails(this.createOrderForm.erpType);
-        }, 1);
-        this.product.open=true;
+    removeGiftProduct(row) {
+      const index = this.giftProducts.findIndex(item => item.id === row.id);
+      if (index !== -1) this.giftProducts.splice(index, 1);
+    },
+    handleAddProduct() {
+      if (!this.createOrderForm.erpType) {
+        this.$message.warning("请先选择ERP");
+        return;
       }
+      setTimeout(() => {
+        if (this.$refs.Details) {
+          this.$refs.Details.getDetails(this.createOrderForm.erpType);
+        }
+      }, 1);
+      this.product.open = true;
     },
-    compute(){
-      this.totalMoney=0;
-      var that=this;
-      this.products.forEach (function (value) {
-          that.totalMoney += value.money;
+    computeTotalMoney() {
+      this.totalMoney = 0;
+      this.products.forEach(item => {
+        this.totalMoney += item.money || 0;
       });
     },
-    handleProductCountChange(row){
-      this.tablekey = !this.tablekey
-      row.money=row.count*row.price;
+    handleProductCountChange(row) {
+      this.tablekey = !this.tablekey;
+      row.money = row.count * row.price;
+      this.computeTotalMoney();
       this.$forceUpdate();
-      this.compute();
     },
-    selectProduct(row){
-      for(var i=0;i<this.products.length;i++){
-        if(this.products[i].id==row.id){
-          return;
-        }
+    handleGiftProductCountChange(row) {
+      row.money = row.count * row.price;
+      this.$forceUpdate();
+    },
+    selectProduct(row) {
+      for (let i = 0; i < this.products.length; i++) {
+        if (this.products[i].id === row.id) return;
       }
-      row.count=1;
-      row.money=row.count*row.price;
-      this.products.push(row);
-      this.$message.success("商品"+ row.productName + "添加成功")
-      this.compute();
+      const newRow = { ...row, count: 1, money: row.price };
+      this.products.push(newRow);
+      this.$message.success("商品 " + row.productName + " 添加成功");
+      this.computeTotalMoney();
     },
+    // 地址联动
     convertCityData(array) {
-      return array.map(item => {
-        return {
-          'cityId': item.value,
-          'name': item.label,
-          'parentId':  item.pid,
-          'children': item.children && this.convertCityData(item.children)
-        }
-      });
+      return array.map(item => ({
+        cityId: item.value,
+        name: item.label,
+        parentId: item.pid,
+        children: item.children && this.convertCityData(item.children)
+      }));
     },
-    districtChange(val){
-      const item = this.district.find(i => i.cityId === val)
-      this.createOrderForm.district=item.name;
+    districtChange(val) {
+      const item = this.district.find(i => i.cityId === val);
+      if (item) this.createOrderForm.district = item.name;
     },
-    cityChange(val){
-      const item = this.city.find(i => i.cityId === val)
-      this.district = item.children
-      this.createOrderForm.district=null;
-      this.createOrderForm.city=item.name;
-      this.createOrderForm.cityId=val;
+    cityChange(val) {
+      const item = this.city.find(i => i.cityId === val);
+      if (item) {
+        this.district = item.children || [];
+        this.createOrderForm.district = '';
+        this.createOrderForm.districtId = null;
+        this.createOrderForm.city = item.name;
+      }
     },
-    provinceChange(val){
-      const item = this.citys.find(i => i.cityId === val)
-      this.city = item.children
-      this.district=[];
-      this.createOrderForm.city=null;
-      this.createOrderForm.district=null;
-      this.createOrderForm.province=item.name;
+    provinceChange(val) {
+      const item = this.citys.find(i => i.cityId === val);
+      if (item) {
+        this.city = item.children || [];
+        this.district = [];
+        this.createOrderForm.city = '';
+        this.createOrderForm.district = '';
+        this.createOrderForm.cityId = null;
+        this.createOrderForm.districtId = null;
+        this.createOrderForm.province = item.name;
+      }
     },
-    getCityList(){
+    getCityList() {
       getCitys().then(res => {
-          this.loading = false;
-          this.citys = this.convertCityData(res.data)
-          this.province=this.citys.filter(item => item.parentId===0 )
-        })
+        this.loading = false;
+        this.citys = this.convertCityData(res.data);
+        this.province = this.citys.filter(item => item.parentId === 0);
+      });
     },
-    handleCreateOrder(row){
+    handleCreateOrder(row) {
       this.createOrderReset();
       this.createOrder.open = true;
       this.createOrderForm.companyCustomerId = row.id;
@@ -836,7 +877,6 @@ export default {
     claimStatusFormat(row) {
       return row.claimStatus === 1 ? '已认领' : '未认领';
     },
-    // 完善状态格式化
     completeStatusFormat(row) {
       return row.completeStatus === 1 ? '已完善' : '未完善';
     },
@@ -853,21 +893,14 @@ export default {
     },
     getList() {
       this.loading = true;
-      // 构建参数,过滤掉 null/undefined/空字符串
       const params = this.addDateRange(this.queryParams, this.dateRange);
       if (this.createTimeRange && this.createTimeRange.length === 2) {
         params.beginCreateTime = this.createTimeRange[0];
         params.endCreateTime = this.createTimeRange[1];
       }
-      // 处理 purchased:false 时不传
-      if (!params.purchased) {
-        delete params.purchased;
-      }
-      // 删除值为 null、undefined 或空字符串的属性
+      if (!params.purchased) delete params.purchased;
       Object.keys(params).forEach(key => {
-        if (params[key] === null || params[key] === undefined || params[key] === '') {
-          delete params[key];
-        }
+        if (params[key] === null || params[key] === undefined || params[key] === '') delete params[key];
       });
       listCustomer(params).then(response => {
         this.customerList = response.rows;
@@ -888,24 +921,14 @@ export default {
       this.queryParams.maxBuyCount = null;
       this.handleQuery();
     },
-    /**
-     * 认领客户:打开独立弹窗,要求输入认领号码
-     */
     handleClaim(row) {
       this.currentClaimRow = row;
       this.claimForm.claimNumber = '';
       this.claimDialogVisible = true;
-      // 清除表单校验
       this.$nextTick(() => {
-        if (this.$refs.claimForm) {
-          this.$refs.claimForm.clearValidate();
-        }
+        if (this.$refs.claimForm) this.$refs.claimForm.clearValidate();
       });
     },
-    /**
-     * 执行认领提交
-     * 先获取当前登录用户的客服和医生信息,再调用认领接口
-     */
     submitClaim() {
       this.$refs.claimForm.validate(valid => {
         if (!valid) return;
@@ -915,14 +938,11 @@ export default {
           return;
         }
         this.claimSubmitLoading = true;
-        // 获取当前登录用户的客服及医生信息
         getCompanyUserAndDoctor().then(res => {
           const userData = res.data;
           if (!userData || !userData.doctorId) {
             this.$message.error("未找到绑定医生,无法认领");
-            this.claimSubmitLoading = false;
-            this.claimDialogVisible = false;
-            return;
+            throw new Error("未找到绑定医生");
           }
           const claimParams = {
             id: this.currentClaimRow.id,
@@ -930,7 +950,7 @@ export default {
             companyUserName: userData.companyUserName,
             doctorId: userData.doctorId,
             doctorName: userData.doctorName,
-            claimPhone: this.claimForm.claimNumber   // 认领号码
+            claimPhone: this.claimForm.claimNumber
           };
           return claimCustomer(claimParams);
         }).then(() => {
@@ -938,10 +958,8 @@ export default {
           this.claimDialogVisible = false;
           this.getList();
         }).catch(err => {
-          // 直接从 err 中取出后端返回的错误信息
           const errorMsg = err?.message || err?.msg || "认领失败,请稍后重试";
           this.$message.error(errorMsg);
-          // 不再输出 console.error,避免重复显示
         }).finally(() => {
           this.claimSubmitLoading = false;
         });
@@ -956,8 +974,7 @@ export default {
     },
     handleDetail(row) {
       this.reset();
-      const id = row.id;
-      getCustomer(id).then(response => {
+      getCustomer(row.id).then(response => {
         this.form = response.data;
         if (this.form.sex !== undefined && this.form.sex !== null) {
           this.form.sex = String(this.form.sex);
@@ -1035,7 +1052,6 @@ export default {
       try {
         const valid = await this.$refs["form"].validate();
         if (!valid) return;
-
         if (this.form.id != null) {
           await updateCustomer(this.form);
           this.$message.success("修改成功");
@@ -1051,6 +1067,7 @@ export default {
         if (e.message) this.$message.error(e.message);
       }
     },
+    // 客户删除方法(保持原有)
     handleDelete(row) {
       const ids = row.id || this.ids.join(",");
       this.$confirm('是否确认删除该客户信息?', '提示', {
@@ -1062,16 +1079,14 @@ export default {
       }).then(() => {
         this.getList();
         this.$message.success("删除成功");
-      }).catch(() => {
-      });
+      }).catch(() => {});
     },
     handleExport() {
       this.$modal.confirm('是否确认导出所有客户信息?').then(() => {
         return exportCustomer(this.addDateRange(this.queryParams, this.dateRange));
       }).then(response => {
         this.download(response.msg, "客户信息数据.xlsx");
-      }).catch(() => {
-      });
+      }).catch(() => {});
     },
     download(content, fileName) {
       const blob = new Blob([content]);
@@ -1116,39 +1131,33 @@ export default {
     },
     handleCollection(row) {
       if (!row.phone) {
-        this.$message.warning('该客户未登记手机号,无法查看信息采集表')
-        return
+        this.$message.warning('该客户未登记手机号,无法查看信息采集表');
+        return;
       }
-      this.currentId = row.id
-      this.collectionVisible = true
+      this.currentId = row.id;
+      this.collectionVisible = true;
     },
-    // 查看认领记录
     handleViewLog(row) {
-      // 重置分页
-      this.claimLogQueryParams.pageNum = 1
-      this.claimLogQueryParams.companyCustomerId = row.id
-      this.claimLogDialogVisible = true
-      this.getClaimLogList()
+      this.claimLogQueryParams.pageNum = 1;
+      this.claimLogQueryParams.companyCustomerId = row.id;
+      this.claimLogDialogVisible = true;
+      this.getClaimLogList();
     },
-    // 获取认领记录列表
     getClaimLogList() {
-      this.claimLogLoading = true
-      // 构建参数,删除空值
-      const params = { ...this.claimLogQueryParams }
+      this.claimLogLoading = true;
+      const params = { ...this.claimLogQueryParams };
       Object.keys(params).forEach(key => {
-        if (params[key] === null || params[key] === undefined || params[key] === '') {
-          delete params[key]
-        }
-      })
+        if (params[key] === null || params[key] === undefined || params[key] === '') delete params[key];
+      });
       getCustomerLogList(params).then(response => {
-        this.claimLogList = response.rows || []
-        this.claimLogTotal = response.total || 0
-        this.claimLogLoading = false
+        this.claimLogList = response.rows || [];
+        this.claimLogTotal = response.total || 0;
+        this.claimLogLoading = false;
       }).catch(() => {
-        this.claimLogLoading = false
-        this.claimLogList = []
-        this.claimLogTotal = 0
-      })
+        this.claimLogLoading = false;
+        this.claimLogList = [];
+        this.claimLogTotal = 0;
+      });
     }
   },
 }