Merge pull request '需求发布接口对接' (#56) from chenxuelian into dev

Reviewed-on: http://git.hchyun.com/feashow/pupil/pulls/56
This commit is contained in:
1171906056
2023-01-17 15:37:18 +00:00
2 changed files with 105 additions and 87 deletions

View File

@@ -30,7 +30,7 @@
</u-form-item> </u-form-item>
<u-form-item label="分类" borderBottom> <u-form-item label="分类" borderBottom>
<view class="select-view" @tap="showCategoryPicker = true"> <view class="select-view" @tap="showCategoryPicker = true">
<text v-if="needsPublishForm.cate_id">{{cateName}}</text> <text v-if="needsPublishForm.class">{{needsPublishForm.class}}</text>
<text v-else style="color:#CCCCCC;">请选择分类</text> <text v-else style="color:#CCCCCC;">请选择分类</text>
<u-icon name="arrow-right" color="#969696" size="14"></u-icon> <u-icon name="arrow-right" color="#969696" size="14"></u-icon>
</view> </view>
@@ -40,16 +40,16 @@
</view> </view>
<u-form-item label="产品" borderBottom> <u-form-item label="产品" borderBottom>
<view class="select-view" @tap="showProductPicker = true"> <view class="select-view" @tap="showProductPicker = true">
<text v-if="needsPublishForm.cate_id">{{cateName}}</text> <text v-if="needsPublishForm.product">{{needsPublishForm.product}}</text>
<text v-else style="color:#CCCCCC;">请选择产品类型</text> <text v-else style="color:#CCCCCC;">请选择产品类型</text>
<u-icon name="arrow-right" color="#969696" size="14"></u-icon> <u-icon name="arrow-right" color="#969696" size="14"></u-icon>
</view> </view>
<u-picker :show="showProductPicker" :columns="productPickerColumn" @cancel="showProductPicker = false" <u-picker :show="showProductPicker" :columns="productPickerColumn"
@confirm="getProductValue"></u-picker> @cancel="showProductPicker = false" @confirm="getProductValue"></u-picker>
</u-form-item> </u-form-item>
<u-form-item label="定位" borderBottom> <u-form-item label="定位" borderBottom>
<view class="select-view" @tap="selectProductPosition"> <view class="select-view" @tap="showPositionPicker = true">
<text v-if="needsPublishForm.tagids">{{tagName}}</text> <text v-if="needsPublishForm.loc">{{needsPublishForm.loc}}</text>
<text v-else style="color:#CCCCCC;">请选择产品定位</text> <text v-else style="color:#CCCCCC;">请选择产品定位</text>
<u-icon name="arrow-right" color="#969696" size="14"></u-icon> <u-icon name="arrow-right" color="#969696" size="14"></u-icon>
</view> </view>
@@ -65,8 +65,8 @@
<view v-if="tabCurrent === 1" style="margin-bottom: 20rpx;"> <view v-if="tabCurrent === 1" style="margin-bottom: 20rpx;">
<u-form-item label="上传图片" labelPosition="top"> <u-form-item label="上传图片" labelPosition="top">
<view style="padding-left: 20rpx;margin-top: 20rpx;"> <view style="padding-left: 20rpx;margin-top: 20rpx;">
<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple <u-upload :fileList="fileList1" :auto-upload="false" @afterRead="afterRead" @delete="deletePic"
:maxCount="10"></u-upload> name="1" multiple :maxCount="10"></u-upload>
</view> </view>
</u-form-item> </u-form-item>
</view> </view>
@@ -146,10 +146,13 @@
categoryPickerList: [ categoryPickerList: [
['类别1', '类别', '类别'] ['类别1', '类别', '类别']
], ],
fileList1: [], fileList1: [
// uploads/images/20230117/202301172309397deda1543.jpg
],
isLoad: true, isLoad: true,
cateName: null, cateName: null,
tagName: null tagName: null,
token: null
} }
}, },
onLoad(options) { onLoad(options) {
@@ -168,48 +171,57 @@
return return
} }
this.isLoad = true this.isLoad = true
this.getProductPickerList() this.token = uni.getStorageSync('token')
this.getFormData()
// this.getProductPickerList()
}, },
methods: { methods: {
tabChange(data) { tabChange(data) {
this.tabCurrent = data.index this.tabCurrent = data.index
this.needsPublishForm = {} this.needsPublishForm = {}
}, },
selectProductPosition() { getFormData() {
if (this.needsPublishForm.cate_id) { this.$apiServe.getIdeasAndNeedsFormdata().then(res => {
this.showPositionPicker = true console.log(res.data.data)
} else { const formData = res.data.data
this.$toast.warn('请先选择产品类型') this.productPickerColumn[0] = formData.product
} this.positionPickerColumn[0] = formData.loc
}, this.categoryPickerList[0] = formData.class
getProductPickerList() { // this.productPickerList = res.data.data.map((item, index) => {
const data = {} // temp.push(item.name)
const temp = [] // return item
this.$apiServe.getCategories(data).then(res => { // })
this.productPickerList = res.data.data.map((item, index) => { // this.productPickerColumn[0] = [...temp]
temp.push(item.name)
return item
})
this.productPickerColumn[0] = [...temp]
}).finally(_ => {}) }).finally(_ => {})
}, },
getPositionPickerList() { // getProductPickerList() {
if(this.needsPublishForm.cate_id) { // const data = {}
const data = { // const temp = []
pid: this.needsPublishForm.cate_id // this.$apiServe.getCategories(data).then(res => {
} // this.productPickerList = res.data.data.map((item, index) => {
this.$apiServe.getTags(data).then(res => { // temp.push(item.name)
const temp = [] // return item
this.positionPickerList = res.data.data.map((item, index) => { // })
temp.push(item.name) // // this.productPickerColumn[0] = [...temp]
return item // }).finally(_ => {})
}) // },
this.positionPickerColumn[0] = temp // getPositionPickerList() {
}).finally(_ => {}) // if (this.needsPublishForm.cate_id) {
} else { // const data = {
that.$toast.warn('请先选择产品类型') // pid: this.needsPublishForm.cate_id
} // }
}, // this.$apiServe.getTags(data).then(res => {
// const temp = []
// this.positionPickerList = res.data.data.map((item, index) => {
// temp.push(item.name)
// return item
// })
// this.positionPickerColumn[0] = temp
// }).finally(_ => {})
// } else {
// that.$toast.warn('请先选择产品类型')
// }
// },
getCityValue(data) { getCityValue(data) {
console.log(data) console.log(data)
this.showCityPicker = false this.showCityPicker = false
@@ -219,32 +231,32 @@
getProductValue(data) { getProductValue(data) {
this.showProductPicker = false this.showProductPicker = false
this.showCategoryPicker = false this.showCategoryPicker = false
console.log(data) this.needsPublishForm.product= data.value[0]
const obj = this.productPickerList.find(item => { // console.log(data)
return item.name === data.value[0] // const obj = this.productPickerList.find(item => {
}) // return item.name === data.value[0]
this.cateName = data.value[0] // })
if (obj) { // this.cateName = data.value[0]
this.needsPublishForm.cate_id = obj.id // if (obj) {
} // this.needsPublishForm.cate_id = obj.id
this.needsPublishForm.tagids = null // }
this.getPositionPickerList() // this.needsPublishForm.tagids = null
// this.getPositionPickerList()
}, },
getPositionValue(data) { getPositionValue(data) {
this.showPositionPicker = false this.showPositionPicker = false
this.needsPublishForm.loc = data.value[0]
const obj = this.positionPickerList.find(item => { // const obj = this.positionPickerList.find(item => {
return item.name === data.value[0] // return item.name === data.value[0]
}) // })
this.tagName = data.value[0] // this.tagName = data.value[0]
if (obj) { // if (obj) {
this.needsPublishForm.tagids = obj.id // this.needsPublishForm.tagids = obj.id
} // }
}, },
getCategoryValue(data) { getCategoryValue(data) {
this.showCategoryPicker = false this.showCategoryPicker = false
this.needsPublishForm.cate_id = data.value[0] this.needsPublishForm.class = data.value[0]
}, },
getCode() { getCode() {
if (this.$refs.uCode.canGetCode) { if (this.$refs.uCode.canGetCode) {
@@ -274,6 +286,9 @@
async afterRead(event) { async afterRead(event) {
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式 // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file) let lists = [].concat(event.file)
console.log(this.fileList1)
console.log(lists)
console.log(this[`fileList${event.name}`])
let fileListLen = this[`fileList${event.name}`].length let fileListLen = this[`fileList${event.name}`].length
lists.map((item) => { lists.map((item) => {
this[`fileList${event.name}`].push({ this[`fileList${event.name}`].push({
@@ -296,25 +311,27 @@
}, },
uploadFilePromise(url) { uploadFilePromise(url) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const data = { // const data = {
file: new File // file: new File
}
let a = apiService.postImage(data).then(res => {
console.log(res)
})
// let a = uni.uploadFile({
// url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
// filePath: url,
// name: 'file',
// formData: {
// user: 'test'
// },
// success: (res) => {
// setTimeout(() => {
// resolve(res.data.data)
// }, 1000)
// } // }
// }); // let a = apiService.postImage(data).then(res => {
// console.log(res)
// })
let a = uni.uploadFile({
url: apiService.uploadImgUrl, // 仅为示例,非真实的接口地址
filePath: url,
name: 'file',
header: {
"Content-Type": "multipart/form-data",
"token": this.token
},
success: (res) => {
setTimeout(() => {
console.log(JSON.parse(res.data).data.url)
resolve(JSON.parse(res.data).data.url)
}, 1000)
}
});
}) })
}, },
//BlobUrl转blob数据 //BlobUrl转blob数据
@@ -361,6 +378,7 @@
// }) // })
return return
} }
this.token = uni.getStorageSync('token')
this.isLoad = true this.isLoad = true
}, },
failToLoad() { failToLoad() {

View File

@@ -205,7 +205,7 @@ const toast = {
} }
} }
const apiService = { const apiService = {
uploadImgUrl: serverHost, uploadImgUrl: serverHost + `/upload/image/`,
imgUrl: serverHost, imgUrl: serverHost,
// login: data => { // login: data => {
// data = Object.assign(data || {}, {}) // data = Object.assign(data || {}, {})
@@ -375,10 +375,10 @@ const apiService = {
resolve(service.post(url, data)) resolve(service.post(url, data))
}) })
}, },
submitIdeasAndNeeds(data) { getIdeasAndNeedsFormdata(data) {
const url = `/require/release/` const url = `/require/formdata/`
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(service.putWithFormData(url, data)) resolve(service.post(url, data))
}) })
}, },
postMobileByMnp(data) { postMobileByMnp(data) {