<template>
	<view class="product">
		<view class="productList" v-for="(item,index) in list" :key="index" @click="handleActive(item)">
			<view class="name" v-if="isName">
				<view class="post" :style="{'width':!isMoney?'60%':'100%'}">
					<image :src="item.userinfo.avatar" class="mr-10 avatar" mode="aspectFill"></image>
					<view class="bold size16 mr-10">{{item.userinfo.name}}</view>
					<view class="vip">{{item.userinfo.posname}}</view>
				</view>
				<text class="call" v-if="!isMoney" @click="handleCall(user.authlist,item.userinfo.phone)" @click.stop>
					拨打电话
				</text>
			</view>
			<view class="info">
				<view class="bold size16 title">
					<text class="" :style="{'width':isState?'80%':'100%'}">{{item.title}}</text>
					<text class="state" v-if="isState">
						{{item.status==4?'待审核':item.status==5?'已驳回':'审核通过'}}
					</text>
				</view>
				<view class="mt-5 c999 size14">{{item.desc}}</view>
				<view class="image" v-if="isMoney&&item.pics.length">
					<image v-for="(img,ind) in item.pics" :key="ind" :src="img.url" mode="aspectFill" v-if="ind<3">
					</image>
				</view>
				<view class="address" v-if="isMoney">
					<text class="mr-10" v-if="item.industryname">行业：{{item.industryname}}</text>
					<text>地址：{{item.province}}{{item.city}}{{item.area}}{{item.address}}</text>
				</view>
				<view v-if="item.type!=9">
					<view class="money mt-10" v-if="isMoney">
						<!-- <text class="redcolor size16 mr-5 bold" v-if="item.vipprice">会员价:￥{{item.vipprice}}</text>
						<text class="size12 c999" v-if="item.price">市场价:￥{{item.price}}</text> -->
						<text class="call" @click.stop v-if="isPhone"
							@click="handleCall(user.authlist,item.userinfo.phone)">
							联系方式
						</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 联系人弹框 -->
		<secratary></secratary>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		name: "productList",
		props: {
			isName: { //是否显示头部个人信息
				type: Boolean,
				default: true
			},
			isPhone: { //是否显示电话
				type: Boolean,
				default: true
			},
			isState: { //是否显示审核状态
				type: Boolean,
				default: false
			},
			isMoney: { //是否显示价格
				type: Boolean,
				default: true
			},
			list: {
				type: Array,
				default () {
					return []
				}
			},
		},
		computed: {
			...mapState(["user"]),
			userInfo() {
				return this.user.name ? this.user : uni.getStorageSync('UserInfo')
			}
		},
		methods: {
			handleActive(item) {
				this.$emit("handleDetail", item)
			},
			handleCall(authlist, num) {
				let that = this
				console.log("authlist", authlist, that.userInfo)
				if (authlist.length) {
					let arr = authlist.findIndex(v => v.code == 'phone:show')
					if (arr == -1) {
						that.$store.commit("changeSecratary", true);
					} else {
						uni.makePhoneCall({
							phoneNumber: num, //仅为示例
							success: () => {
								console.log("拨打电话成功")
								that.$model.getSetClickNumber({
									userId: that.userInfo.id ? that.userInfo.id : 0,
									clickPhone: num,
								}).then(res => {});
							}
						})
					}
				} else {
					that.$store.commit("changeSecratary", true);
				}
			}

		}
	}
</script>

<style scoped lang="scss">
	.image {
		:nth-child(2) {
			margin: 0 10px;
		}
	}
</style>