{extend name="main"}
{block name="style"}
{css href="__TEMPLATE_STATIC__/user.css"}
<style type="text/css">
	.el-table td.gutter, .el-table th.gutter{background-color: }
</style>
{/block}
{block name="header"}
{include file="module/user_top_nav"/}
{/block}
{block name="body"}
<div class="flex1 flex h-100">
	<div class="w-180px bg-dark p-4 overflow-y-auto">
	{include file="module/user/company_left" left="module/user/company_left_vip"/}
	</div>
	<div class="frame-body flex-1 overflow-y-auto py-3">
		<div class="container-xl pb-4 shadow bg-white">
			<el-tabs v-model="activeName">
				<el-tab-pane label="索取发票" name="invoice"></el-tab-pane>
				<el-tab-pane label="我的发票" name="invoice_list"></el-tab-pane>
				<el-tab-pane label="发票抬头" name="invoice_info"></el-tab-pane>
				<el-tab-pane label="邮寄地址" name="mail_address"></el-tab-pane>
				<el-tab-pane label="电子邮件" name="email"></el-tab-pane>
			</el-tabs>
			<div v-show="activeName==='invoice' && !next">
				<div class="flex py-3 flex-center">
					<div class="el-table-column--selection">
						<div class="cell">
							<el-checkbox v-model="invoice.all_selected" :true-label="1" :false-label="0" @change="getInvoiceAll"
							:disabled="!tableData.length||!invoiceconfig.invoice_status"></el-checkbox>
						</div>
					</div>
					<div class="flex-1 pl-2 small">
						全选(支持跨分页)：有{{search.total}}个订单可申请发票，可开票总额：￥ {{search.price}}
					</div>
				</div>
				<div class="table-responsive text-666666">
					<el-table
						ref="multipleTable"
				      	:data="tableData"
			    		stripe
			    		max-height="650"
			    		v-loading="search.ajax"
			    		style="width: 100%;"
			    		header-cell-class-name="bg-F4F4F4"
	    				@selection-change="handleSelectionChange">
					  <el-table-column
					      type="selection"
					      width="45">
					  </el-table-column>
				      <el-table-column
				        label="订单内容">
					      <template slot-scope="scope">
					      	<div class="text-info">{{scope.row.otitle}}</div>
					      	<div class="flex small">
					      		<div>{{scope.row.otrade}}</div>
					      		<div class="px-2">|</div>
						        <el-popover trigger="hover" placement="top">
						          <p>创建时间: {{ scope.row.create_time }}</p>
						          <p>更新时间: {{ scope.row.update_time }}</p>
						          <p v-if="scope.row.status===0">过期时间: {{ scope.row.expire_time }}</p>
						          <p v-if="scope.row.status===1 || scope.row.status===2">支付时间: {{ scope.row.pay_time }}</p>
						          <p v-if="scope.row.status===1 || scope.row.status===2">完成时间: {{ scope.row.finish_time }}</p>
						          <p v-if="scope.row.status===-1">取消时间: {{ scope.row.cancel_time }}</p>
						          <div slot="reference" class="name-wrapper">
						            下单时间：{{ scope.row.create_time }}
						          </div>
						        </el-popover>
						    </div>
					      </template>
				      </el-table-column>
				      <el-table-column
				        label="订单金额"
				        width="120">
					      <template slot-scope="scope">
					      	<span class="text-primary">{{scope.row.oprice}}</span>
					      	<div class="small text-secondary" v-if="scope.row.score>0">抵扣积分:{{scope.row.score}}</div>
					      </template>
				      </el-table-column>
				      <el-table-column
				        label="支付方式"
				        width="100">
					      <template slot-scope="scope">
					      	<span v-if="scope.row.pay_type === 1">支付宝</span>
					      	<span v-else-if="scope.row.pay_type === 2">微信</span>
					      	<span v-else-if="scope.row.pay_type === 3">苹果</span>
					      	<span v-else-if="scope.row.pay_type === 4">积分</span>
					      	<span v-else-if="scope.row.status===1 || scope.row.status===2">未知</span>
					      </template>
				      </el-table-column>
				    </el-table>
				</div>
				<div class="flex py-3 flex-center">
					<div class="el-table-column--selection">
						<div class="cell">
							<el-checkbox 
								:indeterminate="multipleSelection.length>0 && multipleSelection.length!==tableData.length"
								@change="toggleSelectionAll" 
								v-model="all_selected"
								:disabled="!tableData.length||!invoiceconfig.invoice_status"></el-checkbox>
						</div>
					</div>
					<div class="pl-2">
						<el-button type="primary" size="mini" 
							@click="invoiceNext"
							:disabled="!tableData.length||!invoiceconfig.invoice_status">下一步</el-button>
					</div>
					<div class="flex-1 pl-2">
						待开票金额：<span class="text-success pr-2">￥ {{price}}</span>已选{{multipleSelection.length}}个订单共￥ {{price}}
					</div>
					<div>
						<el-pagination
						  background
						  :hide-on-single-page="true"
						  @current-change="setPageChange"
					      :current-page="search.page"
					      :page-size="search.per_page"
					      layout="total,  prev, pager, next, jumper"
					      :total="search.total">
					    </el-pagination>
					</div>
				</div>
			</div>
			<div v-show="activeName==='invoice_list'">
				<el-table
					ref="invoiceList"
			      	:data="invoiceData"
		    		stripe
		    		v-loading="invoice_search.ajax"
		    		style="width: 100%;"
		    		row-class-name="row-flex">
				  <el-table-column
					  type="selection"
					  width="55">
				  </el-table-column>
			      <el-table-column
			        prop="id"
			        label="ID"
			        width="100">
			      </el-table-column>
			      <el-table-column
			      	prop="invoice_title"
			        label="发票抬头"
			        min-width="200">
				      <template slot-scope="scope">
			        	{{scope.row.invoice_title}}
				      </template>
			      </el-table-column>
			      <el-table-column
			      	prop="price"
			        label="发票总额"
			        width="120">
			      </el-table-column>
			      <el-table-column
			      	prop="order_sum"
			        label="订单数量"
			        width="120">
			      </el-table-column>
			      <el-table-column
			        label="状态"
			        width="80">
				      <template slot-scope="scope">
				      	<transition>
				      		<el-button type="success" size="minism"
				      		v-if="scope.row.status==1">已处理</el-button>
				      		<el-button type="info" size="minism" 
				      		v-else="scope.row.status==0">待处理</el-button>
						</transition>
				      </template>
			      </el-table-column>
			      <el-table-column
			        label="时间线"
			        width="180">
				      <template slot-scope="scope">
				        <el-popover trigger="hover" placement="top">
				          <p>创建时间: {{ scope.row.create_time }}</p>
				          <p>更新时间: {{ scope.row.update_time }}</p>
				          <div slot="reference" class="name-wrapper">
				            <el-tag size="small" type="info">{{ scope.row.create_time }}</el-tag>
				          </div>
				        </el-popover>
				      </template>
			      </el-table-column>
			      <el-table-column
			        label="/"
			        width="100">
				      <template slot-scope="scope">
				        <el-button
				            type="info"
				            size="minism"
				            @click="showFind(scope.row)"
				            v-if="scope.row.status===1">
				            详情
				        </el-button>
				      </template>
			      </el-table-column>
			    </el-table>
			    <div class="py-3">
				<el-pagination
				  background
			      @current-change="handleCurrentChange"
			      :current-page="invoice_search.page"
			      :page-size="invoice_search.pageSize"
			      layout="total, prev, pager, next, jumper"
			      :total="invoice_search.total">
			    </el-pagination>
			    </div>
			</div>
			<div v-show="activeName==='invoice' && next">
				<div class="small py-3 bg-F4F4F4 rounded px-2">
					您选取了{{multipleSelection.length}}条单据开具发票（若选中多条订单，订单金额将合并开具在一张票据中），开票金额合计：<span class="text-success pr-2">￥ {{price}}</span>
				</div>
				<el-form label-width="120px">
					  <el-form-item label="发票抬头" v-if="invoiceInfo.type" class="mb-0">
					    {{invoiceInfo.invoice_title}}
					  </el-form-item>

					  <el-form-item label="开具类型" class="mb-0">
					  	{{invoiceInfo.type?'企业':'个人'}}
					  </el-form-item>

					  <el-form-item label="发票类型" class="mb-0">
					  	{{invoiceInfo.invoice_type?'增值税专用发票':'增值税普通发票'}}
					  </el-form-item>

					  <el-form-item label="税务登记证号" v-if="invoiceInfo.type" class="mb-0">
					    {{invoiceInfo.invoice_uscc}}
					  </el-form-item>

					  <el-form-item label="开户银行名称" v-if="invoiceInfo.type" class="mb-0">
					    {{invoiceInfo.bank_of_deposit}}
					  </el-form-item>

					  <el-form-item label="基本开户账号" v-if="invoiceInfo.type" class="mb-0">
					    {{invoiceInfo.basic_deposit_account}}
					  </el-form-item>
					  <el-form-item label="注册场所地址" v-if="invoiceInfo.type" class="mb-0">
					    {{invoiceInfo.reg_address}}
					  </el-form-item>

					  <el-form-item label="注册固定电话" v-if="invoiceInfo.type" class="mb-0">
					    {{invoiceInfo.reg_tel}}
					  </el-form-item>
					  <el-table
					    :data="invoiceInfo.mail_address"
					    style="width: 100%"
			    		header-cell-class-name="bg-F4F4F4"
					    @current-change="invoiceInfoAddressCurrent">
					    <el-table-column
					      width="50">
					      <template slot-scope="scope">
					      	<span class="el-radio__input mr-2" :class="{'is-checked':invoice.address_id==scope.row.id}">
					      		<span class="el-radio__inner"></span>
					      	</span>
					      </template>
					    </el-table-column>
					    <el-table-column
					      prop="name"
					      label="收件人"
					      width="100">
					    </el-table-column>
					    <el-table-column
					      prop="mobile"
					      label="电话号码"
					      width="120">
					    </el-table-column>
					    <el-table-column
					      label="地址">
					      <template slot-scope="scope">
					      	{{getAreaText(scope.row.area)}}{{scope.row.address}}
					      </template>
					    </el-table-column>
					    <el-table-column
					      prop="postcode"
					      label="邮编"
					      width="100">
					    </el-table-column>
					  </el-table>

					  <el-form-item class="pt-3">
					    <el-button @click="next=false;" size="small">上一步</el-button>
					    <el-button type="primary" @click="applyInvoice" size="small">索取发票</el-button>
					  </el-form-item>
				</el-form>
			</div>
			<div v-show="activeName!=='invoice'&&activeName!=='invoice_list'">
				<el-form :model="form" @submit.native.prevent="submitForm" :rules="rules" ref="form" label-width="120px" :label-position="labelPosition">
					<div v-show="activeName=='invoice_info'">

					  <el-form-item label="开具类型" prop="type">
					    <el-radio-group class="ml-0 ml-sm-2" v-model="form.type">
					      <el-radio :label="0">个人</el-radio>
					      <el-radio :label="1">企业</el-radio>
					    </el-radio-group>
					  </el-form-item>

					  <el-form-item label="发票抬头" prop="invoice_title">
					    <el-input v-model="form.invoice_title" class="col-12 col-sm-6 pl-0 pr-0" maxlength="30" show-word-limit></el-input>
					  </el-form-item>

					  <el-form-item label="发票类型" prop="invoice_type">
					    <el-radio-group class="ml-0 ml-sm-2" v-model="form.invoice_type">
					      <el-radio :label="0">增值税普通发票</el-radio>
					      <el-radio :label="1" v-if="form.type">增值税专用发票</el-radio>
					    </el-radio-group>
					  </el-form-item>

					  <el-form-item label="税务登记证号" prop="invoice_uscc" v-if="form.type">
					    <el-input v-model="form.invoice_uscc" class="col-12 col-sm-4 pl-0 pr-0"></el-input>
					  </el-form-item>

					  <el-form-item label="开户银行名称" :prop="form.invoice_type?'bank_of_deposit':''" v-if="form.type">
					    <el-input v-model="form.bank_of_deposit" class="col-12 col-sm-7 pl-0 pr-0"></el-input>
					  </el-form-item>

					  <el-form-item label="基本开户账号" :prop="form.invoice_type?'basic_deposit_account':''" v-if="form.type">
					    <el-input v-model="form.basic_deposit_account" class="col-12 col-sm-4 pl-0 pr-0"></el-input>
					  </el-form-item>
					  <el-form-item label="注册场所地址" :prop="form.invoice_type?'reg_address':''" v-if="form.type">
					    <el-input v-model="form.reg_address" class="col-12 col-sm-7 pl-0 pr-0"></el-input>
					  </el-form-item>

					  <el-form-item label="注册固定电话" :prop="form.invoice_type?'reg_tel':''" v-if="form.type">
					    <el-input v-model="form.reg_tel" class="col-12 col-sm-3 pl-0 pr-0"></el-input>
					  </el-form-item>
					</div>
					<div class="py-3" v-show="activeName=='mail_address'">
						<div class="pb-3 small">
							共{{form.mail_address.length}}个地址，最多保存5个
						</div>
						<el-table
						    :data="form.mail_address"
						    style="width: 100%"
				    		header-cell-class-name="bg-F4F4F4">
						    <el-table-column
						      prop="name"
						      label="收件人"
						      width="100">
						    </el-table-column>
						    <el-table-column
						      prop="mobile"
						      label="电话号码"
						      width="120">
						    </el-table-column>
						    <el-table-column
						      label="地址">
						      <template slot-scope="scope">
						      	<span class="text-danger small" v-if="scope.row.is_default">[默认]</span>{{getAreaText(scope.row.area)}}{{scope.row.address}}
						      </template>
						    </el-table-column>
						    <el-table-column
						      prop="postcode"
						      label="邮编"
						      width="100">
						    </el-table-column>
						    <el-table-column
						      label="操作"
						      width="120">
						      <template slot-scope="scope">
					    		<el-link type="primary" icon="el-icon-edit" :underline="false" @click="editItem(scope.$index,scope.row);">编辑</el-link>
								<el-link type="danger" icon="el-icon-delete" :underline="false" @click="delItem(scope.$index,scope.row);">删除</el-link>
						      </template>
						    </el-table-column>
						</el-table>
						<div class="py-3" v-if="!showAddMailAddress && !editForm.mail_address">
							<el-link type="success" :underline="false" @click="showAddMailAddress=true;">新增地址</el-link>
							<span class="text-secondary">(最多添加5个)</span>
						</div>
						<div class="py-3" v-if="showAddMailAddress || editForm.mail_address">
							<el-form-item label="收件人" prop="mail_address_name">
								<el-input v-model="mail_address.name" class="col-12 col-sm-3 pl-0 pr-0"></el-input>
							</el-form-item>
						  	<el-form-item label="选择地区" prop="mail_address_area">
							    <el-cascader 
							    	v-model="mail_address.area"
							    	placeholder="试试搜索：北京"
							    	filterable
									:props="defaultProps"
							    	:options="arealist"
							     	:show-all-levels="true" class="col-12 col-sm-5 pl-0 pr-0">
							    </el-cascader>
						  	</el-form-item>

							<el-form-item label="详细地址" prop="mail_address_address">
								<el-input v-model="mail_address.address" class="col-12 col-sm-8 pl-0 pr-0"></el-input>
							</el-form-item>

							<el-form-item label="联系电话" prop="mail_address_mobile">
								<el-input v-model="mail_address.mobile" class="col-12 col-sm-5 pl-0 pr-0" maxlength="11"></el-input>
							</el-form-item>

							<el-form-item label="邮政编码" prop="mail_address_postcode">
								<el-input v-model="mail_address.postcode" class="col-12 col-sm-2 pl-0 pr-0" maxlength="6"></el-input>
							</el-form-item>

							<el-form-item label="">
								<el-checkbox v-model="mail_address.is_default" :true-label="1" :false-label="0">设为默认地址</el-checkbox>
							</el-form-item>

							<div class="flex pb-5">
								<div style="width: 120px;"></div>
								<div class="flex-1">
									<el-button type="success" size="mini" @click="editComplete();">{{editForm.mail_address?'保存':'添加'}}</el-button>
					    			<el-button @click="resetDevelopmentHistory()" size="mini">取消</el-button>
								</div>
							</div>
						</div>
					</div>
					<div v-show="activeName=='email'">
						<el-form-item label="邮箱" prop="email">
						  	{{userInfo.email}}
						  	<el-link href="/user/security" type="primary" :underline="false" target="_blank">去设置</el-link>
						</el-form-item>
					</div>

				  <el-form-item>
				    <el-button type="primary" @click="submitForm('form')">立即保存</el-button>
				  </el-form-item>
				</el-form>
			</div>
		</div>
	</div>
