需求: 实现实习岗位的上传功能。 难点: 其中有两个部分“岗位职责”和“岗位要求”是数组结构。上传信息的管理者在上传中可以对某一行进行删除或添加操作,调整数组中的信息。 成果:
HTML部分代码
<view class="work_request">
<view class="subtitle">【岗位要求】</view>
<block wx:for="{{work_request}}" wx:key="index">
<view class="work_intro_item">{{index+1}}.
<input class="text" maxlength="-1" placeholder="岗位要求" bindinput="inputRequest" data-index="{{index}}"
value="{{work_request[index]}}"></input>
<view class="button">
<view class="add" bindtap="addrequest">+</view>
<view class="minus" bindtap="minusrequest" data-index="{{index}}">-</view>
</view>
</view>
</block>
</view>
<view class="salary_detail">
<view class="subtitle">【薪资情况】</view>
<block wx:for="{{salary_detail}}" wx:key="index">
<view class="work_intro_item">{{index+1}}.
<input class="text" maxlength="-1" placeholder="薪资情况" bindinput="inputSalary" data-index="{{index}}"
value="{{salary_detail[index]}}"></input>
<view class="button">
<view class="add" bindtap="addsalary">+</view>
<view class="minus" bindtap="minussalary" data-index="{{index}}">-</view>
</view>
</view>
</block>
</view>
CSS部分代码
.subtitle {
font-size: 14px;
font-weight: 600;
color: #5c5a5a;
width: 200rpx;
}
.work_intro,.work_request{
padding-bottom: 20px;
}
.work_intro_item {
display: flex;
justify-content: space-around;
align-items: center;
}
.button{
display: flex;
font-size: 30px;
}
.add{
color: red;
}
.minus{
color: blue;
}
JS部分代码
data: {
work_intro:[''],
work_request:['']
},
inputIntro:function (e) {
let index = e.currentTarget.dataset.index
let work_intro = this.data.work_intro
work_intro[index] = e.detail.value
this.setData({
work_intro:work_intro
})
},
inputRequest:function (e) {
let index = e.currentTarget.dataset.index
let work_request = this.data.work_request
work_request[index] = e.detail.value
this.setData({
work_request:work_request
})
},
addline:function () {
let work_intro = this.data.work_intro
work_intro.push('')
this.setData({
work_intro:work_intro
})
},
addrequest:function () {
let work_request = this.data.work_request
work_request.push('')
this.setData({
work_request:work_request
})
},
minusline:function (e) {
let index = e.currentTarget.dataset.index
let work_intro = this.data.work_intro
work_intro.splice(index,1)
this.setData({
work_intro:work_intro
})
},
minusrequest:function (e) {
let index = e.currentTarget.dataset.index
let work_request = this.data.work_request
work_request.splice(index,1)
console.log(index,work_request)
this.setData({
work_request:work_request
})
},
formSubmit: function (e) {
let data = e.detail.value
let work_intro = this.data.work_intro.map((item,index)=>{
item = (index+1)+'.'+item
return item
})
let work_request = this.data.work_request.map((item,index)=>{
if(item!==''){
item = (index+1)+'.'+item
return item
}
})
let newIntern = Object.assign(
data,
{work_intro: work_intro},
{work_request:work_request}
)
wx.cloud.database().collection('internlist').add({
data:newIntern,
success:res=>{
console.log(res)
wx.showToast({
title: '上传成功',
})
}
})
},
|