<template>
<el-drawer :title="titleMap[mode]" v-model="visible" :size="1000" destroy-on-close :close-on-click-modal="false" @closed="$emit('closed')">
	<el-main>
		<el-form ref="dialogForm" :model="form" :rules="rules" label-width="160px">
			<el-form-item label="退款金额" prop="amount">
				<el-input v-model="form.amount" placeholder="请输入退款金额" disabled />
			</el-form-item>
			<el-form-item label="退款原因" prop="reason">
				<el-input type="textarea" v-model="form.reason" disabled />
			</el-form-item>
			<el-form-item label="退款凭证" prop="images" v-if="false">
				<sc-upload v-model="form.images" title="退款凭证" />
			</el-form-item>
			<el-form-item label="备注" prop="remark">
				<el-input type="textarea" v-model="form.remark" />
			</el-form-item>
			<el-form-item label="状态" prop="status">
				<el-select v-model="form.status" placeholder="请选择状态" style="width: 160px;">
					<el-option v-for="item in [{label: '退款中', value: 0}, {label: '同意退款', value: 1}, {label: '拒绝退款', value: 2}]" :key="item.value" :label="item.label" :value="item.value" />
				</el-select>
			</el-form-item>
		</el-form>
	</el-main>
	<template #footer>
		<el-button type="primary" @click="onSubmit">确认提交</el-button>
	</template>
</el-drawer>
</template>

<script>
import scEditor from '@/components/scEditor'

export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {add: '新增', edit: '编辑', audit: '审核'},
			form: {type_id: 0, operate: []},
			rules: {
				title: [{required: true, message: '请输入商品名称'}]
			},
			visible: false,
			isSaveing: false,
			cache: {}
		}
	},
	components: {
		scEditor
	},
	watch: {
		"form.operate"(value){
			this.priceTab = value[0]
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode='add'){
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		onSubmit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					let res
					if(this.mode == 'edit'){
						res = await this.$API.order.refund.edit.post(this.form);
					}else if(this.mode == 'add'){
						res = await this.$API.order.refund.add.post(this.form);
					}else if (this.mode == 'audit') {
						res = await this.$API.order.refund.audit.post(this.form);
					}

					this.isSaveing = false;
					if(res.code == 1){
						this.$emit('success', res.data)
						this.visible = false;
						this.$message.success("操作成功")
					}else{
						this.$message.error(res.message)
					}
				}
			})
		},
		//表单注入数据
		setData(data){
			this.loading = true
			Object.assign(this.form, data)
		}
	}
}
</script>
