<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="开始日期" prop="startDate">
        <el-date-picker
          v-model="queryParams.startDate"
          type="date"
          placeholder="选择开始日期"
          value-format="yyyy-MM-dd"
          clearable
        />
      </el-form-item>
      <el-form-item label="结束日期" prop="endDate">
        <el-date-picker
          v-model="queryParams.endDate"
          type="date"
          placeholder="选择结束日期"
          value-format="yyyy-MM-dd"
          clearable
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" 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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wecom:customerExport:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" width="80" />
      <el-table-column label="客户名称" align="center" prop="customerName" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="描述" align="center" prop="description" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="性别" align="center" prop="gender" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.gender === 1 ? '男' : scope.row.gender === 2 ? '女' : '未知' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="添加人" align="center" prop="addUserName" width="120" :show-overflow-tooltip="true" />
      <el-table-column label="添加人账号" align="center" prop="addUserAccount" width="120" :show-overflow-tooltip="true" />
      <el-table-column label="添加人所属部门" align="center" prop="addUserDepartment" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="添加时间" align="center" prop="addTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.addTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="来源" align="center" prop="source" width="120" :show-overflow-tooltip="true" />
      <el-table-column label="手机" align="center" prop="mobile" width="120" />
      <el-table-column label="企业" align="center" prop="company" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="邮箱" align="center" prop="email" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="地址" align="center" prop="address" width="200" :show-overflow-tooltip="true" />
      <el-table-column label="职务" align="center" prop="position" width="120" :show-overflow-tooltip="true" />
      <el-table-column label="电话" align="center" prop="phone" width="120" />
      <el-table-column label="标签组1(投放)" align="center" prop="tagGroup1" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组2(公司孵化)" align="center" prop="tagGroup2" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组3(商务)" align="center" prop="tagGroup3" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组4(成交日期)" align="center" prop="tagGroup4" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组5(年级组)" align="center" prop="tagGroup5" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组6(客户属性)" align="center" prop="tagGroup6" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组7(成交)" align="center" prop="tagGroup7" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组8(成交品牌)" align="center" prop="tagGroup8" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组9(线索通标签)" align="center" prop="tagGroup9" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组10(A1组)" align="center" prop="tagGroup10" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组11(B1组)" align="center" prop="tagGroup11" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组12(C1组)" align="center" prop="tagGroup12" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组13(D1组)" align="center" prop="tagGroup13" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组14(E1组)" align="center" prop="tagGroup14" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组15(意向度)" align="center" prop="tagGroup15" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组16(自然流)" align="center" prop="tagGroup16" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组17(F1组)" align="center" prop="tagGroup17" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="标签组18(G1组)" align="center" prop="tagGroup18" width="150" :show-overflow-tooltip="true" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listCustomerExport, exportCustomerExport } from "@/api/wecom/customerExport"

export default {
  name: "CustomerExport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户导出数据表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startDate: undefined,
        endDate: undefined,
        customerName: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询客户导出数据列表 */
    getList() {
      this.loading = true
      listCustomerExport(this.queryParams).then(response => {
        this.dataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/wecom/customerExport/export', {
        ...this.queryParams
      }, `客户导出数据_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
