﻿<template>
	<transition name="el-zoom-in-center">
		<div class="NCC-preview-main">
			<div class="NCC-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="small" label-width="113px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="10" >
						<el-form-item label="类型" prop="type">
							<el-radio-group v-model="dataForm.type" required :style='{}' >
								<el-radio v-for="(item, index) in typeOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="14" >
						<el-form-item label="供应商名称" prop="partnerId" v-if="dataForm.type==1">
							<el-select v-model="dataForm.partnerId" placeholder="请选择" clearable required :style='{"width":"100%"}' filterable >
								<el-option v-for="(item, index) in supplierIdOptions" :key="index" :label="item.F_Name" :value="item.F_Id" ></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="合作方名称" prop="partnerId" v-if="dataForm.type==2">
							<el-select v-model="dataForm.partnerId" placeholder="请选择" clearable required :style='{"width":"100%"}' filterable >
								<el-option v-for="(item, index) in partnerIdOptions" :key="index" :label="item.F_Name" :value="item.F_Id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="纳税人识别号" prop="creditCode">
							<el-input v-model="dataForm.creditCode" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="注册地址" prop="address">
							<el-input v-model="dataForm.address" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="联系电话" prop="mobile">
							<el-input v-model="dataForm.mobile" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="开户行" prop="bank">
							<el-input v-model="dataForm.bank" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="银行账号" prop="account">
							<el-input v-model="dataForm.account" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="备注信息" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建人" prop="creatorUserId">
							<el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建时间" prop="creatorTime">
							<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改人" prop="lastModifyUserId">
							<el-input v-model="dataForm.lastModifyUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改时间" prop="lastModifyTime">
							<el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					id:'',
					type:"1",
					partnerId:undefined,
					creditCode:undefined,
					address:undefined,
					mobile:undefined,
					bank:undefined,
					account:undefined,
					remark:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					type:[
						{
							required:true,
							message:'请输入类型',
							trigger:'change'
						},
					],
					partnerId:[
						{
							required:true,
							message:'请输入名称',
							trigger:'change'
						},
					],
					creditCode:[
						{
							required:true,
							message:'请输入纳税人识别号',
							trigger:'blur'
						},
					],
					mobile:[
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系电话',
							trigger:'blur'
						},
					],
				},
				typeOptions:[{"fullName":"供应商","id":"1"},{"fullName":"合作方","id":"2"}],
				partnerIdOptions : [],
				supplierIdOptions: [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getpartnerIdOptions();
			this.getsupplierIdOptions();
		},
		mounted() {
        },
		methods: {
			getsupplierIdOptions(){
				previewDataInterface('208733355913512197').then(res => {
					this.supplierIdOptions = res.data
				});
			},
			getpartnerIdOptions(){
				previewDataInterface('208733616207824133').then(res => {
					this.partnerIdOptions = res.data
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyZbPartnerbill/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/SubDev/ZyZbPartnerbill`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/SubDev/ZyZbPartnerbill/' + this.dataForm.id,
                                method: 'PUT',
                                data: this.dataForm
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>
