Browse Source

fix:优化

super-yimizi 6 days ago
parent
commit
8b54334df0
2 changed files with 198 additions and 42 deletions
  1. 1 19
      application/api/controller/third/Wechat.php
  2. 197 23
      public/assets/js/backend/shop/goods.js

+ 1 - 19
application/api/controller/third/Wechat.php

@@ -72,7 +72,7 @@ class Wechat extends Base
             $user = auth_user();
             $mobile = $this->wechat->getUserPhoneNumber();
 
-            $this->svalidate(['mobile' => $mobile], '.bindWechatMiniProgramMobile');
+            $this->validate(['mobile' => $mobile], '.bindWechatMiniProgramMobile');
 
             $user->mobile = $mobile;
             $verification = $user->verification;
@@ -174,22 +174,4 @@ class Wechat extends Base
             $this->error($msg);
         }
     }
-
-    /**
-     * 微信小程序订阅模板消息
-     */
-    public function subscribeTemplate()
-    {
-        $templates = [];
-        // 获取订阅消息模板
-        $notificationConfig = NotificationConfig::where('channel', 'WechatMiniProgram')->enable()->select();
-
-        foreach ($notificationConfig as $k => $config) {
-            if ($config['content'] && isset($config['content']['template_id']) && $config['content']['template_id']) {
-                $templates[$config['event']] = $config['content']['template_id'];
-            }
-        }
-
-        $this->success('获取成功', $templates);
-    }
 }

+ 197 - 23
public/assets/js/backend/shop/goods.js

@@ -563,6 +563,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 // 初始化选项卡验证提示系统
                 that.initTabValidation();
                 
+                // 监听单规格表单区域的显示状态变化(新增页面也需要)
+                that.watchSingleSpecFormVisibility();
+                
                 Controller.api.bindevent();
                 Controller.api.add_sku();
             });
@@ -595,12 +598,92 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 // 编辑时初始化商品类型选择状态
                 that.initEditTypeState();
                 
+                // 延迟再次尝试填充单规格数据,解决某些情况下数据不显示的问题
+                setTimeout(function() {
+                    console.log('延迟再次尝试填充单规格数据');
+                    that.initSingleSpecData();
+                }, 1000);
+                
+                // 监听单规格表单区域的显示状态变化
+                that.watchSingleSpecFormVisibility();
                 
                 Controller.api.bindevent();
                 Controller.api.add_sku();
             });
         },
         
