<template>
  <div style="margin-bottom:15px">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          style="width:200px"
          v-model="queryParams.customerName"
          placeholder="请输入客户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"/>
      </el-form-item>

      <el-form-item label="跟进阶段" prop="status">
        <el-select style="width:220px" filterable  v-model="queryParams.status" placeholder="请选择跟进阶段" clearable size="small">
           <el-option
                v-for="item in statusOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
        </el-select>
      </el-form-item>
      <el-form-item label="客户标签" prop="tags">
            <el-select style="width:220px" multiple  filterable v-model="tagIds" placeholder="请选择客户标签" clearable size="small">
              <el-option
                    v-for="item in tagsOptions"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  />
            </el-select>
          </el-form-item>
          <el-form-item label="客户类型" prop="customerType">
        <el-select style="width:220px" multiple filterable  v-model="ctsTypeArr" placeholder="请选择客户类型" clearable size="small">
           <el-option
                v-for="item in typeOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
        </el-select>
      </el-form-item>

      <el-form-item label="领取时间" prop="receiveTime">
        <el-date-picker
              style="width:220px"
              clearable size="small"
              v-model="dateRange"
              type="daterange"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="customerList" height="550px" ref="dataList">
          <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="客户编码" align="center" prop="customerCode" />
            <el-table-column  label="客户名称"   align="center" prop="customerName" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  {{scope.row.customerName}}
                <!-- <el-link @click="handleShow(scope.row)" :underline="false" type="primary" >{{scope.row.customerName}}</el-link> -->
                </template>
            </el-table-column>
            <el-table-column  label="手机" width="120px"  align="center" prop="mobile"   >
                <template slot-scope="scope">
                {{scope.row.mobile}}
                </template>
            </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  width="120px"  label="跟进阶段"  align="center" prop="visitStatus">
                <template slot-scope="scope">
                    <el-tag prop="visitStatus" v-for="(item, index) in statusOptions"    v-if="scope.row.status==item.dictValue">{{item.dictLabel}}</el-tag>
                    <!-- <el-button  v-hasPermi="['crm:customer:addVisitStatus']"  type="text" size="mini">修改</el-button> -->
                </template>
            </el-table-column>
            <el-table-column  label="客户类型" 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>
                    <!-- <el-button   v-hasPermi="['crm:customer:addCustomerType']"  type="text" size="mini" @click="handleCustomerType(scope.row)">修改</el-button> -->
                </template>
            </el-table-column>
            <el-table-column  label="标签" align="center" prop="tags"   >
                <template slot-scope="scope">
                {{scope.row.tags}}
                <!-- <el-button  v-hasPermi="['crm:customer:addTag']"  type="text" size="mini" @click="handleAddTag(scope.row)">打标签</el-button> -->
                </template>
            </el-table-column>
            <!-- <el-table-column  label="备注" width="120px"  align="center" prop="remark"   >
                <template slot-scope="scope">
                {{scope.row.remark}}
                <el-button   v-hasPermi="['crm:customer:addRemark']" type="text" size="mini" @click="handleAddRemark(scope.row)">修改备注</el-button>
                </template>
            </el-table-column> -->
            <!-- <el-table-column label="进线客户详情" align="center" :show-overflow-tooltip="true" prop="registerDesc" />
            <el-table-column label="领取时间" align="center" prop="startTime" />
            <el-table-column label="进线客户提交日期" align="center" prop="registerSubmitTime" /> -->
            <el-table-column label="创建时间"  width="100" align="center" prop="customerCreateTime" >
            </el-table-column>
            <!-- <el-table-column label="操作" align="center" width="100px" >
                <template slot-scope="scope">
                <el-button
                    size="mini"
                    type="text"
                    @click="handleSelect(scope.row)"
                >选择</el-button>
                </template>
            </el-table-column> -->
    </el-table> 
    <pagination
      style="padding-bottom:10px;"
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
        <div  class="footer">
            <el-button type="primary" @click="handleSelect($refs.dataList)">添加</el-button>
        </div>
  </div>
</template>

<script>
import { getMyCustomerList } from "@/api/crm/customer";
export default {
  name: "selectCustomer",
  data() {
    return {
      loading: true,
      total: 0,
      queryParams: {
            customerName: null,
            pageNum: 1,
            pageSize: 10,
            status:null,
      },
      statusOptions:[],
      typeOptions:[],
      sourceOptions:[],
      sexOptions:[],
      tagsOptions:[],
      customerList: [],
      tagIds:[],
      ctsTypeArr:[],
      dateRange:[],
    };
  },
  created() {
    this.getDicts("crm_customer_user_status").then((response) => {
        this.statusOptions = response.data;
    });
    this.getDicts("common_sex").then((response) => {
      this.sexOptions = response.data;
    });
    this.getDicts("crm_customer_source").then((response) => {
      this.sourceOptions = response.data;
    });
    this.getDicts("crm_customer_type").then((response) => {
      this.typeOptions = response.data;
    });
    this.getDicts("crm_customer_tag").then((response) => {
        this.tagsOptions = response.data;
    });
     this.getList();
  },

  methods: {
    // handleSelect(row){
    //   this.$emit('selectCustomer',row);
    // },
    handleSelect(selectedRows){
      this.$emit('selectCustomer',selectedRows);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList(){
        this.loading = true;
        if(this.tagIds.length>0){
            this.queryParams.tags=this.tagIds.toString();
        }
        else{
            this.queryParams.tags=null
        }
        if(this.ctsTypeArr.length>0){
        this.queryParams.customerType=this.ctsTypeArr.toString();
      }
      else{
        this.queryParams.customerType=null
      }
        getMyCustomerList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.customerList = response.rows;
            this.total = response.total;
            this.loading = false;
        });
    }
  }
};
</script>
<style scoped>
 
 .footer{
  margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}
</style>
