Browse Source

修复bug

liujd 6 years ago
parent
commit
3795806b86

+ 33 - 30
mobile-code/src/admin/ad/add.vue

@@ -38,8 +38,8 @@
 						<span class="app-color-3 app-size-24">只能上传jpg/png格式</span>
 					</div>
 					<div class="line-img">
-						<input v-model="form.endTime" name="endTime" type="text" hidden />
-						<app-uploader @chooseImage="chooseUploader" :multiple="false" ref="appUploader" :imgList.sync="imgList" />
+						<input :value="adImgStr" name="adImgStr" type="text" hidden />
+						<app-uploader :multiple="false" ref="appUploader" :imgList.sync="form.adImg" />
 					</div>
 				</tui-list-cell>
 			</div>
@@ -68,7 +68,7 @@
 						<div class="goods-list-wrap" v-if="!$util.isEmpty(goodsData)">
 							<div class="goods-list">
 								<div class="list-img">
-									<img :src="goodsData.imgSmallList[0]" alt="商品图片" mode="center" />
+									<img :src="goodsData.smallImgList[0]" alt="商品图片" mode="center" />
 								</div>
 								<div class="list-right">
 									<div>{{ goodsData.goodsName }}</div>
@@ -107,17 +107,17 @@ export default {
 		return {
 			form: {
 				adName: '',
-				adImg: '',
+				adImg: [],
 				status: 0,
 				inTurn: '',
 				type: 0,
 				style: 0,
 				url: '',
 				goodsId: '',
-				startTime: null,
-				endTime: null
+				startTime: '',
+				endTime: ''
 			},
-			imgList: [],
+			// imgList: [],
 			goodsData: {}
 		}
 	},
@@ -125,6 +125,12 @@ export default {
 		this.setPageTitle()
 		this.init()
 	},
