<template>
	<view>
		<!-- :class="specClass" :style="'top:' +  contactTop + 'px;'" -->
		<view :class="[className,classNames]" :style="styles" @click="customerServiceChat" v-if="type == 2">
			<image lazy-load="true" :src="imgUrl" :mode="imageMode" v-if="imgUrl" :style="imgStyle"></image>
			<view v-if="buttonText">
				{{buttonText}}
			</view>
		</view>
		<button style="font-size: inherit;color: inherit;" open-type="contact" hover-class="none" :class="className" v-else>
			<image lazy-load="true" :src="imgUrl" v-if="imgUrl" :style="imgStyle"></image>
			<view v-if="buttonText">{{buttonText}}</view>
		</button>
	</view>
</template>

<script>
	const app = getApp();
	const req = require("../../utils/request.js");

	export default {
		data() {
			return {
				chatPrams: {},
				type: 1
			};
		},

		components: {},
		props: {
			imgUrl: String,
			buttonText: String,
			className: String,
			classNames: String,
			styles: String,
			imageMode: String,
			isUpdate: {
				type: Boolean,
				default: true
			},
			productType: {
				type: Number,
				default: 0
			},
			imgStyle: String
		},
		watch: {},

		mounted() {
			// console.log('ready');
			this.getChatPrams();
			// this.getChatList();
		},

		methods: {
			getChatPrams() {
				let that = this;
				let chatPrams = req.getStorage('chatService');
				if(chatPrams){
					that.chatPrams = chatPrams;
					that.type = chatPrams.type;
					console.log('type==', that.type)
					that.$forceUpdate();
				}
			},
			customerServiceChat() {
				let chatPrams = this.chatPrams;
				wx.openCustomerServiceChat({
					extInfo: {
						url: chatPrams.url
					},
					corpId: chatPrams.enterpriseId,
					success(res) {
						console.log('调用微信客服')
					}
				})
			},
		}
	};
</script>
<style>
	@import "./index.css";
</style>
