<template>
  <div class="app-container">
  	<div style="margin-bottom:10px">
  		<el-button type="success" @click="addBtn">新增</el-button>
  	</div>
    <!--搜索-->
    <el-form class="mt_15" ref="form" inline size="small">
  		<el-form-item label="账号">
    		<el-input v-model.trim="searchParm.account" clearable placeholder='关键词'></el-input>
  		</el-form-item>
  		<el-form-item label="收藏链接">
    		<el-input v-model.trim="searchParm.linkUrl" clearable></el-input>
  		</el-form-item>
  		<el-form-item label="状态">
  			<el-select v-model.trim="searchParm.status" placeholder="请选择">
			    <el-option
			      v-for="item in statusList"
			      :key="item.name"
			      :label="item.name"
			      :value="item.id">
			    </el-option>
			  </el-select>
  		</el-form-item>
  		<el-form-item>
    		<el-button type="primary" @click="goSearch">搜索</el-button>
    		<el-button type="warning" @click="resetForm">重置</el-button>
  		</el-form-item>
		</el-form>
    <!--表格渲染-->
    <el-table ref="table" border size="small" :data="list" :header-cell-style="{textAlign:'center'}">
    	<el-table-column label="序号" type="index" width="50" />
    	<el-table-column label="买家ID" prop="buyerId" align="center"/>
    	<el-table-column label="账号" prop="account" align="center"/>
    	<el-table-column label="国家" prop="country" align="center"/>
      <el-table-column label="状态描述" prop="paymentResults" align="center"/>
      <el-table-column label="状态" prop="status" align="center">
      	<template slot-scope="scope">
	     		{{ scope.row.status | getStatus}}
	     	</template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createdAt" align="center"/>
      <el-table-column label="修改时间" prop="updatedAt" align="center"/>
      <el-table-column label="操作" width="270" align="left" >
      	<template slot-scope="scope">
					<el-button type="info" @click="getBtnById(scope.row.id)">查看</el-button>
					<el-button type="warning" @click="editById(scope.row)" style="margin-left: 0px">修改</el-button>
					<span v-if="scope.row.status == 1" slot="footer">
      			<el-button type="danger" @click="delById(scope.row.id)">删除</el-button>
      		</span>
      	</template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div class="mt_15">
	    <el-pagination
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="searchParm.page"
	      :page-sizes="[10, 20, 30, 40, 50]"
	      :page-size="searchParm.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="total">
	    </el-pagination>
  </div>
  
  <!--新增弹窗-->
  <el-dialog :visible.sync="dialogAddVisible" :title="dialogAddTitle" center width="45%">
  	<div class="dialog-content">
  		 <el-form ref="addParm" size="small" :model="addParm" :rules="rules" label-width="100px">
  		 	<el-form-item label="买家账号" prop="buyerName">
            <el-input v-model.trim="addParm.buyerName" clearable style="width:270px"/>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="goSearchBuyer"
              style="width:130px"
            >请选择买家</el-button>
          </el-form-item>
	  		<div v-for="(item, index) in form.dynamicItem" :key="index">
	  			<el-form-item label="收藏链接" prop="'dynamicItem.' + index + 'linkUrl'">
		    		<el-input v-model.trim="item.linkUrl" clearable></el-input>
		  		</el-form-item>
		  		<el-form-item>
		  			<el-button v-if="index+1 == form.dynamicItem.length" @click="addItem" type="primary">增加</el-button>
		  			<el-button v-if="index !== 0" @click="deleteItem(item,index)" type="danger">删除</el-button>
		  		</el-form-item>
	  		</div>
			</el-form>
  	</div>
  	<span slot="footer">
  		<el-button type="info" @click="sureAddCancle('addParm')">取消</el-button>
      <el-button type="primary" @click="sureAdd('addParm')">确认</el-button>
  	</span>
  </el-dialog>
  
  
  <!-- 买家弹窗 -->
	<el-dialog :visible.sync="dialogBuyerVisible" :title="dialogBuyerTitle" center width="75%">
	  <div class="dialog-content">
	    <!--搜索-->
	    <el-form class="mt_15" ref="form" inline size="small">
	      <el-form-item label="账号">
	        <el-input v-model.trim="searchBuyerParm.account" clearable placeholder="账号"></el-input>
	      </el-form-item>
	      <el-form-item label="昵称">
	        <el-input v-model.trim="searchBuyerParm.nickName" clearable></el-input>
	      </el-form-item>
	      <el-form-item label="密码">
	        <el-input v-model.trim="searchBuyerParm.pwd" clearable></el-input>
	      </el-form-item>
	      <el-form-item label="公司">
	        <el-select v-model.trim="searchBuyerParm.companyId" placeholder="请选择">
	          <el-option
	            v-for="item in companys"
	            :key="item.name"
	            :label="item.name"
	            :value="item.id"
	          ></el-option>
	        </el-select>
	      </el-form-item>
	      <el-form-item label="平台">
	        <el-select v-model.trim="searchBuyerParm.platformId" placeholder="请选择">
	          <el-option
	            v-for="item in platformList"
	            :key="item.id"
	            :label="item.name"
	            :value="item.id"
	          ></el-option>
	        </el-select>
	      </el-form-item>
	      <el-form-item>
	        <el-button type="primary" @click="goSearchBuyer">搜索</el-button>
	        <el-button type="warning" @click="resetBuyerForm">重置</el-button>
	      </el-form-item>
	    </el-form>
	    <!--表格渲染-->
	    <el-table
	      ref="table"
	      border
	      size="small"
	      :data="buyerList"
	      :header-cell-style="{textAlign:'center'}"
	      :cell-style="{textAlign:'center'}"
	    >
	      <el-table-column label="序号" type="index" width="50" />
	      <el-table-column label="账号" prop="account" />
	      <el-table-column label="所属国家" prop="contntryShort" />
	      <el-table-column label="昵称" prop="nickName" />
	      <el-table-column label="密码" prop="pwd" />
	      <el-table-column label="公司" prop="companyName" />
	      <el-table-column label="平台" prop="platformName" />
	      <el-table-column label="VPNIP" prop="ipAddress" />
	      <el-table-column label="信用卡卡号" prop="number" />
	      <el-table-column label="州" prop="state" />
	      <el-table-column label="国家" prop="country" />
	      <el-table-column label="地址1" prop="addressline1" />
	      <el-table-column label="占用状态" prop="status">
	        <template slot-scope="scope">{{ scope.row.status | getBuyerStatus}}</template>
	      </el-table-column>
	      <el-table-column label="创建时间" prop="createdAt" />
	      <el-table-column label="修改时间" prop="updatedAt" />
	      <el-table-column label="操作" width="220">
	        <template slot-scope="scope">
	          <el-button type="info" @click="getBuyerBtnById(scope.row.id)">查看</el-button>
			  <el-button type="success" @click="getBuyerById(scope.row)" v-if="buyerId !== scope.row.id">选中</el-button>
			  <div v-if="buyerId === scope.row.id">已选中</div>
	        </template>
	      </el-table-column>
	    </el-table>
	    <!--分页-->
	    <div class="mt_15">
	      <el-pagination
	        @size-change="handleSizeChange"
	        @current-change="handleCurrentChange"
	        :current-page="searchBuyerParm.page"
	        :page-sizes="[10, 20, 30, 40, 50]"
	        :page-size="searchBuyerParm.pageSize"
	        layout="total, sizes, prev, pager, next, jumper"
	        :total="total"
	      ></el-pagination>
	    </div>
	  </div>
	</el-dialog>
  
  
   <!--修改弹窗-->
  <el-dialog :visible.sync="dialogEditVisible" :title="dialogEditTitle" center width="45%">
  	<div class="dialog-content">
  		 <el-form ref="editParm" size="small" :model="editParm" :rules="rules" label-width="100px">
	  		<el-form-item label="买家账号" prop="buyerName">
	        <el-input v-model.trim="editParm.buyerName" :disabled="true" style="width:200px" />
	        <el-button
	          type="primary"
	          icon="el-icon-search"
	          @click="goSearchBuyer"
	          style="width:130px"
	        >请选择设</el-button>
	      </el-form-item>
	  		<div v-for="(item, index) in form.dynamicItem" :key="index">
	  			<el-form-item label="收藏链接" prop="linkUrl">
		    		<el-input v-model.trim="item.linkUrl" clearable></el-input>
		  		</el-form-item>
		  		<el-form-item>
		  			<el-button v-if="index+1 == form.dynamicItem.length" @click="addItem" type="primary">增加</el-button>
		  			<el-button v-if="index !== 0" @click="deleteItem(item,index)" type="danger">删除</el-button>
		  		</el-form-item>
	  		</div>
			</el-form>
  	</div>
  	<span slot="footer">
  		<el-button type="info" @click="sureEditCancle('editParm')">取消</el-button>
      <el-button type="primary" @click="sureEdit('editParm')">确认</el-button>
  	</span>
  </el-dialog>
  
  
  <!--详情弹窗-->
  <el-dialog :visible.sync="dialogDetailVisible" :title="dialogDetailTitle" center width="45%">
  	<div class="dialog-content">
  		 <el-form ref="form" size="small" label-width="100px">
	  		<el-form-item label="国家" prop="country">
	    		<el-input v-model.trim="detailParm.country" :disabled="true" clearable></el-input>
	  		</el-form-item>
	  		<el-form-item label="账号" prop="account">
	    		<el-input v-model.trim="detailParm.account" :disabled="true" clearable></el-input>
	  		</el-form-item>
	  		<el-form-item label="收藏链接" prop="linkUrl">
	    		<el-input v-model.trim="detailParm.linkUrl" :disabled="true" clearable></el-input>
	  		</el-form-item>
	  		<el-form-item label="执行结果" prod="response">
	    		<el-input v-model.trim="detailParm.response" :disabled="true" clearable></el-input>
	  		</el-form-item>
	  		<el-form-item label="状态" prod="status">
  			<el-select v-model.trim="detailParm.status" :disabled="true" placeholder="请选择">
			    <el-option
			      v-for="item in detailStatusList"
			      :key="item.name"
			      :label="item.name"
			      :value="item.id">
			    </el-option>
			  </el-select>
			  </el-form-item>
			</el-form>
  	</div>
  </el-dialog>
  
  <!--详情弹窗-->
    <el-dialog :visible.sync="dialogBuyerDetailVisible" :title="dialogBuyerDetailTitle" center width="45%">
      <div class="dialog-content">
        <el-form ref="form" size="small" label-width="120px">
          <el-form-item label="账号" prop="account">
            <el-input v-model.trim="detailBuyerParm.account" :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="昵称" prop="nickName">
            <el-input v-model.trim="detailBuyerParm.nickName" :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="pwd">
            <el-input v-model.trim="detailBuyerParm.pwd" :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="公司" prop="companyId">
            <el-select v-model.trim="detailBuyerParm.companyId" disabled placeholder="请选择">
              <el-option
                v-for="item in companys"
                :key="item.name"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="平台" prop="platformId">
            <el-select v-model.trim="detailBuyerParm.platformId" disabled placeholder="请选择">
              <el-option
                v-for="item in platformList"
                :key="item.name"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>

          <!--国家-->
          <el-form-item label="国家" prop="contntryShort">
            <el-input v-model.trim="detailBuyerParm.contntryShort" disabled clearable></el-input>
          </el-form-item>
          <!--VPN vpnId -->
          <el-form-item label="VPNIP" prop="vpnIp">
            <el-input v-model.trim="detailBuyerParm.vpnIp" disabled clearable></el-input>
          </el-form-item>
          <!--信用卡ID  cardId -->
          <el-form-item label="信用卡卡号" prop="cardNumber">
            <el-input v-model.trim="detailBuyerParm.cardNumber" disabled clearable></el-input>
          </el-form-item>
          <!--用户等级    level -->
          <el-form-item label="用户等级" prop="level">
            <el-select v-model.trim="detailBuyerParm.level" disabled placeholder="请选择">
              <el-option
                v-for="item in levelList"
                :key="item.name"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <!--占用状态 occupyStatus -->
          <el-form-item label="占用状态" prop="occupyStatus">
            <el-select v-model.trim="detailBuyerParm.occupyStatus" disabled placeholder="请选择">
              <el-option
                v-for="item in occupyStatusList"
                :key="item.name"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <!--状态 status -->
          <el-form-item label="状态" prop="status">
            <el-select v-model.trim="detailBuyerParm.status" disabled placeholder="请选择">
              <el-option
                v-for="item in buyerStatusList"
                :key="item.name"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <!--占用账户-->
          <el-form-item label="占用账户" prop="occupyAccount">
            <el-input v-model.trim="detailBuyerParm.occupyAccount" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--账户余额-->
          <el-form-item label="账户余额" prop="balance">
            <el-input v-model.trim="detailBuyerParm.balance" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--购买总金额-->
          <el-form-item label="账户购买总金额" prop="buyTotalMoney">
            <el-input v-model.trim="detailBuyerParm.buyTotalMoney" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--地址1-->
          <el-form-item label="地址1" prop="addressline1">
            <el-input v-model.trim="detailBuyerParm.addressline1" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--国家-->
          <el-form-item label="国家" prop="country">
            <el-input v-model.trim="detailBuyerParm.country" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--州-->
          <el-form-item label="州" prop="state">
            <el-input v-model.trim="detailBuyerParm.state" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--电话-->
          <el-form-item label="电话" prop="tel">
            <el-input v-model.trim="detailBuyerParm.tel" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--lastname-->
          <el-form-item label="lastname" prop="lastname">
            <el-input v-model.trim="detailBuyerParm.lastname" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--税号-->
          <el-form-item label="税号" prop="vatNumber">
            <el-input v-model.trim="detailBuyerParm.vatNumber" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--城市-->
          <el-form-item label="城市" prop="city">
            <el-input v-model.trim="detailBuyerParm.city" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--地址2-->
          <el-form-item label="地址2" prop="addressline2">
            <el-input v-model.trim="detailBuyerParm.addressline2" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--firstname-->
          <el-form-item label="firstname" prop="firstname">
            <el-input v-model.trim="detailBuyerParm.firstname" :disabled="true" clearable></el-input>
          </el-form-item>
          <!--邮政编码-->
          <el-form-item label="邮政编码" prop="postalcode">
            <el-input v-model.trim="detailBuyerParm.postalcode" :disabled="true" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>
