define(['zepto', 'medtap'], function($, medtap) {
	var myCard = {
		limit: 10,
		offset: 1,
		hasMore: false,
		firstLoad: false,
		pageNum: 1,
		pageSize: 20,
		init: function() {
			myCard.getUserInfo();
			myCard.getMyCard();
			// myCard.getMyReply();
			myCard.bindEve();
			myCard.getWechatTicket();
			
		},
		bindEve: function() {
			$('.publish_user_name').on('click', function() {
				$('.content_mod').show();
				$('.change_name_warp').show();
			});
			
			//取消
			$('.change_name_warp').on('click', '.change_btn_cancle', function() {
				$('.content_mod').hide();
				$('.change_name_warp').hide();
				$('.new_nick').val('');
			})
			
			//确定
			$('.change_name_warp').on('click', '.change_btn_confirm', function() {
				var newNick = $('.new_nick').val();
				//myCard.updateNickname(newNick);
				if(!newNick){
					medtap.toast({
						message:'请输入新的昵称',
						time:2000
					})
				}else{
					myCard.updateNickname(newNick);
				}
			});
			
			//切换查询
			$('.silder_tap_item').on('click', function() {
				$(this).addClass('on');
				$(this).siblings().removeClass('on');
				var type = '';
				var id = $(this).attr('id');
				if (id == 'my') {
					myCard.firstLoad = false;
					myCard.offset = 1;
					myCard.getMyCard();
				} else if (id == 'collect') {
					myCard.firstLoad = false;
					myCard.offset = 1;
					myCard.getMyCollect();
					// 新加回复
				} else if (id == 'reply') {
					myCard.firstLoad = false;
					myCard.offset = 1;
					myCard.getMyReply();
				}
			});
			
			//滚动加载
			$(window).scroll(function() {
				var scrollTop = $(this).scrollTop(); //滚动条距离顶部的高度
				var scrollHeight = $(document).height(); //当前页面的总高度
				var clientHeight = $(this).height(); //当前可视的页面高度
				if (scrollTop + clientHeight >= scrollHeight) { //距离顶部+当前高度 >=文档总高度 即代表滑动到底部 
					//滚动条到达底部
					if (myCard.hasMore == true) {
						var type = ''
						if ($('#my').hasClass('on')) {
							myCard.firstLoad = true;
							myCard.offset += 1;
							myCard.getMyCard();
						} else if ($('#collect').hasClass('on')) {
							myCard.firstLoad = true;
							myCard.offset += 1;
							myCard.getMyCollect();
						}else if ($('#reply').hasClass('on')) {
							myCard.firstLoad = true;
							myCard.offset += 1;
							myCard.getMyReply();
						}
					} else {
			
					}
				} else if (scrollTop <= 0) {
					//滚动条到达顶部
					return
				}
			});
			
		},
		getWechatTicket:function(){
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/wechat/lung/fetchWechatTicket',
				type: 'GET',
				async: false,
				data: {
					url: window.location.href
				},
				success: function(res) {
					var data = res.content;
					wx.config({
						debug: false,
						appId: data.appId, // 必填，公众号的唯一标识
						timestamp: data.timestamp, // 必填，生成签名的时间戳
						nonceStr: data.nonceStr, // 必填，生成签名的随机串
						signature: data.signature, // 必填，签名，见附录1
						jsApiList: [
							'previewImage',
						]
					})
				}
			})
		},
		previewImage:function(){
			$('.list_item_content_img').on('click', 'img', function() {
				var imgArray = [];
				var curImageSrc = $(this).attr('src');
				if (curImageSrc) {
					$('.list_item_content_img img').each(function(index, el) {
						var itemSrc = $(this).attr('src');
						imgArray.push(itemSrc);
					});
					wx.previewImage({
						current: curImageSrc,
						urls: imgArray
					});
				}
			});
		},
		getMyCard: function() {
			medtap.loading(1);
			medtap.submitAjax({
				url: "https://gateway.medtap.cn/operation/pubbbs/publish/mine",
				type: 'get',
				async: false,
				data: {
					limit: myCard.limit,
					offset: myCard.offset
				},
				success: function(res) {
					// console.log('获取我的帖子数据',res)
					medtap.loading(0);
					if (res.success == true) {
						var list = res.content.list;
						if (list.length == 0) {
							//未发布
							myCard.hasMore = false;
							if(myCard.offset > 1){
								setTimeout(function() {
									medtap.toast({
										message: '没有更多了',
										time: 2000
									})
								}, 1000)
							}else{
								$('.list_warp').html('')
								$('.no_list').show();
							}
						} else {
							$('.no_list').hide();
							myCard.hasMore = true;
							var str = '';
							// 新加发帖审核部分条件字符串 
							// 审核通过显示删除和编辑 对应字段 status'审核状态(2:审核拒绝,1:已审核;0:未审核)
							var editIsshow = 	'<div class="litst_item_headers_tools clearfix">' +
							'<div class="tools clearfix delete_btn">' +
							'<img src="../images/post_ldelete_buttn@2x.png">' +
							'<span class="tools_title">删除</span>' +
							'</div>' +
							'<div class="tools clearfix editor_btn">' +
							'<img src="../images/post_leditor_buttn@2x.png">' +
							'<span class="tools_title">编辑</span>' +
							'</div>' +
							'</div>' 
							// 状态0
							var waitStr = '<div>' +
							'<p class="waitStr">审核中</p>' +
							'</div>' 
							// 状态2
							for (var i = 0; i < list.length; i++) {
								var picUrl = list[i].picUrls || '';
								//单张
								// 最终显示的内容结构字符串
								var showStr =  ''
									// 底部显示审批的结果
								var showBottom = ''
								// 要显示的条件判断语句
								switch (list[i].status){
									case 0:
									showStr = ''
									showBottom=waitStr
									break;
									case 1:
									showStr = editIsshow
									showBottom=''
									break;	
									case 2:
									showStr =editIsshow
									showBottom='<div class="show_refuseStr">' +
									'<p>审核未通过: <span> '+list[i].rejectRemark +'</span> </p>' +
									'</div>' 
									break;
								 }
								if (picUrl.length != 0 && picUrl.length < 2) {
									str += '<div class="list_item" data-id="' + list[i].publishId + '" data-status="' + list[i].status + '">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' + list[i].profile + '" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' + list[i].nickname + '</p>' +
										'<p class="txt_gray post_card_time">' + list[i].updateTime.substring(5, 16) + '</p>' +
										'</div>' +
										showStr +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'<div class="list_item_content_img">' +
										'<img src="' + picUrl + '">' +
										'</div>' +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										'<div class="tools clearfix seen">' +
										'<img src="../images/post_seen_png@2x.png">' +
										'<span class="seenNum">' + list[i].viewCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix reply">' +
										'<img src="../images/post_reply_png@2x.png">' +
										'<span class="replyNum">' + list[i].commentCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix like">' +
										'<img src="../images/post_unlike_png@2x.png">' +
										'<span class="likeNum">' + list[i].upCount + '</span>' +
										'</div>' +
										'</div>' +
										showBottom +
										'</div>';
								} else if (picUrl.length > 1) { //多张
									var imgStr = ''
									for (var j = 0; j < picUrl.length; j++) {
										imgStr += '<img src="' + picUrl[j] + '">'
									}
									str += '<div class="list_item" data-id="' + list[i].publishId + '" data-status="' + list[i].status + '">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' + list[i].profile + '" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' + list[i].nickname + '</p>' +
										'<p class="txt_gray post_card_time">' + list[i].updateTime.substring(5, 16) + '</p>' +
										'</div>' +
										showStr +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'<div class="list_item_content_imgMore clearfix">' +
										imgStr +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										'<div class="tools clearfix seen">' +
										'<img src="../images/post_seen_png@2x.png">' +
										'<span class="seenNum">' + list[i].viewCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix reply">' +
										'<img src="../images/post_reply_png@2x.png">' +
										'<span class="replyNum">' + list[i].commentCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix like">' +
										'<img src="../images/post_unlike_png@2x.png">' +
										'<span class="likeNum">' + list[i].upCount + '</span>' +
										'</div>' +
										'</div>' +
										'</div>' +
										showBottom +
										'</div>';
								} else {
									str += '<div class="list_item" data-id="' + list[i].publishId + '" data-status="' + list[i].status + '">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' + list[i].profile + '" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' + list[i].nickname + '</p>' +
										'<p class="txt_gray post_card_time">' + list[i].updateTime.substring(5, 16) + '</p>' +
										'</div>' +
										showStr +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										'<div class="tools clearfix seen">' +
										'<img src="../images/post_seen_png@2x.png" >' +
										'<span class="seenNum">' + list[i].viewCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix reply">' +
										'<img src="../images/post_reply_png@2x.png" >' +
										'<span class="replyNum">' + list[i].commentCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix like">' +
										'<img src="../images/post_unlike_png@2x.png" >' +
										'<span class="likeNum">' + list[i].upCount + '</span>' +
										'</div>' +
										'</div>' +
										showBottom +
										'</div>';
								}
							}
							if (myCard.offset > 1) {
								$('.list_warp').append(str);
							} else {
								$('.list_warp').html(str);
							}

							//删除操作
							$('.delete_btn').on('click', function(e) {
								e.stopPropagation();
								var id = $(this).parents('.list_item').attr('data-id');
								console.log(id)
								$('#showDialog').show();
								$('.dialog-content-bd').html('确定要删除这条帖子吗?')
								$('.dialog-btn-confirm').on('click', function() {
									$('#showDialog').hide();
									myCard.deleteMine(id);
								});
								$('.dialog-btn-cancel').on('click',function(){
									$('#showDialog').hide();
								})
							});
							
							//编辑我的帖子
							$('.editor_btn').on('click',function(e){
								e.stopPropagation();
								var id = $(this).parents('.list_item').attr('data-id');
								myCard.editMypublish(id);
							});
							
							//帖子详情
							$('.list_item').on('click',function(e){
								e.stopPropagation();
								var id = $(this).attr('data-id');
								var status = $(this).attr('data-status');
								medtap.pushWindow('cardDetail.html?cardId=' + id +'&status=' + status);
							})
							
							myCard.previewImage();
						}
					}
				}
			})
		},
		// 新加我的回复
		getMyReply: function() {
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/operation/pubbbs/publishComment/mine',
				type: 'POST',
				async: true,
				contentType: 'application/json',
				data: {
						pageNum:myCard.pageNum,
						pageSize:myCard.pageSize
				},
				success: function(res){
					console.log('回复',res)
					medtap.loading(0);
					if (res.success == true) {
						var list = res.content.list;
						if (list.length == 0) {
							//未发布
							myCard.hasMore = false;
							if (myCard.offset > 1) {
								setTimeout(function() {
									medtap.toast({
										message: '没有更多了',
										time: 2000
									});
								}, 1000);
							} else {
								$('.list_warp').html('');
								$('.no_list').show();
							}
						} else {
							$('.no_list').hide();
							myCard.hasMore = true;
							var str = '';
							for (var i = 0; i < list.length; i++) {
								var picUrl = list[i].picUrls || '';
								//单张
								if (picUrl.length != 0 && picUrl.length < 2) {
									str +=
										'<div class="list_item" data-id="' +
										list[i].publishId +
										'">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' +
										list[i].profile +
										'" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' +
										list[i].nickname +
										'</p>' +
										'<p class="txt_gray post_card_time">' +
										list[i].updateTime.substring(5, 16) +
										'</p>' +
										'</div>' +
										'<div class="litst_item_headers_tools clearfix">' +
										// '<div class="tools clearfix delete_btn">' +
										// '<img src="../images/post_ldelete_buttn@2x.png">' +
										// '<span class="tools_title">删除</span>' +
										// '</div>' +
										// '<div class="tools clearfix editor_btn">' +
										// '<img src="../images/post_leditor_buttn@2x.png">' +
										// '<span class="tools_title">编辑</span>' +
										// '</div>' +
										'</div>' +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'<div class="list_item_content_img">' +
										'<img src="' +
										picUrl +
										'">' +
										'</div>' +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										// '<div class="tools clearfix seen">' +
										// '<img src="../images/post_seen_png@2x.png">' +
										// '<span class="seenNum">' +
										// list[i].viewCount +
										// '</span>' +
										// '</div>' +
										// '<div class="tools clearfix reply">' +
										// '<img src="../images/post_reply_png@2x.png">' +
										// '<span class="replyNum">' +
										// list[i].commentCount +
										// '</span>' +
										// '</div>' +
										// '<div class="tools clearfix like">' +
										// '<img src="../images/post_unlike_png@2x.png">' +
										// '<span class="likeNum">' +
										// list[i].upCount +
										// '</span>' +
										// '</div>' +
										'</div>' +
										'</div>';
								} else if (picUrl.length > 1) {
									//多张
									var imgStr = '';
									for (var j = 0; j < picUrl.length; j++) {
										imgStr += '<img src="' + picUrl[j] + '">';
									}
									str +=
										'<div class="list_item" data-id="' +
										list[i].publishId +
										'">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' +
										list[i].profile +
										'" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' +
										list[i].nickname +
										'</p>' +
										'<p class="txt_gray post_card_time">' +
										list[i].updateTime.substring(5, 16) +
										'</p>' +
										'</div>' +
										'<div class="litst_item_headers_tools clearfix">' +
										// '<div class="tools clearfix delete_btn">' +
										// '<img src="../images/post_ldelete_buttn@2x.png">' +
										// '<span class="tools_title">删除</span>' +
										// '</div>' +
										// '<div class="tools clearfix editor_btn">' +
										// '<img src="../images/post_leditor_buttn@2x.png">' +
										// '<span class="tools_title">编辑</span>' +
										// '</div>' +
										'</div>' +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'<div class="list_item_content_imgMore clearfix">' +
										imgStr +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										// '<div class="tools clearfix seen">' +
										// '<img src="../images/post_seen_png@2x.png">' +
										// // '<span class="seenNum">' +
										// // list[i].viewCount +
										// // '</span>' +
										// '</div>' +
										// '<div class="tools clearfix reply">' +
										// '<img src="../images/post_reply_png@2x.png">' +
										// '<span class="replyNum">' +
										// list[i].commentCount +
										// '</span>' +
										// '</div>' +
										// '<div class="tools clearfix like">' +
										// '<img src="../images/post_unlike_png@2x.png">' +
										// '<span class="likeNum">' +
										// list[i].upCount +
										// '</span>' +
										// '</div>' +
										'</div>' +
										'</div>' +
										'</div>';
								} else {
									str +=
										'<div class="list_item" data-id="' +
										list[i].publishId +
										'">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' +
										list[i].profile +
										'" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' +
										list[i].nickname +
										'</p>' +
										'<p class="txt_gray post_card_time">' +
										list[i].updateTime.substring(5, 16) +
										'</p>' +
										'</div>' +
										'<div class="litst_item_headers_tools clearfix">' +
										// '<div class="tools clearfix delete_btn">' +
										// '<img src="../images/post_ldelete_buttn@2x.png">' +
										// '<span class="tools_title">删除</span>' +
										// '</div>' +
										// '<div class="tools clearfix editor_btn">' +
										// '<img src="../images/post_leditor_buttn@2x.png">' +
										// '<span class="tools_title">编辑</span>' +
										// '</div>' +
										'</div>' +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										// '<div class="tools clearfix seen">' +
										// '<img src="../images/post_seen_png@2x.png" >' +
										// '<span class="seenNum">' +
										// list[i].viewCount +
										// '</span>' +
										// '</div>' +
										// '<div class="tools clearfix reply">' +
										// '<img src="../images/post_reply_png@2x.png" >' +
										// '<span class="replyNum">' +
										// list[i].commentCount +
										// '</span>' +
										// '</div>' +
										// '<div class="tools clearfix like">' +
										// '<img src="../images/post_unlike_png@2x.png" >' +
										// '<span class="likeNum">' +
										// list[i].upCount +
										// '</span>' +
										// '</div>' +
										'</div>' +
										'</div>';
								}
							}
							if (myCard.offset > 1) {
								$('.list_warp').append(str);
							} else {
								$('.list_warp').html(str);
							}
								//删除操作
								$('.delete_btn').on('click', function(e) {
									e.stopPropagation();
									var id = $(this).parents('.list_item').attr('data-id');
									$('#showDialog').show();
									$('.dialog-content-bd').html('确定要删除这条回复吗?');
									$('.dialog-btn-confirm').on('click', function() {
										$('#showDialog').hide();
										myCard.deleteMine(id);
									});
									$('.dialog-btn-cancel').on('click', function() {
										$('#showDialog').hide();
									});
								});
						//帖子详情
						$('.list_item').on('click',function(e){
							e.stopPropagation();
							var id = $(this).attr('data-id');
							medtap.pushWindow('cardDetail.html?cardId=' + id);
						})

							myCard.previewImage();
						}
					}
				}
			});
		},
		//我的收藏
		getMyCollect: function() {
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/operation/pubbbs/publishCollect',
				type: 'get',
				async: false,
				data: {
					limit: myCard.limit,
					offset: myCard.offset
				},
				success: function(res) {
					medtap.loading(0);
					if(res.success == true){
						//var list = res.content.
						var list = res.content.list;
						if (list.length == 0) {
							//未发布
							myCard.hasMore = false;
							if(myCard.offset > 1){
								setTimeout(function() {
									medtap.toast({
										message: '没有更多了',
										time: 2000
									})
								}, 1000)
							}else{
								$('.list_warp').html('')
								$('.no_list').show();
							}
						} else {
							$('.no_list').hide();
							myCard.hasMore = true;
							var str = '';
							for (var i = 0; i < list.length; i++) {
								var picUrl = list[i].picUrls || '';
								
								//单张
								if (picUrl.length != 0 && picUrl.length < 2) {
									str += '<div class="list_item" data-id="' + list[i].publishId + '">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' + list[i].profile + '" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' + list[i].nickname + '</p>' +
										'<p class="txt_gray post_card_time">' + list[i].updateTime.substring(5, 16) + '</p>' +
										'</div>' +
										'<div class="litst_item_headers_tools clearfix">' +
										'<div class="tools clearfix delete_btn">' +
										'<span class="tools_title">取消收藏</span>' +
										'</div>' +
										'</div>' +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'<div class="list_item_content_img">' +
										'<img src="' + picUrl + '">' +
										'</div>' +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										'<div class="tools clearfix seen">' +
										'<img src="../images/post_seen_png@2x.png">' +
										'<span class="seenNum">' + list[i].viewCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix reply">' +
										'<img src="../images/post_reply_png@2x.png">' +
										'<span class="replyNum">' + list[i].commentCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix like">' +
										'<img src="../images/post_unlike_png@2x.png">' +
										'<span class="likeNum">' + list[i].upCount + '</span>' +
										'</div>' +
										'</div>' +
										'</div>';
								} else if (picUrl.length > 1) { //多张
									var imgStr = ''
									for (var j = 0; j < picUrl.length; j++) {
										imgStr += '<img src="' + picUrl[j] + '">'
									}
									str += '<div class="list_item" data-id="' + list[i].publishId + '">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' + list[i].profile + '" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' + list[i].nickname + '</p>' +
										'<p class="txt_gray post_card_time">' + list[i].updateTime.substring(5, 16) + '</p>' +
										'</div>' +
										'<div class="litst_item_headers_tools clearfix">' +
										'<div class="tools clearfix delete_btn">' +
										'<span class="tools_title">取消收藏</span>' +
										'</div>' +
										'</div>' +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'<div class="list_item_content_imgMore clearfix">' +
										imgStr +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										'<div class="tools clearfix seen">' +
										'<img src="../images/post_seen_png@2x.png">' +
										'<span class="seenNum">' + list[i].viewCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix reply">' +
										'<img src="../images/post_reply_png@2x.png">' +
										'<span class="replyNum">' + list[i].commentCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix like">' +
										'<img src="../images/post_unlike_png@2x.png">' +
										'<span class="likeNum">' + list[i].upCount + '</span>' +
										'</div>' +
										'</div>' +
										'</div>' +
										'</div>';
								} else {
									str += '<div class="list_item" data-id="' + list[i].publishId + '">' +
										'<div class="list_item_header clearfix">' +
										'<img src="' + list[i].profile + '" class="user_profile">' +
										'<div class="user_info">' +
										'<p class="user_name">' + list[i].nickname + '</p>' +
										'<p class="txt_gray post_card_time">' + list[i].updateTime.substring(5, 16) + '</p>' +
										'</div>' +
										'<div class="litst_item_headers_tools clearfix">' +
										'<div class="tools clearfix delete_btn">' +
										'<span class="tools_title">取消收藏</span>' +
										'</div>' +
										'</div>' +
										'</div>' +
										'<div class="list_item_content">' +
										'<div class="list_item_content_desc">' +
										list[i].content +
										'</div>' +
										'</div>' +
										'<div class="list_item_tools clearfix">' +
										'<div class="tools clearfix seen">' +
										'<img src="../images/post_seen_png@2x.png" >' +
										'<span class="seenNum">' + list[i].viewCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix reply">' +
										'<img src="../images/post_reply_png@2x.png" >' +
										'<span class="replyNum">' + list[i].commentCount + '</span>' +
										'</div>' +
										'<div class="tools clearfix like">' +
										'<img src="../images/post_unlike_png@2x.png" >' +
										'<span class="likeNum">' + list[i].upCount + '</span>' +
										'</div>' +
										'</div>' +
										'</div>';
								}
							}
							if (myCard.offset > 1) {
								$('.list_warp').append(str);
							} else {
								$('.list_warp').html(str);
							}
						
							//删除操作
							$('.delete_btn').unbind('click').bind('click', function(e) {
								e.stopPropagation();
								var id = $(this).parents('.list_item').attr('data-id');
								$('#showDialog').show();
								$('.dialog-content-bd').html('确定取消收藏这条帖子吗?')
								$('.dialog-btn-confirm').on('click', function() {
									$('#showDialog').hide();
									myCard.cancelCollect(id);
									/* myCard.getMyCollect(); */
								});
								$('.dialog-btn-cancel').on('click',function(){
									$('#showDialog').hide();
								})
							});
							
							$('.list_item').on('click',function(e){
								e.stopPropagation();
								var id = $(this).attr('data-id');
								medtap.pushWindow('cardDetail.html?cardId=' + id);
							})
							myCard.previewImage();
						}
					}
				}
			})
		},
		//删除帖子
		deleteMine: function(id) {
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/operation/pubbbs/publish/mineDelete',
				type: 'post',
				async: false,
				contentType: 'application/json',
				data: {
					id: id
				},
				success: function(res) {
					// console.log('删除后',res)
					medtap.loading(0);
					if (res.success == true) {
						setTimeout(function() {
							medtap.toast({
								message: '删除成功',
								time: 2000
							});
							setTimeout(function(){
								window.location.reload();
							},1800)
						}, 1000)
					}
				}
			})
		},
		//取消收藏
		cancelCollect:function(id){
			var collectResult;
			medtap.loading(1);
			medtap.submitAjax({
				url:'https://gateway.medtap.cn/operation/pubbbs/publishCollect',
				type:'POST',
				async: false,
				contentType: 'application/json',
				data:{
					publishId:parseInt(id)
				},
				success:function(res){
					medtap.loading(0);
					if(res.success == true){
						$('.list_warp .list_item').each(function(index, el) {
							var _this = this
							var sId = $(this).attr('data-id');
							if(sId == id ){
								$(this).remove();
								if(!$('.list_warp').html()){
									$('.no_list').show();
								}else{
									$('.no_list').hide();
								}
							}
						});
					}
				}
			})
		},
		editMypublish:function(id){
			medtap.pushWindow('newCard.html?id=' + id);
		},
		updateNickname:function(name){
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/user/updateNickname',
				type: 'POST',
				async: false,
				contentType: 'application/json',
				data: {
					nickname: name
				},
				success: function(res) {
					medtap.loading(0);
					if(res.success == true){
						setTimeout(function() {
							medtap.toast({
								message: '修改成功',
								time: 2000
							})
							$('.content_mod').hide();
							$('.change_name_warp').hide();
							$('.new_nick').val('');
							setTimeout(function(){
								window.location.reload();
							},1800)
						}, 1000)
					}
				}
			})
		},
		getUserInfo:function(){
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/user/getUserDetail',
				type: 'GET',
				async: false,
				data: {
			
				},
				success: function(res) {
					medtap.loading(0);
					var userInfo = res.content.userInfo;
					$('.change_name_nickname').html(userInfo.nickname)
					$('.publish_user_name').html(userInfo.nickname);
					$('.publish_user_profile').attr('src',userInfo.profile);
				}
			})
		}
	}
	myCard.init();
})
