(global["webpackJsonp"] = global["webpackJsonp"] || []).push([["pkgManage/common/vendor"],{

/***/ 298:
/*!*********************************************!*\
  !*** D:/project/zhizhu/utils/clone-tool.js ***!
  \*********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */(function(uni) {

var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.adjustPrice = adjustPrice;
exports.clearNewItemIds = clearNewItemIds;
exports.dateToTimestamp = dateToTimestamp;
exports.formatLogMessage = formatLogMessage;
exports.generateDeviceId = generateDeviceId;
exports.getNewItemIds = getNewItemIds;
exports.loadFromStorage = loadFromStorage;
exports.saveToStorage = saveToStorage;
exports.validateDate = validateDate;
var _cryptoJs = _interopRequireDefault(__webpack_require__(/*! crypto-js */ 167));
/**
 * 商品克隆工具辅助函数
 */

/**
 * 生成设备ID
 * 基于设备信息生成唯一标识符
 */
function generateDeviceId() {
  try {
    // 获取系统信息
    var systemInfo = uni.getSystemInfoSync();

    // 组合设备信息
    var deviceInfo = [systemInfo.deviceId || '', systemInfo.deviceBrand || '', systemInfo.deviceModel || '', systemInfo.system || '', systemInfo.platform || '', systemInfo.SDKVersion || ''].filter(function (item) {
      return item;
    }).join('|');

    // 使用MD5生成设备ID
    if (deviceInfo) {
      return _cryptoJs.default.MD5(deviceInfo).toString().toUpperCase();
    } else {
      return 'UNKNOWN_DEVICE_' + Math.random().toString(36).substring(2, 10);
    }
  } catch (e) {
    console.error('生成设备ID失败:', e);
    return 'ERROR_DEVICE_' + Math.random().toString(36).substring(2, 10);
  }
}

/**
 * 验证日期格式 (YYYYMMDD)
 * @param {string} dateStr - 日期字符串
 * @returns {boolean} - 是否有效
 */
function validateDate(dateStr) {
  if (!dateStr || dateStr.length !== 8) {
    return false;
  }
  try {
    var year = parseInt(dateStr.substring(0, 4));
    var month = parseInt(dateStr.substring(4, 6));
    var day = parseInt(dateStr.substring(6, 8));
    if (year < 1900 || year > 2100 || month < 1 || month > 12 || day < 1 || day > 31) {
      return false;
    }

    // 检查特定月份的天数
    if (month === 2) {
      // 闰年检查
      var isLeapYear = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
      if (day > (isLeapYear ? 29 : 28)) {
        return false;
      }
    } else if ([4, 6, 9, 11].includes(month) && day > 30) {
      return false;
    }
    return true;
  } catch (e) {
    return false;
  }
}

/**
 * 日期字符串转时间戳
 * @param {string} dateStr - 日期字符串 (YYYYMMDD)
 * @param {boolean} endOfDay - 是否为当天结束时间
 * @returns {number} - 时间戳(秒)
 */
function dateToTimestamp(dateStr) {
  var endOfDay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  if (!dateStr || dateStr.length !== 8) {
    throw new Error('日期格式错误，必须是8位数字(YYYYMMDD)');
  }
  var year = parseInt(dateStr.substring(0, 4));
  var month = parseInt(dateStr.substring(4, 6)) - 1; // 月份从0开始
  var day = parseInt(dateStr.substring(6, 8));
  var date;
  if (endOfDay) {
    date = new Date(year, month, day, 23, 59, 59);
  } else {
    date = new Date(year, month, day, 0, 0, 0);
  }
  return Math.floor(date.getTime() / 1000);
}

/**
 * 调整价格
 * @param {number|string} originalPrice - 原始价格
 * @param {number} configType - 调整类型 (1:折扣, 2:加减值, 3:指定金额)
 * @param {number} value - 调整值
 * @returns {string} - 调整后的价格字符串(保留2位小数)
 */
function adjustPrice(originalPrice, configType, value) {
  try {
    var price = parseFloat(originalPrice);
    if (isNaN(price)) {
      return originalPrice.toString();
    }
    switch (configType) {
      case 1:
        // 折扣
        price *= value / 100;
        break;
      case 2:
        // 加减值
        price += value;
        break;
      case 3:
        // 指定金额
        price = value;
        break;
    }

    // 确保价格为正数
    price = Math.max(0.01, price);
    return price.toFixed(2);
  } catch (e) {
    console.error('价格调整失败:', e);
    return originalPrice.toString();
  }
}

/**
 * 格式化日志消息
 * @param {string} message - 日志消息
 * @returns {string} - 格式化后的日志消息
 */
function formatLogMessage(message) {
  var timestamp = new Date().toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  });
  return "[".concat(timestamp, "] ").concat(message);
}

/**
 * 保存数据到本地存储
 * @param {string} key - 存储键名
 * @param {any} data - 要存储的数据
 * @returns {boolean} - 是否成功
 */
function saveToStorage(key, data) {
  try {
    uni.setStorageSync(key, JSON.stringify(data));
    return true;
  } catch (e) {
    console.error("\u4FDD\u5B58\u6570\u636E\u5931\u8D25 (".concat(key, "):"), e);
    return false;
  }
}

/**
 * 从本地存储加载数据
 * @param {string} key - 存储键名
 * @param {any} defaultValue - 默认值
 * @returns {any} - 加载的数据或默认值
 */
function loadFromStorage(key) {
  var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  try {
    var value = uni.getStorageSync(key);
    if (value) {
      return JSON.parse(value);
    }
    return defaultValue;
  } catch (e) {
    console.error("\u52A0\u8F7D\u6570\u636E\u5931\u8D25 (".concat(key, "):"), e);
    return defaultValue;
  }
}

/**
 * 获取新商品ID列表
 * @returns {Array} - 新商品ID列表
 */
function getNewItemIds() {
  try {
    var newIds = uni.getStorageSync('kongfz_new_ids') || [];
    return Array.isArray(newIds) ? newIds : [];
  } catch (e) {
    console.error('获取新商品ID列表失败:', e);
    return [];
  }
}

/**
 * 清空新商品ID列表
 * @returns {boolean} - 是否成功
 */
function clearNewItemIds() {
  try {
    uni.removeStorageSync('kongfz_new_ids');
    return true;
  } catch (e) {
    console.error('清空新商品ID列表失败:', e);
    return false;
  }
}
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"]))

/***/ }),

/***/ 299:
/*!***************************************!*\
  !*** D:/project/zhizhu/api/kongfz.js ***!
  \***************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */(function(uni) {

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.batchUpdatePddPlatformId = batchUpdatePddPlatformId;
exports.deleteItem = deleteItem;
exports.fetchItems = fetchItems;
exports.getItemTplFields = getItemTplFields;
exports.login = login;
exports.submitItemForm = submitItemForm;
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
 * 孔夫子旧书网API服务
 */

/**
 * 登录孔夫子旧书网
 * @param {string} username - 用户名
 * @param {string} password - 密码
 * @returns {Promise<{success: boolean, token: string, message: string}>} - 登录结果
 */
function login(username, password) {
  return new Promise(function (resolve, reject) {
    if (!username || !password) {
      resolve({
        success: false,
        message: '请输入用户名和密码'
      });
      return;
    }

    // 构建请求参数
    var url = 'https://login.kongfz.com/Pc/Login/account';
    var data = {
      loginName: username,
      loginPass: password,
      autoLogin: '0',
      returnUrl: 'http://user.kongfz.com/'
    };

    // 发送请求
    uni.request({
      url: url,
      method: 'POST',
      data: data,
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
        // 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
      },

      success: function success(res) {
        console.log("登录...", res);
        // 检查登录是否成功
        if (res.data && res.data.indexOf("window.location.href='https://login.kongfz.cn/Pc/Session/rsync") !== -1) {
          // 提取PHPSESSID
          var cookies = res.cookies;
          var phpsessid = '';
          if (cookies && cookies.length > 0) {
            var _iterator = _createForOfIteratorHelper(cookies),
              _step;
            try {
              for (_iterator.s(); !(_step = _iterator.n()).done;) {
                var cookie = _step.value;
                if (cookie.indexOf('PHPSESSID=') !== -1) {
                  phpsessid = cookie.split('PHPSESSID=')[1].split(';')[0];
                  break;
                }
              }
            } catch (err) {
              _iterator.e(err);
            } finally {
              _iterator.f();
            }
          }
          if (phpsessid) {
            resolve({
              success: true,
              token: phpsessid,
              message: '登录成功'
            });
          } else {
            resolve({
              success: false,
              message: '登录失败: 未找到PHPSESSID'
            });
          }
        } else {
          // 尝试解析错误信息
          try {
            var _data = JSON.parse(res.data);
            if (_data.errCode === 1001) {
              resolve({
                success: false,
                message: '登录失败: 账号或密码错误'
              });
            } else if (_data.errInfo) {
              resolve({
                success: false,
                message: "\u767B\u5F55\u5931\u8D25: ".concat(_data.errInfo)
              });
            } else {
              resolve({
                success: false,
                message: '登录失败: 未知错误'
              });
            }
          } catch (e) {
            resolve({
              success: false,
              message: '登录失败: 响应不包含成功跳转信息'
            });
          }
        }
      },
      fail: function fail(err) {
        reject(new Error("\u767B\u5F55\u8BF7\u6C42\u5931\u8D25: ".concat(err.errMsg)));
      }
    });
  });
}

/**
 * 获取商品列表
 * @param {string} token - 登录令牌
 * @param {Object} params - 查询参数
 * @param {function} onProgress - 进度回调
 * @returns {Promise<Array>} - 商品列表
 */
function fetchItems(token) {
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var onProgress = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  return new Promise(function (resolve, reject) {
    if (!token) {
      reject(new Error('请先登录获取Token'));
      return;
    }
    // const token = 'ebb26189289d0dc068f9aac748881bccf890e694';
    var url = 'https://seller.kongfz.com/pc-gw/book-manage-service/client/pc/goods/unSold/list';
    var headers = {
      'Cookie': "PHPSESSID=".concat(token)
      // 'Cookie': 'PHPSESSID=ebb26189289d0dc068f9aac748881bccf890e694'
      // 'User-Agent' 头在浏览器环境中无法设置，会被拒绝
      // 'Content-Type': 'application/json'
    };

    var page = 1;
    var size = 50;
    var allItemIds = [];
    var fetchPage = function fetchPage() {
      // 准备请求体
      var requestBody = {
        "requestType": "onSale",
        // 标识 出售中
        "isItemSnEqual": "0",
        "page": page,
        "size": size
      };

      // 添加可选参数
      if (params.itemSn) requestBody.itemSn = params.itemSn;
      if (params.priceMin) requestBody.priceMin = params.priceMin;
      if (params.priceMax) requestBody.priceMax = params.priceMax;
      if (params.startCreateTime) requestBody.startCreateTime = params.startCreateTime;
      if (params.endCreateTime) requestBody.endCreateTime = params.endCreateTime;

      // 调用进度回调
      if (onProgress) {
        onProgress("\u6B63\u5728\u83B7\u53D6\u7B2C ".concat(page, " \u9875\u6570\u636E..."));
        // 添加请求参数日志
        if (page === 1) {
          onProgress("\u8BF7\u6C42\u53C2\u6570: ".concat(JSON.stringify(requestBody)));
        }
      }
      console.log("请求参数", requestBody);

      // 发送请求
      uni.request({
        url: url,
        method: 'POST',
        data: requestBody,
        header: headers,
        success: function success(res) {
          if (res.statusCode !== 200) {
            console.error('API 失败响应:', res);
            reject(new Error("API\u8FD4\u56DE\u9519\u8BEF: HTTP ".concat(res.statusCode)));
            return;
          }
          var data = res.data;
          if (!data.status) {
            console.error('API 失败响应:', data);
            reject(new Error("API\u8FD4\u56DE\u9519\u8BEF: ".concat(data.errMessage || '未知错误')));
            return;
          }

          // 获取商品列表
          var result = data.result || {};
          var productInfo = result.productInfoPageResult || {};
          var items = productInfo.list || [];
          var pager = productInfo.pager || {};

          // 提取商品ID
          var _iterator2 = _createForOfIteratorHelper(items),
            _step2;
          try {
            for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
              var item = _step2.value;
              var itemId = item.itemId;
              if (itemId) {
                allItemIds.push({
                  id: itemId,
                  status: 'wait'
                });
              }
            }

            // 更新状态
          } catch (err) {
            _iterator2.e(err);
          } finally {
            _iterator2.f();
          }
          var totalPages = pager.pages || 0;
          var totalCount = pager.count || 0;
          if (onProgress) {
            onProgress("\u83B7\u53D6\u5230 ".concat(items.length, " \u4E2A\u5546\u54C1 (\u7B2C ").concat(page, "/").concat(totalPages, " \u9875)"));
            // 添加更详细的商品信息
            if (items.length > 0) {
              var firstItem = items[0];
              onProgress("\u5546\u54C1\u793A\u4F8B: ID=".concat(firstItem.itemId, ", \u6807\u9898=").concat(firstItem.title || '无标题', ", \u4EF7\u683C=").concat(firstItem.price || '未知'));
            }
            // 添加总数信息
            onProgress("\u5F53\u524D\u5DF2\u83B7\u53D6: ".concat(allItemIds.length, "/").concat(totalCount, " \u4E2A\u5546\u54C1"));
          }

          // 检查是否还有下一页
          if (page >= totalPages) {
            if (onProgress) {
              onProgress("\u62C9\u53D6\u5B8C\u6210\uFF0C\u5171\u83B7\u53D6 ".concat(allItemIds.length, " \u4E2A\u5546\u54C1"));
              if (allItemIds.length === 0) {
                onProgress('未找到符合条件的商品，请检查筛选条件');
              } else {
                onProgress("\u5546\u54C1ID\u793A\u4F8B: ".concat(allItemIds.slice(0, 3).map(function (item) {
                  return item.id;
                }).join(', ')).concat(allItemIds.length > 3 ? '...' : ''));
              }
            }
            resolve(allItemIds);
          } else {
            page++;
            // 延迟1秒后获取下一页
            if (onProgress) {
              onProgress("\u7B49\u5F851\u79D2\u540E\u83B7\u53D6\u4E0B\u4E00\u9875...");
            }
            setTimeout(fetchPage, 1000);
          }
        },
        fail: function fail(err) {
          var errorMsg = "\u62C9\u53D6\u5546\u54C1\u5931\u8D25: ".concat(err.errMsg);
          if (onProgress) {
            onProgress(errorMsg);
            onProgress('请检查网络连接是否正常');
            onProgress('请确认登录状态是否有效');
          }
          reject(new Error(errorMsg));
        }
      });
    };

    // 开始获取第一页
    fetchPage();
  });
}

/**
 * 获取商品模板字段
 * @param {string} token - 登录令牌
 * @param {string} itemId - 商品ID
 * @returns {Promise<Object>} - 商品模板字段
 */
function getItemTplFields(token, itemId) {
  return new Promise(function (resolve, reject) {
    if (!token) {
      reject(new Error('请先登录获取Token'));
      return;
    }
    var url = "https://seller.kongfz.com/pc/itemInfo/getTplFields?itemId=".concat(itemId, "&isClone=1&v=").concat(Math.floor(Date.now() / 1000));
    uni.request({
      url: url,
      method: 'GET',
      header: {
        'Cookie': "PHPSESSID=".concat(token),
        // 'User-Agent' 头在浏览器环境中无法设置，会被拒绝
        'Referer': 'https://seller.kongfz.com/',
        'Origin': 'https://seller.kongfz.com'
      },
      success: function success(res) {
        if (res.statusCode !== 200) {
          reject(new Error("HTTP\u9519\u8BEF: ".concat(res.statusCode)));
          return;
        }
        var data = res.data;
        if (data.status === 1) {
          resolve(data);
        } else {
          reject(new Error("API\u8FD4\u56DE\u9519\u8BEF: ".concat(data.message || '未知错误')));
        }
      },
      fail: function fail(err) {
        reject(new Error("\u8BF7\u6C42\u5931\u8D25: ".concat(err.errMsg)));
      }
    });
  });
}

/**
 * 提交商品表单
 * @param {string} token - 登录令牌
 * @param {Object} itemData - 商品数据
 * @param {Object} priceConfig - 价格配置
 * @returns {Promise<boolean>} - 是否成功
 */
function submitItemForm(token, itemData, priceConfig) {
  return new Promise(function (resolve, reject) {
    if (!token) {
      reject(new Error('请先登录获取Token'));
      return;
    }

    // 准备表单数据
    var formData = {
      "pageType": "clone"
    };

    // 添加图书基本信息（bookSection）
    var bookSection = itemData.data && itemData.data.bookSection || [];
    var _iterator3 = _createForOfIteratorHelper(bookSection),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var field = _step3.value;
        var key = field.key;
        var value = field.value;

        // 处理嵌套字段（如出版时间）
        if (field.group) {
          var _iterator7 = _createForOfIteratorHelper(field.group),
            _step7;
          try {
            for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
              var subField = _step7.value;
              var subKey = subField.key;
              var subValue = subField.value;
              if (subKey && subValue !== null && subValue !== undefined) {
                formData[subKey] = String(subValue);
              }

              // 处理options中的嵌套
              if (subField.options) {
                var selectedValue = subField.value; // 获取当前选中的值
                var _iterator8 = _createForOfIteratorHelper(subField.options),
                  _step8;
                try {
                  for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
                    var option = _step8.value;
                    var optionValue = option.value;
                    // 如果选项是当前选中的，或者选项中有group字段，则处理其中的字段
                    if (String(optionValue) === String(selectedValue) || option.group) {
                      if (option.group) {
                        var _iterator9 = _createForOfIteratorHelper(option.group),
                          _step9;
                        try {
                          for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
                            var optionField = _step9.value;
                            var optionKey = optionField.key;
                            var _optionValue = optionField.value;
                            if (optionKey && _optionValue !== null && _optionValue !== undefined) {
                              formData[optionKey] = String(_optionValue);
                            }

                            // 处理更深层的嵌套
                            if (optionField.group) {
                              var _iterator10 = _createForOfIteratorHelper(optionField.group),
                                _step10;
                              try {
                                for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
                                  var deepField = _step10.value;
                                  var deepKey = deepField.key;
                                  var deepValue = deepField.value;
                                  if (deepKey && deepValue !== null && deepValue !== undefined) {
                                    formData[deepKey] = String(deepValue);
                                  }
                                }
                              } catch (err) {
                                _iterator10.e(err);
                              } finally {
                                _iterator10.f();
                              }
                            }
                          }
                        } catch (err) {
                          _iterator9.e(err);
                        } finally {
                          _iterator9.f();
                        }
                      }
                    }
                  }
                } catch (err) {
                  _iterator8.e(err);
                } finally {
                  _iterator8.f();
                }
              }

              // 处理更深层的嵌套（如年月）
              if (subField.group) {
                var _iterator11 = _createForOfIteratorHelper(subField.group),
                  _step11;
                try {
                  for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
                    var _deepField = _step11.value;
                    var _deepKey = _deepField.key;
                    var _deepValue = _deepField.value;
                    if (_deepKey && _deepValue !== null && _deepValue !== undefined) {
                      formData[_deepKey] = String(_deepValue);
                    }
                  }
                } catch (err) {
                  _iterator11.e(err);
                } finally {
                  _iterator11.f();
                }
              }
            }
          } catch (err) {
            _iterator7.e(err);
          } finally {
            _iterator7.f();
          }
        }

        // 添加顶层字段
        if (key && value !== null && value !== undefined) {
          formData[key] = String(value);
        }

        // 特殊处理 yearsGroup 字段，确保处理其 options 中的字段
        if (key === 'yearsGroup' && field.options) {
          var _selectedValue = value; // 获取当前选中的值
          var _iterator12 = _createForOfIteratorHelper(field.options),
            _step12;
          try {
            for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
              var _option = _step12.value;
              var _optionValue2 = _option.value;
              // 如果选项是当前选中的，处理其中的字段
              if (String(_optionValue2) === String(_selectedValue) && _option.group) {
                var _iterator13 = _createForOfIteratorHelper(_option.group),
                  _step13;
                try {
                  for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
                    var _optionField = _step13.value;
                    var _optionKey = _optionField.key;
                    var _optionValue3 = _optionField.value;
                    if (_optionKey && _optionValue3 !== null && _optionValue3 !== undefined) {
                      formData[_optionKey] = String(_optionValue3);
                    }

                    // 处理出版时间的年月字段
                    if (_optionKey === 'pubDate' && _optionField.group) {
                      var _iterator14 = _createForOfIteratorHelper(_optionField.group),
                        _step14;
                      try {
                        for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
                          var dateField = _step14.value;
                          var dateKey = dateField.key;
                          var dateValue = dateField.value;
                          if (dateKey && dateValue !== null && dateValue !== undefined) {
                            formData[dateKey] = String(dateValue);
                          }
                        }
                      } catch (err) {
                        _iterator14.e(err);
                      } finally {
                        _iterator14.f();
                      }
                    }
                  }
                } catch (err) {
                  _iterator13.e(err);
                } finally {
                  _iterator13.f();
                }
              }
            }
          } catch (err) {
            _iterator12.e(err);
          } finally {
            _iterator12.f();
          }
        }
      }

      // 添加商品基本信息
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    var goodsSection = itemData.data && itemData.data.goodsSection || [];
    var _iterator4 = _createForOfIteratorHelper(goodsSection),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var _field = _step4.value;
        var _key = _field.key;
        var _value = _field.value;

        // 跳过 images 字段，因为我们会单独处理图片
        if (_key === 'images') {
          var images = _field.images || [];
          for (var i = 0; i < images.length; i++) {
            formData["images[".concat(i, "][imgId]")] = String(images[i].imgId || '');
            formData["images[".concat(i, "][imgType]")] = String(images[i].imgType || '');
            formData["images[".concat(i, "][imgDesc]")] = '';
            formData["images[".concat(i, "][isMain]")] = String(images[i].isMain || '');
            formData["images[".concat(i, "][imgUrl]")] = images[i].imgUrl || '';
          }
          continue;
        }

        // 处理带有 group 的字段（例如尺寸 sizeLength/sizeWidth/sizeHeight）
        if (_field.group && Array.isArray(_field.group)) {
          var _iterator15 = _createForOfIteratorHelper(_field.group),
            _step15;
          try {
            for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
              var _subField = _step15.value;
              var _subKey = _subField.key;
              var _subValue = _subField.value;
              if (_subKey && _subValue !== null && _subValue !== undefined) {
                formData[_subKey] = String(_subValue);
              }
            }
          } catch (err) {
            _iterator15.e(err);
          } finally {
            _iterator15.f();
          }
        }
        if (_key && _value !== null && _value !== undefined) {
          // 特殊处理价格字段
          if (_key === 'price') {
            try {
              var price = parseFloat(_value);
              // 应用价格调整
              if (priceConfig.configType === 1) {
                // 折扣
                price *= priceConfig.value / 100;
              } else if (priceConfig.configType === 2) {
                // 加减值
                price += priceConfig.value; // priceConfig.value已经包含了正负号
              } else if (priceConfig.configType === 3) {
                // 直接赋值
                price = priceConfig.value;
              }
              formData[_key] = price.toFixed(2);
            } catch (e) {
              formData[_key] = String(_value);
            }
          } else {
            // 添加到表单数据
            formData[_key] = String(_value);
          }
        }
      }

      // 添加物流信息
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    var shippingSection = itemData.data && itemData.data.shippingSection || [];
    var _iterator5 = _createForOfIteratorHelper(shippingSection),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _field2 = _step5.value;
        var _key2 = _field2.key;
        var _value2 = _field2.value;
        if (_key2 && _value2 !== null && _value2 !== undefined) {
          formData[_key2] = String(_value2);
        }
      }

      // 添加交付信息
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    var deliverSection = itemData.data && itemData.data.deliverSection || [];
    var _iterator6 = _createForOfIteratorHelper(deliverSection),
      _step6;
    try {
      for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
        var _field3 = _step6.value;
        var _key3 = _field3.key;
        var _value3 = _field3.value;
        if (_key3 && _value3 !== null && _value3 !== undefined) {
          formData[_key3] = String(_value3);
        }
      }

      // 添加分类ID
    } catch (err) {
      _iterator6.e(err);
    } finally {
      _iterator6.f();
    }
    var categorySection = itemData.data && itemData.data.categorySection || {};
    if (categorySection.value !== null && categorySection.value !== undefined) {
      formData.catId = String(categorySection.value);
    }
    var symbols = ['.', ',', '，', '~'];
    var randomSymbol = symbols[Math.floor(Math.random() * symbols.length)];
    var originalName = formData['itemName']; // 或 form_data.itemName
    var newName = originalName + randomSymbol;
    if (newName.length > 60) {
      var maxOriginalLength = 60 - randomSymbol.length;
      newName = originalName.slice(0, maxOriginalLength) + randomSymbol;
    }
    formData['itemName'] = newName;
    var url = 'https://seller.kongfz.com/pc/itemInfo/add';
    console.log("formData1111111111", formData);
    // 发送请求
    uni.request({
      url: url,
      method: 'POST',
      data: formData,
      header: {
        'Cookie': "PHPSESSID=".concat(token),
        // 'User-Agent' 头在浏览器环境中无法设置，会被拒绝
        'Content-Type': 'application/x-www-form-urlencoded',
        'Referer': 'https://seller.kongfz.com/',
        'Origin': 'https://seller.kongfz.com'
      },
      success: function success(res) {
        console.log("处理后的res", res);
        if (res.statusCode !== 200) {
          reject(new Error("HTTP\u9519\u8BEF: ".concat(res.statusCode)));
          return;
        }
        var data = res.data;
        if (res.statusCode === 200 && data.status === 1) {
          // 保存新商品ID到本地存储，同时保存对应的旧商品ID
          if (data.data) {
            try {
              var newId = String(data.data); // 确保newId为字符串
              var oldId = String(formData.itemId); // 确保oldId为字符串

              // 严格校验oldId和newId都不为空
              var existingNewIds = uni.getStorageSync('kongfz_new_ids') || [];
              var newIds = Array.isArray(existingNewIds) ? existingNewIds : [];
              if (oldId && newId && oldId.trim() !== '' && newId.trim() !== '') {
                newIds.push({
                  oldId: oldId,
                  newId: newId,
                  createTime: new Date().toISOString()
                });
                uni.setStorageSync('kongfz_new_ids', newIds);
                console.log('新商品ID已保存:', newId, '对应旧ID:', oldId);
                console.log('存储的ids', newIds);
              } else {
                console.warn('跳过保存无效的商品ID:', {
                  oldId: oldId,
                  newId: newId
                });
              }
            } catch (e) {
              console.error('保存新商品ID失败:', e);
            }
          }
          resolve(true);
        } else {
          resolve(false);
        }
      },
      fail: function fail(err) {
        reject(new Error("\u63D0\u4EA4\u8868\u5355\u5931\u8D25: ".concat(err.errMsg)));
      }
    });
  });
}

