<template>
  <div>
    <div class="miantitle">
      <span>客户管理</span>
      <span> / 客户列表</span>
    </div>
    <div class="app-container">
      <el-card class="box-card noborder">
        <div class="tables">
          <div class="empty" v-if="tableData.total==0">
            <img src="@/assets/images/project/empty.png">
            <div class="p1">添加你的第一位客户吧</div>
            <div class="p2">抱歉,你还未添加客户，快去添加吧</div>
            <div class="btn btn_primary h36 w88" @click="opennew">添加客户</div>
            <div class="btn btn_primary btn_shallow h36 w88" @click="pldrs">批量导入</div>
          </div>
          <div class="table_search">
            <div class="searchInput">
              <el-input type="text" v-model="serchParam.companyName" placeholder="输入企业名称查询"></el-input>
              <div class="btn">搜索</div>
            </div>
            <div class="dc">
              <div class="total">共126条</div>
              <div class="btn-export" @click="pldrs"><img src="@/assets/images/project/import.png">批量导入</div>
              <div class="btn btn_primary h32 p10" @click="opennew"><div class="img img1"></div>添加客户</div>
            </div>
          </div>
          <el-table v-if="tableData.total>0"
            :data="tableData.rows"
            stripe border
            style="width: 100%"
            :default-sort = "{prop: 'date', order: 'descending'}"
          >
            <el-table-column
              prop="index"
              label="序号"
              width="47">
              <template slot-scope='scope'>
                <span>{{ (serchParam.pageNum - 1) * serchParam.pageSize + scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="date"
              label="企业名称"
              width="441">
            <template slot-scope="scope">
              <div class="ps1">
                <div class="wordprimary ps2" @click="toDetail(scope.row.companyId,'')">{{scope.row.companyName}}</div>
                <div class="ps3">
                  <div  @click="toDetail(scope.row.companyId,1)">写跟进<img src="@/assets/images/project/edit_1.png"></div>
                  <div  @click="toDetail(scope.row.companyId,2)">编辑信息<img src="@/assets/images/project/edit_2.png"></div>
                </div>
              </div>
            </template>

            </el-table-column>
            <el-table-column
              prop="cooperationProject"
              label="合作项目"
              width="76">
            </el-table-column>
            <el-table-column
              prop="followProject"
              label="跟进项目"
              width="76">
            </el-table-column>
            <el-table-column
              prop="reserveProject"
              label="储备项目"
              width="76">
            </el-table-column>
            <el-table-column
              prop="legalPerson"
              label="法定代表人"
              width="110">
            </el-table-column>
            <el-table-column
              prop="name"
              label="注册地区"
              width="160">
            </el-table-column>
            <el-table-column
              prop="registerCapitalStr"
              label="注册资本金（万元）"
              width="140">
            </el-table-column>
            <el-table-column
              prop="creditLevel"
              label="企业主体评级" width="100">
            </el-table-column>
            <el-table-column
              prop="isOn"
              label="上市公司" width="76">
              <template slot-scope="scope">
                {{scope.row.isOn == 1?"是":"否"}}
              </template>
            </el-table-column>
            <el-table-column
              prop="isMajor"
              label="局级大客户" width="88">
              <template slot-scope="scope">
                {{scope.row.isMajor == 1?"是":"否"}}
              </template>
            </el-table-column>
            <el-table-column
              prop="customerLevel"
              label="客户等级" width="76">
            </el-table-column>
            <el-table-column
              prop="companyNature"
              label="客户性质" width="76">
            </el-table-column>
            <el-table-column
              prop="companyLevel"
              label="客户级别" width="76">
            </el-table-column>
            <el-table-column
              prop="address"
              label="企业母公司" width="268">
              <template slot-scope="scope">
                <div class="wordprimary">{{scope.row.superCompany}}</div>
              </template>
            </el-table-column>
            <el-table-column
              prop="mainBusiness"
              label="主营业务" width="120">
            </el-table-column>
            <el-table-column
              prop="companyAttribute"
              label="发包属性" width="120">
            </el-table-column>
            <el-table-column
              prop="followUser"
              label="跟进人" width="110">
            </el-table-column>
          </el-table>
          <div class="bottems" v-if="tableData.total>0">
            <el-pagination
              background
              :page-size="serchParam.pageSize"
              :current-page="1"
              @current-change="handleCurrentChange"
              layout="prev, pager, next"
              :total="tableData.total">
            </el-pagination>
          </div>
        </div>
        <el-dialog
          class="popups"
          :visible.sync="dialogVisible"
          width="534px">
          <div class="poptitle">
            <img src="@/assets/images/economies/icon.png">
            <span>添加客户</span>
          </div>
          <div class="popform j">
            <div class="row">
              <span class="left"><i>*</i>企业名称：</span>
              <el-input type="text" placeholder="请输入"></el-input>
            </div>
            <div class="row">
              <span class="left">客户等级：</span>
              <el-select  placeholder="请选择">
                <el-option v-for="(item,index) in customerLevel" :label="item.dictLabel" :value="item.dictValue"></el-option>
              </el-select>
            </div>
            <div class="row">
              <span class="left">法定代表人：</span>
              <el-input type="text" placeholder="请输入"></el-input>
            </div>
            <div class="row">
              <span class="left">注册资本（万）：</span>
              <el-input type="text" placeholder="请输入"></el-input>
            </div>
            <div class="row">
              <span class="left">企业注册地：</span>
              <el-cascader :options="addressList" clearable></el-cascader>
            </div>
            <div class="row">
              <span class="left">统一社会信用代码：</span>
              <el-input type="text" placeholder="请输入"></el-input>
            </div>
            <div class="popbot">
              <div class="wordprimary">前往城投平台寻找客户线索></div>
              <div class="btn btn_cancel h32" @click="cancel">返回</div>
              <div class="btn btn_primary h32">添加</div>
            </div>
          </div>
        </el-dialog>
      </el-card>
    </div>
    <div class="uploadwin" v-if="pldr">
      <div class="upload" v-if="addfile==false">
        <div class="up_title">批量导入客户</div>
        <div class="up_box">
          <el-upload v-if="isUpload == false"
            class="upload-demo"
            drag
            action="https://jsonplaceholder.typicode.com/posts/"
            multiple>
            <img class="up_img" src="@/assets/images/project/upload.png">
            <div class="up_text">点击选择或将文件(xls，xlsx)拖拽至此上传成员名录</div>
            <div class="up_tip">导入的文件内容必须依照下载模板的要求填写</div>
            <div class="up_tip">上传文件最大为2M，仅支持Excel表格文件（xls,xlsx)</div>
            <div class="up_tip">导入已存在的客户将自动跳过</div>
          </el-upload>
          <div class="up_success" v-else>
            <img src="@/assets/images/project/success.png">上传成功
          </div>
          <div class="btn_download" v-if="isUpload == true"><div class="img"></div>点击下载</div>
        </div>
        <div class="btns">
          <div class="btn btn_primary btn_disabled h34" v-if="isUpload==false">确定导入</div>
          <div class="btn btn_primary h34" @click="qddr" v-else>确定导入</div>
          <div class="btn btn_default h34">取消</div>
        </div>
      </div>
      <div class="success" v-if="addfile==true">
        <div v-if="addsuccess==false">
          <img class="img" src="@/assets/images/project/clock.png">
          <div class="p1">查询客户中...</div>
          <div class="p2">请耐心等待，过程大概30秒</div>
        </div>
        <div v-if="addsuccess == true">
          <div class="p3">
            <img src="@/assets/images/project/success.png">查询成功
          </div>
          <div class="p2">成功导入32家客户信息</div>
          <div class="btns">
            <div class="btn btn_primary h32">查看</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import "@/assets/styles/project.scss"
  import {getCustomerList} from '@/api/custom/custom'
  import {getEnterprise,getDictType,} from '@/api/main'
  import prvinceTree from '@/assets/json/provinceTree'
  import axios from 'axios'
export default {
  name: 'CustomList',
  data() {
    return{
      pldr: false,
      serchParam:{
        companyName:'',
        pageNum:1,
        pageSize:20
      },

      dialogVisible:false,
      textarea:"",
      nowedit:-1,//当前正在编辑的文本
      tipslit:[],//项目标签
      tipsvalue:"",//标签填写内容
      tableData: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
      ],
      isUpload:false,//有上传的文件
      addfile:true,//已上传文件
      addsuccess:true,//已成功加入数据


      customerLevel:[],//客户等级
      addressList:[],//地区
    }
  },
  created() {
    this.getCustomerList()
    this.getDictType()
    this.prvinceTree()
  },
  methods:{
    getDictType(){
      //获取客户等级
      getDictType('customer_level_type').then(result=>{
        this.customerLevel = result.code == 200 ? result.data:[]
      })
    },
    pldrs(){
      this.pldr = true
      this.addfile = false
      this.isUpload = false
      this.addsuccess = false
    },
    qddr(){
      this.addfile = true
      this.addsuccess = false
    },
    //获取客户列表
    getCustomerList(){
      getCustomerList(this.serchParam).then(result=>{
        this.tableData =result
      })
    },
    //跳转到客户详情
    toDetail(id,type){
      if(type == 1){//跟进

      }else if(type == 2){//编辑信息

      }
    },
    //翻页
    handleCurrentChange(val) {
      this.serchParam.pageNum=val
      console.log(`当前页: ${val}`);
    },
    cancel(){
      this.dialogVisible = false
    },
    //打开新建窗口
    opennew(){
      this.dialogVisible = true
    },

    //地区
    async prvinceTree() {
      // await axios.post("https://files.jiansheku.com/file/json/common/provinceTree.json", {}, {
      //   headers: {
      //     'Content-Type': 'application/json'
      //   }
      // }).then(res => {
      //   if (res.data.code == 200) {
      //     console.log(res.data.data)
      //   }
      // })
      // console.log(prvinceTree)
      this.addressList = prvinceTree;
      this.getadd(this.addressList)
    },
    getadd(row) {
      this.addrcallback(row,this.getadd)
    },
    addrcallback(row,callback){
      if(row){
        row.forEach(item => {
          item.value = item.id
            callback &&  callback(item.children)
        })
      }
    },
  }
}
</script>

