<template>
  <div class="app-container">
    <search-filter :search-datas.sync="searchDatas"  :selectedId="selectedId" showadd @transfer="btn_transfer" @search="btn_search" @delorders="btn_deletes" @export="btn_export"></search-filter>
    <el-table v-loading="loading" :data="dataLists" border stripe @selection-change="changeSelects">
      <el-table-column type="selection" width="40" fixed></el-table-column>
      <el-table-column prop="F_Name" label="客户姓名" align="center"  width=""></el-table-column>
      <el-table-column prop="F_Sex" label="客户性别" align="center"  width=""></el-table-column>
      <el-table-column prop="F_Age" label="客户年龄" align="center"  width=""></el-table-column>
      <el-table-column prop="F_Mobile" label="手机号码1" align="center"  width=""></el-table-column>
      <el-table-column prop="F_Mobile1" label="手机号码2" align="center"  width=""></el-table-column>
      <el-table-column prop="F_Phone" label="联系方式" align="center"  width="100px"></el-table-column>
      <el-table-column prop="F_Label" label="会员标签" align="center"  width=""></el-table-column>
      <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>
      <el-table-column prop="F_Postcode" label="邮编" align="center"  width=""></el-table-column>
      <el-table-column prop="F_ShoeSize" label="鞋码" align="center"  width=""></el-table-column>
      <el-table-column prop="Birthday" label="会员生日" align="center"  width="100px"></el-table-column>
      <el-table-column prop="F_Score" label="会员积分" align="center"  width=""></el-table-column>
      <el-table-column prop="F_Recommender" label="推荐人" align="center"  width=""></el-table-column>
      <el-table-column prop="F_Saleperson" label="销售负责人" align="center"  width="90px"></el-table-column>
      <el-table-column prop="F_Money" label="累计消费金额" align="center"  width=""></el-table-column>
      <el-table-column prop="F_TotalScore" label="累计积分" align="center"  width=""></el-table-column>
      <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"
      class="pagination"
      @pagination="getList">
    </pagination>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getOrderLists, deleteOrder,deletesMember } from '@/api/memberManagement/memberList'
import searchFilter from './components/searchFilter'
import addOrEdit from './components/addOrEdit'
import detail from './components/detail'
import transfer from './components/transfer'
import { formatterContent } from '@/utils'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装

export default {
  name: 'memberLabel',
  components: {
    Pagination,
    searchFilter
  },
  data() {
    return {
      searchDatas: {
        VIPCode: '', //会员卡编号
        customerName: '', //客户姓名
        phoneNumber: '', //手机号码
        memberType: '', //会员类型
        province: '', //省份
        city: '', //市
        county: '', //县区
        township: '', //乡镇
        address: '', //详细地址
        birthday: '', //会员生日
        referrer: '', //推荐人
        saleperson: '', //销售负责人
        // contactFrequency: '', //联系频次
        provinceCity: [], // 省市下拉绑定的值
        provinceCityText: [], // 省市下拉绑定文本值
      },
      loading: false,
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [],// 列表数据
      multipleSelection: [], // 选中的数据
      selectedId: [], //选中的id
    }
  },
  created() {
    this.getList()
    document.onkeyup = (e) => {
      if (e.keyCode === 13) {
        this.getList()
      }
    }
  },
  computed: {
    ...mapGetters([
      'token'
    ])
  },
  methods: {
    getList() {
      this.loading = true
      return new Promise(resolve => {
        const params = {
          pageindex: this.pageParams.pageindex, // int 第几页
          pagesize: this.pageParams.pagesize, // int 每页几条信息
          name: this.searchDatas.customerName.trim(), //客户姓名
          phone: this.searchDatas.phoneNumber.trim(), //手机号码
          type: this.searchDatas.memberType, //会员类型
          province: this.searchDatas.provinceCityText&&this.searchDatas.provinceCityText[0], //省份
          city: this.searchDatas.provinceCityText[1]&&this.searchDatas.provinceCityText[1], //市
          area: this.searchDatas.provinceCityText[2]&&this.searchDatas.provinceCityText[2], //县区
          town: this.searchDatas.provinceCityText[3]&&this.searchDatas.provinceCityText[3], //乡镇
          address: this.searchDatas.address.trim(), //详细地址
          birthday: this.searchDatas.memberBirthday, //会员生日
          recommender: this.searchDatas.referrer.trim(), //推荐人
          saleperson: this.searchDatas.saleperson.trim(), //销售负责人
          // contact: this.searchDatas.contactFrequency.trim(), //联系频次
        }
        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_search(val,data) {
      this.searchDatas.provinceCityText=data
      this.pageParams.pageindex = 1
      this.getList()
    },
    btn_export(val,data) {
      this.searchDatas.provinceCityText=data
      window.location.href = this.$store.getters.serverConfig.BASE_API + 'api/vipinfo/exportexcel?name=' + this.searchDatas.customerName +
					'&phone=' + this.searchDatas.phoneNumber + //手机号码
					'&province=' + (this.searchDatas.provinceCityText.length>0?this.searchDatas.provinceCityText[0]:'') +
					'&city=' + (this.searchDatas.provinceCityText.length>1?this.searchDatas.provinceCityText[1]:'') +
					'&area=' + (this.searchDatas.provinceCityText.length>2?this.searchDatas.provinceCityText[2]:'') +
					'&town=' + (this.searchDatas.provinceCityText.length>3?this.searchDatas.provinceCityText[3]:'') +
					'&type=' + this.searchDatas.memberType + //会员类型
					'&address=' + this.searchDatas.address + //地址
					'&recommender=' + this.searchDatas.referrer + //推荐人
					'&saleperson=' + this.searchDatas.saleperson + //销售负责人
					// '&token=' + this.token + 
					'&birthday=' + this.searchDatas.birthday
    },
    btn_detail(editId) {
      this.$layer.iframe({
        content: {
          content: detail, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'rowid': editId }// props
        },
        area: ['80%', '90%'],
        title: '详情'
      })
    },
    btn_edit(editId) {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'rowid': editId.toString() }// props
        },
        area: ['80%', '90%'],
        title: '编辑会员信息'
      })
    },
    //批量删除
    btn_deletes(){
      if(this.selectedId.length==0){
        this.$message('请选择一个选项')
        return
      }else{
          this.$confirm('您确定要删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deletesMember(this.selectedId).then(response => {
            if (response.state.toLowerCase() === 'success') {
              this.getList()
              this.$message.success('删除成功!')
            }
          })
        }).catch(() => {
          this.$message.info('已取消删除')
        })
      }
      
    },
    //转移
    btn_transfer(){
      if(this.selectedId.length==0){
        this.$message('请选择一个选项')
        return
      }else{
         this.$layer.iframe({
          content: {
            content: transfer, // 传递的组件对象
            parent: this, // 当前的vue对象
            data: { 'rowid': this.selectedId }// props
          },
          area: ['40%', '40%'],
          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('已取消删除')
      })
    },
    changeSelects(val) {
      const ids = []
      this.multipleSelection = val
      for (let i=0; i<this.multipleSelection.length; i++) {
        ids.push(this.multipleSelection[i].F_ID)
      }
      this.selectedId = ids;
    },
  }
}
</script>

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

</style>
