From 6ad52eb2c6dde0a54db41ac107747ad8e87ec50d Mon Sep 17 00:00:00 2001 From: lwh <2679599887@qq.com> Date: Thu, 15 Jun 2023 15:16:42 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=BC=80=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/upload/index.js | 7 +- pages/usercenter/apply-shop/index.js | 110 ++++++++++++++++-- pages/usercenter/apply-shop/index.json | 7 +- pages/usercenter/apply-shop/index.wxml | 18 ++- pages/usercenter/person-info/index.js | 3 +- services/_utils/request.js | 2 +- .../usercenter/apply-shop/addOrUpdateShop.js | 22 ++++ .../apply-shop/getFirstGoodsCategoryList.js | 19 +++ 8 files changed, 171 insertions(+), 17 deletions(-) create mode 100644 services/usercenter/apply-shop/addOrUpdateShop.js create mode 100644 services/usercenter/apply-shop/getFirstGoodsCategoryList.js diff --git a/components/upload/index.js b/components/upload/index.js index 98f7af8..3342afc 100644 --- a/components/upload/index.js +++ b/components/upload/index.js @@ -1,4 +1,5 @@ // components/upload/index.js +import { ServerBasePath } from '~/services/_utils/request' Component({ /** * 组件的属性列表 @@ -39,8 +40,10 @@ Component({ // this.triggerEvent('customEvent', dataToPass); // 触发自定义事件,并传递值 // }, + + + handleAdd(e) { - console.log(111); const { fileList @@ -73,7 +76,7 @@ Component({ } = fileList; const task = wx.uploadFile({ - url: 'http://192.168.1.102:8888/api/Common/UploadFile', // 仅为示例,非真实的接口地址 + url: ServerBasePath + '/Common/UploadFile', // 仅为示例,非真实的接口地址 filePath: file.url, name: 'file', formData: { diff --git a/pages/usercenter/apply-shop/index.js b/pages/usercenter/apply-shop/index.js index a741233..727dacd 100644 --- a/pages/usercenter/apply-shop/index.js +++ b/pages/usercenter/apply-shop/index.js @@ -1,10 +1,24 @@ // pages/usercenter/apply-shop/index.js +import { + ServerBasePath +} from '~/services/_utils/request' +import { + getFirstGoodsCategoryList +} from '~/services/usercenter/apply-shop/getFirstGoodsCategoryList' +import { + addOrUpdateShop +} from '~/services/usercenter/apply-shop/addOrUpdateShop' +import Toast from 'tdesign-miniprogram/toast/index'; + Page({ /** * 页面的初始数据 */ data: { + shopBusinessCategoryText: '', + shopBusinessCategoryVisible: false, + shopBusinessCategoryList: [], shopInfo: { ShopBusinessCategoryGuid: "", ShopName: "", @@ -17,11 +31,91 @@ Page({ // 提交 submit() { - console.log(this.data.shopInfo); let data = this.data.shopInfo + data.ShopBusinessCategoryGuid = data.ShopBusinessCategoryGuid[0] data.ShopLogo = data.ShopLogo.map(item => item.url).join(',') data.ShopBusinessLicense = data.ShopBusinessLicense.map(item => item.url).join(',') - console.log(data); + addOrUpdateShop(data).then((res) => { + if (res.code === 200) { + Toast({ + context: this, + selector: '#t-toast', + message: res.data, + theme: 'success', + }) + this.setData({ + shopInfo: null + }) + // 返回上一页 + setTimeout(() => { + const pages = getCurrentPages(); //获取小程序页面栈 + const beforePage = pages[pages.length - 1]; //获取上个页面的实例对象 -2是上上一个页面 + wx.navigateBack({ + delta: 1, + }); + beforePage.onLoad(); + }, 1000); + } else { + Toast({ + context: this, + selector: '#t-toast', + message: res.Msg, + theme: 'error', + }) + } + }) + }, + + init() { + // 获取经营类目 + getFirstGoodsCategoryList().then((res) => { + this.setData({ + shopBusinessCategoryList: res.data + }) + }) + }, + + onLoad(options) { + this.init() + }, + + + // 选项切换 + onColumnChange(e) {}, + + // 选中 + onPickerChange(e) { + const { + key + } = e.currentTarget.dataset; + const { + value, + label + } = e.detail; + + this.setData({ + [`${key}Visible`]: false, + [`shopInfo.ShopBusinessCategoryGuid`]: value, + [`${key}Text`]: label.join(' '), + }); + }, + + // 选项取消 + onPickerCancel(e) { + const { + key + } = e.currentTarget.dataset; + this.setData({ + [`${key}Visible`]: false, + }); + }, + + + // 选择经营类目 + onshopBusinessCategoryPicker() { + this.setData({ + shopBusinessCategoryVisible: true + }); }, onChangeShopName(e) { @@ -80,7 +174,7 @@ Page({ const { ShopBusinessLicense } = this.data.shopInfo; - + ShopBusinessLicense.splice(index, 1); this.setData({ "shopInfo.ShopBusinessLicense": ShopBusinessLicense, @@ -105,7 +199,7 @@ Page({ } = ShopLogo; const task = wx.uploadFile({ - url: 'http://192.168.1.102:8888/api/Common/UploadFile', // 仅为示例,非真实的接口地址 + url: ServerBasePath + 'Common/UploadFile', // 仅为示例,非真实的接口地址 filePath: file.url, name: 'file', formData: { @@ -144,7 +238,7 @@ Page({ } = ShopBusinessLicense; const task = wx.uploadFile({ - url: 'http://192.168.1.102:8888/api/Common/UploadFile', // 仅为示例,非真实的接口地址 + url: ServerBasePath + 'Common/UploadFile', // 仅为示例,非真实的接口地址 filePath: file.url, name: 'file', formData: { @@ -174,12 +268,6 @@ Page({ // // }); // }, - /** - * 生命周期函数--监听页面加载 - */ - onLoad(options) { - - }, /** * 生命周期函数--监听页面初次渲染完成 diff --git a/pages/usercenter/apply-shop/index.json b/pages/usercenter/apply-shop/index.json index da0ed45..a9a044d 100644 --- a/pages/usercenter/apply-shop/index.json +++ b/pages/usercenter/apply-shop/index.json @@ -4,7 +4,12 @@ "t-textarea": "tdesign-miniprogram/textarea/textarea", "t-button": "tdesign-miniprogram/button/button", "t-upload": "tdesign-miniprogram/upload/upload", - "van-button": "@vant/weapp/button/index" + "van-button": "@vant/weapp/button/index", + "t-picker": "tdesign-miniprogram/picker/picker", + "t-picker-item": "tdesign-miniprogram/picker-item/picker-item", + "t-cell-group": "tdesign-miniprogram/cell-group/cell-group", + "t-cell": "tdesign-miniprogram/cell/cell", + "t-toast": "tdesign-miniprogram/toast/toast" }, "navigationBarTitleText": "申请开店" } \ No newline at end of file diff --git a/pages/usercenter/apply-shop/index.wxml b/pages/usercenter/apply-shop/index.wxml index 24a76e5..2dc8e21 100644 --- a/pages/usercenter/apply-shop/index.wxml +++ b/pages/usercenter/apply-shop/index.wxml @@ -2,7 +2,7 @@ - + + + + + + + \ No newline at end of file diff --git a/pages/usercenter/person-info/index.js b/pages/usercenter/person-info/index.js index 4733064..ec46df7 100644 --- a/pages/usercenter/person-info/index.js +++ b/pages/usercenter/person-info/index.js @@ -8,6 +8,7 @@ import { phoneEncryption } from '~/utils/util'; import Toast from 'tdesign-miniprogram/toast/index'; +import { ServerBasePath } from '~/services/_utils/request' Page({ data: { @@ -150,7 +151,7 @@ Page({ let tempFilePath = tempFilePaths[0]; // 上传图片到服务器 wx.uploadFile({ - url: 'http://192.168.1.102:8888/api/Common/UploadFile', // 上传接口地址 + url: ServerBasePath + 'Common/UploadFile', // 上传接口地址 filePath: tempFilePath, // 要上传的文件的临时路径 name: 'file', // 上传文件对应的字段名 success: function (uploadRes) { diff --git a/services/_utils/request.js b/services/_utils/request.js index e8eab5f..666dc06 100644 --- a/services/_utils/request.js +++ b/services/_utils/request.js @@ -3,7 +3,7 @@ import { getStorage } from '~/utils/storage' -const ServerBasePath = 'http://192.168.1.102:8888/api/'; +export const ServerBasePath = 'http://localhost:8888/api/'; // 网络请求封装 export function request(option) { diff --git a/services/usercenter/apply-shop/addOrUpdateShop.js b/services/usercenter/apply-shop/addOrUpdateShop.js new file mode 100644 index 0000000..9ca4cb1 --- /dev/null +++ b/services/usercenter/apply-shop/addOrUpdateShop.js @@ -0,0 +1,22 @@ +import { + request +} from '~/services/_utils/request'; + + +/** 提交店铺审核 */ +export function addOrUpdateShop(data) { + return new Promise((resolve, reject) => { + request({ + url: `ShopApi/addOrUpdateShop`, + method: 'POST', + data: data, + success: function (res) { + + resolve(res); + }, + fail: function (error) { + reject(error); + } + }); + }); +} \ No newline at end of file diff --git a/services/usercenter/apply-shop/getFirstGoodsCategoryList.js b/services/usercenter/apply-shop/getFirstGoodsCategoryList.js new file mode 100644 index 0000000..7144b5b --- /dev/null +++ b/services/usercenter/apply-shop/getFirstGoodsCategoryList.js @@ -0,0 +1,19 @@ +import { + request +} from '~/services/_utils/request'; + +/** 获取经营类目列表 */ +export function getFirstGoodsCategoryList() { + return new Promise((resolve, reject) => { + request({ + url: `ShopApi/getFirstGoodsCategoryList`, + method: 'GET', + success: function (res) { + resolve(res); + }, + fail: function (error) { + reject(error); + } + }); + }); +} \ No newline at end of file