</div>
<el-drawer
  title="我是标题"
  :visible.sync="selectedData.id"
  :before-close="handleClose"
  :with-header="false"
  ref="drawer">
  <div class="wrap h-100 p-3">
  	<div>
		<el-divider content-position="left">发票抬头</el-divider>
		<el-form label-width="120px">
			  <el-form-item label="发票抬头" v-if="selectedData.type" class="mb-0">
			    {{selectedData.invoice_title}}
			  </el-form-item>

			  <el-form-item label="开具类型" class="mb-0">
			  	{{selectedData.type?'企业':'个人'}}
			  </el-form-item>

			  <el-form-item label="发票类型" class="mb-0">
			  	{{selectedData.invoice_type?'增值税专用发票':'增值税普通发票'}}
			  </el-form-item>

			  <el-form-item label="税务登记证号" v-if="selectedData.type" class="mb-0">
			    {{selectedData.invoice_uscc}}
			  </el-form-item>

			  <el-form-item label="开户银行名称" v-if="selectedData.type" class="mb-0">
			    {{selectedData.bank_of_deposit}}
			  </el-form-item>

			  <el-form-item label="基本开户账号" v-if="selectedData.type" class="mb-0">
			    {{selectedData.basic_deposit_account}}
			  </el-form-item>
			  <el-form-item label="注册场所地址" v-if="selectedData.type" class="mb-0">
			    {{selectedData.reg_address}}
			  </el-form-item>

			  <el-form-item label="注册固定电话" v-if="selectedData.type" class="mb-0">
			    {{selectedData.reg_tel}}
			  </el-form-item>
		</el-form>
  	</div>
  	<div>
		<el-divider content-position="left">邮寄地址</el-divider>
		<el-form label-width="120px">
			  <el-form-item label="收件人" class="mb-0">
			    {{selectedData.name}}
			  </el-form-item>
			  <el-form-item label="电话号码" class="mb-0">
			    {{selectedData.mobile}}
			  </el-form-item>
			  <el-form-item label="地址" class="mb-0">
			    {{selectedData.area1_text}}{{selectedData.area2_text}}{{selectedData.area3_text}}{{selectedData.address}}
			  </el-form-item>
			  <el-form-item label="邮编" class="mb-0">
			    {{selectedData.postcode}}
			  </el-form-item>
		</el-form>
  	</div>
  	<div class="flex1" v-if="selectedData.status===1">
		<el-divider content-position="left">物流信息</el-divider>
		<el-form label-width="120px">
			  <el-form-item label="发票编号" class="mb-0">
			    {{selectedData.invoice_number}}
			  </el-form-item>
			  <el-form-item label="物流公司" class="mb-0">
			    {{selectedData.courier}}
			  </el-form-item>
			  <el-form-item label="物流单号" class="mb-0">
			    {{selectedData.courier_number}}
			  </el-form-item>
		</el-form>
  	</div>
  </div>
