360 lines
8.3 KiB
Vue
360 lines
8.3 KiB
Vue
<template>
|
||
<view>
|
||
<uni-popup ref="popup" type="bottom" background-color="#fff">
|
||
<view class="popup_title">添加产品</view>
|
||
<view class="searbox">
|
||
<image :src="BASE_IMG_URL+'search.png'" class="searchimg" mode=""></image>
|
||
<input type="text" placeholder="输入产品编号/名称搜索" @input="queryList" class="selfinput">
|
||
</view>
|
||
<view class="type-tabs" v-if="typeList.length">
|
||
<u-tabs name="name" :list="typeList" :is-scroll="true" active-color="#008EFF" :current="typeCurrent"
|
||
@change="changeType"></u-tabs>
|
||
</view>
|
||
<scroll-view scroll-y class="scrollbox" lower-threshold="30">
|
||
<view class="pop_list">
|
||
<view class="pop_li" v-for="(item,index) in list" :key="index">
|
||
<view class="pop_li_top">
|
||
<view class="pop_title">{{item.name}}</view>
|
||
<view class="pop_num">{{item.num}}</view>
|
||
</view>
|
||
<view class="pop_info" @tap.stop="changeSelect(index)">
|
||
<view class="pop_radio">
|
||
<radio color='#008EFF' :checked="item.select" ></radio>
|
||
</view>
|
||
<image :src="item.img ? item.img : BASE_IMG_URL+'img/index-4.png'" class="infoimg" mode=""></image>
|
||
<view class="pop_info_cen">
|
||
<view class="pop_info_text">单位:{{item.unit}}</view>
|
||
<view class="pop_info_text">零售价:¥{{item.price}}</view>
|
||
<view class="pop_info_text">批发价:¥{{item.wholesale}}</view>
|
||
<view class="pop_bottom" @tap.stop.prevent v-if="showNumber">
|
||
数量
|
||
<view class="conright">
|
||
<uni-number-box :min="1" v-model="item.number" @change="(e)=>{changeNumber(e,index)}"></uni-number-box>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<u-empty v-if="list.length == 0" text="暂无更多"></u-empty>
|
||
</view>
|
||
</scroll-view>
|
||
<view class="popup_bottom">
|
||
<view class="pp_left_box">
|
||
<view class="pp_left">
|
||
<radio color="#008EFF" :checked="isAll" @click="selectAll"></radio>全选
|
||
</view>
|
||
<view class="selectnum">已选{{selectArr.length}}项</view>
|
||
</view>
|
||
<view class="pp_right">
|
||
<view class="right_btn remove" @click="closePopup">取消</view>
|
||
<view class="right_btn sure" @click="sureSelectData">确定</view>
|
||
</view>
|
||
</view>
|
||
</uni-popup>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import { netContractProduct, netProductTypeList } from '@/api/kehu.js'
|
||
import { BASE_IMG_URL } from '@/util/api.js'
|
||
|
||
export default{
|
||
props:{
|
||
showProduct:{
|
||
type:Boolean,
|
||
default:false
|
||
},
|
||
showNumber:{
|
||
type:Boolean,
|
||
default:true
|
||
}
|
||
},
|
||
data(){
|
||
return{
|
||
BASE_IMG_URL:BASE_IMG_URL,
|
||
name:'',
|
||
list:[],
|
||
isAll:false,
|
||
selectArr:[],
|
||
typeList:[],
|
||
typeCurrent:0,
|
||
typeId:'',
|
||
selectedMap:{}
|
||
}
|
||
},
|
||
methods:{
|
||
queryList(e) {
|
||
this.name = e.detail.value
|
||
this.getProductList()
|
||
},
|
||
async init() {
|
||
this.$refs.popup.open()
|
||
this.list = []
|
||
this.name = ''
|
||
this.isAll = false
|
||
this.selectArr = []
|
||
this.selectedMap = {}
|
||
this.typeId = ''
|
||
this.typeCurrent = 0
|
||
if(!this.typeList.length){
|
||
await this.getTypeList()
|
||
}
|
||
this.getProductList()
|
||
},
|
||
getTypeList() {
|
||
return netProductTypeList().then(res=>{
|
||
const data = res.data || []
|
||
const tabs = [{id:'', name:'全部'}].concat(data.map(item=>({
|
||
...item,
|
||
name: item.name || item.title || item.cate_name || item.label || item.text
|
||
})))
|
||
this.typeList = tabs
|
||
})
|
||
},
|
||
getProductList() {
|
||
let params = {
|
||
name:this.name,
|
||
type_id:this.typeId
|
||
}
|
||
netContractProduct(params).then(res=>{
|
||
let arr = res.data
|
||
arr.forEach(ele=>{
|
||
const saved = this.selectedMap[ele.id]
|
||
if(saved){
|
||
ele.select = true
|
||
ele.number = saved.number || 1
|
||
this.selectedMap[ele.id] = {...ele}
|
||
}else{
|
||
ele.number = 1
|
||
ele.select = false
|
||
}
|
||
})
|
||
this.list = arr
|
||
this.refreshSelectedState()
|
||
})
|
||
},
|
||
changeType(index) {
|
||
this.typeCurrent = index
|
||
const current = this.typeList[index]
|
||
this.typeId = current && current.id ? current.id : ''
|
||
this.getProductList()
|
||
},
|
||
changeNumber(e,index) {
|
||
let obj = this.list[index]
|
||
if(e > 1){
|
||
obj.select = true
|
||
}
|
||
obj.number = e
|
||
this.$set(this.list,index,obj)
|
||
this.handleSelect()
|
||
},
|
||
//选择
|
||
changeSelect(index) {
|
||
let obj = this.list[index]
|
||
obj.select = !obj.select
|
||
this.$set(this.list,index,obj)
|
||
this.handleSelect()
|
||
},
|
||
//全选
|
||
selectAll() {
|
||
this.isAll = !this.isAll
|
||
let arr = this.list
|
||
if(this.isAll){
|
||
arr.forEach(ele=>{
|
||
ele.select = true
|
||
this.selectedMap[ele.id] = {...ele}
|
||
})
|
||
}else{
|
||
arr.forEach(ele=>{
|
||
ele.select = false
|
||
delete this.selectedMap[ele.id]
|
||
})
|
||
}
|
||
this.list = arr
|
||
this.refreshSelectedState()
|
||
},
|
||
closePopup() {
|
||
this.$refs.popup.close()
|
||
},
|
||
handleSelect() {
|
||
let arr = this.list
|
||
arr.forEach(ele=>{
|
||
if(ele.select){
|
||
this.selectedMap[ele.id] = {...ele}
|
||
}else{
|
||
delete this.selectedMap[ele.id]
|
||
}
|
||
})
|
||
this.refreshSelectedState()
|
||
},
|
||
refreshSelectedState(){
|
||
this.selectArr = Object.keys(this.selectedMap)
|
||
this.isAll = this.list.length ? this.list.every(item=>item.select) : false
|
||
},
|
||
//确定
|
||
sureSelectData() {
|
||
const newarr = Object.values(this.selectedMap)
|
||
this.closePopup()
|
||
this.$emit('selectList',newarr)
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
view{
|
||
box-sizing: border-box;
|
||
}
|
||
.popup_title{
|
||
text-align: center;
|
||
font-size:34rpx;
|
||
color:#333333;
|
||
padding:24rpx;
|
||
}
|
||
.searbox{
|
||
width:650rpx;
|
||
height:68rpx;
|
||
border-radius: 34rpx;
|
||
margin:0 auto;
|
||
border:1rpx solid $uni-text-color;
|
||
display: flex;
|
||
justify-content: flex-start;
|
||
align-items: center;
|
||
padding:0 15rpx;
|
||
.searchimg{
|
||
width:48rpx;
|
||
height:48rpx;
|
||
margin-right:15rpx;
|
||
}
|
||
.selfinput{
|
||
width:450rpx;
|
||
font-size:26rpx;
|
||
color:$uni-text-color;
|
||
}
|
||
}
|
||
.type-tabs{
|
||
padding:0 24rpx;
|
||
}
|
||
.scrollbox{
|
||
width:100%;
|
||
height:700rpx;
|
||
.pop_list{
|
||
padding:24rpx;
|
||
.pop_li{
|
||
background:#fff;
|
||
box-shadow: 1rpx 1rpx 8rpx 2rpx rgba(0,0,0,0.1);
|
||
border-radius: 24rpx;
|
||
margin-bottom:24rpx;
|
||
.pop_li_top{
|
||
padding:28rpx;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
border-bottom:1rpx solid #f5f5f5;
|
||
.pop_title{
|
||
font-size:34rpx;
|
||
color:#333333;
|
||
}
|
||
.pop_num{
|
||
font-size:30rpx;
|
||
color:#666666;
|
||
}
|
||
}
|
||
.pop_info{
|
||
display: flex;
|
||
justify-content: flex-start;
|
||
align-items: center;
|
||
padding:24rpx 30rpx;
|
||
.pop_radio{
|
||
margin-right:32rpx;
|
||
radio{
|
||
transform: scale(0.7);
|
||
}
|
||
}
|
||
.infoimg{
|
||
width:140rpx;
|
||
height:140rpx;
|
||
border-radius: 20rpx;
|
||
margin-right:60rpx;
|
||
}
|
||
.pop_info_cen{
|
||
.pop_info_text{
|
||
font-size:28rpx;
|
||
color:#666666;
|
||
margin-bottom:15rpx;
|
||
}
|
||
.pop_bottom{
|
||
display: flex;
|
||
justify-content: flex-start;
|
||
align-items: center;
|
||
font-size:28rpx;
|
||
color:#666666;
|
||
.conright{
|
||
margin-left:10rpx;
|
||
.stepbtn{
|
||
width:38rpx;
|
||
height:38rpx;
|
||
border:1rpx solid $uni-text-color;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
.popup_bottom{
|
||
width:100%;
|
||
padding:0 24rpx;
|
||
height:100rpx;
|
||
border-top:1rpx solid #f5f5f5;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
.pp_left_box{
|
||
display: flex;
|
||
justify-content: flex-start;
|
||
align-items: center;
|
||
.pp_left{
|
||
display: flex;
|
||
justify-content: flex-start;
|
||
align-items: center;
|
||
font-size:26rpx;
|
||
color:3333;
|
||
radio{
|
||
transform: scale(0.7);
|
||
}
|
||
}
|
||
.selectnum{
|
||
font-size:30rpx;
|
||
color:#FE9440;
|
||
margin-left:24rpx;
|
||
}
|
||
}
|
||
|
||
.pp_right{
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
align-items: center;
|
||
.right_btn{
|
||
width:165rpx;
|
||
height:60rpx;
|
||
font-size:30rpx;
|
||
text-align: center;
|
||
border-radius: 30rpx;
|
||
}
|
||
.remove{
|
||
border:1rpx solid $uni-text-color;
|
||
color:$uni-text-color;
|
||
line-height: 58rpx;
|
||
margin-right:24rpx;
|
||
}
|
||
.sure{
|
||
background:$uni-text-color;
|
||
color:#fff;
|
||
line-height: 58rpx;
|
||
}
|
||
}
|
||
}
|
||
</style>
|