+	computed: {
+		adImgStr() {
+			// let img = JSON
+			return this.form.adImg.join()
+		}
+	},
 	methods: {
 		init() {
 			this.type = this.option.type
@@ -132,8 +138,10 @@ export default {
 			let data = uni.getStorageSync('addAdData')
 			if (data) {
 				uni.removeStorageSync('addAdData')
-				this.form = data.form
-				this.imgList = data.imgList
+				setTimeout(() => {
+					this.form = data.form
+					// this.imgList = data.imgList
+				})
 				this.goodsData = data.goodsData
 			}
 			let goodsData = uni.getStorageSync('adSelGoods')
@@ -185,7 +193,7 @@ export default {
 		selGoodsFn() {
 			let data = {
 				form: this.form,
-				imgList: this.imgList,
+				// imgList: this.imgList,
 				goodsData: this.goodsData
 			}
 			uni.setStorageSync('addAdData', data)
@@ -198,7 +206,7 @@ export default {
 		},
 		startTimeFn(e) {
 			console.log(e)
-			// this.form.startTime = e
+			this.form.startTime = e.detail.value
 		},
 		endTimeFn(e) {
 			this.form.endTime = e.detail.value
@@ -209,31 +217,21 @@ export default {
 		radioChange(e) {
 			this.form.style = e.detail.value
 		},
-		chooseUploader() {
-			console.log('afda')
-			// modifySiteCover({
-			// 	site_info_id: this.detail.site_info_id,
-			// 	cover: encodeURIComponent(this.imgList[0])
-			// }).then(res => {
-			// 	this.form.cover = this.imgList[0]
-			// 	this.imgList.splice(0, 1)
-			// 	uni.showToast({
-			// 		title: '更换成功',
-			// 		icon: 'none'
-			// 	})
-			// })
-		},
 		confirmFn() {
 			let hostFn = this.option.id ? update : add
+			let form = JSON.parse(JSON.stringify(this.form))
+			console.log(form)
+			form.adImg = this.$util.imgSubstr(form.adImg)
+			form.adImg = form.adImg.join()
 			if (this.option.id) {
-				this.form.id = this.option.id
+				form.id = this.option.id
 			}
 			if (this.form.style == 0) {
-				this.form.goodsId = ''
+				form.goodsId = ''
 			} else {
-				this.form.url = ''
+				form.url = ''
 			}
-			hostFn(this.form).then(res => {
+			hostFn(form).then(res => {
 				let promptText = this.option.id ? '修改成功!' : '添加成功!'
 				this.$msg(promptText)
 			})
@@ -245,7 +243,7 @@ export default {
 				{
 					name: 'adName',
 					rule: ['required'],
-					msg: ['请输入名']
+					msg: ['请输入名']
 				},
 				{
 					name: 'startTime',
@@ -256,6 +254,11 @@ export default {
 					name: 'endTime',
 					rule: ['required'],
 					msg: ['请选择结束时间']
+				},
+				{
+					name: 'adImgStr',
+					rule: ['required'],
+					msg: ['请先上传图片']
 				}
 			]
 			// 进行表单检查

+ 4 - 2
mobile-code/src/admin/ad/list.vue

@@ -5,7 +5,7 @@
 			<block v-if="!$util.isEmpty(list.data)">
 				<div class="list" v-for="(item, index) in list.data" :key="index">
 					<div class="list-img">
-						<img :src="item.adImgUrl" :lazy-load="true" alt="广告图片" mode="center" />
+						<app-img :src="item.adImgUrl | default_img" alt="广告图片" mode="center" />
 					</div>
 					<div class="list-right">
 						<div class="app-size-28 app-color-0">{{ item.adName }}</div>
@@ -53,6 +53,7 @@ import AppTabs from '@/components/plugin/tabs'
 import OperateModule from '@/admin/home/components/module/operate'
 import AppWrapperEmpty from '@/components/app-wrapper-empty'
 import ModalModule from '@/components/plugin/modal'
+import AppImg from '@/components/app-img'
 import { list } from '@/mixins'
 // api
 import { getList, del, updateStatus } from '@/api/ad'
@@ -62,7 +63,8 @@ export default {
 		AppTabs,
 		OperateModule,
 		AppWrapperEmpty,
-		ModalModule
+		ModalModule,
+		AppImg
 	},
 	mixins: [list],
 	data() {

+ 29 - 25
mobile-code/src/admin/ad/sel-goods.vue

@@ -1,22 +1,25 @@
 <template>
 	<div class="app-content">
-		<sel-search-module :list="list.data" @search="searchFn" @change="changeFn">
-			<template v-slot:img="{ item }">
-				<div class="list-img">
-					<img :src="item.imgSmallList[0]" alt="商品图片" mode="center" />
-				</div>
-			</template>
-			<template v-slot:detail="{ item }">
-				<div class="list-right">
-					<div class="list-name">{{ item.goodsName }}</div>
-					<div class="app-price">¥{{ item.price }}</div>
-				</div>
-			</template>
-		</sel-search-module>
+		<block v-if="!$util.isEmpty(list.data)">
+			<sel-search-module :list="list.data" @search="searchFn" @change="changeFn">
+				<template v-slot:img="{ item }">
+					<div class="list-img">
+						<app-img :src="item.smallImgList[0] | default_img" alt="商品图片" mode="center" />
+					</div>
+				</template>
+				<template v-slot:detail="{ item }">
+					<div class="list-right">
+						<div class="list-name">{{ item.goodsName }}</div>
+						<div class="app-price">¥{{ item.price }}</div>
+					</div>
+				</template>
+			</sel-search-module>
+		</block>
 	</div>
 </template>
 
 <script>
+import AppImg from '@/components/app-img'
 import SelSearchModule from '@/admin/home/components/sel-search'
 import { list } from '@/mixins'
 // api
@@ -24,7 +27,8 @@ import { getListB } from '@/api/goods'
 export default {
 	name: 'sel-goods',
 	components: {
-		SelSearchModule
+		SelSearchModule,
+		AppImg
 	},
 	mixins: [list],
 	data() {
@@ -87,16 +91,16 @@ export default {
 </script>
 
 <style lang="scss" scoped>
-.list-img {
-	width: 160px;
-	height: 160px;
-	margin-right: 40px;
-}
-.list-right {
-	font-size: 28px;
-	.list-name {
-		font-size: 30px;
-		margin-bottom: 20px;
+	.list-img {
+		width: 160px;
+		height: 160px;
+		margin-right: 40px;
+	}
+	.list-right {
+		font-size: 28px;
+		.list-name {
+			font-size: 30px;
+			margin-bottom: 20px;
+		}
 	}
-}
 </style>

+ 1 - 1
mobile-code/src/admin/goodsManage/add.vue

@@ -68,7 +68,7 @@
 					<span class="app-color-3">(最多上传4张)</span>
 				</div>
 				<div class="module-det">
-					<app-uploader :multiple="false" ref="appUploader" :imgList.sync="form.shopImg" />
+					<app-uploader ref="appUploader" :imgList.sync="form.shopImg" :isMain="true" :num="4" />
 				</div>
 			</div>
 			<!-- 商品简介 -->

+ 15 - 27
mobile-code/src/admin/goodsManage/category.vue

@@ -49,7 +49,7 @@
 					<div class="inp-list-line">
 						<div class="line-label">图片</div>
 						<div class="line-input flex-strat">
-							<app-uploader :multiple="false" ref="appUploader" :imgList.sync="imgList" />
+							<app-uploader :multiple="false" ref="appUploader" :imgList.sync="modifyForm.img" />
 						</div>
 					</div>
 					<div class="inp-list-line">
@@ -95,13 +95,12 @@ export default {
 			modifyTitle: '添加',
 			modifyForm: {
 				categoryName: '',
-				img: '',
+				img: [],
 				inTurn: 0,
 				status: 1
 			},
 			// 删除弹窗
 			delModal: false,
-			imgList: [],
 			// operate
 			operateShow: false,
 			operateData: {},
@@ -122,7 +121,7 @@ export default {
 
 						this.modifyForm = {
 							categoryName: this.operateData.categoryName,
-							img: this.operateData.img,
+							img: [this.operateData.img],
 							inTurn: this.operateData.inTurn,
 							status: this.operateData.status
 						}
@@ -187,25 +186,18 @@ export default {
 				this.completes(data)
 			})
 		},
-		_categoryAddB() {
+		_categoryAddOrEditB() {
+			let host = this.modifyTitle == '编辑' ? categoryUpdateB : categoryAddB
+			let form = JSON.parse(JSON.stringify(this.modifyForm))
+			form.img = this.$util.imgSubstr(form.img)
+			form.img = form.img.join()
+			if (this.modifyTitle == '编辑') {
+				form.categoryId = this.operateData.id
+			}
 			categoryAddB({
-				...this.modifyForm
+				...form
 			}).then(res => {
-				this.$msg('新增成功!')
-				this.modalCancel()
-				this.operateCancle()
-				setTimeout(() => {
-					this.resetList()
-					this._list()
-				}, 1000)
-			})
-		},
-		_categoryUpdateB() {
-			categoryUpdateB({
-				categoryId: this.operateData.id,
-				...this.modifyForm
-			}).then(res => {
-				this.$msg('修改成功!')
+				this.$msg('操作成功!')
 				this.modalCancel()
 				this.operateCancle()
 				setTimeout(() => {
@@ -223,7 +215,7 @@ export default {
 		resetForm() {
 			this.modifyForm = {
 				categoryName: '',
-				img: '',
+				img: [],
 				inTurn: 0,
 				status: 1
 			}
@@ -232,11 +224,7 @@ export default {
 			if (e.index === 0) {
 				this.modalCancel()
 			} else {
-				if (this.modifyTitle == '编辑') {
-					this._categoryUpdateB()
-				} else {
-					this._categoryAddB()
-				}
+				this._categoryAddOrEditB()
 			}
 		},
 		modalCancel() {

+ 2 - 1
mobile-code/src/admin/goodsManage/img-store.vue

@@ -358,10 +358,11 @@ export default {
 	}
 	// list
 	.list-wrap {
-		height: calc(100vh - 200px);
+		height: calc(100vh - 220px);
 		@include disFlex(flex-start, flex-start);
 		flex-wrap: wrap;
 		position: relative;
+		padding-top: 20px;
 		.list {
 			width: 30%;
 			margin-left: 2.5%;

+ 60 - 51
mobile-code/src/admin/home/components/sel-search.vue

@@ -1,9 +1,9 @@
 <template>
 	<div class="sel-search-module">
 		<div class="input-wrap">
-			<app-search-module placeholder="请输入名称" :isBtn="true"  @search="searchFn" />
+			<app-search-module placeholder="请输入名称" :isBtn="true" @search="searchFn" />
 		</div>
-        <!-- 列表 -->
+		<!-- 列表 -->
 		<div class="list-wrap">
 			<!-- 多选 -->
 			<block v-if="multi">
@@ -22,29 +22,33 @@
 						<div class="checkbox-wrap">
 							<radio :value="index + ''" :checked="item.checked" />
 						</div>
-                        <!-- 图片块 -->
-                        <slot name="img" :item="item">
-                            <div class="list-img">
-				                <app-avatar-module :src="item.avatarUrl" :width="120" />
-                            </div>
-                        </slot>
-                        <!-- 列表详情块 -->
-                        <slot name="detail" :item="item">
-                            <div class="list-right">
-                                <div class="list-name">{{ item.userName }}</div>
-                                <div>手机号: {{ item.mobile }}</div>
-                                <div>会员等级: {{ item.userAsset.memberLevel }}</div>
-                                <div>最后访问: {{ item.visitTimeFormat }}</div>
-                            </div>
-                        </slot>
+						<!-- 图片块 -->
+						<slot name="img" :item="item">
+							<block v-if="isMember">
+								<div class="list-img">
+									<app-avatar-module :src="item.avatarUrl" :width="120" />
+								</div>
+							</block>
+						</slot>
+						<!-- 列表详情块 -->
+						<slot name="detail" :item="item">
+							<block v-if="isMember">
+								<div class="list-right">
+									<div class="list-name">{{ item.userName }}</div>
+									<div>手机号: {{ item.mobile }}</div>
+									<div>会员等级: {{ item.userAsset.memberLevel }}</div>
+									<div>最后访问: {{ item.visitTimeFormat }}</div>
+								</div>
+							</block>
+						</slot>
 					</label>
 				</radio-group>
 			</block>
 		</div>
-        <!-- 按钮 -->
-        <div class="app-footer">
-            <div class="admin-button-com middle blue" @click="confirmFn">确认</div>
-        </div>
+		<!-- 按钮 -->
+		<div class="app-footer">
+			<div class="admin-button-com middle blue" @click="confirmFn">确认</div>
+		</div>
 	</div>
 </template>
 
@@ -65,6 +69,11 @@ export default {
 		multi: {
 			type: Boolean,
 			default: false
+		},
+		// 是否是选择用户
+		isMember: {
+			type: Boolean,
+			default: false
 		}
 	},
 	data() {
@@ -111,36 +120,36 @@ export default {
 		width: calc(100% - 50px);
 		background-color: #fff;
 		padding: 22px 20px 22px 30px;
-    }
-    // 列表
+	}
+	// 列表
 	.list-wrap {
-        width: 100%;
-        background-color: #fff;
-        .list {
-            width: calc(100% - 60px);
-            margin: 0 30px;
-            padding: 10px 0 20px;
-            @include disFlex(center, flex-start);
-            border-bottom: 2px solid $borderColor;
-            .list-img {
-                margin: 0 20px;
-            }
-            .list-right {
-                color: $fontColor3;
-                .list-name {
-                    color: #333;
-                    font-size: 30px;
-                    margin-bottom: 10px;
-                }
-            }
-        }
+		width: 100%;
+		background-color: #fff;
+		.list {
+			width: calc(100% - 60px);
+			margin: 0 30px;
+			padding: 10px 0 20px;
+			@include disFlex(center, flex-start);
+			border-bottom: 2px solid $borderColor;
+			.list-img {
+				margin: 0 20px;
+			}
+			.list-right {
+				color: $fontColor3;
+				.list-name {
+					color: #333;
+					font-size: 30px;
+					margin-bottom: 10px;
+				}
+			}
+		}
+	}
+	// 按钮
+	.app-footer {
+		justify-content: flex-end;
+		.admin-button-com {
+			width: 160px;
+			margin-right: 30px;
+		}
 	}
-    // 按钮
-    .app-footer {
-        justify-content: flex-end;
-        .admin-button-com {
-            width: 160px;
-            margin-right: 30px;
-        }
-    }
 </style>

+ 1 - 1
mobile-code/src/admin/staff/sel-member.vue

@@ -1,6 +1,6 @@
 <template>
 	<div class="app-content">
-		<sel-search-module :list="list.data" @search="searchFn" @change="changeFn"></sel-search-module>
+		<sel-search-module :list="list.data" :isMember="true" @search="searchFn" @change="changeFn"></sel-search-module>
 	</div>
 </template>
 

+ 35 - 2
mobile-code/src/components/app-uploader.vue

@@ -4,10 +4,11 @@
 			<slot>
 				<ul>
 					<li class="list_img" v-for="(item,index) in showImgList" :key="index" :style="{ width: size + 'rpx', height: size + 'rpx' }">
+						<div v-if="isMain" class="main-btn" :class="{'mian': index == 0}" @click.stop="mainImg(index)">主</div>
 						<view class="iconfont icondelete" @click="delImg(index)"></view>
 						<img :src="item" @click="viewImg(item)" :style="{ width: size + 'rpx', height: size + 'rpx' }" :mode="imgMode" />
 					</li>
-					<li v-if="showImgList.length < num" class="uploadImg" @click="chooseImage" :style="{ width: size + 'rpx', height: size + 'rpx' }">
+					<li v-if="showImgList.length < num && (multiple || showImgList.length == 0)" class="uploadImg" @click="chooseImage" :style="{ width: size + 'rpx', height: size + 'rpx' }">
 						<view class="iconfont icontupiantianjia"></view>
 					</li>
 				</ul>
@@ -82,6 +83,11 @@ export default {
 		uploadPicApi: {
 			type: Function,
 			default: uploadPic
+		},
+		// 是否显示主图切换
+		isMain: {
+			type: Boolean,
+			default: false
 		}
 	},
 	data() {
@@ -299,6 +305,17 @@ export default {
 			res.tempFilePaths = newtempFilePaths
 			// console.log('过滤完了')
 		},
+		// 设为主图
+		mainImg(index) {
+			if (index == 0) return false
+			this.$msg('操作成功!')
+			// let imgArr = JSON.parse(JSON.stringify(this.showImgList))
+			let imgUrl = this.showImgList[index]
+			this.showImgList.splice(index, 1)
+			this.showImgList.unshift(imgUrl)
+			// this.$emit('mainImg', index)
+			this.postMsg()
+		},
 		// 删除
 		async delImg(index) {
 			if (this.disabled) {
@@ -342,7 +359,7 @@ export default {
 	},
 	watch: {
 		imgList(val) {
-			console.log('监听')
+			console.log('监听图片数据变化')
 			this.showImgList = [...val]
 		}
 	}
@@ -386,6 +403,22 @@ export default {
 					padding: 0 2px;
 					background-color: rgba(0, 0, 0, 0.45);
 				}
+
+				.main-btn {
+					position: absolute;
+					top: 0;
+					left: 0;
+					z-index: 999;
+					@include disFlex(center, center);
+					width: 44px;
+					height: 44px;
+					background-color: #CCC;
+					color: #fff;
+					&.mian {
+						background-color: $mainColor;
+						color: #fff;
+					}
+				}
 			}
 		}
 

+ 11 - 17
mobile-code/src/mixins/list.js

@@ -11,23 +11,16 @@ export default {
 			}
 		}
 	},
-	computed: {
-		totalPages() {
-			if (!this.$util.isEmpty(this.list.total)) {
-				return Math.ceil(this.list.total / this.list.limit)
-			}
-			return 0
-		}
-	},
 	data() {
 		return {
 			list: {
 				data: [],
 				page: 1,
-				limit: 10,
+				pageSize: 20,
 				loading: true,
 				finished: false,
-				total: 0
+				total: 0,
+				totalPage: 0
 			}
 		}
 	},
@@ -36,10 +29,11 @@ export default {
 			this.list = {
 				data: [],
 				page: 1,
-				limit: 10,
+				pageSize: 20,
 				loading: true,
 				finished: false,
-				total: null
+				total: null,
+				totalPage: null
 			}
 		},
 		completes(res, listKey) {
@@ -47,11 +41,11 @@ export default {
 			if (res.code !== 1) {
 				this.list.finished = true
 			}
-			this.list.data = this.list.page === 1
-				? res.data.list || res.data.data || res.data[listKey] : this.list.data.concat(res.data.list || res.data.data || res.data[listKey])
-			this.list.total = res.data.total
-			if (this.totalPages <= this.list.page ||
-				(!this.$util.isEmpty(res.data.current_page) && res.data.current_page == res.data.last_page)) {
+			let listArr = res.data.list || res.data.data || res.data[listKey]
+			this.list.data = this.list.page === 1 ? listArr : this.list.data.concat(listArr)
+			this.list.total = res.data.totalPage * this.list.pageSize
+			this.list.totalPage = res.data.totalPage || res.totalPage
+			if (!res.data.moreData) {
 				this.list.finished = true
 			} else {
 				++this.list.page

+ 12 - 6
mobile-code/src/utils/util.js

@@ -14,12 +14,18 @@ const isEmpty = (val) => {
 }
 
 // 截取图片上传字符串
-const imgSubstr = (arr) => {
-	return arr.map(e => {
-		let index = e.indexOf('/uploads/')
-		e = e.substring(index)
-		return e
-	})
+const imgSubstr = (val) => {
+	if (isEmpty(val)) return []
+	if (isArray(val)) {
+		return val.map(e => {
+			let index = e.indexOf('/uploads/')
+			e = e.substring(index)
+			return e
+		})
+	} else {
+		let index = val.indexOf('/uploads/')
+		return val.substring(index)
+	}
 }
 
 // 是否为数组