<template>
	<view :style="[mainStyle]" v-if="isShowView">
		<view class="service-bar" v-if="dataList.length > 0">
			<view v-for="(item, index) in dataList" :key="index" class="bar-item">
				<view class="bar-top" @click="jumpUrl('fillPrescription/detail/detail?id=' + item.id)">
					<view><image :src="getImg(item)" class="prescription-image"></image></view>
					<view>
						<view class="prescription-data" style="margin-bottom: 30rpx;">
							<text class="prescription-tinfo">服务处方编号</text>
							<text class="prescription-dinfo">{{ item.id }}</text>
						</view>
						<view class="prescription-data">
							<text class="prescription-tinfo">处方提交时间</text>
							<text class="prescription-dinfo">{{ item.createDate }}</text>
						</view>
					</view>
				</view>
				<view class="bar-bottom">
					<!-- 0 待审核 1已审核 2驳回 -->
					<view>{{ item.state == 1 ? '已抓药' : item.state == 2 ? '拒绝抓药' : '待审核' }}</view>
					<view class="buttons">
						<view class="btn" @click="jumpUrl('fillPrescription/detail/detail?id=' + item.id)">处方详情</view>
						<view class="btn btn-red" v-if="item.state == 1" @click="jumpUrl('mine/orderDet/orderDet?id=' + item.orderId)">查看报价</view>
					</view>
				</view>
			</view>
		</view>

		<view class="nodata" v-else>
			<image :src="picUrlss + 'empty_sc.png'"></image>
			<text>暂无药方记录</text>
		</view>
		<!-- 按钮 -->
		<view class="bottom-bar">
			<view class="bottom-btn" @click="jumpUrl('fillPrescription/uploadPrescription/uploadPrescription')"><text>上传药方</text></view>
			<view class="bottom-text ddflex">
				<image src="../static/images/help.png"></image>
				<view class="bottom-text-share" @click="jumpUrl('fillPrescription/process/process')">了解按方抓药流程</view>
			</view>
		</view>
	</view>
</template>

<script>
const app = getApp();
const req = require('../../utils/request.js');
const api = require('../../utils/api.js');
const utils = require('../../utils/util.js');
export default {
	data() {
		return {
			mainStyle: app.globalData.mainStyle,
			picUrlss: req.public.picUrls,
			isShowView: false,
			isFirst: true,
			form: {
				page: 1,
				limit: 10
			},
			isLoad: true,
			dataList: []
		};
	},
	components: {},
	props: {},
	onLoad: function(options) {
		// this.getDataList(true);
	},
	onShow() {
		this.form.page = 1;
		this.isLoad = true;
		this.getDataList(this.isFirst);
	},

	onReachBottom: function() {
		this.form.page++;
		this.getDataList(false);
	},
	methods: {
		jumpUrl(url) {
			if (!req.isLogin()) return false;
			app.globalData.navigateTo(url);
		},

		getImg(item) {
			var url = '';
			var list = item.drugImgUrl.split(',');
			if (list.length > 0) {
				url = list[0];
			}
			return url;
		},

		getDataList(isShow) {
			if (!this.isLoad) {
				return;
			}
			this.form.type = this.type;
			this.isLoad = false;
			this.isFirst = false;
			req.getRequest(
				'/api/orderdurg/page',
				this.form,
				data => {
					if (data && data.length == this.form.limit) {
						this.isLoad = true;
					}
					if (this.form.page > 1) {
						data = this.dataList.concat(data);
					} else {
						if (data && data.length > 0) {
							this.isLoad = true;
						}
					}
					this.dataList = data;
					this.isShowView = true;
				},
				isShow
			);
		}
	},
	mounted() {}
};
</script>

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