<template>
	<view>
		<page @listDomUpdate="listDomUpdateFn" ref='page' noteEmpty='暂无商品列表' :api='api' @updateList="updateList">
			<productList :products="listParse" @imgclick="navInfo" titletxt="新人商品仅限第一次下单的用户"></productList>
		</page>
	</view>
</template>

<script>
	import page from "./page.vue"
	import productList from './glance/productList.vue';

	import {
		findListFirstCommodity,
		jumpLink
	} from '../js/request.js'

	export default {
		components: {
			page,
			productList
		},
		data() {
			return {
				list: [],
				listParse: [],
				api: findListFirstCommodity,
			}
		},
		methods: {
			parseList(val = this.list) {
				const that = this
				this.listParse = val.map(it => {
					const product = it.commodityInfo
					const name = product.vo.productName
					return {
						'src': that.productPreviewPicture(product),
						'imghref': product,
						'name': name,
						'shortlabel': product.vo.note,
						'marketinglabel': '新人专享价',
						'oriprice': product.vo.originalPrice,
						'curprice': it.price
					}
				})
			},
			updateList(list) {
				this.list = list
				this.parseList(list)
			},
			pullDownRefresh() {
				this.$refs.page.pullDownRefresh()
			},
			reachBottom() {
				this.$refs.page.reachBottom()
			},
			listDomUpdateFn() {
				this.$emit('listDomUpdate')
			},
			navInfo(item) {
				// #ifdef H5
				const WEB_VIEW_ANDROID = window.Browser && window.Browser.versions.android && window.file
				const WEB_VIEW_IOS = window.Browser && window.Browser.versions.ios && window.webkit
				if (WEB_VIEW_ANDROID) {
					try {
						window.file.productDetail(id)
					} catch (e) {
						this.$api.msg(`APP`)
						console.error(e)
					}
				} else if (WEB_VIEW_IOS && window.webkit.messageHandlers) {
					try {
						window.webkit.messageHandlers.productDetail.postMessage(id)
					} catch (e) {
						this.$api.msg(`APP`)
						console.error(e)
					}
				} else {
					jumpLink(`/?id=${item.id}#/commodity_details`, null, true)
				}
				// #endif
				// #ifdef MP
				jumpLink(`/?id=${item.id}#/commodity_details`, null, true)
				// #endif
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