+        // 监听单规格表单区域的显示状态变化
+        watchSingleSpecFormVisibility: function() {
+            var that = this;
+            
+            // 使用MutationObserver监听DOM变化
+            if (typeof MutationObserver !== 'undefined') {
+                var observer = new MutationObserver(function(mutations) {
+                    mutations.forEach(function(mutation) {
+                        // 检查单规格表单是否变为可见
+                        var $singleSpecForm = $('#single-spec-form');
+                        if ($singleSpecForm.length > 0 && $singleSpecForm.is(':visible')) {
+                            // 检查关键字段是否为空
+                            var $priceField = $('#c-price');
+                            var $stocksField = $('#c-stocks');
+                            
+                            if ($priceField.length > 0 && $stocksField.length > 0) {
+                                var currentPrice = $priceField.val();
+                                var currentStocks = $stocksField.val();
+                                
+                                // 如果字段为空且有SKU数据,则重新填充
+                                if ((!currentPrice || currentPrice === '') && 
+                                    (!currentStocks || currentStocks === '') &&
+                                    Config.goods && Config.goods.spec_type == '0' && 
+                                    Config.goods_skus && Config.goods_skus.length > 0) {
+                                    
+                                    console.log('检测到单规格表单变为可见且数据为空,重新填充数据');
+                                    setTimeout(function() {
+                                        that.initSingleSpecData();
+                                    }, 100);
+                                }
+                            }
+                        }
+                    });
+                });
+                
+                // 开始观察
+                observer.observe(document.body, {
+                    childList: true,
+                    subtree: true,
+                    attributes: true,
+                    attributeFilter: ['style', 'class']
+                });
+                
+                // 存储observer引用以便后续清理
+                this._singleSpecObserver = observer;
+            }
+            
+            // 同时监听选项卡切换事件
+            $('a[href="#skus"]').on('shown.bs.tab', function() {
+                console.log('切换到价格库存选项卡');
+                setTimeout(function() {
+                    // 检查是否为单规格且数据未填充
+                    var specType = $('input[name="row[spec_type]"]:checked').val();
+                    if (specType == '0') {
+                        var $priceField = $('#c-price');
+                        var $stocksField = $('#c-stocks');
+                        
+                        if ($priceField.length > 0 && $stocksField.length > 0) {
+                            var currentPrice = $priceField.val();
+                            var currentStocks = $stocksField.val();
+                            
+                            if ((!currentPrice || currentPrice === '') && 
+                                (!currentStocks || currentStocks === '')) {
+                                console.log('价格库存选项卡:检测到单规格数据为空,重新填充');
+                                that.initSingleSpecData();
+                            }
+                        }
+                    }
+                }, 200);
+            });
+        },
+        
         // 检查多选控件是否为空
         isMultiSelectEmpty: function(value) {
             if (Array.isArray(value)) {
@@ -747,33 +830,114 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             }
             
             // 如果是单规格且有SKU数据,填充单规格表单
+            this.initSingleSpecData();
+        },
+        
+        // 初始化单规格数据填充
+        initSingleSpecData: function() {
+            var that = this;
+            
             if (Config.goods && Config.goods.spec_type == '0' && Config.goods_skus && Config.goods_skus.length > 0) {
-                console.log('填充单规格数据');
+                console.log('开始填充单规格数据');
                 var sku = Config.goods_skus[0];
+                console.log('SKU数据:', sku);
                 
-                // 延迟填充数据,确保DOM已渲染
-                setTimeout(function() {
-                    $('#c-price').val(sku.price || '');
-                    $('#c-lineation_price').val(sku.lineation_price || '');
-                    $('#c-cost_price').val(sku.cost_price || '');
-                    $('#c-stocks').val(sku.stocks || '');
-                    $('#c-weight').val(sku.weight || '');
-                    $('#c-volume').val(sku.volume || '');
-                    $('#c-sku-sn').val(sku.sku_sn || '');
-                    $('#c-single-image').val(sku.image || '');
+                // 多次尝试填充数据,确保DOM已渲染
+                var fillAttempts = 0;
+                var maxAttempts = 5;
+                
+                function attemptFill() {
+                    fillAttempts++;
+                    console.log('第' + fillAttempts + '次尝试填充单规格数据');
+                    
+                    // 检查关键元素是否存在
+                    var $priceField = $('#c-price');
+                    var $stocksField = $('#c-stocks');
                     
-                    // 更新单规格图片预览
-                    if (sku.image) {
-                        var $preview = $('#p-single-image');
-                        var img = '<li><a href="' + Fast.api.cdnurl(sku.image, true) + '" data-url="' + sku.image + '" target="_blank"><img src="' + Fast.api.cdnurl(sku.image, true) + '"/></a></li>';
-                        $preview.html(img);
+                    if ($priceField.length === 0 || $stocksField.length === 0) {
+                        console.log('关键元素未找到,等待DOM渲染完成...');
+                        if (fillAttempts < maxAttempts) {
+                            setTimeout(attemptFill, 200 * fillAttempts);
+                        } else {
+                            console.error('单规格表单元素未找到,填充失败');
+                        }
+                        return;
                     }
                     
-                    console.log('单规格数据填充完成');
-                }, 200);
+                    // 填充数据
+                    try {
+                        console.log('填充销售价:', sku.price);
+                        $priceField.val(sku.price || '0.01');
+                        
+                        console.log('填充划线价:', sku.lineation_price);
+                        $('#c-lineation_price').val(sku.lineation_price || '0.00');
+                        
+                        console.log('填充成本价:', sku.cost_price);
+                        $('#c-cost_price').val(sku.cost_price || '0.00');
+                        
+                        console.log('填充库存:', sku.stocks);
+                        $stocksField.val(sku.stocks || '1');
+                        
+                        console.log('填充重量:', sku.weight);
+                        $('#c-weight').val(sku.weight || '0.00');
+                        
+                        console.log('填充体积:', sku.volume);
+                        $('#c-volume').val(sku.volume || '0.00');
+                        
+                        console.log('填充SKU编码:', sku.sku_sn);
+                        $('#c-sku-sn').val(sku.sku_sn || '');
+                        
+                        console.log('填充图片:', sku.image);
+                        $('#c-single-image').val(sku.image || '');
+                        
+                        // 更新单规格图片预览
+                        if (sku.image) {
+                            var $preview = $('#p-single-image');
+                            if ($preview.length > 0) {
+                                var img = '<li><a href="' + Fast.api.cdnurl(sku.image, true) + '" data-url="' + sku.image + '" target="_blank"><img src="' + Fast.api.cdnurl(sku.image, true) + '"/></a></li>';
+                                $preview.html(img);
+                                console.log('单规格图片预览已更新');
+                            }
+                        }
+                        
+                        // 触发字段变化事件,确保验证状态正确
+                        $priceField.trigger('change');
+                        $stocksField.trigger('change');
+                        
+                        console.log('单规格数据填充完成');
+                        
+                        // 验证填充结果
+                        setTimeout(function() {
+                            var currentPrice = $priceField.val();
+                            var currentStocks = $stocksField.val();
+                            console.log('验证填充结果 - 价格:', currentPrice, '库存:', currentStocks);
+                            
+                            if (!currentPrice || currentPrice === '' || !currentStocks || currentStocks === '') {
+                                console.warn('单规格数据填充可能不完整,重新尝试...');
+                                if (fillAttempts < maxAttempts) {
+                                    setTimeout(attemptFill, 300);
+                                }
+                            }
+                        }, 100);
+                        
+                    } catch (error) {
+                        console.error('填充单规格数据时发生错误:', error);
+                        if (fillAttempts < maxAttempts) {
+                            setTimeout(attemptFill, 200 * fillAttempts);
+                        }
+                    }
+                }
+                
+                // 开始填充尝试
+                setTimeout(attemptFill, 300);
+                
             } else if (Config.goods && Config.goods.spec_type == '1') {
                 console.log('多规格商品,等待Vue组件初始化多规格数据');
                 // 多规格数据由Vue组件的init方法处理
+            } else {
+                console.log('无需填充单规格数据,或数据不完整');
+                console.log('Config.goods:', Config.goods);
+                console.log('Config.goods_skus:', Config.goods_skus);
             }
         },
         
@@ -2201,11 +2365,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     // 使用FastAdmin的Favisible系统自动控制显示隐藏
                     $(document).trigger('fa.event.favisible');
                     
-                    // 如果切换到单规格,清空多规格数据(可选)
-                    if (specType == '0' && typeof vm !== 'undefined' && vm) {
-                        console.log('切换到单规格,清空多规格数据');
-                        // vm.specList = [];
-                        // vm.tableData = [];
+                    // 如果切换到单规格,在编辑模式下重新填充单规格数据
+                    if (specType == '0') {
+                        console.log('切换到单规格');
+                        
+                        // 清空多规格数据(可选)
+                        if (typeof vm !== 'undefined' && vm) {
+                            console.log('清空多规格数据');
+                            // vm.specList = [];
+                            // vm.tableData = [];
+                        }
+                        
+                        // 延迟填充单规格数据,确保表单已显示
+                        setTimeout(function() {
+                            Controller.initSingleSpecData();
+                        }, 200);
                     }
                     
                     // 如果切换到多规格,确保Vue组件已初始化