<template>
	<view class="edit-address full-height full-width">

		<view class="form full-width">
			<view style="width: 100%; height: 70upx; display: flex;align-items: center; justify-content: center;   ">
				<view style="display: flex;font-size: 30upx; margin:auto;
				width: 300upx; height: 70upx; background: #282932; border-radius: 50upx; color: #FFFFFF;">
					<view :class="{'previewAxtiveLeft':!preview}" @click=" onclickTitle(false) "
						style="line-height: 70upx; text-align: center; width: 150upx;">
						自定义
					</view>
					<view :class="{'previewAxtiveRight':preview}" @click="onclickTitle(true)  "
						style="line-height: 70upx; text-align: center; width: 150upx;">
						预置尺寸
					</view>
				</view>
			</view>

			<!-- 宽{{pixel_Width}}高:{{pixel_Height}}比例{{pixel_scale}} -->
			<view v-if="!preview" class="full-width" scroll-y style="height: calc(100% - 160upx);overflow: scroll;">
				<view style=" height: 700upx; overflow: scroll;
				 overflow: hidden;
				 margin:0upx auto 40upx;display: flex; margin-top: 10upx;
				justify-content: center; align-items: center;  "
					:style="{width: (pixel_Width * pixel_scale) +'px', borderRadius:  defalutFillet + 'px'}">
					<view
						:style="{width: (pixel_Width * pixel_scale) +'px',height: (pixel_Height * pixel_scale) +'px', borderRadius: defalutFillet + 'px'}"
						style="background: #FFFFFF; margin:auto; box-shadow: 0px 2px 6px 0px rgba(0,0,0,0.5);">
					</view>
				</view>
				<view style="position: relative;">
					<!-- 自定义高度 -->
					<view style="display: flex; align-items: center; justify-content: center; margin-top: 5upx;">
						<view style="font-size: 30upx; font-weight: 400; color: #FFFFFF; width: 180upx;">物料宽度：</view>
						<view style="width: 282upx; height: 66upx; background: #282932; border-radius: 30upx; 
						display: flex; align-items: center;">
							<input type="digit" placeholder="请输入宽度" @input="moneyChangeWidth" :value="inputWidth"
								style="color: #FFFFFF; font-size: 28upx; padding-left: 35upx;width: 200upx;" />
							<view style="color: #898989; font-size: 26upx; width: 82upx;">{{companyValue}}</view>
						</view>
					</view>
					<view
						style="display: flex; align-items: center; justify-content: center; margin-top: 20upx; position: relative;">
						<view style="font-size: 30upx; font-weight: 400; color: #FFFFFF; width: 180upx;">物料高度：</view>
						<view style="width: 282upx; height: 66upx; background: #282932; border-radius: 30upx; 
						display: flex; align-items: center;">
							<input type="digit" :value="inputHeight" placeholder="请输入高度" @input="moneyChangeHeight"
								style="color: #FFFFFF; font-size: 28upx; padding-left: 35upx;width: 200upx;" />
							<view style="color: #898989; font-size: 26upx; width: 82upx;">{{companyValue}}</view>
						</view>
					</view>
					<view style="display: flex; align-items: center;justify-content: center;  margin-top: 25upx;">
						<view style="font-size: 30upx; font-weight: 400; color: #FFFFFF; width: 180upx;">圆角半径：</view>
						<view style="width: 282upx; height: 66upx; 
							display: flex; align-items: center; margin-top: 5upx;">
							<!-- 滑块封装 -->
							<NumSlider ref="NumSlider" :min="0" :max="100" :width="sliderdefaultWith" :disabled="false"
								:range="false" @highChange="highChange" :leftX="sliderdefaultWith" />
						</view>
					</view>
				</view>
			</view>
			<!-- 预置 -->
			<view v-if="preview" class="full-width">
				<view
					style="height: 90upx; display: flex; align-items: center;width: calc(100% - 60upx); margin: auto;">
					<view style="display: flex;align-items: center; font-size: 28upx;">
						<view :class="{'classificationLeft':!Specifications}" @click="OnclickSpecifications(0)" style="line-height: 60upx; text-align: center; width: 131upx;
							height: 60upx; background: #282932; border-radius: 30upx;">
							内置
						</view>
						<view :class="{'classificationRight':Specifications}" @click="OnclickSpecifications(1)" style="line-height: 60upx; text-align: center; width: 131upx; margin-left: 20upx;
						height: 60upx; background: #282932; border-radius: 30upx;">
							常用
						</view>
					</view>
				</view>

				<view class="full-width">
					<!-- 动态数据 -->
					<view scroll-y @scrolltolower="loadMore()" class="full-width">
						<view v-for="(item, index) in LoupanList" :key="index" class="eq_list"
							@click.preven="refundNumorder(item)" @touchstart.preven="touchstart(item,index)"
							@touchend.prevent="touchend">
							<view class="eq_list_div">
								<view style="font-size: 30upx;font-weight: 500;">{{item.name}}</view>
								<view style="margin-left: auto; margin-right: 20upx;">
									<label class="fa fa-angle-right align-right sub-color"
										style="font-size: 40upx;"></label>
								</view>
							</view>
						</view>
						<!-- 暂无相关信息 -->
						<view class="align-center content-color"
							style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);"
							v-if="LoupanList.length == 0 || LoupanList.length == null">
							<span class="iconfont icon-wushuju"
								style="font-size: 100upx; text-align: center; color: #B2B2B2;"></span>
							<view style="color: #B2B2B2; text-align: center; line-height: 50upx;font-size: 23upx;">
								暂无相关信息</view>
						</view>
					</view>
					<!-- 动态数据完 -->
				</view>
				<!-- 返回顶部 -->
				<view class="to-top content-color" @click="totop()">
					<view class="fa fa-angle-right to-top-icon"></view>
				</view>
			</view>
		</view>
		<mpvue-picker ref="mpvuePicker" :themeColor="'#53B2B0'" :mode="mode" :pickerValueDefault="pickerValueDefault"
			@onChange="onChange" @onConfirm="onConfirm" @onCancel="onCancel" :pickerValueArray="pickerValueArray">
		</mpvue-picker>
		<view class="footer" v-if="!preview">
			<view class="footer_but" hover-class="hover-class-bg" @click="onSave()">确认定制</view>
		</view>

	</view>
