chooseFavorite.vue 5.24 KB
Newer Older
1
<template>
renjie's avatar
renjie committed
2 3
	<view class="big-box" :style="{'padding-top': statusBarHeight + 'px'}">
		<view class="nav-bar" :style="{'height': navHeight + 'px'}">
4 5
			<picker mode="selector" @change="companyChage" :value="index" :range="companyArr" range-key="merchantName">
				<view class="company">{{companyArr[index] ? companyArr[index].merchantName : '请选择公司'}}</view>
renjie's avatar
renjie committed
6
			</picker>
7
			<u-icon name="arrow-down" color="#fff"></u-icon>
renjie's avatar
renjie committed
8 9 10 11
		</view>
		<view class="outer-container">
			<view class="inner-container">
				<view class="icon">
renjie's avatar
renjie committed
12 13
					<image class="favorite" src="./static/album/favorite.png"></image>
					<image class="start" src="./static/album/star.png"></image>
renjie's avatar
renjie committed
14 15
				</view>
				<view class="img-box">
16
					<view class="item" v-for="(item, index) in imgArr" :key="item.templateId" @click="imageChange(item)">
17
						<image class="img" :src="item.templateUrl" mode="widthFix"></image>
18
						<checkbox class="checkbox blue round" :checked="item.value" :value="item.templateId" shape="circle"></checkbox>
renjie's avatar
renjie committed
19 20 21 22 23
					</view>
				</view>
				<button class="btn" @click="saveClick">提交</button>
			</view>
		</view>
24 25 26 27
	</view>
</template>

<script>
renjie's avatar
renjie committed
28 29 30 31 32 33 34 35 36
export default {
  data() {
    return {
      statusBarHeight: 0,
      capsule: 0,
      navHeight: 0,
      index: 0,// 选中的公司索引-默认选中第一个
      companyArr: [],// 公司枚举
      imgArr: [],//图片
renjie's avatar
renjie committed
37
      option: {},//路由传参
renjie's avatar
renjie committed
38 39 40 41
    }
  },
  methods: {
    saveClick() {//---提交
42 43 44 45 46 47 48 49 50
      const templateIds = this.imgArr.map(item => {
        if(item.value) return item.templateId
      }) || []
			
      if(!templateIds.length) return uni.showToast({
        title: '您还没有选择模板哟!',
        icon: 'none'
      })
			
renjie's avatar
renjie committed
51
      const data = {
52 53 54
        merchantId: this.companyArr[this.index].merchantId,//商店id
        openid: uni.getStorageSync('openid'), //openid
        templateIds//模板Id
renjie's avatar
renjie committed
55
      }
56
      this.$request('wechatUser/pdAlbum/saveVisitorSurvey', data).then(res => {
renjie's avatar
renjie committed
57 58 59 60 61 62
			  if (res.code === '00') {
			    uni.showToast({
			      title: '提交成功',
			      icon: 'success'
			    })
          uni.navigateTo({
63
            url: `./albumIndex?template=true&merchantId=${data.merchantId}`
renjie's avatar
renjie committed
64 65 66 67 68 69 70 71 72 73 74
          })
			  }else{
			    uni.showToast({
			      title: res.message,
			      icon: 'none'
			    })
			  }
      })
    },
    companyChage(e) {//---公司变化
      this.index = Number(e.detail.value)
75
      this.imgArr = this.companyArr[this.index].templateDetailList
renjie's avatar
renjie committed
76 77
    },
    imageChange(item) {//---图片选择
78
      this.$set(item, 'value', !item.value)
79 80
      this.$set(item, 'show', false)
      this.$set(item, 'show', true)
renjie's avatar
renjie committed
81 82 83 84 85 86 87
    },
    recordDeviceInfo() {//---记录设备信息
      this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight // 状态栏高度
      this.capsule = uni.getMenuButtonBoundingClientRect() // 胶囊大小、位置数据
      this.navHeight = (this.capsule.top - this.statusBarHeight) * 2 + this.capsule.height // 导航栏高度
    }
  },
renjie's avatar
renjie committed
88 89
  onLoad(option) {
    this.recordDeviceInfo()
90 91 92 93 94 95
    this.option = option
		
    this.companyArr = JSON.parse(option.surveyConfig)
    const imgArr = []
    this.companyArr.forEach(item => {
      imgArr.push(...item.templateDetailList)
renjie's avatar
renjie committed
96
    })
97 98 99 100
    imgArr.forEach(item => {
      this.$set(item, 'value', false)
      this.$set(item, 'show', true)
    })
101
    this.imgArr = this.companyArr[0].templateDetailList
renjie's avatar
renjie committed
102 103
  }		
}
104 105
</script>

renjie's avatar
renjie committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
<style lang="scss" scoped>
	.big-box {
		display: flex;
		flex-direction: column;
		height: 100%;
		background-color: #3688FF;
		color: #fff;
	}
	.nav-bar {
		display: flex;
		align-items: center;
		picker {
			max-width: 50%;
		}
		.company {
			margin: 0 12rpx 0 24rpx;
			font-size: 36rpx;
			font-weight: 700;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}
	.outer-container {
		flex: 1;
		margin: 16rpx 16rpx 24rpx 16rpx;
		border-radius: 96rpx;
renjie's avatar
renjie committed
133
		background: url('@/pages/album/static/album/dash-bg.png');
renjie's avatar
renjie committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
		background-size: 100% 100%;
		padding: 16rpx;
		overflow: hidden;
		.inner-container {
			display: flex;
			flex-direction: column;
			width: 100%;
			height: 100%;
			background-color: #3041D7;
			border-radius: 96rpx;
		}
		.img-box {
			display: flex;
			flex-wrap: wrap;
			align-content: flex-start;
			overflow-y: auto;
			flex: 1;
			margin: 42rpx 20rpx;
			padding: 24rpx 16rpx;
			background-color: #fff;
			box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0,0,0,0.16);
			border-radius: 16rpx;
			.item {
				width: 49%;
				height: 236rpx;
				border-radius: 16rpx;
				margin-bottom: 16rpx;
				position: relative;
				overflow: hidden;
				&:nth-child(2n-1) {
					margin-right: 2%;
				}
				.img {
					width: 100%;
					heigit: 100%;
169
					border-radius: 16rpx;
renjie's avatar
renjie committed
170 171 172
				}
				.checkbox {
					position: absolute;
173 174 175
					right: 0;
					top: 8rpx;
					transform: scale(0.8);
renjie's avatar
renjie committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
				}
			}
		}
		.icon {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 78rpx;
			.favorite {
				width: 318rpx;
				height: 94rpx;
			}
			.start {
				width: 180rpx;
				height: 118rpx
			}
		}
		.btn {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 440rpx;
			height: 80rpx;
			margin-bottom: 24rpx;
			background: linear-gradient(90deg, #3688FF 0%, #539FFF 100%);
			border-radius: 40rpx 40rpx 40rpx 40rpx;
			font-size: 32rpx;
		}
	}
205
</style>