Просмотр исходного кода

优化客户信息表制单样式

cgp 1 неделя назад
Родитель
Сommit
adfcf9628f

+ 10 - 1
src/api/member/handwriteCollection/handwriteCollection.js

@@ -17,7 +17,7 @@ export function getCollection(id) {
   })
 }
 
-// 新增
+// 新增(不用修改订单状态)
 export function addCollection(data) {
   return request({
     url: '/handwrite/collection',
@@ -26,6 +26,15 @@ export function addCollection(data) {
   })
 }
 
+// 新增(需要修改订单状态)
+export function addCollectionAndUpdateOrderStatus(data) {
+  return request({
+    url: '/handwrite/collection/addCollectionAndUpdateOrderStatus',
+    method: 'post',
+    data: data
+  })
+}
+
 // 修改
 export function updateCollection(data) {
   return request({

+ 12 - 0
src/api/store/storeProduct.js

@@ -28,3 +28,15 @@ export function getStoreProduct(productId) {
     method: 'get'
   })
 }
+
+/**
+ * 根据订单号判断订单中的商品是否包含药品
+ * @param {string} orderCode 订单号
+ * @returns {Promise} 返回 flag(true:包含药品, false:不包含药品)
+ */
+export function getProductMedicineFlagByOrderCode(orderCode) {
+  return request({
+    url: `/store/store/storeProduct/getProductMedicineFlagByOrderCode/${orderCode}`,
+    method: 'get'
+  })
+}

+ 209 - 133
src/views/qw/companyCustomer/index.vue

@@ -730,7 +730,6 @@
             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">
@@ -803,7 +802,6 @@
             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">
@@ -1109,6 +1107,44 @@
         >
       </div>
     </el-dialog>
+
+    <!-- ========== 手写信息采集新增弹窗 ========== -->
+    <el-dialog
+      title="新增手写信息采集表"
+      :visible.sync="handwriteDialogVisible"
+      width="700px"
+      append-to-body
+      :close-on-click-modal="false"
+      @close="resetHandwriteForm"
+    >
+      <el-form ref="handwriteForm" :model="handwriteForm" :rules="handwriteRules" label-width="100px">
+        <el-form-item label="手写信息采集表" prop="billImgUrl">
+          <div style="display: flex; align-items: center; gap: 10px;">
+            <image-upload
+              v-model="handwriteForm.billImgUrl"
+              :limit="1"
+              style="flex: 1;"
+            />
+          </div>
+        </el-form-item>
+        <el-form-item label="补充图片" prop="extraImgUrl">
+          <image-upload v-model="handwriteForm.extraImgUrl" :limit="10" multiple />
+        </el-form-item>
+        <el-form-item label="患者姓名" prop="patientName">
+          <el-input v-model="handwriteForm.patientName" placeholder="请输入患者姓名" />
+        </el-form-item>
+        <el-form-item label="患者电话" prop="patientPhone">
+          <el-input v-model="handwriteForm.patientPhone" placeholder="请输入患者电话" />
+        </el-form-item>
+        <el-form-item label="订单号" prop="orderCode">
+          <el-input v-model="handwriteForm.orderCode" disabled />
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="submitHandwriteForm">确 定</el-button>
+        <el-button @click="handwriteDialogVisible = false">取 消</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
@@ -1127,7 +1163,7 @@ import {
   getCanUsePayReceiptList,
   getOrderList,
   getQRCode,
-  getAddress, // 新增导入
+  getAddress,
 } from "@/api/qw/companyCustomer";
 import { parseTime } from "@/utils/common";
 import { getCitys } from "@/api/hisStore/city";
@@ -1135,10 +1171,15 @@ import CollectionInfoDialog from "./CollectionInfoDialog.vue";
 import productSelect from "../../hisStore/components/erpProductSelect";
 import { createUserOrder } from "@/api/hisStore/storeOrder";
 import { getCitys as getKdnCitys } from "@/api/store/city";
+// 手写信息采集相关API
+import { addCollectionAndUpdateOrderStatus } from "@/api/member/handwriteCollection/handwriteCollection";
+// 药品标志API
+import { getProductMedicineFlagByOrderCode } from "@/api/store/storeProduct";
+import ImageUpload from "@/components/ImageUpload";
 
 export default {
   name: "Customer",
-  components: { CollectionInfoDialog, productSelect },
+  components: { CollectionInfoDialog, productSelect, ImageUpload },
   data() {
     // 自定义校验:手机号
     const validatePhone = (rule, value, callback) => {
@@ -1190,9 +1231,23 @@ export default {
         callback();
       }
     };
-
+    // 手写信息采集自定义校验:手写信息采集表图片始终必填
+    const validateBillImgUrl = (rule, value, callback) => {
+      if (!value) {
+        callback(new Error("手写信息采集表图片不能为空"));
+      } else {
+        callback();
+      }
+    };
+    // 补充图片校验:仅在订单包含药品时必填
+    const validateExtraImgUrl = (rule, value, callback) => {
+      if (this.medicineFlag && (!value || value === '')) {
+        callback(new Error("当前订单包含药品,补充图片不能为空"));
+      } else {
+        callback();
+      }
+    };
     return {
-      // 原有数据...
       loading: true,
       ids: [],
       single: true,
@@ -1330,7 +1385,6 @@ export default {
       totalMoney: 0.0,
       payTypeOptions: [],
 
-      // ========== 新增:订单列表相关数据 ==========
       orderListDialogVisible: false,
       orderListLoading: false,
       orderList: [],
@@ -1343,7 +1397,6 @@ export default {
         orderCode: null,
         productName: null,
       },
-      // 订单状态映射(根据后端 FsStoreOrderVO.status 字段)
       orderStatusMap: {
         "-3": "已取消",
         "-2": "已退款",
@@ -1353,7 +1406,6 @@ export default {
         2: "待收货",
         3: "交易完成",
       },
-      // 二维码弹窗
       qrCodeDialogVisible: false,
       qrCodeImage: null,
       currentOrderId: null,
@@ -1361,6 +1413,32 @@ export default {
       kdnCityIds: null,
       kdnAddress: null,
       kdnCitys: [],
+
+      // 手写信息采集弹窗数据
+      handwriteDialogVisible: false,
+      handwriteForm: {
+        billImgUrl: null,
+        extraImgUrl: null,
+        patientName: '',
+        patientPhone: '',
+        orderCode: ''
+      },
+      medicineFlag: false, // 当前订单是否包含药品
+      handwriteRules: {
+        billImgUrl: [
+          { validator: validateBillImgUrl, trigger: 'change' }
+        ],
+        extraImgUrl: [
+          { validator: validateExtraImgUrl, trigger: 'change' }
+        ],
+        patientName: [
+          { required: true, message: "患者姓名不能为空", trigger: "blur" }
+        ],
+        patientPhone: [
+          { required: true, message: "患者电话不能为空", trigger: "blur" },
+          { pattern: /^1[3-9]\d{9}$/, message: "请输入正确的手机号码", trigger: "blur" }
+        ]
+      }
     };
   },
   created() {
@@ -1378,25 +1456,21 @@ export default {
       if (nodes && nodes.length > 0) {
         const selectedNode = nodes[0];
         if (selectedNode.pathValues && selectedNode.pathValues.length >= 3) {
-          // 设置ID字段
           this.createOrderForm.provinceId = selectedNode.pathValues[0];
           this.createOrderForm.cityId = selectedNode.pathValues[1];
           this.createOrderForm.districtId = selectedNode.pathValues[2];
         }
-        // 设置名称字段
         if (selectedNode.pathLabels && selectedNode.pathLabels.length >= 3) {
           this.createOrderForm.province = selectedNode.pathLabels[0];
           this.createOrderForm.city = selectedNode.pathLabels[1];
           this.createOrderForm.district = selectedNode.pathLabels[2];
         }
       }
-      console.log(this.createOrderForm)
     },
     sAddress(row) {
       getAddress(row.address)
         .then((response) => {
           const addressJson = response.data;
-          // 检查解析结果是否有效
           if (
             !addressJson ||
             !addressJson.data ||
@@ -1405,7 +1479,6 @@ export default {
             this.$message.error("地址解析失败:未找到有效的省市区信息");
             return;
           }
-          // 回填省市区名称
           this.createOrderForm.province = addressJson.data.provinceName;
           this.createOrderForm.city = addressJson.data.cityName;
           this.createOrderForm.district = addressJson.data.expAreaName;
@@ -1413,7 +1486,6 @@ export default {
             (addressJson.data.streetName || "") +
             (addressJson.data.address || "");
 
-          // 根据名称查找对应ID
           const province = this.kdnCitys.find(
             (o) => o.label === addressJson.data.provinceName
           );
@@ -1436,19 +1508,14 @@ export default {
             return;
           }
 
-          // 设置ID字段(用于校验)
           this.createOrderForm.provinceId = province.value;
           this.createOrderForm.cityId = city.value;
           this.createOrderForm.districtId = district.value;
-
-          // 设置级联选择器的值
           this.kdnCityIds = [province.value, city.value, district.value];
         })
         .catch((error) => {
           console.error("地址解析接口错误:", error);
-          const errorMsg =
-            error?.msg || error?.message || "地址智能识别失败,请手动选择";
-          this.$message.error(errorMsg);
+          this.$message.error(error?.msg || error?.message || "地址智能识别失败,请手动选择");
         });
     },
     getKdnCitys() {
@@ -1456,7 +1523,6 @@ export default {
         this.kdnCitys = res.data;
       });
     },
-    // 支付方式格式化
     payTypeFormat(payType) {
       if (!payType) return "-";
       const option = this.payTypeOptions.find(
@@ -1464,7 +1530,6 @@ export default {
       );
       return option ? option.dictLabel : payType;
     },
-    // 格式化收款记录显示文本
     getReceiptLabel(item) {
       if (!item.saleTime) return `无时间 - ${item.totalFee}元`;
       const date = new Date(item.saleTime);
@@ -1475,10 +1540,8 @@ export default {
       const hours = String(date.getHours()).padStart(2, "0");
       const minutes = String(date.getMinutes()).padStart(2, "0");
       const seconds = String(date.getSeconds()).padStart(2, "0");
-      const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
-      return `${formattedTime} - ${item.totalFee}元`;
+      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds} - ${item.totalFee}元`;
     },
-    // 订单状态格式化方法
     orderStatusFormat(status) {
       const key = String(status);
       return this.orderStatusMap[key] || status;
@@ -1497,7 +1560,6 @@ export default {
         this.$message.error("获取收款记录失败,请稍后重试");
       }
     },
-    //自动填充抵扣金额
     handleReceiptChange(selectedId) {
       const selected = this.receiptList.find((item) => item.id === selectedId);
       if (selected) {
@@ -1509,7 +1571,6 @@ export default {
 
     createOrderSubmitForm() {
       this.$refs["createOrderForm"].validate((valid) => {
-        // 手动校验地址联动
         if (
           !this.createOrderForm.province ||
           !this.createOrderForm.city ||
@@ -1532,33 +1593,11 @@ export default {
             district: this.createOrderForm.district,
             totalAmount: this.totalMoney,
           };
-          console.log("params", params);
-          return;
           createUserOrder(params)
             .then((response) => {
               if (response.code === 200) {
-                // 获取返回的订单数据
                 const order = response.order;
-                const payLimitTime = response.payLimitTime;
-
-                // 判断是否需要显示支付二维码(全款支付且订单未支付)
-                // 注意:payType === '1' 表示全款支付
-                if (
-                  this.createOrderForm.payType === "1" &&
-                  order &&
-                  order.paid === 0
-                ) {
-                  // 关闭制单弹窗
-                  this.createOrder.open = false;
-                  this.createOrderReset();
-                  // 显示二维码弹窗
-                  this.showOrderQrCode(order.id);
-                } else {
-                  this.msgSuccess("创建成功");
-                  this.createOrder.open = false;
-                  this.createOrderReset();
-                  this.getList();
-                }
+                this.handleOrderCreateSuccess(order, params);
               }
             })
             .catch((err) => {
@@ -1568,43 +1607,124 @@ export default {
       });
     },
 
-    //显示订单二维码弹窗
-    showOrderQrCode(orderId) {
-      this.currentOrderId = orderId;
-      this.qrCodeImage = null;
-      this.qrCodeDialogVisible = true;
-
-      const loading = this.$loading({
-        lock: true,
-        text: "正在生成二维码...",
-        spinner: "el-icon-loading",
-        background: "rgba(0, 0, 0, 0.7)",
+    // 制单成功后的处理逻辑
+    handleOrderCreateSuccess(order, orderParams) {
+      this.createOrder.open = false;
+      this.createOrderReset();
+      // 弹出提示确认框
+      this.$confirm('请上传手写信息采集,否则无法发货!', '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        // 确保订单列表弹窗打开并刷新
+        if (this.currentCustomerId) {
+          this.orderQueryParams.companyCustomerId = this.currentCustomerId;
+          this.orderListDialogVisible = true;
+          this.getOrderList();
+        } else {
+          this.$message.warning("无法获取客户信息,请手动刷新订单列表");
+          this.orderListDialogVisible = true; // 仍打开弹窗,但可能无法正确筛选
+        }
+        // 打开手写信息采集新增弹窗
+        // this.openHandwriteDialog(order, orderParams);
+      }).catch(() => {
+        this.getList();
+        this.$message.info("已取消上传手写信息采集");
       });
+    },
 
-      getQRCode(orderId)
-        .then((response) => {
-          if (response.url) {
-            this.qrCodeImage = response.url;
-          } else {
-            this.$message.error("获取二维码失败:返回数据无效");
-            this.qrCodeDialogVisible = false;
-            // 二维码生成失败时刷新列表
+    // 打开手写信息采集弹窗并预填信息
+    async openHandwriteDialog(order, orderParams) {
+      this.resetHandwriteForm();
+      this.handwriteForm.patientName = orderParams.realName || '';
+      this.handwriteForm.patientPhone = orderParams.phone || '';
+      this.handwriteForm.orderCode = order.orderCode;
+
+      // 调用接口判断订单中的商品是否包含药品
+      try {
+        const res = await getProductMedicineFlagByOrderCode(order.orderCode);
+        if (res.code === 200 && res.flag !== undefined) {
+          this.medicineFlag = res.flag === true || res.flag === 'true';
+        } else {
+          this.medicineFlag = false;
+        }
+      } catch (error) {
+        console.error("获取药品标志失败", error);
+        this.medicineFlag = false;
+      }
+
+      // 动态更新校验规则(手写信息采集表图片始终必填,补充图片根据药品标志决定)
+      this.updateHandwriteRules();
+      this.handwriteDialogVisible = true;
+    },
+
+    // 更新手写信息采集表单校验规则
+    updateHandwriteRules() {
+      const rules = {
+        billImgUrl: [
+          { required: true, message: "手写信息采集表图片不能为空", trigger: "change" }
+        ],
+        patientName: [
+          { required: true, message: "患者姓名不能为空", trigger: "blur" }
+        ],
+        patientPhone: [
+          { required: true, message: "患者电话不能为空", trigger: "blur" },
+          { pattern: /^1[3-9]\d{9}$/, message: "请输入正确的手机号码", trigger: "blur" }
+        ]
+      };
+      if (this.medicineFlag) {
+        rules.extraImgUrl = [
+          { required: true, message: "当前订单包含药品,补充图片不能为空", trigger: "change" }
+        ];
+      } else {
+        rules.extraImgUrl = [];
+      }
+      this.handwriteRules = rules;
+      if (this.$refs.handwriteForm) {
+        this.$refs.handwriteForm.clearValidate();
+      }
+    },
+
+    resetHandwriteForm() {
+      this.handwriteForm = {
+        billImgUrl: null,
+        extraImgUrl: null,
+        patientName: '',
+        patientPhone: '',
+        orderCode: ''
+      };
+      this.medicineFlag = false;
+      this.updateHandwriteRules();
+    },
+
+    submitHandwriteForm() {
+      this.$refs.handwriteForm.validate(async (valid) => {
+        if (!valid) return;
+        const params = {
+          patientName: this.handwriteForm.patientName,
+          patientPhone: this.handwriteForm.patientPhone,
+          orderCode: this.handwriteForm.orderCode,
+          billImgUrl: this.handwriteForm.billImgUrl,
+          extraImgUrl: this.handwriteForm.extraImgUrl
+        };
+        try {
+          const res = await addCollectionAndUpdateOrderStatus(params);
+          if (res.code === 200) {
+            this.$message.success("手写信息采集表新增成功");
+            this.handwriteDialogVisible = false;
+            this.getOrderList();
             this.getList();
+          } else {
+            this.$message.error(res.msg || "新增失败");
           }
-        })
-        .catch((error) => {
-          this.$message.error(error.msg || error.message || "生成二维码失败");
-          this.qrCodeDialogVisible = false;
-          // 二维码生成失败时刷新列表
-          this.getList();
-        })
-        .finally(() => {
-          loading.close();
-        });
+        } catch (error) {
+          this.$message.error(error.message || "新增失败");
+        }
+      });
     },
 
     onQrCodeDialogClose() {
-      // 关闭二维码弹窗时刷新客户列表
       this.getList();
     },
     createOrderCancel() {
@@ -1708,7 +1828,6 @@ export default {
       this.$message.success("商品 " + row.productName + " 添加成功");
       this.computeTotalMoney();
     },
-    // 地址联动
     convertCityData(array) {
       return array.map((item) => ({
         cityId: item.value,
@@ -1717,31 +1836,6 @@ export default {
         children: item.children && this.convertCityData(item.children),
       }));
     },
-    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);
-      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);
-      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() {
       getCitys().then((res) => {
         this.loading = false;
@@ -1753,11 +1847,10 @@ export default {
       this.createOrderReset();
       this.createOrder.open = true;
       this.createOrderForm.companyCustomerId = row.id;
+      this.currentCustomerId = row.id;
       this.sAddress(row);
-      // 每次打开弹窗时重新获取收款记录列表
       this.fetchReceiptList();
     },
-    // 认领状态格式化
     claimStatusFormat(row) {
       return row.claimStatus === 1 ? "已认领" : "未认领";
     },
@@ -1966,7 +2059,6 @@ export default {
         if (e.message) this.$message.error(e.message);
       }
     },
-    // 客户删除方法(保持原有)
     handleDelete(row) {
       const ids = row.id || this.ids.join(",");
       this.$confirm("是否确认删除该客户信息?", "提示", {
@@ -1981,7 +2073,8 @@ export default {
           this.getList();
           this.$message.success("删除成功");
         })
-        .catch(() => {});
+        .catch(() => {
+        });
     },
     handleExport() {
       this.$modal
@@ -1994,7 +2087,8 @@ export default {
         .then((response) => {
           this.download(response.msg, "客户信息数据.xlsx");
         })
-        .catch(() => {});
+        .catch(() => {
+        });
     },
     download(content, fileName) {
       const blob = new Blob([content]);
@@ -2055,7 +2149,7 @@ export default {
     },
     getClaimLogList() {
       this.claimLogLoading = true;
-      const params = { ...this.claimLogQueryParams };
+      const params = {...this.claimLogQueryParams};
       Object.keys(params).forEach((key) => {
         if (
           params[key] === null ||
@@ -2076,7 +2170,6 @@ export default {
           this.claimLogTotal = 0;
         });
     },
-    /** 打开订单列表弹窗 */
     handleViewOrderList(row) {
       this.currentCustomerId = row.id;
       this.orderQueryParams.companyCustomerId = row.id;
@@ -2085,13 +2178,9 @@ export default {
       this.orderListDialogVisible = true;
       this.getOrderList();
     },
-
-    /** 获取订单列表 */
-    /** 获取订单列表 */
     getOrderList() {
       this.orderListLoading = true;
-      const params = { ...this.orderQueryParams };
-      // 清理空参数
+      const params = {...this.orderQueryParams};
       Object.keys(params).forEach((key) => {
         if (
           params[key] === null ||
@@ -2104,7 +2193,6 @@ export default {
       getOrderList(params)
         .then((response) => {
           let rows = response.rows || [];
-          // 预处理每个订单的商品信息
           rows = rows.map((order) => {
             let parsedItems = [];
             if (order.items && order.items.length) {
@@ -2127,7 +2215,7 @@ export default {
                 };
               });
             }
-            return { ...order, parsedItems };
+            return {...order, parsedItems};
           });
           this.orderList = rows;
           this.orderTotal = response.total || 0;
@@ -2139,29 +2227,21 @@ export default {
           this.orderTotal = 0;
         });
     },
-
-    /** 订单列表搜索 */
     handleOrderQuery() {
       this.orderQueryParams.pageNum = 1;
       this.getOrderList();
     },
-
-    /** 重置订单列表查询 */
     resetOrderQuery() {
       this.orderQueryParams.orderCode = "";
       this.orderQueryParams.productName = "";
       this.handleOrderQuery();
     },
-
-    /** 关闭订单列表弹窗时重置数据 */
     orderListClose() {
       this.orderList = [];
       this.orderTotal = 0;
       this.orderQueryParams.pageNum = 1;
       this.orderQueryParams.productName = "";
     },
-
-    /** 获取订单二维码 */
     handleGetQrCode(row) {
       if (!row.id) {
         this.$message.error("订单信息异常,无法获取二维码");
@@ -2170,14 +2250,12 @@ export default {
       this.currentOrderId = row.id;
       this.qrCodeImage = null;
       this.qrCodeDialogVisible = true;
-
       const loading = this.$loading({
         lock: true,
         text: "正在生成二维码...",
         spinner: "el-icon-loading",
         background: "rgba(0, 0, 0, 0.7)",
       });
-
       getQRCode(row.id)
         .then((response) => {
           if (response.url) {
@@ -2195,8 +2273,6 @@ export default {
           loading.close();
         });
     },
-
-    /** 下载二维码 */
     downloadQrCode() {
       if (!this.qrCodeImage) {
         this.$message.warning("二维码尚未生成");