<template>
	<view>
		<view class="bg-white padding text-xl text-black text-bold">
			{{demand.title}}（<text class="text-red text-bold">{{demand.num}}人</text>）
		</view>
		<view class="bg-white padding-lr padding-bottom">
			<view class="text-lg text-red text-bold">{{demand.ftype_text}}：{{demand.fwagall}}</view>
		</view>
		<view class="bg-white padding-lr padding-bottom flex justify-between">
			<view><text class="text-red text-bold">{{demand.wtype_text}}</text></view>
			<view><text class="text-red text-bold">{{demand.zwagall}}</text></view>
			<text class="text-sm text-gray">{{demand.city}} {{demand.district}}</text>
		</view>
		<view class="bg-white padding-lr padding-bottom margin-bottom-sm align-center">
			<view v-for="(item,index) in demand.tags" :key="index" class="cu-tag light bg-grey margin-bottom-xs">{{item}}</view>
		</view>
		
		<view class="cu-bar bg-white solids-bottom">
			<view class="action">
				<text class="cuIcon-titles text-red"></text> 接单记录
			</view>
			<view class="action">
				<text class="text-df">共 {{logcount}} 条 </text>
				<view class="cuIcon-right"></view>
			</view>
		</view>
		<view class="cu-list menu-avatar">
			<block v-for="(item,index) in plist" :key="index">
				<view class="cu-item ">
					<view class="cu-avatar radius lg" :style="'background-image:url('+item.worker.tilpic+');'"></view>
					<view class="content">
						<view class="text-black">
							<view class="text-cut">{{item.worker.title}}（<text class="text-red text-bold">{{item.num}}人</text></view>）
						</view>
						<view class="text-gray text-sm flex">
							<view class="text-cut">接单时间：{{item.createtime}}</view>
						</view>
					</view>
					<view class="action">
						<button class="cu-btn bg-themeBtn cuIcon" @tap="makeTelephone" :data-telephone="item.worker.mobile">
							<text class="cuIcon-phone"></text>
						</button>
					</view>
				</view>
			</block>
		</view>
		<uni-load-more :status="pstatus"></uni-load-more>
		
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				isRotate: false,
				userinfo: false,
				workerinfo: false,
				demand: {},
				logcount: 0,
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(option) {
			_this = this;
			var demandid = option.demandid || 0;
			_this.userinfo = _this.checkLogin("/pages/my/my");
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			if (_this.userinfo === false || _this.workerinfo === false) {
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.$req.ajax({
				path: "wdemand/pagewdemandlog",
				data: {
					demandid: demandid,
					workerid: _this.workerinfo.id
				}
			}).then((data) => {
				_this.demand = data.demand;
				_this.logcount = data.logcount;
				_this.getMore();
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			getMore: function() {
				_this.$req.ajax({
					path: "wdemand/wdemandloglist",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						workerid: _this.workerinfo.id,
						demandid: _this.demand.id
					}
				}).then((data) => {
					_this.pstatus = data.pstatus;
					_this.plist = _this.plist.concat(data.plist);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			delWorderlog: function(e) {
				var itemlogid = e.currentTarget.dataset.itemlogid;
				var itemindex = e.currentTarget.dataset.itemindex;
				uni.showModal({
					title: '信息提示',
					content: '删除后不可恢复，确定要删除吗？',
					success: function(res) {
						if (res.confirm) {
							_this.$req.ajax({
								path: "worder/dellog",
								data: {
									userid: _this.userinfo.id,
									getworkerid: _this.workerinfo.id,
									logid: itemlogid
								}
							}).then((data) => {
								_this.modalName = null;
								_this.plist.splice( itemindex, 1 );
							}).catch((err) => {
								uni.showModal({
									title: '信息提示',
									content: err,
									showCancel: false
								});
							});
						}
					}
				});
			},
			
			tabSelect: function(e) {
				_this.status = e.currentTarget.dataset.status;
				_this.pageRefresh();
			},
			
			makeTelephone: function(e) {
				var telephone = e.currentTarget.dataset.telephone;
				uni.makePhoneCall({
					phoneNumber: telephone
				});
			}
		}
	}
</script>

<style>
</style>
