<template>
	<view>
		<view class="paddding-x-two" v-if="JSON.stringify(detailData) != '{}'">
			<releaseForm :detailData="detailData" :statusBtn="detailInfo.status" @submit="handleSubmit"></releaseForm>
		</view>
	</view>
</template>

<script>
	import {
		orderDetailMsgNew,
		updateOrderFunction
	} from '../../api/system/index.js'
	import releaseForm from '@/components/form.vue'
	export default {
		components: {
			releaseForm
		},
		data() {
			return {
				detailInfo: {},//从上个页面接受的参数
				detailData:{},//详情页的数据
			}
		},
		onLoad(option) {
			if(option.detailInfo){
				this.detailInfo = JSON.parse(decodeURIComponent(option.detailInfo))
				this.getOrder()
			}
		},
		methods: {
			//获取订单详情列表
			getOrder() {
				let that = this
				orderDetailMsgNew({
					id: that.detailInfo.id
				}).then(res => {
					if (res.code == 200) {
						that.detailData = res.data
					}
				})
			},
			//重新发布和修改按钮事件
			async handleSubmit(data){
				let that = this
				if(that.detailInfo.status == 1){
					that.$set(data,'status',0)
				}
				const back_data = await updateOrderFunction(data)
				const {code} = back_data
				if(code == 200){
					uni.showToast({
						title: '修改成功!',
						icon: 'none',
						duration: 2000,
						success() {
							let cleatTime = setTimeout(() => {
								clearTimeout(cleatTime)
								that.$uniGo.navigateBack({
									delta:1
								})
							}, 1000)
							
						}
					})
				}
			}
		}
	}
</script>

<style>
	@import url("@/css/form.css");

	::v-deep .u-border {
		border: 0 !important;
		background: #F5F5F5 !important;
	}

	::v-deep .u-upload__wrap__preview {
		margin: 0 6rpx 10rpx 0 !important;
	}
</style>
