<template>
	<view class="con">
		<view class="search ddflex">
			<image src="../../static/images/ssico.png" class="ssico"></image>
			<input v-model="cTitle" placeholder="搜索附近位置" @input="inputTopicText" placeholder-class="placeholder" class="ipt fflex" />
			<!-- <view class="clear">取消</view> -->
		</view>
		<!-- <view class="new" v-if="cTitle">
			<view class="tip">没有找到想要参与的话题？</view>
			<view class="create" @click="getSaveTopic()">
				创建新话题：
				<text>{{ cTitle }}</text>
			</view>
		</view> -->
		<view class="list">
			<view class="li ddflex" @click="selectedBack('')">
				<image src="../static/images/ht_no.png"></image>
				<view class="fflex tover">不显示位置</view>
			</view>
			<view class="li" @click="selectedBack(item)">
				<view class="li-t tover">长沙市</view>
				<text class="li-b tover">当前所在区域</text>
			</view>
			<view class="li" @click="selectedBack(item)">
				<view class="li-t tover">新芙蓉小雅(尖山店)</view>
				<text class="li-b tover">军民融合产业园1栋B座207-208号</text>
			</view>
			<view class="li" @click="selectedBack(item)">
				<view class="li-t tover">长沙华瑞IT教育</view>
				<text class="li-b tover">尖山路39号长沙中电软件园21栋</text>
			</view>
		</view>
	</view>
</template>

<script>
const app = getApp();
const req = require('../../utils/request.js');
export default {
	data() {
		return {
			isLoad: true,
			form: {
				page: 1,
				limit: 10
			},
			topicList: [],
			cTitle: '' //输入的话题关键词
		};
	},
	onLoad() {
		this.getListTopic();
	},
	onReachBottom() {
		this.form.page++;
		this.getListTopic();
	},
	methods: {
		// 监听获取话题输入
		inputTopicText(e) {
			this.isLoad = true;
			this.form.page = 1;
			this.getListTopic();
		},

		selectedBack(obj) {
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			let prevPage = pages[pages.length - 2]; //上一页页面实例
			prevPage.$vm.htObj = obj; //修改上一页data里面的searchVal参数值为1211
			uni.navigateBack({
				//uni.navigateTo跳转的返回，默认1为返回上一级
				delta: 1
			});
		},

		getListTopic() {
			if (!this.isLoad) return false;
			this.isLoad = false;
			let that = this;
			if (this.cTitle) {
				this.form.search = this.cTitle;
			} else {
				this.form.search = '';
			}
			this.form.orderType=1;
			req.getRequest('/api/v3/dialogue/list', this.form, data => {
				if (data && data.length >= this.form.limit) {
					this.isLoad = true;
				}
				if (that.form.page > 1) {
					data = that.topicList.concat(data);
				}
				that.topicList = data;
			});
		},

		getSaveTopic() {
			var dataP = {
				title: this.cTitle
			};
			req.postRequest('/api/v3/dialogue/save', dataP, data => {
				this.selectedBack(data);
			});
		}
	}
};
</script>

<style>
@import './index.css';
</style>