</template>

<script>
	import Enums from '@/util/Enums';
	import mpvuePicker from '../../components/mpvue-picker/mpvuePicker.vue';
	import userService from '@/service/UserService';
	import homeservice from '@/service/homeservice.js';
	import uniPopup from '../index/common/uni-popup/uni-popup.vue';
	import NumSlider from '../index/components/NumSlider.vue'
	import myhead from './head/head.vue'; // 页眉

	export default {
		components: {
			mpvuePicker,
			uniPopup,
			NumSlider,
			myhead
		},
		computed: {

		},
		data() {
			return {
				mode: 'selector',
				pickerValueArray: [{
						label: '毫米',
						value: 0
					},
					{
						label: '厘米',
						value: 1
					}
				],
				pickerValueDefault: [0],
				companyValue: '毫米',
				equalRatioState: false, //固定宽高比率
				directionState: false, //横屏竖屏
				wValue: 0, //固定宽高比率计算
				hValue: 0, //固定宽高比率计算
				previewWidth: 0, //基础
				previewHeight: 0, //基础
				inputWidth: 0, //文本框显示数据
				inputHeight: 0, //文本框显示数据
				pixel_Width: 0, //实际像素
				pixel_Height: 0, //实际像素
				pixel_scale: 1, //自动缩放屏幕比率，防止超出屏幕
				convert_rate: 10, //毫米和像素的转换比率
				OldConvert_rate: 10, //最大值是 210mm*297mm 毫米-像素的转换比率(接口获取数据记录保存下来)
				render_cove_width: 0, //最大宽度
				render_cove_height: 0, //最大高度
				data: {
					windowWidth: null, // 屏幕宽度
					windowHeight: null, // 屏幕高度
					pixelRate: null // 屏幕宽度比率
				},
				preview: false, //自定义预览
				//上拉状态
				dataLoadState: {
					pullDownRefresh: false,
					reachBottom: false
				},
				LoupanList: [],
				Specifications: false, //预置分类
				//判断是否为长按
				nav: true,
				Loop: null,
				good: null,
				parameter: {
					machine_id: null,
					goods_id: null,
					key: null
				},
				manyGoodSelectData: [], //查询更多商品
				type: 1, //类型 1 自定义 2 选择列表
				selectItemData: null, // 选中对象
				sliderdefaultWith: 120,
				defalutFillet: 0, //默认圆角大小
				initialMax: 0,
				heiPixelRate: null, //屏幕宽度比率
				filletScale: 1, //比例
				newDefalutFilletData: 0,
				headheight: 0, //头部高度
				queryPage: {},
				good_id: "217", //产品Id
				isFirstPage: true,
				machineDetail: null, //设备对象
				pixelScale: 0.6, //比例
			}
		},


		methods: {

			onclickTitle(preview) {
				this.preview = preview
				if (this.preview) {
					this.defalutFillet = 0
					this.newDefalutFilletData = 0;
					if (!this.Specifications) {
						this.dataLoadState = {
							pullDownRefresh: false,
							reachBottom: false
						}
						this.LoupanList = []
						this.queryPage.page = 1;
						this.queryPage.total = 0;
						this.Specifications = false
						this.queryPage.s = 'CanvasSize.list'
						this.loadGoodsList(Enums.DATA_DIRECTION.UP);
					}
				}
			},

			//调转明细界面
			toGoodDetail() {
				uni.navigateTo({
					url: '../index/goodDetail?machine_id=' + this.parameter.machine_id + "&goodTypeData= 2"
				});
			},

			//开关控制圆角
			switchChange(e) {
				if (e.detail.value == true) {
					this.switchIsFillet = true;
				} else {
					this.switchIsFillet = false;
				}
			},

			highChange(val, value) {
				this.newDefalutFilletData = val;
				let defalutFilletValue = Math.floor(this.newDefalutFilletData * this.filletScale)
				this.defalutFillet = Math.floor(defalutFilletValue * (this.pixel_Width * this.pixel_scale / this
					.inputWidth))
			},

			//显示商品弹框
			showManyGoodPop() {
				this.$refs['showManyGood'].open();
			},

			//显示商品弹框
			closeManyGoodPop() {
				this.$refs["showManyGood"].close();
			},

			refundNumorder(item) {
				let real_radius = Number(item.real_radius);
				let real_height = Number(item.real_height);
				let real_width = Number(item.real_width);
				//判断是否超过对应宽高比
				let minWidthAanHeight = 0;
				if (real_height > real_width) {
					minWidthAanHeight = real_width
				} else {
					minWidthAanHeight = real_height
				}
				if (real_radius > minWidthAanHeight / 2) {
					real_radius = Math.floor(minWidthAanHeight / 2)
				}
				let WidthIndex = item.real_width * this.OldConvert_rate
				let HeightIndex = item.real_height * this.OldConvert_rate
				let nameStr = item.name
				let unit = item.unit;
				let customize_size_id = item.id
				//console.log(item)
				if (this.isFirstPage && this.isFirstPage == "true") {
					uni.redirectTo({
						url: '../index/index?machine_id=' + this.parameter.machine_id +
							'&WidthIndex=' + WidthIndex + '&HeightIndex=' + HeightIndex +
							'&OldConvert_rate=' + this.OldConvert_rate + '&unit=' + unit +
							'&title=' + nameStr +
							'&pixel_scale=' + this.pixel_scale +
							'&real_width=' + real_width +
							'&real_height=' + real_height +
							"&defalutFillet=" + real_radius +
							"&good_id=" + this.good_id +
							"&type=2" +
							"&customize_size_id=" + customize_size_id
					})
				} else {
					//console.log("defalutFilletData=" + defalutFilletData)
					let pages = getCurrentPages();
					var prevPage = pages[pages.length - 2]; //上一个页面
					//let machineDetail = encodeURIComponent(JSON.stringify(this.machineDetail));
					var data = {
						WidthIndex: WidthIndex,
						HeightIndex: HeightIndex,
						defalutFillet: real_radius,
						real_width: real_width,
						real_height: real_height,
						title: nameStr,
						OldConvert_rate: this.OldConvert_rate,
						unit: unit,
						type: 2,
						goods_id: this.good_id,
						customize_size_id: customize_size_id
					}
					prevPage.$vm.options = data;
					uni.navigateBack({
						delta: 1
					});
				}
			},

			onSave() {
				if (this.inputWidth == "") {
					uni.showToast({
						title: "宽度不能为空",
						icon: 'none'
					});
					return;
				}
				if (this.inputHeight == "") {
					uni.showToast({
						title: "高度不能为空",
						icon: 'none'
					});
					return;
				}
				let unit = null
				let real_width = null
				let real_height = null
				if (this.companyValue == '毫米') {
					unit = 'mm'
					real_width = this.inputWidth
					real_height = this.inputHeight
				} else if (this.companyValue == '厘米') {
					unit = 'cm'
					real_width = this.inputWidth
					real_height = this.inputHeight
				}
				//210 X 297 - 8 （毫米
				let nameStr = real_width + ' x ' + real_height + '（' + this.companyValue + '）';

				let defalutFilletData = Math.floor(this.newDefalutFilletData * this.filletScale);

				if (defalutFilletData > 0) {
					nameStr = real_width + ' x ' + real_height + ' - ' + defalutFilletData + '（' + this.companyValue + '）';
				}

				let WidthIndex = real_width * this.OldConvert_rate
				let HeightIndex = real_height * this.OldConvert_rate

				//判断是否超过对应宽高比
				let minWidthAanHeight = 0;

				if (this.inputHeight > this.inputWidth) {
					minWidthAanHeight = this.inputWidth
				} else {
					minWidthAanHeight = this.inputHeight
				}
				if (defalutFilletData > minWidthAanHeight / 2) {
					defalutFilletData = Math.floor(minWidthAanHeight / 2)
				}

				homeservice.queryList({
					s: 'CanvasSize.save',
					id: null,
					name: nameStr,
					real_width: real_width,
					real_height: real_height,
					unit: unit,
					real_radius: defalutFilletData
				}).then(result => {
					uni.showToast({
						icon: "success",
						title: '创建成功!',
						duration: 2000
					});
					if (this.isFirstPage && this.isFirstPage == "true") {
						uni.redirectTo({
							url: '../index/index?machine_id=' + this.parameter.machine_id +
								'&WidthIndex=' + WidthIndex + '&HeightIndex=' + HeightIndex +
								'&OldConvert_rate=' + this.OldConvert_rate + '&unit=' + unit +
								'&title=' + nameStr +
								'&pixel_scale=' + this.pixel_scale +
								'&real_width=' + real_width +
								'&real_height=' + real_height +
								"&defalutFillet=" + defalutFilletData +
								"&good_id=" + this.good_id +
								"&type=2" +
								"&customize_size_id=" + result.id
						})
					} else {
						let pages = getCurrentPages();
						var prevPage = pages[pages.length - 2]; //上一个页面
						//let machineDetail = encodeURIComponent(JSON.stringify(this.machineDetail));
						var data = {
							WidthIndex: WidthIndex,
							HeightIndex: HeightIndex,
							defalutFillet: defalutFilletData,
							real_width: real_width,
							real_height: real_height,
							title: nameStr,
							OldConvert_rate: this.OldConvert_rate,
							unit: unit,
							type: 2,
							goods_id: this.good_id,
							customize_size_id: result.id
						}
						prevPage.$vm.options = data;
						uni.navigateBack({
							delta: 1
						});
					}
				}).catch(err => {
					uni.showToast({
						title: err.msg,
						icon: 'none'
					});
				});
			},

			touchstart(item, index) {
				let that = this;
				that.nav = true
				clearInterval(this.Loop); //再次清空定时器，防止重复注册定时器
				this.Loop = setTimeout(function() {
					that.nav = false
					console.log(that.nav)
					uni.showModal({
						title: '删除',
						content: '确认要删除当前尺码吗？',
						confirmText: '删除',
						confirmColor: '#ff3b32',
						success: async function(res) {
							if (res.confirm) {
								that.LoupanList.splice(index, 1)
								homeservice.newqueryList({
									s: 'CanvasSize.del',
									ids: item.id
								}).then(result => {
									uni.showToast({
										icon: "success",
										title: '删除成功!',
										duration: 2000
									});
								}).catch(err => {
									uni.showToast({
										title: err.msg,
										icon: 'none'
									});
								});
							} else if (res.cancel) {
								// console.log('用户点击取消')
							}
						}
					});
				}.bind(this), 500);
			},

			touchend() {
				clearInterval(this.Loop);
			},

			OnclickSpecifications(e) {
				this.dataLoadState = {
					pullDownRefresh: false,
					reachBottom: false
				}
				this.LoupanList = []
				this.queryPage.page = 1;
				this.queryPage.total = 0;
				if (e == 0) {
					this.Specifications = false
					this.queryPage.s = 'CanvasSize.list'
				} else {
					this.Specifications = true
					this.queryPage.s = 'CanvasSize.mylist'
				}
				this.loadGoodsList(Enums.DATA_DIRECTION.UP);
			},

			direction() { //横屏竖屏
				this.directionState = !this.directionState
				// 赋值
				let w = this.pixel_Width
				let h = this.pixel_Height
				this.pixel_Width = h
				this.pixel_Height = w
				this.inputWidth = h / this.convert_rate
				this.inputHeight = w / this.convert_rate
				//固定比率
				this.wValue = h
				this.hValue = w
			},

			equalRatio() { //固定比率
				this.equalRatioState = !this.equalRatioState
				//固定比率
				this.wValue = this.pixel_Width
				this.hValue = this.pixel_Height
			},

			//确定 e.value[0]
			onConfirm(e) {
				if (this.companyValue == e.label) {
					return
				}
				this.companyValue = e.label
				if (e.value[0] == 0) { //毫米
					this.convert_rate = this.OldConvert_rate
				} else if (e.value[0] == 1) { //厘米
					this.convert_rate = this.OldConvert_rate * 10
				}
				// 赋值
				this.inputHeight = this.previewHeight / this.convert_rate
				this.inputWidth = this.previewWidth / this.convert_rate
				this.setData({
					inputWidth: this.previewWidth / this.convert_rate
				})
				this.setData({
					inputHeight: this.previewHeight / this.convert_rate
				})
			},

			moneyChangeWidth(event) {
				let Width = this.moneyone(event.detail.value);
				let Height = null
				// 赋值
				this.setData({
					inputWidth: Width
				}); //文本
				if (this.equalRatioState) { //固定宽高比率
					this.setData({
						inputHeight: (Width / (this.wValue / this.hValue)).toFixed(2)
					}); //文本
					Height = (Width / (this.wValue / this.hValue)).toFixed(2)
				} else { //随便输入
					this.setData({
						inputHeight: this.inputHeight
					}) //文本
				}
				if (Number(Width) > (Number(this.render_cove_width) / this.convert_rate)) {
					Width = (Number(this.render_cove_width) / this.convert_rate) //最大值
					this.setData({
						inputWidth: Width
					}); //赋值文本
					uni.showToast({
						icon: "success",
						title: '宽度最大值' + Width,
						duration: 2000
					});
				}
				if (Number(Height) > (Number(this.render_cove_height) / this.convert_rate)) {
					Height = (Number(this.render_cove_height) / this.convert_rate)
					this.setData({
						inputHeight: Height
					}); //文本
				}
				this.previewWidth = this.inputWidth * this.convert_rate
				this.previewHeight = this.inputHeight * this.convert_rate
				this.pixel_Width = this.previewWidth
				this.pixel_Height = this.previewHeight


				this.getWindowScale();

				// if (this.pixel_Width > (this.data.windowWidth * this.pixelScale)) {
				// 	this.pixel_scale = (this.data.windowWidth * this.pixelScale) / this.pixel_Width
				// } else {
				// 	if (this.pixel_Width < (this.data.windowWidth * this.pixelScale) && this.pixel_Height < (this.data
				// 			.windowHeight * this.pixelScale)) {
				// 		this.pixel_scale = 1
				// 	}
				// }
				// if (this.pixel_Height > (this.data.windowHeight * this.pixelScale)) {
				// 	if ((this.data.windowHeight * this.pixelScale) / this.pixel_Height < this.pixel_scale) {
				// 		this.pixel_scale = (this.data.windowHeight * this.pixelScale) / this.pixel_Height
				// 	}
				// } else {
				// 	if (this.pixel_Width < (this.data.windowWidth * this.pixelScale) && this.pixel_Height < (this.data.windowHeight * this.pixelScale)) {
				// 		this.pixel_scale = 1
				// 	}
				// }
				//console.log("pixel_scale="+this.pixel_scale+"pixel_Width="+this.pixel_Width)

				let real_width = Number(this.inputWidth);
				let real_height = Number(this.inputHeight);
				if (real_width > real_height) {
					this.filletScale = real_width / 100;
				} else {
					this.filletScale = real_height / 100;
				}
				let defalutFilletValue = Math.floor(this.newDefalutFilletData * this.filletScale)
				this.defalutFillet = Math.floor(defalutFilletValue * (this.pixel_Width * this.pixel_scale / this
					.inputWidth));
				this.$refs['NumSlider'].initFilletRadius(this.newDefalutFilletData, this.filletScale);
				return Width
			},

			moneyChangeHeight(event) {
				let Width = null;
				let Height = this.moneyone(event.detail.value);
				this.setData({
					inputHeight: Height
				}) //文本
				if (this.equalRatioState) { //固定宽高比率
					this.setData({
						inputWidth: (Height / (this.hValue / this.wValue)).toFixed(2)
					});
					Width = (Height / (this.hValue / this.wValue)).toFixed(2)
				} else { //随便输入
					this.setData({
						inputWidth: this.inputWidth
					}); //文本
				}
				if (Number(Width) > (Number(this.render_cove_width) / this.convert_rate)) {
					Width = (Number(this.render_cove_width) / this.convert_rate) //最大值
					this.setData({
						inputWidth: Width
					}); //赋值文本
				}
				if (Number(Height) > (Number(this.render_cove_height) / this.convert_rate)) {
					Height = (Number(this.render_cove_height) / this.convert_rate)
					this.setData({
						inputHeight: Height
					}); //文本
					uni.showToast({
						icon: "success",
						title: '高度最大值' + Height,
						duration: 2000
					});
				}
				this.previewWidth = this.inputWidth * this.convert_rate
				this.previewHeight = this.inputHeight * this.convert_rate
				this.pixel_Width = this.previewWidth
				this.pixel_Height = this.previewHeight

				this.getWindowScale();

				// if (this.pixel_Width > (this.data.windowWidth * 0.5)) {
				// 	this.pixel_scale = (this.data.windowWidth * 0.5) / this.pixel_Width
				// } else {
				// 	if (this.pixel_Width < (this.data.windowWidth * 0.5) && this.pixel_Height < (this.data
				// 			.windowHeight * 0.5)) {
				// 		this.pixel_scale = 1
				// 	}
				// }
				// if (this.pixel_Height > (this.data.windowHeight * 0.5)) {
				// 	if ((this.data.windowHeight * 0.5) / this.pixel_Height < this
				// 		.pixel_scale) {
				// 		this.pixel_scale = (this.data.windowHeight * 0.5) / this.pixel_Height
				// 	}
				// } else {
				// 	if (this.pixel_Width < (this.data.windowWidth * 0.5) && this.pixel_Height < (this.data
				// 			.windowHeight * this.pixelScale)) {
				// 		this.pixel_scale = 1
				// 	}
				// }
				let real_width = Number(this.inputWidth);
				let real_height = Number(this.inputHeight);
				if (real_width > real_height) {
					this.filletScale = real_width / 100;
				} else {
					this.filletScale = real_height / 100;
				}
				let defalutFilletValue = Math.floor(this.newDefalutFilletData * this.filletScale)
				this.defalutFillet = Math.floor(defalutFilletValue * (this.pixel_Width * this.pixel_scale / this
					.inputWidth));
				this.$refs['NumSlider'].initFilletRadius(this.newDefalutFilletData, this.filletScale);
				return Height
			},


			//获取屏幕比例
			getWindowScale() {

				if (this.pixel_Width > (this.data.windowWidth * this.pixelScale)) {
					this.pixel_scale = (this.data.windowWidth * this.pixelScale) / this.pixel_Width
				} else {
					if (this.pixel_Width < (this.data.windowWidth * this.pixelScale) && this.pixel_Height < (this.data
							.windowHeight * this.pixelScale)) {
						this.pixel_scale = 1
					}
				}
				if (this.pixel_Height > (this.data.windowHeight * this.pixelScale)) {
					if ((this.data.windowHeight * this.pixelScale) / this.pixel_Height < this.pixel_scale) {
						this.pixel_scale = (this.data.windowHeight * this.pixelScale) / this.pixel_Height
					}
				} else {
					if (this.pixel_Width < (this.data.windowWidth * this.pixelScale) && this.pixel_Height < (this.data
							.windowHeight * this.pixelScale)) {
						this.pixel_scale = 1
					}
				}


			},


			setData(obj) {
				let that = this;
				let keys = [];
				let val, data;
				Object.keys(obj).forEach(function(key) {
					keys = key.split('.');
					val = obj[key];
					data = that.$data;
					keys.forEach(function(key2, index) {
						if (index + 1 == keys.length) {
							that.$set(data, key2, val);
						} else {
							if (!data[key2]) {
								that.$set(data, key2, {});
							}
						}
						data = data[key2];
					})
				});
			},

			//验证输入金额
			moneyone(val) {
				let num = val.toString(); //先转换成字符串类型
				if (num.indexOf('.') == 0) { //第一位就是 .
					num = '1' + num
				} else if (num.indexOf('0') == 0) {
					num = ''
				}
				num = num.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
				num = num.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
				num = num.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				num = num.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
				if (num.indexOf(".") < 0 && num != "") {
					num = parseFloat(num);
				}
				return num
			},

			onChange(e) {

			},

			onCancel(e) {

			},

			//返回顶部
			totop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				})
			},

			loadGoodsList(direction) {
				if (this.dataLoadState.pullDownRefresh || this.dataLoadState.reachBottom) return;
				uni.showLoading({
					title: '正在加载中...',
					mask: true
				})
				this.dataLoadState.pullDownRefresh = direction === Enums.DATA_DIRECTION.UP;
				this.dataLoadState.reachBottom = direction === Enums.DATA_DIRECTION.DOWN;
				if (this.dataLoadState.reachBottom) {
					if (Math.ceil(this.queryPage.total / this.queryPage.per_page) < this.queryPage.page) {
						return setTimeout(() => {
							uni.showToast({
								title: '没有更多数据了！',
								icon: 'none'
							});
						}, 500);
					}
				}
				homeservice.queryList(this.queryPage).then(result => {
					let newList = this.LoupanList.concat(result.data)
					this.LoupanList = newList
					// 分页对象处理
					this.queryPage.total = result.total;
					this.queryPage.per_page = result.per_page;
					// 停止当前页面下拉刷新
					if (this.dataLoadState.pullDownRefresh) uni.stopPullDownRefresh();
					// 数据加载状态处理 false
					this.dataLoadState.pullDownRefresh = false;
					this.dataLoadState.reachBottom = false;
					uni.hideLoading();
				}).catch(err => {
					// 停止当前页面下拉刷新
					if (this.dataLoadState.pullDownRefresh) uni.stopPullDownRefresh();
					// 数据加载状态处理 false
					this.dataLoadState.pullDownRefresh = false;
					this.dataLoadState.reachBottom = false;
					uni.hideLoading();
				});
			},

			//做滚动加载使用
			loadMore() {
				//this.queryPage.page = this.queryPage.page + 1;
				//this.loadGoodsList(Enums.DATA_DIRECTION.DOWN);
			},

			//获取自定义产品信息
			getCustomSizeInfo() {
				var data = {
					s: 'Product.getCustomize',
					machine_id: this.queryPage.machine_id
				};
				homeservice.queryList(data).then(res => {
					let width = this.render_cove_width / this.OldConvert_rate
					let height = this.render_cove_height / this.OldConvert_rate
					//this.render_cove_width = this.machineDetail.size.width * this.OldConvert_rate //最大宽度
					//this.render_cove_height = this.machineDetail.size.height * this.OldConvert_rate //最大高度
					this.good_id = res.id
					this.good = res
					this.wValue = width * this.OldConvert_rate //固定宽高比率计算(像素)
					this.hValue = height * this.OldConvert_rate //固定宽高比率计算(像素)
					this.previewWidth = width * this.OldConvert_rate //基础(像素)
					this.previewHeight = height * this.OldConvert_rate //基础(像素)
					this.inputWidth = width //文本(毫米)
					this.inputHeight = height //文本(毫米)
					this.pixel_Width = width * this.OldConvert_rate //实际(像素)
					this.pixel_Height = height * this.OldConvert_rate //实际(像素)

					this.getWindowScale();

					// if (this.pixel_Width > (this.data.windowWidth * 0.5)) {
					// 	this.pixel_scale = (this.data.windowWidth * 0.5) / this.pixel_Width
					// } else {
					// 	if (this.pixel_Width < (this.data.windowWidth * 0.5) &&
					// 		this.pixel_Height < (this.data.windowHeight * 0.5)) {
					// 		this.pixel_scale = 1
					// 	}
					// }
					// if (this.pixel_Height > (this.data.windowHeight * 0.5)) {
					// 	if ((this.data.windowHeight * 0.5) / this.pixel_Height < 1) {
					// 		this.pixel_scale = (this.data.windowHeight * 0.5) / this.pixel_Height
					// 	}
					// } else {
					// 	if (this.pixel_Width < (this.data.windowWidth * 0.5) && this.pixel_Height < (this.data
					// 			.windowHeight * this.pixelScale)) {
					// 		this.pixel_scale = 1
					// 	}
					// }

					let real_width = Number(this.inputWidth);
					let real_height = Number(this.inputHeight);
					if (real_width > real_height) {
						this.filletScale = real_width / 100;
					} else {
						this.filletScale = real_height / 100;
					}

					this.$refs['NumSlider'].initFilletRadius(that.newDefalutFilletData, that.filletScale);

				}).catch(err => {

				});
			},

			//查设备明细
			getDetailMachine() {
				//this.OldConvert_rate = 10
				this.getCustomSizeInfo();
				// homeservice.WorksList({
				// 	machine_id: this.queryPage.machine_id,
				// 	s: 'machine.detail'
				// }).then(res => {
				// 	//console.log("getDetailMachine")
				// 	this.OldConvert_rate = res.convert_rate
				// 	this.render_cove_width = res.size.width * this.OldConvert_rate //最大宽度
				// 	this.render_cove_height = res.size.height * this.OldConvert_rate //最大高度
				// 	this.getCustomSizeInfo();
				// }).catch(err => {

				// });
			},
		},


		//上拉加载
		onReachBottom() {
			//console.log("加载更多")
			//console.log("加载更多22this.LoupanList.length"+this.LoupanList.length)
			if (this.LoupanList.length < 12) {
				return setTimeout(() => {
					uni.showToast({
						title: '没有更多数据了！',
						icon: 'none'
					});
				}, 500);
			}
			this.queryPage.page = this.queryPage.page + 1;
			this.loadGoodsList(Enums.DATA_DIRECTION.DOWN);
		},


		onLoad(options) {
			//获取屏幕宽高
			this.sliderdefaultWith = uni.upx2px(280) + 22;
			let that = this;

			if (options) {
				this.machineDetail = JSON.parse(options.machineDetail);
				if (this.machineDetail) {
					this.render_cove_width = this.machineDetail.size.width * this.OldConvert_rate //最大宽度
					this.render_cove_height = this.machineDetail.size.height * this.OldConvert_rate //最大高度
				}
			}

			wx.getSystemInfo({
				success: function(res) {
					let pixelRate = res.windowWidth / 750;
					that.data.windowWidth = res.windowWidth // 屏幕宽度
					that.data.windowHeight = res.windowHeight // 屏幕高度
					let heiPixelRate = res.windowHeight / 1452;
					that.heiPixelRate = heiPixelRate
					that.data.pixelRate = pixelRate // 屏幕宽度比率
					if (options) { // 判断是从设备进来
						that.queryPage.machine_id = options.machine_id // 设备id
						that.parameter.machine_id = options.machine_id // 设备id
						//画布接口/查询布置画布列表
						that.LoupanList = []

						that.getDetailMachine()

						if (options.isFirstPage) {
							that.isFirstPage = options.isFirstPage
						}


					}
				}
			});
		},

		created() {
			//设备信息
			let app = uni.getSystemInfoSync();
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			this.headheight = app.statusBarHeight + menuButtonInfo.height + (menuButtonInfo.top - app
				.statusBarHeight) * 2;
		},

		onShow() {

		}
	}