</el-drawer>
{/block}
{block name="footer"}
{include file="module/login"/}
{/block}
{block name="script"}
<script type="text/javascript">
	var arealist={xycms:arealist serialize="json"/};
	{empty name="Find"}
	var invoiceInfo={id:0};
	var formData={
				type:'',
				invoice_title:'',
				invoice_type:'',
				invoice_uscc:'',
				bank_of_deposit:'',
				basic_deposit_account:'',
				reg_address:'',
				reg_tel:'',
				mail_address:[]
			};
	{else/}
	var formData={:json_encode($Find,JSON_UNESCAPED_UNICODE)};
	var invoiceInfo={:json_encode($Find,JSON_UNESCAPED_UNICODE)};
	{/empty}
	var invoiceconfig={
		invoice_status:{xycms:invoiceconfig name="invoice_status"},
		invoice_min_price:{xycms:invoiceconfig name="invoice_min_price"},
	};
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			userInfo:UserInfo,
			loginTabs:XYBase.loginTabs,
			feedback:XYBase.feedback,
			preventWindowClose:false,
			labelPosition:'right',
			activeName:'invoice',
			next:false,
			invoiceconfig:invoiceconfig,
			selectedData:{
				id:0
			},
			invoice_search:{
				type:'invoice',
		    	ajax:false,
				total:0,
				per_page:0,
				page: 1
			},
			invoiceData:[],
			search:{
				type:'order',
		    	ajax:false,
				price:0,
				total:0,
				per_page:0,
				page: 1
			},
			invoice:{
				all_selected:0,
				address_id:invoiceInfo.default_address_id,
				oid:[],
			},
			all_selected:false,
			showAddMailAddress:false,
			price:0.00,
        	multipleSelection: [],
			tableData:[],
			arealist:arealist,
			form:formData,
			invoiceInfo:invoiceInfo,
			editForm:{
				mail_address:false,
			},
			mail_address:{
				id:0,
				index:null,
				name:'',
				area:[],
				address:'',
				mobile:'',
				postcode:'',
				is_default:''
			},
	        defaultProps: {
	          	value: 'id',
	          	label: 'title',
	          	children: 'data',
	        },
	        rules: {
	          type: [
	            { required: true, message: '请选择开具发票类型', trigger: 'change' },
	          ],
	          invoice_title: [
	            { required: true, message: '请输入发票抬头', trigger: 'blur' },
	          ],
	          invoice_type: [
	            { required: true, message: '请选择发票类型', trigger: 'change' },
	          ],
	          invoice_uscc: [
	            { required: true, message: '请输入税务登记证号', trigger: 'blur' },
	          ],
	          bank_of_deposit: [
	            { required: true, message: '请输入开户银行名称', trigger: 'blur' },
	          ],
	          basic_deposit_account: [
	            { required: true, message: '请输入基本开户账号', trigger: 'blur' },
	          ],
	          reg_address: [
	            { required: true, message: '请输入注册场所地址', trigger: 'blur' },
	          ],
	          reg_tel: [
	            { required: true, message: '请输入注册固定电话', trigger: 'blur' },
	          ],
	        }
		},
		watch:{
		    view:XYBase.viewWatch,
		    loginTabs:XYBase.loginTabsWatch,
			userInfo:{
				handler(val,oldVal){
					if (!val.id) {
						window.location.reload();
					}
				},
				deep:true
			},
			multipleSelection(val,oldVal){
				this.price=0;
				this.invoice.oid=[];
				var price=0;
				for (var i = 0; i < val.length; i++) {
					price=price+Number(val[i].oprice);
					this.invoice.oid.push(val[i].oid);
				}
				this.price=price.toFixed(2);
			}
		},
		created(){
			XYBase.created(this);
			if (this.invoiceconfig.invoice_status)
				this.initHtml();
			this.getInvoice();
		},
		methods:XYBase.methods({
			invoiceNext() {
				if (!this.invoiceconfig.invoice_status)return;
				if (this.invoice.oid.length<=0)return XYBase.msg('请先选择需要开票的订单');
				if (this.invoice) {}
				if (this.search.price<this.invoiceconfig.invoice_min_price)return XYBase.msg('可开票总额小于'+this.invoiceconfig.invoice_min_price+'元');
				if (!this.invoiceInfo.id)return XYBase.msg('请先创建发票抬头');
				this.next=true;
			},
			invoiceInfoAddressCurrent(row){
				this.invoice.address_id=row.id;
			},
			applyInvoice(){
				if (!this.invoiceconfig.invoice_status)return;
				if (this.invoice.oid.length<=0)return XYBase.msg('请先选择需要开票的订单');
				if (this.invoice) {}
				if (this.search.price<this.invoiceconfig.invoice_min_price)return XYBase.msg('可开票总额小于'+this.invoiceconfig.invoice_min_price+'元');
				if (!this.invoiceInfo.id)return XYBase.msg('请先创建发票抬头');
				var _this=this;
				var loading=XYBase.openloading();
					_this.sendPost({
						url:'/user/invoice/applyInvoice',
						data:_this.invoice,
					},function(ret){
						loading.close();
						if (ret) {
							if (ret.code === 0) {
								XYBase.success(ret.msg);
								_this.next=false;
								_this.getInvoiceAll();
							}else XYBase.msg(ret.msg);
						}
					});
			},
			getAreaText(area) {
				var areaText='';
				for (var i = 0; i < this.arealist.length; i++) {
					if (area[0]===this.arealist[i].id) {
						areaText=areaText+this.arealist[i].title;
						for (var j = 0; j < this.arealist[i].data.length; j++) {
							if (area[1]===this.arealist[i].data[j].id) {
								areaText=areaText+this.arealist[i].data[j].title;
								for (var n = 0; n < this.arealist[i].data[j].data.length; n++) {
									
									if (area[2]===this.arealist[i].data[j].data[n].id)
									areaText=areaText+this.arealist[i].data[j].data[n].title;
								}
							}
						}
					}
				}
				return areaText;
			},
		    toggleSelectionAll(val) {
		    	if (val) {
		    		this.all_selected=true;
	            	this.$refs.multipleTable.toggleAllSelection();
		    	}else{
		    		this.all_selected=false;
		          	this.$refs.multipleTable.clearSelection();
		      	}
		    },
		    handleSelectionChange(val) {
		        this.multipleSelection = val;
		        if (!this.multipleSelection.length) {
		    		this.all_selected=false;
		        }
		        if (this.multipleSelection.length>=this.tableData.length) {
		    		this.all_selected=true;
		        }else if(this.multipleSelection.length){
		    		this.all_selected=false;
		        }
	      	},
			getInvoiceAll(val){
				var loading=XYBase.openloading();
				// this.price=100;
				var _this=this;
				if (val) {
					_this.sendGet({
						url:'',
						data:_this.invoice,
					},function(ret){
						loading.close();
						if (ret) {
							_this.tableData=[];
							_this.search.total=ret.data.total;
							_this.search.price=0;
							_this.search.per_page=ret.data.per_page;
							if (ret.code === 0) {
								_this.search.price=ret.msg;
								_this.tableData=ret.data.data;
								_this.toggleSelectionAll(1);
							}else XYBase.msg(ret.msg);
						}
					});
				}else{
					loading.close();
					this.all_selected=false;
					this.invoice.all_selected=0;
					this.search.total=0;
					this.search.per_page=0;
					this.search.page=0;
					this.initHtml();
				}
			},
			setPageChange(val){
				this.search.page=val;
				this.initHtml();
			},
			initHtml(){
				var _this=this;
				_this.search.ajax=true;
				_this.search.all_selected=this.invoice.all_selected;
				_this.sendGet({
					url:'',
					data:_this.search,
				},function(ret){
					_this.search.ajax=false;
					if (ret) {
						_this.tableData=[];
						_this.search.total=ret.data.total;
						_this.search.price=0;
						_this.search.per_page=ret.data.per_page;
						if (ret.code === 0) {
							_this.search.price=ret.msg;
							_this.tableData=ret.data.data;
						}else XYBase.msg(ret.msg);
					}
				});
			},
			showFind(row) {
				this.selectedData=row;
			},
		    handleClose(done) {
				this.selectedData={id:0};
		    },
			handleCurrentChange(val){
				this.search.page=val;
				this.getInvoice();
			},
			getInvoice(){
				var _this=this;
				_this.invoice_search.ajax=true;
				_this.sendGet({
					url:'',
					data:_this.invoice_search,
				},function(ret){
					_this.invoice_search.ajax=false;
					if (ret) {
						_this.invoiceData=[];
						_this.invoice_search.total=ret.data.total;
						_this.invoice_search.per_page=ret.data.per_page;
						if (ret.code === 0) {
							_this.invoiceData=ret.data.data;
						}else XYBase.msg(ret.msg);
					}
				});
			},
			editItem(index,row){
				var obj={
					id:row.id,
					index:index,
					name:row.name,
					area:row.area,
					address:row.address,
					mobile:row.mobile,
					postcode:row.postcode,
					is_default:row.is_default
				};
				this.editForm.mail_address=true;
				this.mail_address=obj;
			},
			delItem(index,row){
				var _this=this;
				_this.$confirm('确定要删除【'+row.name+'】邮寄地址吗？', '提示', {
		          confirmButtonText: '删除',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
					if (row.id) {
						const loading=XYBase.openloading();
						_this.sendGet({
							url:'/user/invoice/delInvoiceTitleMailAddress/'+row.id,
						},function(ret){
							loading.close();
							if (ret) {
								if (ret.code === 0) {
									_this.form.mail_address.splice(index,1);
					        		XYBase.success('已删除');
								}else{XYBase.msg(ret.msg);}
							}
						});
					}else{
						_this.form.mail_address.splice(index,1);
		        		XYBase.success('已删除');
					}
		        }).catch(() => {
		        	XYBase.msg('已取消');
		        });
			},
			editComplete(){
				var _this=this;
		  		if(_this.mail_address.name 
		  			&& _this.mail_address.area
		  			&& _this.mail_address.address
		  			&& _this.mail_address.mobile
		  			&& _this.mail_address.postcode){
					_this.preventWindowClose=true;
			  		var obj={
			  			id:_this.mail_address.id,
			  			name:_this.mail_address.name,
						area:_this.mail_address.area,
						address:_this.mail_address.address,
						mobile:_this.mail_address.mobile,
						postcode:_this.mail_address.postcode,
						is_default:_this.mail_address.is_default,
			  		};
			  		if (_this.editForm.mail_address && _this.mail_address.index!=null) {
			  			obj.edit=1;
				  		_this.form.mail_address.splice(_this.mail_address.index,1,obj);
				  		_this.mail_address.index=null;
				  		_this.editForm.mail_address=false;
			  		}else{
			  			if (_this.form.mail_address.length>=5) return XYBase.msg('最多保存5个');
				  		_this.form.mail_address.push(obj);
			  		}
			  		_this.mail_address.id=0;
			  		_this.mail_address.name='';
			  		_this.mail_address.area='';
			  		_this.mail_address.address='';
			  		_this.mail_address.mobile='';
			  		_this.mail_address.postcode='';
			  		_this.mail_address.is_default='';
					_this.showAddMailAddress=false;
		  		}
			},
			resetDevelopmentHistory(){
				var obj={
					id:0,
					index:null,
					name:'',
					area:'',
					address:'',
					mobile:'',
					postcode:'',
					is_default:''
				};
		  		this.editForm.mail_address=false;
				this.mail_address=obj;
				this.showAddMailAddress=false;
			},
			submitForm:function(formName) {
				var _this=this;
				var D=_this.form;
					if (!D.type&&!D.invoice_title)
					D.invoice_title='个人';
				_this.$refs[formName].validate((valid) => {
				  if (valid) {
					const loading = XYBase.openloading();
					_this.sendPost({
						url:'/user/invoice/saveInvoiceTitle',
						data:D,
					},function(ret){
				        loading.close();
				        if (ret) {
							if(ret.code == 0){
								_this.form=ret.data;
								_this.invoiceInfo=ret.data;
								XYBase.success(ret.msg);
								setTimeout(function(){
									_this.preventWindowClose=false;
								},300);
							}else{
								XYBase.msg(ret.msg);
							}
				        }
					});
				  } else {
					return XYBase.warning('请先把表单填写完整。');
				  }
				});
			},
		})
	});
$(function(){
	reloadWindowSize();
	$(window).resize(function(){
		reloadWindowSize();
	});
});
function reloadWindowSize (argument) {
	var winW=$(window).width();
	if(winW <= 576){
		vm.labelPosition='top';
	}else{
		vm.labelPosition='right';
	}
}
window.onbeforeunload=function(e){
	if (vm.preventWindowClose) {
		vm.$confirm('您的发票抬头信息还未保存，确定离开当前页面吗？', '提示', {
          confirmButtonText: '保存',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        	vm.submitForm('form');
        }).catch(() => {
			vm.preventWindowClose=false;
        	XYBase.msg('已取消');
        });
	　　var e = window.event||e;  
	　　e.returnValue=("确定离开当前页面吗？");
	}
} 
</script>
{/block}