<!--
 * @Author: wanglj 471442253@qq.com
 * @Date: 2022-12-15 15:38:21
 * @LastEditors: wanglj
 * @LastEditTime: 2022-12-28 18:01:16
 * @Description: file content
 * @FilePath: \opms_frontend\src\views\customer\follow.vue
-->
<template>
  <div class="follow-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="12">

      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="12">

      </vab-query-form-right-panel>
    </vab-query-form>
    <div class="follow"></div>
    <!-- 新增编辑客户弹窗 -->
    <Edit ref="edit"
          @createContact="createContact"
          @customerSave="customerSave"></Edit>
    <!-- 新建联系人弹窗 -->
    <Contact ref="contact"></Contact>
    <!-- 分配客户 -->
    <Allocate ref="allocate"></Allocate>
  </div>
</template>

<script>
import to from 'await-to-js'
import api from '@/api/customer'
import Contact from './components/Contact'
import Edit from './components/Edit'
import Allocate from './components/Allocate'
export default {
  name: 'OpenSea',
  data () {
    return {
      listLoading: false,
      layout: 'total, sizes, prev, pager, next, jumper',
      list: [],
      total: 0,
      queryForm: {
        pageNum: 1,
        pageSize: 10,
        custCode: '',   // 客户编码
        custName: '',    //客户名称
        custIndustry: '',    // 客户行业  ()
        custLevel: '',     //客户级别
      },
      selectRows: []
    }
  },
  components: {
    Contact,
    Edit,
    Allocate
  },
  mounted () {
    this.fetchData()
    this.getOptions()
  },
  methods: {
    getOptions () {

    },
    async fetchData () {

    },
    reset () {
      this.queryForm = {
        pageNum: 1,
        pageSize: 10
      }
      this.fetchData()
    },
    // 客户编辑
    async handleEdit (row) {
      this.$refs.edit.init([row.id])
    },
    // 客户详情
    handleDetail (row) {
      this.$router.push({
        path: '/customer/detail',
        query: {
          id: row.id
        }
      })
    },
    // 客户删除
    handleDelete (row) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const [err, res] = await to(api.deleteCustomer({ Id: row.id }))
        if (err) return
        if (res.code == 200) {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.fetchData()
        }
      }).catch(() => {
      })
    },
    // 联系人弹窗
    createContact (res) {
      this.$refs.contact.contactForm.custId = res.id
      this.$refs.contact.contactForm.custName = res.name
      this.$refs.contact.contactVisible = true
    },
    customerSave () {
      this.fetchData()
    },
    handleClose (form) {
      this.$refs[form].resetFields()
    },
    // 领取
    handleReceive () {
      if (!this.selectRows.length) return this.$message.warning('请选择客户')
      const arr = this.selectRows.map(item => item.id)
      this.$confirm('确认领取客户?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const [err, res] = await to(api.receiveCustomer({ ids: arr.join() }))
        if (err) return
        if (res.code == 200) {
          this.$message({
            type: 'success',
            message: '领取成功!'
          });
        }
      }).catch(() => {
      })
    }
  }
}
</script>

<style lang="scss" scoped>
$base: '.follow';
.follow {
  height: calc(100vh - 228px);
}
</style>