<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户编码" prop="customerCode">
        <el-input
          style="width:220px"
          v-model="queryParams.customerCode"
          placeholder="请输入客户编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          style="width:220px"
          v-model="queryParams.customerName"
          placeholder="请输入客户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机" prop="mobile">
        <el-input
        style="width:220px"
          v-model="queryParams.mobile"
          placeholder="请输入手机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table  height="500" border v-loading="loading" :data="customerList" ref="customerList" >
      <el-table-column label="客户编码" align="center" prop="customerCode" />
      <el-table-column  label="客户名称"   align="center" prop="customerName" :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column  label="手机" width="120px"  align="center" prop="mobile"  >
      </el-table-column>
      <el-table-column  label="客户来源" align="center" prop="source">
        <template slot-scope="scope">
            <el-tag prop="status" v-for="(item, index) in sourceOptions"    v-if="scope.row.source==item.dictValue">{{item.dictLabel}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column  label="跟进阶段"  width="200" align="center" prop="visitStatus">
        <template slot-scope="scope">
            <el-tag prop="visitStatus" v-for="(item, index) in statusOptions"    v-if="scope.row.visitStatus==item.dictValue">{{item.dictLabel}}</el-tag><br/>
          </template>
      </el-table-column>
      <el-table-column  label="客户类型"  width="200" align="center" prop="customerType">
        <template slot-scope="scope">
            <el-tag prop="status" v-for="(item, index) in typeOptions"    v-if="scope.row.customerType==item.dictValue">{{item.dictLabel}}</el-tag>
          </template>
      </el-table-column>
      <el-table-column  label="标签" width="120px"  align="center" prop="tags"   >
      </el-table-column>
      <el-table-column  label="备注" width="150px"  align="center" prop="remark"   >
      </el-table-column>
      <el-table-column label="进线客户详情" align="center" :show-overflow-tooltip="true" prop="registerDesc" />
      <el-table-column label="最新跟进时间" align="center" prop="lastTime" />
      <el-table-column label="领取时间" align="center" prop="receiveTime" />
      <el-table-column label="进线客户提交日期" align="center" prop="registerSubmitTime" />
      <el-table-column label="创建时间" align="center" prop="customerCreateTime" width="180">
      </el-table-column>
      <el-table-column label="操作"   align="center" fixed="right" width="120px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="medium"
            type="primary"
            plain
            @click="handleBind(scope.row)"
          >绑定</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { getMyCustomerList,recover,exportCustomer  } from "@/api/crm/customer";
export default {
  name: "mycustomer",
  components: {},
  data() {
    return {

      dateRange:[],

      statusOptions:[],
      typeOptions:[],
      sourceOptions:[],

      // 遮罩层
      loading: true,

      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerCode: null,
        customerName: null,
        mobile: null,
        sex: null,
        weixin: null,
        userId: null,
        createUserId: null,
        receiveUserId: null,
        customerUserId: null,
        address: null,
        location: null,
        detailAddress: null,
        lng: null,
        lat: null,
        status: null,
        deptId: null,
        isDel: null,
        customerType: null,
        receiveTime: null,
        poolTime: null,
        companyId: null,
        isLine: null,
        source: null,
        tags: null
      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {
      },
    };
  },
  created() {

    this.getDicts("crm_customer_source").then((response) => {
      this.sourceOptions = response.data;
    });
    this.getDicts("crm_customer_user_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts("crm_customer_type").then((response) => {
      this.typeOptions = response.data;
    });
    this.getList();
  },
  methods: {

    /** 查询客户列表 */
    getList() {
      this.loading = true;

      getMyCustomerList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.customerList = response.rows;
        console.log("哈话",this.customerList)
        this.total = response.total;
        this.loading = false;
      });
    },

    //绑定选择
    handleBind(row){
      console.log("绑定",row)
      this.$emit("bindCustomerId",row.customerId)
      this.$refs.customerList.clearSelection();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
<style>
  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
  .el-dialog__wrapper{
    z-index: 100000;
  }
</style>
