<template>
  <div v-loading="loading">
    <el-table :data="dataLists" border stripe>
      <el-table-column prop="F_Sex" label="客户性别" align="center" width=""/>
      <el-table-column prop="F_Age" label="客户年龄" align="center" width=""/>
      <el-table-column prop="F_Mobile" label="手机号码1" align="center" width=""/>
      <el-table-column prop="F_Mobile1" label="手机号码2" align="center" width=""/>
      <el-table-column prop="F_Phone" label="联系方式" align="center" width="100px"/>
      <el-table-column prop="F_Label" label="会员类型" align="center" width=""/>
      <el-table-column label="详细地址" align="center" width="100px">
        <template slot-scope="scoped">
          <span v-show="scoped.row.F_Province==null?false:true">{{ scoped.row.F_Province }}</span>
          <span v-show="scoped.row.F_City==null?false:true">{{ scoped.row.F_City }}</span>
          <span v-show="scoped.row.F_Area==null?false:true">{{ scoped.row.F_Area }}</span>
          <span v-show="scoped.row.F_Town==null?false:true">{{ scoped.row.F_Town }}</span>
          <span v-show="scoped.row.F_Address==null?false:true">{{ scoped.row.F_Address }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="F_Address1" label="备用地址" align="center" width=""/>
      <el-table-column prop="F_Postcode" label="邮编" align="center" width=""/>
      <el-table-column prop="F_ShoeSize" label="鞋码" align="center" width=""/>
      <el-table-column prop="Birthday" label="会员生日" align="center" width="100px"/>
      <el-table-column prop="F_Score" label="会员积分" align="center" width=""/>
      <el-table-column prop="F_Recommender" label="推荐人" align="center" width=""/>
      <el-table-column prop="F_Saleperson" label="销售负责人" align="center" width="90px"/>
      <el-table-column prop="F_Money" label="累计消费金额" align="center" width=""/>
      <el-table-column prop="F_TotalScore" label="累计积分" align="center" width=""/>
      <el-table-column label="操作" width="140" align="center" class-name="oparate_btn" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" @click="btn_detail(scope.row.F_ID.toString())">详情</el-button>
          <el-button type="text" @click="btn_edit(scope.row.F_ID)">编辑</el-button>
          <el-button type="text" @click="btn_delete(scope.row.F_ID)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="pageParams.total > 0" :total="pageParams.total" :pageindex.sync="pageParams.pageindex" :pagesize.sync="pageParams.pagesize" :auto-scroll="false" class="pagination" @pagination="getList" />
  </div>
</template>

<script>
import { getOrderLists } from '@/api/memberManagement/memberList'
import { deletesMember } from '@/api/memberManagement/memberList'
import cusProdetail from '@/views/memberManagement/memberList/components/detail'
import addOrEdit from '@/views/memberManagement/memberList/components/addOrEdit'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装 @/api/memberManagement/memberList

export default {
  name: 'CustomerList',
  components: {
    Pagination
  },
  filters: {
    isendFilter(status) {
      const statusMap = {
        0: '未到期',
        1: '到期'
      }
      return statusMap[status]
    },
    timeFilter: function(value) {
      return value === '0001-01-01 00:00:00' ? '-' : value
    }
  },
  props: {
    callinNum: {
      type: String,
      default: ''
    },
    cusType: {
      type: String,
      default: '潜在客户'
    }
  },
  data() {
    return {
      loading: false,
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [] // 右侧列表数据
    }
  },
  computed: {
    isSign: function() {
      return this.cusType === '签约客户'
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      return new Promise(resolve => {
        const params = {
          pageindex: this.pageParams.pageindex, // 第几页
          pagesize: this.pageParams.pagesize, // 每页几条信息
          keyword: this.callinNum // 否	string	模糊查询（姓名，手机号码，固话）
        }
        getOrderLists(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.pageParams.total = response.rows.Totals
            this.dataLists = response.rows.Rows
          }
        })
        resolve()
      })
    },
    btn_detail(editId) {
      this.$layer.iframe({
        content: {
          content: cusProdetail, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: editId } // props
        },
        area: ['60%', '75%'],
        title: '查看客户项目信息'
      })
    },
    btn_edit(editId) {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'rowid': editId.toString() }// props
        },
        area: ['80%', '90%'],
        title: '编辑会员信息'
      })
    },
    // 批量删除
    btn_delete(editId) {
      this.$confirm('您确定要将此会员删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletesMember(editId).then(response => {
          if (response.state.toLowerCase() === 'success') {
            this.getList()
            this.$message.success('删除成功!')
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    }
  }
}
</script>

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

</style>
