This commit is contained in:
sjeam 2025-09-05 16:41:56 +08:00
commit 8db7579875
5 changed files with 150 additions and 1 deletions

2
env/.env vendored
View File

@ -12,7 +12,7 @@ VITE_LOGIN_URL = '/pages/login/index'
# 数字乡村
VITE_SERVER_BASEURL = 'http://test.data-middle.lihaink.cn'
VITE_UPLOAD_BASEURL = 'http://test.data-middle.lihaink.cn/upload'
VITE_UPLOAD_BASEURL = 'http://test.data-middle.lihaink.cn/api/upload/image'
# 商城
VITE_SHOP_SERVER_BASEURL = 'https://shop.lihaink.cn'

12
src/api/user.ts Normal file
View File

@ -0,0 +1,12 @@
import { http } from '@/utils/http'
export function userListApi(data: { code: any }) {
return http.get('/api/user/list', data)
}
export function userInfoApi() {
return http.get('/api/user/info')
}
export function commitProduct(data) {
return http.post('/api/user/commitProduct', data)
}

View File

@ -117,6 +117,13 @@
"navigationBarTitleText": "设置"
}
},
{
"path": "pages/my/uploadProduct",
"type": "page",
"style": {
"navigationBarTitleText": "上传商品"
}
},
{
"path": "pages/service/find",
"type": "page"

View File

@ -92,6 +92,13 @@
icon: '/static/icons/my7.png',
color: 'red',
},
{
name: '上传商品',
url: '/pages/my/uploadProduct',
type: 1,
icon: '/static/icons/rural_ecommerce.png',
color: 'red',
},
]"
>
<wd-grid-item use-slot>

View File

@ -0,0 +1,123 @@
<route lang="json5">
{
style: { navigationBarTitleText: '上传商品' },
}
</route>
<script lang="ts" setup>
import { commitProduct, userInfoApi, userListApi } from '@/api/user'
import { useUserStore } from '@/store'
import { getEnvBaseUploadUrl } from '@/utils'
const action: string = `${getEnvBaseUploadUrl()}`
const userInfo = useUserStore().userInfo
const isManager = ref(false)
const userList = ref([])
const formData = reactive({
store_name: '',
number: '',
price: '',
image: [],
user_id: '',
})
function getUserInfo() {
userInfoApi().then((res) => {
if (res.data.group_id == 2) {
isManager.value = true
userListApi({ code: res.data.village }).then((res) => {
res.data.forEach((item) => {
userList.value.push({
label: item.nickname,
value: item.id,
})
})
})
} else {
formData.user_id = res.data.id
}
})
}
function handleSubmit() {
commitProduct(formData).then((res) => {
if (res.code == 1) {
uni.showToast({
title: '上传成功',
})
} else {
uni.showToast({
title: res.data.msg,
})
}
})
}
function goBack() {
uni.navigateBack({
delta: 1,
})
}
function uploadSuccess(res) {
const response = JSON.parse(res.file.response)
if (response.code === 1) {
formData.image.push(response.data.uri)
}
}
getUserInfo()
</script>
<template>
<view class="p-2">
<view class="detail-box bg-white p-2">
<wd-form ref="form" :model="formData">
<wd-cell-group border>
<wd-select-picker
v-if="isManager"
v-model="formData.user_id"
label="村民"
type="radio"
:columns="userList"
filterable
:rules="[{ required: true, message: '请选择村民' }]"
/>
<wd-input
v-model="formData.store_name"
label="商品名称"
prop="store_name"
placeholder="请输入商品名称"
:rules="[{ required: true, message: '请填写商品名称' }]"
/>
<wd-input
v-model="formData.number"
label="数量"
prop="number"
placeholder="请输入数量"
:rules="[{ required: true, message: '请填写数量' }]"
/>
<wd-input
v-model="formData.price"
label="单价"
prop="price"
placeholder="请输入单价"
:rules="[{ required: true, message: '请填写单价' }]"
/>
<view class="flex items-center">
<view class="w-[33%] text-[14px]">图片</view>
<wd-upload
v-model="formData.image"
image-mode="aspectFill"
:action="action"
:limit="9"
@success="uploadSuccess"
/>
</view>
</wd-cell-group>
</wd-form>
</view>
<view class="mt-6">
<button type="primary" size="large" block @click="handleSubmit">提交</button>
</view>
</view>
</template>