import toast from '../../../utils/tool/toast';
import order from "../../../utils/controls/order";

import notice from '@/utils/notice/index';

export default {


	methods:{
		/* 触发更新规则 */
		changeStatus:function(item){

			if (this.updateStatus[item.name]) {


				return this.updateStatus[item.name].map((target)=>{

					if (typeof target === 'string') target = {name:target};

					if (this.target[target.name]) {

						let id = this.target[target.name].flatIdGETIndex(item.id);

						if (target.reload === undefined?item.reload:target.reload) {
							return this.target[target.name].flatReload(1,true);
						}  else if (target.delete === undefined?item.delete:target.delete) {
							return this.target[target.name].flatSplice(id);
						} else {

							let useItem = this.target[target.name].flatGetData(id);

							/* 更新状态值 */
							useItem.statusOrder = order.getOrderStatus(item.toStatus);
							/* 更新状态值 */
							return this.target[target.name].flatSaveData(id,useItem);
						}

					}

				});
			}

		},
	},

	onShow(){
		if (this.storageMsg) {
			toast.success(this.storageMsg);
			this.storageMsg = null;
		}
	},



	created(){
		/* 更新规则 */
		this.updateStatus = {


			/* 如果为售后进入触发 */
			aftermarket:[{
				name:'apply',
				delete:true
			},{
				name:'application',
				reload:true
			}
			]

		}

		notice.on('refund',(item)=>{
			if(item.page === 'refund' && item.msg) {
				this.storageMsg = item.msg;
			}
			return this.changeStatus(item);
		},'order');
	},

	beforeDestroy(){
		return notice.off('refund','order');
	}


}