<style lang="scss" scoped>
  .app-container{
    height: calc(100vh - 134px)
  }
.box-card{
  padding-top: 16px;
  width: 100%;
  height: 100%;
}

  .dc{
    font-size: 12px;
    color: #3D3D3D;
    font-weight: 400;
    position: relative;
    &::after{
      content: ' ';
      width: 2px;
      height: 2px;
      background: rgba(35,35,35,0.4);
      border-radius: 50%;
      position: absolute;
      top: 16px;
      left: 14px;
    }
    >div{
      display: inline-block;
      margin-left: 20px;
    }
  }
  .img.img1{
    margin-right: 2px;
    background: url('../../../../src/assets/images/project/add_2.png')no-repeat center center;
  }
  .w88{
    width: 88px;
  }
  .tables{
    position: relative;
    height: calc(100vh - 134px);
    .empty{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
      .btn{
        margin-right: 8px;
        margin-top: 12px;
      }
    }
  }
  .ps1{
    display: flex;
    justify-content: space-between;
    .ps2{
      width: 270px;
    }
    .ps3{
      width: 150px;
      display: flex;
      justify-content: right;
      >div{
        margin-left: 12px;
        &:hover{
          color: #0CBC6D;
          cursor: pointer;
        }
        >img{
          float: right;
          margin: 3px 0 0 4px
        }
      }
    }
  }
  .popbot{
    .wordprimary{
      display: inline;
      padding-right: 26px;
    }
  }
</style>
