<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="关键字">
              <a-input placeholder="请输入姓名、昵称、联系方式、备注" v-model="queryParam.keywords"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="录入日期">
                <a-range-picker v-model="queryParam.dateQ"
                  format="YYYY-MM-DD"
                  :placeholder="['开始日期', '结束日期']"
                  @change="onCreateTimeChange" />
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="跟进状态">
              <j-dict-select-tag placeholder="请输入跟进状态" v-model="queryParam.followStatus" dictCode="customer_follow_status"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="跟进方式">
              <j-dict-select-tag placeholder="请输入跟进方式" v-model="queryParam.followType" dictCode="customer_follow_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="跟进人">
              <j-dict-select-tag placeholder="请选择跟进人" v-model="queryParam.follower" dictCode="sys_user,realname,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="校区ID">
              <j-dict-select-tag placeholder="请选择校区ID" v-model="queryParam.schoolDistrictId" dictCode="school_organization,name,id"/>
            </a-form-item>
          </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="name" slot-scope="text, record">
          <a href="javascript:;" @click="handleCustomer(record)">{{record.name}}({{record.nickname}})</a>
        </span>
      </a-table>
    </div>
    <CustomerInfo  @info-event='infoReturn' :infoShow="infoShow" :dataPara="infoRow" activeKey = "tab2"></CustomerInfo>
    <customer-follow-modal ref="modalForm" @ok="modalFormOk"></customer-follow-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import CustomerFollowModal from './modules/CustomerFollowModal'
  import CustomerInfo from '../modules/CustomerInfo.vue'
  export default {
    name: 'CustomerFollowList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      CustomerFollowModal,CustomerInfo
    },
    data () {
      return {
        description: '跟进记录管理页面',
        infoShow: false,
        infoRow: {},
        // 表头
        columns: [
          {
            title:'学员姓名',
            align:"center",
            dataIndex: 'name',
            scopedSlots: { customRender: 'name' }
          },
          {
            title:'联系方式',
            align:"center",
            dataIndex: 'contactPhone'
          },
          {
            title:'跟进状态',
            align:"center",
            dataIndex: 'followStatus_dictText'
          },
          {
            title:'跟进方式',
            align:"center",
            dataIndex: 'followType_dictText'
          },
          {
            title:'跟进内容',
            align:"center",
            dataIndex: 'followContent'
          },
          {
            title:'图片',
            align:"center",
            dataIndex: 'followPic'
          },
          {
            title:'跟进日期',
            align:"center",
            dataIndex: 'followTime'
          },
          {
            title:'跟进人',
            align:"center",
            dataIndex: 'follower_dictText'
          },
          {
            title:'校区',
            align:"center",
            dataIndex: 'schoolDistrictId_dictText'
          },
        ],
        url: {
          list: "/customer/customerFollow/listAll",
          delete: "/customer/customerFollow/delete",
          deleteBatch: "/customer/customerFollow/deleteBatch",
          exportXlsUrl: "/customer/customerFollow/exportXls",
          importExcelUrl: "customer/customerFollow/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'schoolDistrictId',text:'校区',dictCode:''})
        fieldList.push({type:'string',value:'cpId',text:'客户id',dictCode:''})
        fieldList.push({type:'string',value:'followStatus',text:'跟进状态',dictCode:''})
        fieldList.push({type:'string',value:'followType',text:'跟进方式',dictCode:''})
        fieldList.push({type:'string',value:'followContent',text:'跟进内容',dictCode:''})
        fieldList.push({type:'string',value:'followPic',text:'图片',dictCode:''})
        fieldList.push({type:'string',value:'salesCode',text:'顾问id',dictCode:''})
        fieldList.push({type:'datetime',value:'followTime',text:'跟进日期'})
        fieldList.push({type:'datetime',value:'nextFollowTime',text:'下次跟进日期'})
        fieldList.push({type:'string',value:'follower',text:'跟进人id',dictCode:''})
        this.superFieldList = fieldList
      },
      onCreateTimeChange: function (value, dateString) {
        this.queryParam.beginTime=dateString[0];
        this.queryParam.endTime=dateString[1];
      },
      infoReturn() {
          this.loadData();
          this.infoShow = false;
      },
      handleCustomer(record) {
        this.infoRow = {
            id: record.cpId,
            name: record.name,
            contactPhone:record.contactPhone,
            nickname: record.nickname
        }
        this.infoShow = true;
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>