/**
 * 批量更新孔网平台商品ID
 * @param {Array} items - 商品ID对应关系数组，格式：[{oldPlatformId: "旧ID", newPlatformId: "新ID"}]
 * @returns {Promise<{success: boolean, message: string}>} - 处理结果
 */
function batchUpdatePddPlatformId(items) {
  return new Promise(function (resolve, reject) {
    if (!items || !Array.isArray(items) || items.length === 0) {
      resolve({
        success: false,
        message: '请提供有效的商品ID对应关系'
      });
      return;
    }
    var url = 'https://api.buzhiyushu.cn/zhishu/shopGoodsPublished/batchUpdateKfzPlatformId';
    uni.request({
      url: url,
      method: 'POST',
      data: items,
      header: {
        'Content-Type': 'application/json'
      },
      success: function success(res) {
        if (res.statusCode === 200) {
          var data = res.data;
          if (data.code === 200) {
            resolve({
              success: true,
              message: data.msg || '操作成功'
            });
          } else {
            resolve({
              success: false,
              message: data.msg || '操作失败'
            });
          }
        } else {
          resolve({
            success: false,
            message: "HTTP\u9519\u8BEF: ".concat(res.statusCode)
          });
        }
      },
      fail: function fail(err) {
        reject(new Error("\u8BF7\u6C42\u5931\u8D25: ".concat(err.errMsg)));
      }
    });
  });
}