</script>

<style lang="scss">
	page {
		background: #101014;
	}

	.equalRatioAxtive {
		color: #E6B01A !important;
		border-color: #E6B01A !important;
	}

	.directionAxtive {
		border-color: #E6B01A !important;
	}

	.classificationLeft {
		background: #E6B01A !important;
	}

	.classificationRight {
		background: #E6B01A !important;
	}

	.previewAxtiveLeft {
		background: #E6B01A;
		box-shadow: 0px 19upx 48upx 1upx rgba(20, 31, 62, 0.35);
		border-radius: 50upx 50upx 0px 50upx;
	}

	.previewAxtiveRight {
		background: #E6B01A;
		box-shadow: 0px 19upx 48upx 1upx rgba(20, 31, 62, 0.35);
		border-radius: 50upx 50upx 50upx 0px;
	}

	.eq_list {
		width: calc(100% - 60upx);
		margin: 20upx auto;
		border-radius: 10upx;
		overflow: hidden;
		color: #FFFFFF;

		.eq_list_div {
			// background: #FFFFFF;
			padding: 40upx 20upx;
			display: flex;
			align-items: center;
			border-bottom: 1px solid #282932;
		}

	}

	// 返回顶部
	.to-top {
		position: fixed;
		bottom: 150upx;
		right: 30upx;
		width: 80upx;
		height: 80upx;
		border-radius: 50%;
		text-align: center;
		line-height: 80upx;
		// box-shadow: 5upx 5upx 5upx #ebeef5;
		transform: rotate(-90deg);
		background: #000;
		opacity: 0.5;
		z-index: 999;
	}

	.to-top-icon {
		color: #FFFFFF;
	}

	.edit-address {

		.form {
			height: 100%;
			color: #FFFFFF;

			.item {
				height: 100upx;
				display: flex;
				align-items: center;
				font-size: 28upx;
				padding: 0 30upx;
				width: calc(100% - 60upx);

				.text {
					width: 200upx;
				}

				.value {
					width: 300upx;
					margin-left: auto;
					background: #212027;
					text-align: center;
					border-radius: 10upx;
					padding: 15upx 0;
					color: #FFFFFF;
					display: flex;
					align-items: center;
				}
			}
		}

		.footer {
			position: fixed;
			bottom: 20upx;
			width: 100%;

			.footer_but {
				margin: auto;
				color: #fff;
				text-align: center;
				line-height: 88upx;
				width: 300upx;
				height: 88upx;
				background: linear-gradient(92deg, #E6B01A, #F29F3D);
				box-shadow: 0px 19upx 48upx 1upx rgba(20, 31, 62, 0.35);
				border-radius: 50upx;
			}
		}
	}
</style>
