<template>
	<view class="body">
		<view class="wrap">
			<view class="logo">
				<view class="u-avatar-wrap">
					<image class="u-avatar-demo" @click="chooseAvatar" :src="storeData.logo" mode="aspectFill"></image>
				</view>
				<view class="title">{{ storeData.merchname }}</view>
			</view>
			<view class="info">
				<u--form :model="storeData" ref="uForm" :errorType="errorType">
					<u-form-item label="商户名称" label-width="220" prop="name"><u-input v-model="storeData.merchname" fontSize='28'
							placeholder="请输入商户名称" /></u-form-item>
					<!-- <u-form-item label="商户简介" label-width="220" prop="desc"><u-input v-model="storeData.desc" fontSize='28'
							placeholder="请输入商户简介" /></u-form-item> -->
					<u-form-item label="联系电话" label-width="220" prop="phone"><u-input v-model="storeData.tel" fontSize='28'
							placeholder="请输入联系电话" /></u-form-item>
					<u-form-item label="店铺位置" label-width="220" prop="phone"><u-input v-model="storeData.address" fontSize='28'
							placeholder="请输入店铺位置" /></u-form-item>
					<!-- <u-form-item label="店铺主题颜色" label-width="220">
						<u-input v-model="storeData.themeText" placeholder="选择店铺主题颜色" :clearable="false"
							@click="showShopTheme = true" />
						<u-icon name="arrow-down-fill" color="#999999" @click="showShopTheme = true"></u-icon>
						<u-select v-model="showShopTheme" @confirm="selectColor" :list="storeData.themearr"></u-select>
					</u-form-item>
					<u-form-item v-if="false" label="扫码送金豆比例" label-width="220" prop="coinRate">
						<u-input v-model="storeData.credit_give" placeholder="请输入金豆比例 单位%" />
						<u-tag text="%" type="success" />
					</u-form-item>
					<u-form-item label="付款后是否跳转店铺" label-width="280" prop="redirect">
						<u-switch v-model="storeData.is_direct2_shop_page" slot="right"></u-switch>
					</u-form-item>
					<u-form-item label="门店轮播图" label-width="280" prop="redirect"></u-form-item> -->
				</u--form>
				<!-- <view class="store-thumbs">
					<u-upload upload-text="*上传门店轮播图" :action="action" :file-list="storeData.thumbs"
						@on-success="uploadThumb" @on-remove="removeImg" @on-progress="showLoading"></u-upload>
				</view> -->

					<view class="bottom"><u-button :disabled="false" class="button" @click="submit">保存设置</u-button>
					</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import util from "../../src/utils/util";
	let that = {},
		storeThumbs = {}
	export default {
		data() {
			return {
				avatar: 'https://cdn.uviewui.com/uview/common/logo.png',
				action: 'https://yld.angyakeji.com/apiv3/fileUploadAndDownload_FSCuANkzFs0/upload',
				// 店铺主题颜色
				showShopTheme: false,
				storeData: {},
				errorType: 'message',
			}
		},
		onLoad() {
			that = this
			// this.init()
		},
		methods: {
			init() {
				getApp().globalData.util.request({
					s: 'Merch.Mershop_Index.get'
				}).then(res => {
					let storeData = res.data.data
					// 处理店铺主题
					for (let i = 0; i < storeData.themearr.length; i++) {
						if (storeData.themearr[i].value == storeData.theme) {
							storeData.themeText = storeData.themearr[i].label;
						}
					}
					storeData.is_direct2_shop_page = (storeData.is_direct2_shop_page == 1)
					// 处理金豆赠送金额小数点显示
					if (parseInt(storeData.credit_give) < storeData.credit_give) {
						storeData.credit_give = parseFloat(storeData.credit_give).toFixed(4);
					} else {
						storeData.credit_give = parseFloat(storeData.credit_give).toFixed(0);
					}
					storeThumbs = JSON.parse(JSON.stringify(storeData.thumbs))
					that.storeData = storeData
				})
			},
			selectColor(items) {
				this.storeData.theme = items[0].value;
				this.storeData.themeText = items[0].label;
			},
			submit() {
				let updata = that.storeData
				updata['s'] = 'Merch.Mershop_Index.update'
				if (updata.thumbs != storeThumbs) { //只有更新了轮播图
					that.updateThumbs()
				}
				getApp().globalData.util.request(updata).then(res => {
					if (res.data.ret == 200) {
						uni.showToast({
							title: '保存成功',
							duration: 2000,
							icon: 'success'
						});
					}
				})
			},
			// 更新轮播图
			updateThumbs() {
				getApp().globalData.util.request({
					"s": 'Merch.Mershop_Index.UpdateMerchThumbs',
					"thumbs": storeThumbs
				}).then()
			},
			chooseAvatar() {
				util.upload().then(success => {
					that.storeData.logo = success
				})
			},
			showLoading() {
				uni.showLoading({
					title: '上传中',
					duration: 2000,
					mask: true
				})
			},
			removeImg(index, list) {
				storeThumbs = list.length ? list : []
			},
			uploadThumb(res) {
				uni.hideLoading()
				if (res.code == 0 && res.data.file.url) {
					storeThumbs.push({
						"url": res.data.file.url
					})
					that.$forceUpdate()
				} else {
					uni.showToast({
						title: '图片上传失败',
						icon: 'fail',
						duration: 2000
					});
				}
			},
		} // /methods
	}
</script>
<style lang="scss" scoped>
	page{
		background-color: #f7f7f7;
	}
	/deep/.u-form-item__body__left__content__label {
	    color: #7f8185 !important;
	    font-size:28rpx !important;
	}
	.logo {
		padding-top: 40rpx;
		padding-bottom: 40rpx;
		width: 100%;
		background-color: #ffffff;

		.u-avatar-wrap {
			overflow: hidden;
			text-align: center;
		}

		.u-avatar-demo {
			width: 150rpx;
			height: 150rpx;
			border-radius: 100rpx;
		}

		.title {
			text-align: center;
			font-size: 40rpx;
			font-weight: 500;
		}
	}

	.info {
		margin-top: 10rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		background-color: #ffffff;
	}
	/deep/.u-form-item{
		border-bottom: 1px solid #f4f6f8;
	}

	.bottom {
		padding: 5%;
	}
</style>