/**
 * 删除商品
 * @param {string} token - 登录令牌
 * @param {string} itemId - 商品ID
 * @returns {Promise<boolean>} - 是否成功
 */
function deleteItem(token, itemId) {
  return new Promise(function (resolve, reject) {
    if (!token) {
      reject(new Error('请先登录获取Token'));
      return;
    }
    var url = 'https://seller.kongfz.com/pc-gw/book-manage-service/client/pc/goods/quickUpdate';

    // 准备JSON数据
    var payload = {
      "itemId": String(itemId),
      "updateType": "delete",
      "value": "1"
    };
    uni.request({
      url: url,
      method: 'POST',
      data: payload,
      header: {
        'Cookie': "PHPSESSID=".concat(token),
        // 'User-Agent' 头在浏览器环境中无法设置，会被拒绝
        'Content-Type': 'application/json; charset=UTF-8',
        'Referer': 'https://seller.kongfz.com/',
        'Origin': 'https://seller.kongfz.com'
      },
      success: function success(res) {
        console.log("delect", res);
        if (res.statusCode !== 200) {
          reject(new Error("HTTP\u9519\u8BEF: ".concat(res.statusCode)));
          return;
        }
        var result = res.data;
        if (result.status === true || result.status === 1) {
          resolve(true);
        } else {
          resolve(false);
        }
      },
      fail: function fail(err) {
        reject(new Error("\u5220\u9664\u5546\u54C1\u65F6\u51FA\u9519: ".concat(err.errMsg)));
      }
    });
  });
}
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"]))

/***/ })

}]);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pkgManage/common/vendor.js.map