<script>
	import { add, editById, getList, getById, deleteById } from '@/api/group/browse'
	import { getBuyerList, getBuyerById } from "@/api/group/dhPay";
	import { getAll } from "@/api/group/company";
export default {
	filters: {
	  getStatus: function (value) {
			   if(value == 1) {
			   		return '待执行';
			   } else if (value == 2) {
			   		return '执行中';
			   } else if (value == 3) {
			   		return '执行成功';
			   } else if(value == 4) {
			   		return '执行失败';
			   }
		  },
		getBuyerStatus:function (value) {
	  	if(value == 1) {
		   	return '已占用';
		   } else{
		   	return '未占用';
		   }
	  }
	},
//	数据
  data() {
    return {
    	searchParm: {
    		page: 1,
    		pageSize: 10,
    		sort:'created_at',
    		order:'desc',
    		account:null,
    		status:null,
    		linkUrl:null
    	},
    	total:0,
      list: [],
      buyerList: [],
      companys:[],
      buyerId: null,
      form: {
      	dynamicItem: [
      		{linkUrl:null}
      	]
      },
	  	uploadHeaders:{ Authorization: this.$store.getters.token },
      dialogAddVisible: false,
      dialogAddTitle: '新增',
      dialogDetailVisible: false,
      dialogDetailTitle: '详情',
      dialogEditVisible: false,
      dialogEditTitle: '修改',
      dialogBuyerVisible: false,
      dialogBuyerTitle: "买家列表",
      dialogBuyerVisible: false,
      dialogBuyerTitle: "买家列表",
      dialogBuyerDetailVisible: false,
	    dialogBuyerDetailTitle: "买家详情",
      updateBoolean: false,
      tempUrl: process.env.VUE_APP_BASE_API + '/api/clickFarming/exportTemp',
     
	   		detailStatusList:[
	        {
	          id: 1,
	          name: '待执行'
	        },
      		{
	          id: 2,
	          name: '执行中',
      		},
      		{
	          id: 3,
	          name: '执行成功'
	        },
      		{
	          id: 4,
	          name: '执行失败'
	        }],
	    statusList:[
	    		{
	          id: null,
	          name: '全部'
	        },
	        {
	          id: 1,
	          name: '待执行'
	        },
      		{
	          id: 2,
	          name: '执行中',
      		},
      		{
	          id: 3,
	          name: '执行成功'
	        },
      		{
	          id: 4,
	          name: '执行失败'
	        }],
	    addMonthList:[
	        {
	          name: 'January (01)'
	        },
      		{
	          name: 'February (02)'
	        },{
	          name: 'March (03)'
	        },{
	          name: 'April (04)'
	        },{
	          name: 'May (05)'
	        },{
	          name: 'June (06)'
	        },{
	          name: 'July (07)'
	        },{
	          name: 'August (08)'
	        },{
	          name: 'September (09)'
	        },{
	          name: 'October (10)'
	        },{
	          name: 'November (11)'
	        },{
	          name: 'December (12)'
	        }
      	],
	      occupyStatusList: [
	        {
	          id: 1,
	          name: "已占用"
	        },
	        {
	          id: 2,
	          name: "未占用"
	        }
	      ],
	      buyerStatusList: [
	      	{
	          id: 1,
	          name: "待注册"
	        },
	        {
	          id: 2,
	          name: "待验证"
	        },
	        {
	          id: 3,
	          name: "待完善"
	        },
	        {
	          id: 4,
	          name: "正常"
	        },
	        {
	          id: 5,
	          name: "异常"
	        },
	        {
	          id: 6,
	          name: "可用但已用"
	        },
	        {
	          id: 7,
	          name: "删除"
	        }
	      ],
	      levelList: [
	        {
	          id: 1,
	          name: "普通"
	        },
	        {
	          id: 2,
	          name: "精品"
	        },
	        {
	          id: 3,
	          name: "压力"
	        },
	        {
	          id: 4,
	          name: "内部账号"
	        }
	      ],
	      platformList: [
	        {
	          id: 1,
	          name: "敦煌"
	        },
	        {
	          id: 2,
	          name: "速卖通"
	        },
	        {
	          id: 3,
	          name: "马帮"
	        }
	      ],
      addParm: {
      	buyerId:null,
    		linkUrl: null
      },
      searchBuyerParm: {
        page: 1,
        pageSize: 10,
        account: null,
        sort: "created_at",
        order: "desc",
        nickName: null,
        pwd: null,
        companyId: null,
        platformId: null
      },
      supplementParm: {
      	clickFarmingId: null,
      	amount: null,
      	paymentResults: null,
      	shop: null,
      	pricesNumber: null,
      	orderId: null,
      	shopName: null,
      	orderDate: null
      },
      editParm: {
      	id: null,
      	buyerId:null,
      	buyerName:null,
    		linkUrl: null
      },
      detailParm: {
      	id: null,
      	buyerId:null,
      	country:null,
      	account: null,
    		vpnShare:null,
    		linkUrl: null,
    		paymentResults: null,
    		status:null
      },
      orderDetailParm: {
      	id: null,
      	createdAt:null,
    		updatedAt:null,
    		amount:null,
    		paymentResults:null,
    		shop:null,
    		pricesNumber:null,
    		orderId:null,
    		shopName:null,
    		orderDate:null
      },
      detailBuyerParm: {
      	id: null,
      	nickName:null,
    		pwd:null,
    		account: null,
    		companyId:null,
    		platformId:null,
    		contntryShort:null,
    		vpnId:null,
				vpnIp:null,
  			cardId:null,
				cardNumber:null,
  			level:null,
  			occupyStatus:null,
  			addressline1:null,
  			country:null,
  			state:null,
  			tel:null,
  			lastname:null,
  			vatNumber:null,
  			city:null,
  			addressline2:null,
  			firstname:null,
  			postalcode:null,
  			status:null
      },
      rules: {
       country: [
         { required: true, message: '请输入国家', trigger: 'blur' }
       ],
        account: [
         { required: true, message: '请输入PIN码', trigger: 'blur' }
       ],
        pwd: [
         { required: true, message: '请输入密码', trigger: 'blur' }
       ],
        vpnShare: [
         { required: true, message: '请输入vpn', trigger: 'blur' }
       ],
       linkUrl: [
         { required: true, message: '请输入vpn', trigger: 'blur' }
       ],
       buyerId: [
         { required: true, message: '请输入买家ID', trigger: 'blur' }
       ]
      }
    }
  },
  // 调用
  created() {
		this.goSearch();
  },
	//方法
  methods: {
	//重置
  	resetForm() {
        this.searchParm.keyWord = null;
				this.searchParm.item=null;
    		this.searchParm.status=null;
    		this.searchParm.shopName='';
    		this.searchParm.payOrderId=null;
    		this.goSearch()
	  },
	  // input 增加 删除方法
	  addItem() {
	  	this.form.dynamicItem.push({
	  		linkUrl: null
	  	});
	  },
	  deleteItem(item,index) {
	  	this.form.dynamicItem.splice(index, 1);
	  },
	  // 获取所有公司信息
    getCompanyAll() {
      getAll()
        .then(res => {
          this.companys = res.data;
          if (res.code == 200) {
            console.log(this.companys);
          }
        })
        .catch(() => {});
    },
	  resetBuyerForm() {
      this.searchBuyerParm.account = null;
      this.searchBuyerParm.pwd = null;
      this.searchBuyerParm.nickName = null;
      this.searchBuyerParm.companyId = null;
      this.searchBuyerParm.platformId = null;
      this.goSearchBuyer();
    },
   	//	查询
		goSearch() {
			this.searchParm.page=1;
			this.getCompanyAll();
			this.getDataList();
		},
		goSearchBuyer() {
      this.dialogBuyerVisible = true;
      this.searchBuyerParm.page = 1;
      this.getBuyerDataList();
    },
    getBuyerDataList() {
      getBuyerList(this.searchBuyerParm)
        .then(res => {
          console.log(res);
          if (res.code == 200) {
            this.buyerList = res.data.list;
            this.buyerTotal = res.data.total;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //	根据id删除
		delById(id){
			this.$confirm('确认删除?','提示',{
				confirmButtonText: '确定',
	      cancelButtonText: '取消',
	      type: 'warning'
			}).then(() => {
				delete({id}).then(res => {
					if(res.code==200) {
						this.$message.success('删除成功!')
						this.getDataList()
					}
				}).catch(err => {
					console.log(err)
				})
			}).catch(() => {
				this.$message.info('取消删除')
			})
		},
		
    getBuyerById(data){
			this.buyerName = data.account;
			this.buyerId = data.id;
			if(this.dialogAddVisible == true) {
				this.addParm.buyerId = data.id;
				this.addParm.buyerName = data.account;
			}
			
			if(this.dialogEditVisible == true) {
				this.editParm.buyerId = data.id;
				this.editParm.buyerName = data.account;
			}
			
			this.dialogBuyerVisible = false;
			console.log(data);
			this.$message.success("选择成功");
		},
		// 查看买家信息根据id
    getBuyerBtnById(id) {
      getBuyerById({ id })
        .then(res => {
          if (res.code == 200) {
            this.detailBuyerParm.id = res.data.id;
            this.detailBuyerParm.nickName = res.data.nickName;
            this.detailBuyerParm.pwd = res.data.pwd;
            this.detailBuyerParm.account = res.data.account;
            this.detailBuyerParm.companyId = res.data.companyId;
            this.detailBuyerParm.platformId = res.data.platformId;
            this.detailBuyerParm.contntryShort = res.data.contntryShort;
            this.detailBuyerParm.vpnId = res.data.vpnId;
            this.detailBuyerParm.vpnIp = res.data.ipAddress;
            this.detailBuyerParm.cardNumber = res.data.number;
            this.detailBuyerParm.cardId = res.data.cardId;
            this.detailBuyerParm.level = res.data.level;
            this.detailBuyerParm.occupyStatus = res.data.occupyStatus;
            this.detailBuyerParm.occupyAccount = res.data.occupyAccount;
            this.detailBuyerParm.balance = res.data.balance;
            this.detailBuyerParm.buyTotalMoney = res.data.buyTotalMoney;
            this.detailBuyerParm.addressline1 = res.data.addressline1;
            this.detailBuyerParm.country = res.data.country;
            this.detailBuyerParm.state = res.data.state;
            this.detailBuyerParm.tel = res.data.tel;
            this.detailBuyerParm.lastname = res.data.lastname;
            this.detailBuyerParm.vatNumber = res.data.vatNumber;
            this.detailBuyerParm.city = res.data.city;
            this.detailBuyerParm.addressline2 = res.data.addressline2;
            this.detailBuyerParm.firstname = res.data.firstname;
            this.detailBuyerParm.postalcode = res.data.postalcode;
            this.detailBuyerParm.status = res.data.status;

            this.dialogBuyerDetailVisible = true;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
		beforeAvatarUpload(file) {
	    console.log(file);
	//  const isXlsl = file.type === 'xlsl';
	    const isLt10M = file.size / 1024 / 1024 <10;
	
	//  if (!isXlsl) {
	//    this.$message.error('上传头像图片只能是 xlsl 格式!');
	//  }
	    if (!isLt10M) {
	      this.$message.error('上传头像图片大小不能超过 10MB!');
	    }
	//  return isXlsl && isLt10M;
	    return isLt10M;
	 },
  uploadSuccess(res, file) {
  	this.dialogImportVisible = false;
    if(res.code==200) {
    	  console.log(res.data);
				this.$message.success('导入成功!');
				
				if(res.data != null) {
					window.location.href = res.data;
				}
		}
			this.getDataList();
  },
		// 新增
		addBtn(){
			this.addParm = {    		
    		buyerId:null,
      	country:null,
      	account: null,
    		pwd:null,
    		vpnShare:null,
    		linkUrl: null
		  }
			this.form.dynamicItem[0].linkUrl = null;
			this.dialogAddVisible = true;
		},
		//	修改
		editById(data){
			
			getById({id: data.id}).then(res => {
				if(res.code==200) {
					
					// input 增加 删除 处理
					this.form.dynamicItem = [];
					if (res.data.linkUrl.includes(";")) {
						res.data.linkUrl.split(';').forEach((item) => {
						    this.form.dynamicItem.push({
						  		linkUrl: item
						  	});
						});
					} else {
						this.form.dynamicItem.push({
				  		linkUrl: res.data.linkUrl
				  	});
					}
					
					this.editParm.id = res.data.id;
    			this.editParm.buyerId= res.data.buyerId;
    			this.editParm.buyerName= res.data.account;
    			this.buyerId = res.data.buyerId;
					console.log(res.data);
					this.dialogEditVisible = true;
				}
			}).catch(err => {
				this.$message.error(err);
				console.log(err)
			})
		},
		// 确认修改
		sureEdit(editParm){
			this.$refs.editParm.clearValidate();
		  	this.editParm.linkUrl = this.form.dynamicItem.map(function (elem) {
        return elem.linkUrl;
     }).join(";");
         
			this.$refs[editParm].validate((valid) => {
		  if (valid) {
					editById(this.editParm).then(res => {
						if(res.code==200) {
							this.editParm.buyerId = this.buyerId;
							this.dialogEditVisible = false
							this.$message.success('修改成功!')
							this.getDataList()
						}
					}).catch(err => {
						this.$message.error(err);
						console.log(err)
					})
			  } else {
					console.log('error submit!!');
					return false;
			  }
			});
		},
		sureEditCancle(editParm) {
			dialogEditVisible=flase
			this.$refs.editParm.clearValidate();
		},
		// 确认新增
		sureAdd(addParm){
			if (this.form.dynamicItem.length > 1) {
				this.addParm.linkUrl = this.form.dynamicItem.map(function (elem) {
                            return elem.linkUrl;
                        }).join(";");
			} else {
				this.addParm.linkUrl = this.form.dynamicItem[0].linkUrl;
			}
			
			this.$refs[addParm].validate((valid) => {
		  if (valid) {
			  	this.$refs.addParm.clearValidate();
					add(this.addParm).then(res => {
					if(res.code==200) {
						this.addParm.buyerId = this.buyerId;
								this.dialogAddVisible = false
								this.$message.success('新增成功!')
								this.getDataList()
							}
					}).catch(err => {
						this.$message.error(err);
							console.log(err)
					})
			  } else {
					console.log('error submit!!');
					return false;
			  }
			});
		},
		sureAddCancle(addParm) {
			dialogAddVisible=flase
			this.$refs.addParm.clearValidate();
		},
		// 查看根据id
		getBtnById(id){
			getById({id}).then(res => {
				if(res.code==200) {
					this.detailParm.id = res.data.id;
    			this.detailParm.linkUrl = res.data.linkUrl;
    			this.detailParm.status = res.data.status;
    			this.detailParm.status = res.data.status;
    			this.detailParm.country = res.data.country;
    			this.detailParm.account = res.data.account;
    			this.detailParm.paymentResults = res.data.paymentResults;
					this.dialogDetailVisible = true
					
				}
			}).catch(err => {
				console.log(err)
			})
		},
		// 分页获取表格数据
		getDataList(){
			getList(this.searchParm).then(res => {
					if(res.code==200) {
						this.list = res.data.list;
						this.total = res.data.total;
					}
				}).catch(err => {
					console.log(err)
				})
		},
	
		//	分页
		handleSizeChange(val) {
   		console.log(`每页 ${val} 条`);
   		this.searchParm.pageSize = val;
   		this.getDataList();
  	},
  	handleCurrentChange(val) {
    	console.log(`当前页: ${val}`);
    	this.searchParm.page = val;
    	this.getDataList();
  	}
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
