<template>
	<view>
		<view class="hm-p-b-100">
			<view class="hm-header-xian"></view>
			<scroll-view scroll-y class="hm-w-h" @scrolltolower="reachBottom">
			<view  v-if="list.total>0">
				<view v-for="(item, index) in list.data" :key="index" class="list">
					<view @click="phone(item.phone)" class="hm-col-0 hm-font-30 hm-font-b hm-p-b-20 hm-border-b">
						{{item.shop.shop_name}}
						<view class="hm-dis-block-inline hm-fr">
							<u-icon color="#999" name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="hm-p-tb-20 hm-border-b">
						<text class="hm-col-tips">约定时间：</text>{{item.pact_time.text}} 
						<text class="hm-col-tips hm-m-l-50">约定状态：</text>
						<text v-if="item.status.value == 10" class="hm-col-warning">{{item.status.text}}</text>
						<text v-if="item.status.value == 20" class="hm-col-error">{{item.status.text}}</text>
						<text v-if="item.status.value == 30" class="hm-col-success">{{item.status.text}}</text>
						<text v-if="item.status.value == 40" class="hm-col-info">{{item.status.text}}</text>
					</view>
					<view class="hm-p-t-20 hm-text-right">
						<view class="hm-dis-block-inline">
							<u-button type="error" size="small" @click="remove(item.pact_id)" text="删除"></u-button>
						</view>
					</view>
				</view>
				<u-loadmore :status="loadStatus" bgColor="#f3f4f6" line></u-loadmore>
			</view>
			<view v-else class="hm">
				<img :src="applet.domain + '/addons/food/img/empty/data.png'" />
				<view class="text">暂无预定记录</view>
			</view>
			</scroll-view>
			<!-- 技术支持 -->
			<view class="hm">
				{{applet.copyright}} <text class="v">V{{applet.version}}</text>
			</view>
			<view class="hm-footer-fixed">
				<view class="hm-p-lr-b25 hm-w-b100">
					<u-button @click="goTo('user/pact/add')" type="success" text="预约订桌"></u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const App = getApp();
	export default {
		data() {
			return {
				applet: {},
				list: {data:{}},
				page: 1,
				loadStatus: 'loadmore',
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			let _this = this;
			_this.applet = uni.getStorageSync('applet');
			_this.getList();
		},

		onShow() {},

		methods: {
			
			/**
			 * 获取数据
			 */
			getList: function() {
				let _this = this;
				App._get('user.pact/lists', {
					page: _this.page
				}, function(result) {
					_this.list = result.data;
				});
			},
			
			/**
			 * 触底加载
			 */
			reachBottom: function() {
				let _this = this;
				_this.loadStatus = "loading"; //加载中
				// 已经是最后一页
				if (_this.page >= _this.list.last_page) {
					_this.loadStatus = "nomore"; //没有数据
					return false;
				}
				// 加载下一页列表
				_this.page = _this.page + 1;
				_this.getList();
			},
			/**
			 * 移除收货地址
			 */
			remove: function(id) {
				let _this = this;
				uni.showModal({
					title: "提示",
					content: "您确定要删除该记录吗?",
					success: function(o) {
						o.confirm && App._post_form('user.pact/delete', {
							id: id
						}, function(result) {
							_this.getList();
						});
					}
				});
			},
			/**
			 * 客服组件 - 拨打电话
			 */
			phone: function(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				});
			},
			/**
			 * 页面跳转
			 */
			goTo: function(url) {
				App.goTo(url);
			}
		}
	};

</script>
<style lang="scss" scoped>
	.list{
		background-color: #fff;
		padding: 20rpx;
		margin-bottom: 10rpx;
		border-bottom: 1rpx solid #f3f4f6;
	}
</style>

