<template>
	<view>
		<view class="info">
			<view class="info-c">
				<view class="status ddflex"><image :src="'../static/images/' + (params.state == 1?'dai_sy.png':'yi_hx.png')"></image>{{params.state == 1 ? '待核销':'已核销'}}</view>
				<view class="infos">
					<view class="shop ddflex" v-if="params.showProduct.merchantName"><image src="../static/images/dpico1.png"></image>{{params.showProduct.merchantName}}</view>
					<view class="product ddflex">
						<image :src="params.showProduct.pic" mode="aspectFill"></image>
						<view class="fflex">
							<view class="pro-tit">{{params.showProduct.title}}</view>
							<view class="specs" v-if="params.showProduct.specs">规格<text v-for="(it,index) in params.showProduct.specs" :key="index">{{it.value}}</text></view>
							<view class="pro-opt ddflex">
								<view class="price"><text>￥</text>{{params.showProduct.money}}</view>
								<view class="count">×{{params.showProduct.quantity}}</view>
							</view>
						</view>
					</view>
					<view class="code-info ddflex">
						<view class="fflex">
							<view class="code-sta"><text>{{params.state == 1 ? '待核销':'已核销'}}</text><block v-if="params.exspireTime&&params.state == 1">{{params.exspireTime}} 到期</block></view>
							<view class="code-ma">{{params.code}}</view>
						</view>
						<!-- <view class="tk-btn">申请退款</view> -->
					</view>
				</view>
			</view>
		</view>
		<view class="det">
			<view class="li ddflex">
				<view class="label">用户</view>
				<view class="item fflex">{{params.nickName}}</view>
			</view>
			<view class="li ddflex">
				<view class="label">手机号码</view>
				<view class="item fflex">{{params.phone}}</view>
			</view>
		</view>
		<view class="det" v-if="params.state == 2">
			<view class="li ddflex">
				<view class="label">核销时间</view>
				<view class="item fflex">{{params.useTime}}</view>
			</view>
			<view class="li ddflex">
				<view class="label">核销人员</view>
				<view class="item fflex">{{params.useUser}}</view>
			</view>
			<view class="li ddflex">
				<view class="label">核销门店</view>
				<view class="item fflex">{{params.writeMerchant}}</view>
			</view>
		</view>
		<view class="btn" @click="writeOrder()" v-else>确认核销</view>
	</view>
</template>

<script>
	const app = getApp();
	const req = require("../../utils/request.js");
	export default {
		data() {
			return {
				code: '',
				params: ''
			};
		},
		onLoad(options) {
			this.code = options.code;
			this.getData();
		},
		onReachBottom() {
		},
		methods: {
			// 判断周几
			getWeek(dateString) {
				let dateArray = dateString.split("-");
				let date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
				return "周" + "日一二三四五六".charAt(date.getDay());
			},
			// 计算天数
			DateMinus(date1,date2){//date1:小日期   date2:大日期
			　　var sdate = new Date(date1); 
			　　var now = new Date(date2); 
			　　var days = now.getTime() - sdate.getTime(); 
			　　var day = parseInt(days / (1000 * 60 * 60 * 24)); 
			　　return day; 
			 },
			getData(){
				req.getRequest('/api/v3/secondary/card/writeDetail',{code: this.code},res=>{
					this.params = res;
				})
			},
			writeOrder(){
				this.confirmMsg()
			},
			confirmMsg(){
				let that = this;
				uni.showModal({
					title:'确认核销',
					content:'一旦确认后操作将不可撤回，确定要核销吗？',
					success: function (res) {
						if (res.confirm) {
							that.writeOff();
						} else if (res.cancel) {
						}
					}
				})
			},
			writeOff(){
				let params = {
					code: this.code
				}
				req.postRequest('/api/v3/secondary/card/write', params, res=>{
					req.msg('核销成功');
					this.getData();
				})
			}
		}
	};
</script>

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