From 2a0d89f1e39c05334333daeaa1f9567d737fb94d Mon Sep 17 00:00:00 2001 From: SwTt29 <2055018491@qq.com> Date: Fri, 5 Dec 2025 09:40:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A9=E5=B1=95=E5=9C=B0=E5=8C=BA=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E7=9A=84=E4=B8=AD=E5=9B=BD=E7=9C=81=E5=B8=82=E5=8C=BA?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/seller/index.js | 476 +++++++++++++++++++++++++--------------- pages/seller/index.wxml | 66 +++++- pages/seller/index.wxss | 116 ++++++++++ 3 files changed, 470 insertions(+), 188 deletions(-) diff --git a/pages/seller/index.js b/pages/seller/index.js index 2e90c56..470ac7b 100644 --- a/pages/seller/index.js +++ b/pages/seller/index.js @@ -23,17 +23,24 @@ Page({ showYolkSelectModal: false, // 控制蛋黄选择弹窗显示 selectedNameIndex: -1, // 商品名称弹窗中选中的索引 selectedYolkIndex: -1,//蛋黄弹窗中选中的索引, - // 商品名称选项列表 - productNameOptions: ['罗曼粉', '伊莎粉', '罗曼灰', '海蓝灰', '海蓝褐', '绿壳', '粉一', '粉二', '粉八', '京粉1号', '京红', '京粉6号', '京粉3号', '农大系列', '黑鸡土蛋', '双黄蛋', '大午金凤', '黑凤'], + // 商品名称选项列表 + productNameOptions: ['罗曼粉', '伊莎粉', '罗曼灰', '海蓝灰', '海蓝褐', '绿壳', '粉一', '粉二', '粉八', '京粉1号', '京红', '京粉6号', '京粉3号', '农大系列', '黑鸡土蛋', '双黄蛋', '大午金凤', '黑凤'], // 蛋黄选项 yolkOptions: ['红心', '黄心', '双色'], // 规格选项 - specOptions: ['格子装', '散托', '不限规格','净重47+', '净重46-47', '净重45-46', '净重44-45', '净重43-44', '净重42-43', '净重41-42', '净重40-41', '净重39-40', '净重38-39', '净重37-39','净重37-38' , '净重36-38', '净重36-37', '净重35-36', '净重34-35', '净重33-34', '净重32-33', '净重32-34', '净重31-32', '净重30-35', '净重30-34', '净重30-32', '净重30-31', '净重29-31', '净重29-30', '净重28-29', '净重28以下', '毛重52以上', '毛重50-51', '毛重48-49', '毛重47-48', '毛重46-47', '毛重45-47', '毛重45-46', '毛重44-45', '毛重43-44', '毛重42-43', '毛重41-42', '毛重40-41', '毛重38-39', '毛重36-37', '毛重34-35', '毛重32-33', '毛重30-31', '毛重30以下'], + specOptions: ['格子装', '散托', '不限规格', '净重47+', '净重46-47', '净重45-46', '净重44-45', '净重43-44', '净重42-43', '净重41-42', '净重40-41', '净重39-40', '净重38-39', '净重37-39', '净重37-38', '净重36-38', '净重36-37', '净重35-36', '净重34-35', '净重33-34', '净重32-33', '净重32-34', '净重31-32', '净重30-35', '净重30-34', '净重30-32', '净重30-31', '净重29-31', '净重29-30', '净重28-29', '净重28以下', '毛重52以上', '毛重50-51', '毛重48-49', '毛重47-48', '毛重46-47', '毛重45-47', '毛重45-46', '毛重44-45', '毛重43-44', '毛重42-43', '毛重41-42', '毛重40-41', '毛重38-39', '毛重36-37', '毛重34-35', '毛重32-33', '毛重30-31', '毛重30以下'], // 规格搜索相关变量 specSearchKeyword: '', // 创建货源弹窗中的规格搜索关键词 editSpecSearchKeyword: '', // 编辑货源弹窗中的规格搜索关键词 filteredSpecOptions: [], // 过滤后的规格选项数组 filteredEditSpecOptions: [], // 编辑货源过滤后的规格选项数组 + // 地区选择相关变量 + showRegionSelectModal: false, // 控制地区选择弹窗显示 + currentRegionMode: 'create', // 当前地区选择模式:create 或 edit + regionOptions: ['北京', '上海', '天津', '重庆', '河北', '石家庄', '唐山', '秦皇岛', '邯郸', '邢台', '保定', '张家口', '承德', '沧州', '廊坊', '衡水', '山西', '太原', '大同', '阳泉', '长治', '晋城', '朔州', '晋中', '运城', '忻州', '临汾', '吕梁', '内蒙古', '呼和浩特', '包头', '乌海', '赤峰', '通辽', '鄂尔多斯', '呼伦贝尔', '巴彦淖尔', '乌兰察布', '兴安盟', '锡林郭勒盟', '阿拉善盟', '辽宁', '沈阳', '大连', '鞍山', '抚顺', '本溪', '丹东', '锦州', '营口', '阜新', '辽阳', '盘锦', '铁岭', '朝阳', '葫芦岛', '吉林', '长春', '吉林', '四平', '辽源', '通化', '白山', '松原', '白城', '延边朝鲜族自治州', '黑龙江', '哈尔滨', '齐齐哈尔', '鸡西', '鹤岗', '双鸭山', '大庆', '伊春', '佳木斯', '七台河', '牡丹江', '黑河', '绥化', '大兴安岭地区', '江苏', '南京', '无锡', '徐州', '常州', '苏州', '南通', '连云港', '淮安', '盐城', '扬州', '镇江', '泰州', '宿迁', '浙江', '杭州', '宁波', '温州', '嘉兴', '湖州', '绍兴', '金华', '衢州', '舟山', '台州', '丽水', '安徽', '合肥', '芜湖', '蚌埠', '淮南', '马鞍山', '淮北', '铜陵', '安庆', '黄山', '滁州', '阜阳', '宿州', '六安', '亳州', '池州', '宣城', '福建', '福州', '厦门', '莆田', '三明', '泉州', '漳州', '南平', '龙岩', '宁德', '江西', '南昌', '景德镇', '萍乡', '九江', '新余', '鹰潭', '赣州', '吉安', '宜春', '抚州', '上饶', '山东', '济南', '青岛', '淄博', '枣庄', '东营', '烟台', '潍坊', '济宁', '泰安', '威海', '日照', '临沂', '德州', '聊城', '滨州', '菏泽', '河南', '郑州', '开封', '洛阳', '平顶山', '安阳', '鹤壁', '新乡', '焦作', '濮阳', '许昌', '漯河', '三门峡', '南阳', '商丘', '信阳', '周口', '驻马店', '湖北', '武汉', '黄石', '十堰', '宜昌', '襄阳', '鄂州', '荆门', '孝感', '荆州', '黄冈', '咸宁', '随州', '恩施土家族苗族自治州', '湖南', '长沙', '株洲', '湘潭', '衡阳', '邵阳', '岳阳', '常德', '张家界', '益阳', '郴州', '永州', '怀化', '娄底', '湘西土家族苗族自治州', '广东', '广州', '深圳', '珠海', '汕头', '佛山', '韶关', '湛江', '肇庆', '江门', '茂名', '惠州', '梅州', '汕尾', '河源', '阳江', '清远', '东莞', '中山', '潮州', '揭阳', '云浮', '广西', '南宁', '柳州', '桂林', '梧州', '北海', '防城港', '钦州', '贵港', '玉林', '百色', '贺州', '河池', '来宾', '崇左', '海南', '海口', '三亚', '三沙', '儋州', '四川', '成都', '自贡', '攀枝花', '泸州', '德阳', '绵阳', '广元', '遂宁', '内江', '乐山', '南充', '眉山', '宜宾', '广安', '达州', '雅安', '巴中', '资阳', '阿坝藏族羌族自治州', '甘孜藏族自治州', '凉山彝族自治州', '贵州', '贵阳', '六盘水', '遵义', '安顺', '毕节', '铜仁', '黔西南布依族苗族自治州', '黔东南苗族侗族自治州', '黔南布依族苗族自治州', '云南', '昆明', '曲靖', '玉溪', '保山', '昭通', '丽江', '普洱', '临沧', '楚雄彝族自治州', '红河哈尼族彝族自治州', '文山壮族苗族自治州', '西双版纳傣族自治州', '大理白族自治州', '德宏傣族景颇族自治州', '怒江傈僳族自治州', '迪庆藏族自治州', '西藏', '拉萨', '日喀则', '昌都', '林芝', '山南', '那曲', '阿里', '陕西', '西安', '铜川', '宝鸡', '咸阳', '渭南', '延安', '汉中', '榆林', '安康', '商洛', '甘肃', '兰州', '嘉峪关', '金昌', '白银', '天水', '武威', '张掖', '平凉', '酒泉', '庆阳', '定西', '陇南', '临夏回族自治州', '甘南藏族自治州', '青海', '西宁', '海东', '海北藏族自治州', '黄南藏族自治州', '海南藏族自治州', '果洛藏族自治州', '玉树藏族自治州', '海西蒙古族藏族自治州', '宁夏', '银川', '石嘴山', '吴忠', '固原', '中卫', '新疆', '乌鲁木齐', '克拉玛依', '吐鲁番', '哈密', '阿克苏地区', '喀什地区', '和田地区', '昌吉回族自治州', '博尔塔拉蒙古自治州', '巴音郭楞蒙古自治州', '克孜勒苏柯尔克孜自治州', '伊犁哈萨克自治州', '塔城地区', '阿勒泰地区', '石河子', '阿拉尔', '图木舒克', '五家渠', '北屯', '铁门关', '双河', '可克达拉', '昆玉', '胡杨河', '新星'], // 地区选项列表(包含中国大部分省市区) + regionSearchKeyword: '', // 创建货源弹窗中的地区搜索关键词 + editRegionSearchKeyword: '', // 编辑货源弹窗中的地区搜索关键词 + filteredRegionOptions: [], // 过滤后的地区选项数组 newSupply: { name: '', // 品种 price: '', @@ -47,7 +54,8 @@ Page({ imageUrls: [] // 图片URL数组,支持多张图片 }, newSupplyRegionArray: [], // 新创建货源的省市区数组 - editSupplyRegionArray: [], // 编辑货源的省市区数组, + editSupplyRegionArray: [], // 编辑货源的省市区数组 + selectedRegionIndex: -1, // 地区弹窗中选中的地区索引 editSupply: { yolkIndex: 0, specIndex: 0 @@ -139,7 +147,7 @@ Page({ filteredSpecOptions: this.data.specOptions, filteredEditSpecOptions: this.data.specOptions }); - + // 尝试从本地存储加载草稿数据 const draftData = wx.getStorageSync('newSupplyDraft'); if (draftData) { @@ -148,7 +156,7 @@ Page({ }); console.log('从本地存储加载了草稿数据'); } - + console.log('卖家页面onLoad执行完毕'); }, @@ -352,7 +360,7 @@ Page({ // 页面不是初次显示,正常加载数据 this.loadSupplies(); } - + // 更新自定义tabBar状态 if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ @@ -1175,10 +1183,10 @@ Page({ try { const res = await API.uploadUserInfo(uploadData) console.log('用户信息上传成功:', res) - + // 入驻成功后,将用户类型设置为seller API.updateUserType('seller'); - + return res } catch (err) { console.error('用户信息上传失败:', err) @@ -1236,22 +1244,22 @@ Page({ // 显示添加货源弹窗 showAddSupply(e) { console.log('点击创建新货源按钮'); - + // 阻止事件冒泡,防止触发父元素的点击事件 if (e && e.stopPropagation) { e.stopPropagation(); } - + // 从本地存储加载之前保存的货源数据 const savedSupply = wx.getStorageSync('newSupplyDraft') || { name: '', price: '', minOrder: '', yolk: '', spec: '', imageUrls: [] }; - + // 直接显示创建货源弹窗,无需登录验证 this.setData({ showImagePreview: false, showModal: true, newSupply: savedSupply }); - + // 锁定页面滚动 this.disablePageScroll(); }, @@ -1316,7 +1324,7 @@ Page({ const newSupply = this.data.newSupply newSupply[field] = value this.setData({ newSupply }) - + // 实时保存到本地存储 wx.setStorageSync('newSupplyDraft', newSupply); }, @@ -1338,7 +1346,7 @@ Page({ onNewSupplyRegionChange(e) { const regionArray = e.detail.value const region = regionArray.join(' ') - + this.setData({ newSupplyRegionArray: regionArray, newSupply: { @@ -1346,7 +1354,7 @@ Page({ region: region } }) - + // 实时保存到本地存储 wx.setStorageSync('newSupplyDraft', this.data.newSupply); }, @@ -1355,7 +1363,7 @@ Page({ onEditSupplyRegionChange(e) { const regionArray = e.detail.value const region = regionArray.join(' ') - + this.setData({ editSupplyRegionArray: regionArray, editSupply: { @@ -1364,7 +1372,7 @@ Page({ } }) }, - + // 处理蛋黄选择变更 onYolkChange(e) { const index = e.detail.value @@ -1374,24 +1382,24 @@ Page({ 'newSupply.yolk': yolk }) }, - + // 处理规格选择变更 - 现在直接打开自定义弹窗 onSpecChange(e) { // 由于我们使用自定义弹窗,这个函数现在只需要打开弹窗即可 this.openSpecSelectModal({ currentTarget: { dataset: { mode: 'create' } } }); }, - + // 处理编辑模式下的蛋黄选择变更 onEditYolkChange(e) { console.warn('此方法已弃用,请使用openYolkSelectModal替代'); }, - + // 处理编辑模式下的规格选择变更 - 现在直接打开自定义弹窗 onEditSpecChange(e) { // 由于我们使用自定义弹窗,这个函数现在只需要打开弹窗即可 this.openSpecSelectModal({ currentTarget: { dataset: { mode: 'edit' } } }); }, - // 商品名称选择变化处理 + // 商品名称选择变化处理 onNameChange(e) { const index = e.detail.value const productName = this.data.productNameOptions[index] @@ -1410,7 +1418,7 @@ Page({ const userId = wx.getStorageSync('userId'); const openid = wx.getStorageSync('openid'); const userInfo = wx.getStorageSync('userInfo'); - + if (!userId || !openid || !userInfo) { console.log('用户未登录,显示登录提示'); // 登录前保存当前表单数据到本地存储 @@ -1433,7 +1441,7 @@ Page({ }); return; } - + const { name, price, minOrder, yolk, spec, region, imageUrls } = this.data.newSupply if (!name || !price || !minOrder || !yolk) { wx.showToast({ title: '请填写完整信息', icon: 'none', duration: 2000 }) @@ -1448,22 +1456,22 @@ Page({ .then(response => { const userInfoRes = response.data; console.log('获取用户信息成功:', userInfoRes) - + // 检查partnerstatus字段 const partnerStatus = userInfoRes.partnerstatus || 'pending' console.log('用户合作状态:', partnerStatus) - + if (partnerStatus !== 'approved') { throw new Error('partnerstatus_not_approved') } - + // 第一步:先创建商品(不带图片) const productData = { productName: name, price: price, // 保留原始字符串,不进行数字转换 quantity: Number(minOrder), grossWeight: this.data.newSupply.grossWeight && this.data.newSupply.grossWeight !== '' ? this.data.newSupply.grossWeight : "", - + yolk: yolk, specification: spec || '', region: region || '', // 【新增】添加地区字段 @@ -1472,7 +1480,7 @@ Page({ } console.log('第一步:准备创建商品,数据:', productData) - + // 更新加载提示 wx.showLoading({ title: '正在创建商品...', mask: true }) @@ -1519,10 +1527,10 @@ Page({ showModal: false, newSupply: { name: '', price: '', minOrder: '', yolk: '', spec: '', imageUrls: [] } }) - + // 清除本地存储的草稿数据 wx.removeStorageSync('newSupplyDraft'); - + this.enablePageScroll() // 重新加载数据 @@ -1785,106 +1793,106 @@ Page({ return Promise.reject(err); }) .then(() => { - // 【关键修复】准备商品数据 - 确保包含地区字段 - const productData = { - productName: editSupply.name, - price: editSupply.price, // 保留原始字符串,不进行数字转换 - quantity: Number(editSupply.minOrder), - grossWeight: editSupply.grossWeight !== undefined && editSupply.grossWeight !== null && editSupply.grossWeight !== '' ? editSupply.grossWeight : "", - yolk: editSupply.yolk, - specification: editSupply.spec || '', - region: editSupply.region || '', // 【重要】确保地区字段传递 - imageUrls: editSupply.imageUrls || [], - created_at: new Date().toISOString(), - status: autoPublishAfterEdit ? 'pending_review' : '' - }; - - console.log('【调试】准备提交的商品数据:', { - productData: productData, - hasRegion: !!productData.region, - regionValue: productData.region - }); - - // 判断是编辑现有商品还是创建新商品 - if (editSupply.serverProductId) { - // 编辑现有商品 - productData.productId = editSupply.serverProductId; - - console.log('【调试】调用API.editProduct,商品ID:', editSupply.serverProductId); + // 【关键修复】准备商品数据 - 确保包含地区字段 + const productData = { + productName: editSupply.name, + price: editSupply.price, // 保留原始字符串,不进行数字转换 + quantity: Number(editSupply.minOrder), + grossWeight: editSupply.grossWeight !== undefined && editSupply.grossWeight !== null && editSupply.grossWeight !== '' ? editSupply.grossWeight : "", + yolk: editSupply.yolk, + specification: editSupply.spec || '', + region: editSupply.region || '', // 【重要】确保地区字段传递 + imageUrls: editSupply.imageUrls || [], + created_at: new Date().toISOString(), + status: autoPublishAfterEdit ? 'pending_review' : '' + }; + + console.log('【调试】准备提交的商品数据:', { + productData: productData, + hasRegion: !!productData.region, + regionValue: productData.region + }); - // 【关键修复】使用正确的API调用格式 - const requestData = { - openid: openid, - productId: editSupply.serverProductId, - product: { - productName: productData.productName, - price: productData.price, - quantity: productData.quantity, - grossWeight: productData.grossWeight, - yolk: productData.yolk, - specification: productData.specification, - region: productData.region, // 【重要】确保在product对象中传递地区字段 - imageUrls: productData.imageUrls - }, - status: productData.status || '' - }; + // 判断是编辑现有商品还是创建新商品 + if (editSupply.serverProductId) { + // 编辑现有商品 + productData.productId = editSupply.serverProductId; + + console.log('【调试】调用API.editProduct,商品ID:', editSupply.serverProductId); + + // 【关键修复】使用正确的API调用格式 + const requestData = { + openid: openid, + productId: editSupply.serverProductId, + product: { + productName: productData.productName, + price: productData.price, + quantity: productData.quantity, + grossWeight: productData.grossWeight, + yolk: productData.yolk, + specification: productData.specification, + region: productData.region, // 【重要】确保在product对象中传递地区字段 + imageUrls: productData.imageUrls + }, + status: productData.status || '' + }; - console.log('【调试】最终发送的请求数据:', requestData); + console.log('【调试】最终发送的请求数据:', requestData); - // 直接使用wx.request调用,避免API封装层的问题 - wx.request({ - url: API.BASE_URL + '/api/product/edit', - method: 'POST', - data: requestData, - success: (res) => { - console.log('【调试】编辑商品成功响应:', res); - wx.hideLoading(); - this.setData({ showEditModal: false }); - this.enablePageScroll(); - wx.showToast({ title: '更新成功', duration: 2000 }); + // 直接使用wx.request调用,避免API封装层的问题 + wx.request({ + url: API.BASE_URL + '/api/product/edit', + method: 'POST', + data: requestData, + success: (res) => { + console.log('【调试】编辑商品成功响应:', res); + wx.hideLoading(); + this.setData({ showEditModal: false }); + this.enablePageScroll(); + wx.showToast({ title: '更新成功', duration: 2000 }); - // 重新加载数据 - setTimeout(() => { - this.loadSupplies(); - }, 100); - }, - fail: (err) => { - console.error('【调试】编辑商品失败:', err); - wx.hideLoading(); - wx.showToast({ title: '保存失败,请重试', icon: 'none', duration: 2000 }); - } - }); - } else { - // 创建新商品并提交审核 - // 调用添加商品接口 - wx.request({ - url: API.BASE_URL + '/api/product/add', - method: 'POST', - data: productData, - success: (res) => { - console.log('商品创建成功:', res); - wx.hideLoading(); + // 重新加载数据 + setTimeout(() => { + this.loadSupplies(); + }, 100); + }, + fail: (err) => { + console.error('【调试】编辑商品失败:', err); + wx.hideLoading(); + wx.showToast({ title: '保存失败,请重试', icon: 'none', duration: 2000 }); + } + }); + } else { + // 创建新商品并提交审核 + // 调用添加商品接口 + wx.request({ + url: API.BASE_URL + '/api/product/add', + method: 'POST', + data: productData, + success: (res) => { + console.log('商品创建成功:', res); + wx.hideLoading(); - // 关闭编辑弹窗 - this.setData({ showEditModal: false }); - // 恢复页面滚动 - this.enablePageScroll(); + // 关闭编辑弹窗 + this.setData({ showEditModal: false }); + // 恢复页面滚动 + this.enablePageScroll(); - wx.showToast({ title: '更新成功,等待审核', duration: 2000 }); + wx.showToast({ title: '更新成功,等待审核', duration: 2000 }); - // 重新加载商品列表 - setTimeout(() => { - this.loadSupplies(); - }, 100); - }, - fail: (err) => { - console.error('商品创建失败:', err); - wx.hideLoading(); - wx.showToast({ title: '创建失败,请重试', icon: 'none', duration: 2000 }); + // 重新加载商品列表 + setTimeout(() => { + this.loadSupplies(); + }, 100); + }, + fail: (err) => { + console.error('商品创建失败:', err); + wx.hideLoading(); + wx.showToast({ title: '创建失败,请重试', icon: 'none', duration: 2000 }); + } + }); } }); - } - }); }, // 预览图片 @@ -2025,7 +2033,7 @@ Page({ } else if (e.touches.length === 1) { // 单指触摸时记录触摸点 - 使用pageX和pageY而非clientX和clientY const touch = e.touches[0] - this.setData({ + this.setData({ lastTouchPoint: { pageX: touch.pageX, pageY: touch.pageY @@ -2110,7 +2118,7 @@ Page({ // 假设屏幕宽度为375px const screenWidth = 375 let newScale = 2 - + this.setData({ scale: newScale }) }, @@ -2223,7 +2231,7 @@ Page({ // 计算蛋黄和规格的索引值 const yolkIndex = this.data.yolkOptions.indexOf(supply.yolk) >= 0 ? this.data.yolkOptions.indexOf(supply.yolk) : 0; const specIndex = this.data.specOptions.indexOf(supply.spec) >= 0 ? this.data.specOptions.indexOf(supply.spec) : 0; - + // 设置编辑货源数据,显示编辑弹窗 const supplyWithFormattedTime = { ...supply, @@ -2293,7 +2301,7 @@ Page({ const userId = wx.getStorageSync('userId'); const openid = wx.getStorageSync('openid'); const userInfo = wx.getStorageSync('userInfo'); - + if (!userId || !openid || !userInfo) { wx.showModal({ title: '提示', @@ -2307,7 +2315,7 @@ Page({ }); return; } - + // 检查用户合作状态 API.getUserInfo(openid) .then(response => { @@ -2332,7 +2340,7 @@ Page({ }); return; } - + const id = e.currentTarget.dataset.id // 优先使用编辑中的商品数据 let supply = null @@ -2355,7 +2363,7 @@ Page({ }); return; } - + wx.showLoading({ title: '处理中...', mask: true }); // 判断当前货源状态,决定设置什么状态 @@ -2840,25 +2848,25 @@ Page({ // 注意:这里不立即清空 currentRejectSupply,确保后续操作能使用 }); }, - + // 打开规格选择弹窗 openSpecSelectModal: function (e) { const mode = e.currentTarget.dataset.mode || 'create'; const currentSpec = mode === 'create' ? this.data.newSupply.spec : this.data.editSupply.spec; const specOptions = this.data.specOptions; let selectedIndex = -1; - + // 查找当前选中规格的索引 if (currentSpec) { selectedIndex = specOptions.indexOf(currentSpec); } - + // 通过全局数据控制自定义tab-bar的显示状态 const app = getApp(); if (app && app.globalData) { app.globalData.showTabBar = false; } - + this.setData({ showSpecSelectModal: true, currentSpecMode: mode, @@ -2868,7 +2876,7 @@ Page({ showTabBar: false // 隐藏底部tab-bar }); }, - + // 关闭规格选择弹窗 closeSpecSelectModal: function () { // 通过全局数据控制自定义tab-bar的显示状态 @@ -2876,7 +2884,7 @@ Page({ if (app && app.globalData) { app.globalData.showTabBar = true; } - + this.setData({ showSpecSelectModal: false, modalSpecSearchKeyword: '', @@ -2884,26 +2892,26 @@ Page({ showTabBar: true // 显示底部tab-bar }); }, - + // 弹窗中规格搜索输入 onModalSpecSearchInput: function (e) { const keyword = e.detail.value; const specOptions = this.data.specOptions; let filteredOptions = specOptions; - + if (keyword) { filteredOptions = specOptions.filter(option => { return option.toLowerCase().includes(keyword.toLowerCase()); }); } - + this.setData({ modalSpecSearchKeyword: keyword, filteredModalSpecOptions: filteredOptions, selectedModalSpecIndex: -1 // 搜索时重置选择 }); }, - + // 清除弹窗中的规格搜索关键词 clearModalSpecSearch: function () { this.setData({ @@ -2912,18 +2920,18 @@ Page({ selectedModalSpecIndex: -1 }); }, - + // 双击检测变量 lastTapTime: {}, tapCount: {}, - + // 通用双击检测函数 - handleDoubleTap: function(e, type, callback) { + handleDoubleTap: function (e, type, callback) { const currentTime = Date.now(); const tapKey = `${type}-${e.currentTarget.dataset.index}`; const lastTap = this.lastTapTime[tapKey] || 0; const tapInterval = currentTime - lastTap; - + if (tapInterval < 300 && tapInterval > 0) { // 双击事件触发,执行确认选择 callback(); @@ -2935,7 +2943,7 @@ Page({ }, 300); } }, - + // 弹窗中选择规格 onModalSpecSelect: function (e) { const index = e.currentTarget.dataset.index; @@ -2944,13 +2952,13 @@ Page({ selectedModalSpecIndex: index, modalSpecSearchKeyword: selectedSpec // 自动填充搜索框为当前选择的规格 }); - + // 检测双击 this.handleDoubleTap(e, 'spec', () => { this.confirmSpecSelection(); }); }, - + // 确认规格选择 confirmSpecSelection: function () { if (this.data.selectedModalSpecIndex === -1) { @@ -2960,11 +2968,11 @@ Page({ }); return; } - + const selectedSpec = this.data.filteredModalSpecOptions[this.data.selectedModalSpecIndex]; const specOptions = this.data.specOptions; const originalIndex = specOptions.indexOf(selectedSpec); - + // 根据当前模式更新对应的规格信息 if (this.data.currentSpecMode === 'create') { const newSupply = this.data.newSupply; @@ -2973,7 +2981,7 @@ Page({ this.setData({ newSupply: newSupply }); - + // 实时保存到本地存储 wx.setStorageSync('newSupplyDraft', newSupply); } else if (this.data.currentSpecMode === 'edit') { @@ -2982,10 +2990,10 @@ Page({ 'editSupply.specIndex': originalIndex }); } - + // 关闭弹窗 this.closeSpecSelectModal(); - + // 恢复页面滚动 this.enablePageScroll(); @@ -3104,7 +3112,7 @@ Page({ this.setData({ newSupply: newSupply }); - + // 实时保存到本地存储 wx.setStorageSync('newSupplyDraft', newSupply); } else { @@ -3199,7 +3207,7 @@ Page({ this.setData({ newSupply: newSupply }); - + // 实时保存到本地存储 wx.setStorageSync('newSupplyDraft', newSupply); } else { @@ -3273,12 +3281,12 @@ Page({ filterSpecOptions(keyword, type) { const specOptions = this.data.specOptions; let filteredOptions = specOptions; - + if (keyword) { filteredOptions = specOptions.filter(option => { return option.toLowerCase().includes(keyword); }); - + // 如果有匹配的规格选项,自动填充第一个匹配项 if (filteredOptions.length > 0) { if (type === 'create') { @@ -3309,7 +3317,7 @@ Page({ }); } } - + if (type === 'create') { this.setData({ filteredSpecOptions: filteredOptions @@ -3341,6 +3349,118 @@ Page({ }); }, + // 打开创建货源的地区选择弹窗 + openCreateRegionModal() { + this.setData({ + currentRegionMode: 'create', + regionSearchKeyword: '', + filteredRegionOptions: this.data.regionOptions, + showRegionSelectModal: true + }); + }, + + // 打开编辑货源的地区选择弹窗 + openEditRegionModal() { + this.setData({ + currentRegionMode: 'edit', + editRegionSearchKeyword: '', + filteredRegionOptions: this.data.regionOptions, + showRegionSelectModal: true + }); + }, + + // 关闭地区选择弹窗 + closeRegionModal() { + this.setData({ + showRegionSelectModal: false, + selectedRegionIndex: -1 + }); + }, + + // 处理创建货源弹窗中的地区搜索输入 + onRegionSearchInput(e) { + const keyword = e.detail.value.toLowerCase().trim(); + this.setData({ + regionSearchKeyword: keyword + }); + // 过滤地区选项 + this.filterRegionOptions(keyword, 'create'); + }, + + // 处理编辑货源弹窗中的地区搜索输入 + onEditRegionSearchInput(e) { + const keyword = e.detail.value.toLowerCase().trim(); + this.setData({ + editRegionSearchKeyword: keyword + }); + // 过滤地区选项 + this.filterRegionOptions(keyword, 'edit'); + }, + + // 过滤地区选项的通用函数 + filterRegionOptions(keyword, type) { + const regionOptions = this.data.regionOptions; + let filteredOptions = regionOptions; + + if (keyword) { + filteredOptions = regionOptions.filter(option => { + return option.toLowerCase().includes(keyword); + }); + } + + this.setData({ + filteredRegionOptions: filteredOptions + }); + }, + + // 清除地区搜索关键词 + clearRegionSearch() { + this.setData({ + regionSearchKeyword: '', + filteredRegionOptions: this.data.regionOptions + }); + }, + + // 清除编辑弹窗中的地区搜索关键词 + clearEditRegionSearch() { + this.setData({ + editRegionSearchKeyword: '', + filteredRegionOptions: this.data.regionOptions + }); + }, + + // 选择地区 + selectRegion(e) { + const index = e.currentTarget.dataset.index; + this.setData({ + selectedRegionIndex: index + }); + }, + + // 确认地区选择 + confirmRegionSelection() { + const selectedIndex = this.data.selectedRegionIndex; + if (selectedIndex === -1) { + this.closeRegionModal(); + return; + } + + const selectedRegion = this.data.filteredRegionOptions[selectedIndex]; + const mode = this.data.currentRegionMode; + + if (mode === 'create') { + this.setData({ + 'newSupply.region': selectedRegion + }); + } else if (mode === 'edit') { + this.setData({ + 'editSupply.region': selectedRegion + }); + } + + this.closeRegionModal(); + }, + /** * 阻止触摸移动事件(用于WXML绑定) */ @@ -3396,7 +3516,7 @@ Page({ return false } }, - + // 商品名称选择弹窗相关函数 openNameSelectModal() { // 设置当前选中的索引 @@ -3407,55 +3527,55 @@ Page({ currentName = this.data.newSupply.name; } const index = currentName ? this.data.productNameOptions.indexOf(currentName) : -1; - + // 通过全局数据控制自定义tab-bar的显示状态 const app = getApp(); if (app && app.globalData) { app.globalData.showTabBar = false; } - + this.setData({ showNameSelectModal: true, selectedNameIndex: index >= 0 ? index : -1, showTabBar: false // 隐藏底部tab-bar }); }, - + closeNameSelectModal() { // 通过全局数据控制自定义tab-bar的显示状态 const app = getApp(); if (app && app.globalData) { app.globalData.showTabBar = true; } - + this.setData({ showNameSelectModal: false, showTabBar: true // 显示底部tab-bar }); }, - + onNameSelect(e) { const index = e.currentTarget.dataset.index; this.setData({ selectedNameIndex: index }); - + // 检测双击 this.handleDoubleTap(e, 'name', () => { this.confirmNameSelection(); }); }, - + confirmNameSelection() { if (this.data.selectedNameIndex >= 0) { const selectedName = this.data.productNameOptions[this.data.selectedNameIndex]; - + // 通过全局数据控制自定义tab-bar的显示状态 const app = getApp(); if (app && app.globalData) { app.globalData.showTabBar = true; } - + // 根据当前是编辑还是创建模式,更新对应的对象 if (this.data.showEditModal) { this.setData({ @@ -3471,13 +3591,13 @@ Page({ showNameSelectModal: false, showTabBar: true // 显示底部tab-bar }); - + // 实时保存到本地存储 wx.setStorageSync('newSupplyDraft', newSupply); } } }, - + // 蛋黄选择弹窗相关函数 openYolkSelectModal() { // 设置当前选中的索引 @@ -3488,55 +3608,55 @@ Page({ currentYolk = this.data.newSupply.yolk; } const index = currentYolk ? this.data.yolkOptions.indexOf(currentYolk) : -1; - + // 通过全局数据控制自定义tab-bar的显示状态 const app = getApp(); if (app && app.globalData) { app.globalData.showTabBar = false; } - + this.setData({ showYolkSelectModal: true, selectedYolkIndex: index >= 0 ? index : -1, showTabBar: false // 隐藏底部tab-bar }); }, - + closeYolkSelectModal() { // 通过全局数据控制自定义tab-bar的显示状态 const app = getApp(); if (app && app.globalData) { app.globalData.showTabBar = true; } - + this.setData({ showYolkSelectModal: false, showTabBar: true // 显示底部tab-bar }); }, - + onYolkSelect(e) { const index = e.currentTarget.dataset.index; this.setData({ selectedYolkIndex: index }); - + // 检测双击 this.handleDoubleTap(e, 'yolk', () => { this.confirmYolkSelection(); }); }, - + confirmYolkSelection() { if (this.data.selectedYolkIndex >= 0) { const selectedYolk = this.data.yolkOptions[this.data.selectedYolkIndex]; - + // 通过全局数据控制自定义tab-bar的显示状态 const app = getApp(); if (app && app.globalData) { app.globalData.showTabBar = true; } - + // 根据当前是编辑还是创建模式,更新对应的对象 if (this.data.showEditModal) { this.setData({ @@ -3554,7 +3674,7 @@ Page({ showYolkSelectModal: false, showTabBar: true // 显示底部tab-bar }); - + // 实时保存到本地存储 wx.setStorageSync('newSupplyDraft', newSupply); } diff --git a/pages/seller/index.wxml b/pages/seller/index.wxml index e15eb6f..76dd134 100644 --- a/pages/seller/index.wxml +++ b/pages/seller/index.wxml @@ -534,15 +534,13 @@ 地区 - {{newSupply.region || '请选择省市区'}} - + @@ -617,15 +615,13 @@ 地区 - {{editSupply.region || '请选择省市区'}} - + @@ -860,4 +856,54 @@ + + + + + + 取消 + 确定 + + + + + + + + ✕ + + + + + + + + {{item}} + + + + + \ No newline at end of file diff --git a/pages/seller/index.wxss b/pages/seller/index.wxss index 86271b4..d45dc84 100644 --- a/pages/seller/index.wxss +++ b/pages/seller/index.wxss @@ -824,4 +824,120 @@ button { -webkit-transform: translateZ(0); transform: translateZ(0); will-change: transform; +} + +/* 地区选择弹窗样式 */ +.region-select-modal { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.5); + display: flex; + justify-content: center; + z-index: 9999; + overflow: hidden; +} + +.region-select-modal .modal-content { + position: fixed; + bottom: 0; + left: 0; + right: 0; + background: white; + border-radius: 20rpx 20rpx 0 0; + max-height: 80vh; + will-change: transform; + -webkit-transition: transform 0.3s ease; + transition: transform 0.3s ease; +} + +.region-select-modal .modal-header { + padding: 20rpx; + display: flex; + justify-content: space-between; + align-items: center; + border-bottom: 1rpx solid #eee; + background-color: white; + border-radius: 20rpx 20rpx 0 0; +} + +.region-select-modal .modal-title { + font-size: 32rpx; + font-weight: 500; + color: #333; +} + +.region-select-modal .modal-btn { + font-size: 32rpx; + padding: 10rpx 20rpx; +} + +.region-select-modal .modal-btn.cancel { + color: #333; +} + +.region-select-modal .modal-btn.confirm { + color: #07c160; +} + +.region-select-modal .search-area { + padding: 20rpx; + background-color: white; + border-bottom: 1rpx solid #f0f0f0; +} + +.region-select-modal .search-box { + position: relative; + background: #f5f5f5; + border-radius: 40rpx; + padding: 0 30rpx; +} + +.region-select-modal .search-input { + width: 100%; + height: 70rpx; + line-height: 70rpx; + font-size: 28rpx; + background: transparent; + -webkit-appearance: none; + appearance: none; + border: none; + outline: none; +} + +.region-select-modal .search-clear { + position: absolute; + right: 30rpx; + top: 50%; + transform: translateY(-50%); + color: #999; + font-size: 32rpx; + cursor: pointer; +} + +.region-select-modal .region-list { + max-height: 60vh; + overflow-y: auto; + -webkit-overflow-scrolling: touch; +} + +.region-select-modal .region-item { + padding: 32rpx 40rpx; + border-bottom: 1rpx solid #f0f0f0; + font-size: 32rpx; + color: #131413; + text-align: center; + cursor: pointer; + transition: background-color 0.2s ease; +} + +.region-select-modal .region-item:hover { + background-color: #f5f5f5; +} + +.region-select-modal .region-item.selected { + color: #07c160; + background-color: #f0f8f3; } \ No newline at end of file