<template>
  <a-modal
    :width="1200"
    :title="title"
    :visible="visible"
    :destroyOnClose="true"
    @cancel="handleCancel"
    cancelText="关闭"
    :okButtonProps="{style:{display:'none'}}">


    <a-form-model layout="inline" @keyup.enter.native="searchQuery" style="margin-bottom:15px">
      <a-form-model-item>
        <a-input placeholder="邮箱/姓名" v-model="queryParam.searchText"></a-input>
      </a-form-model-item>
      <a-form-model-item>
        <a-button type="primary" @click="searchQuery">查询</a-button>
        <a-button  @click="searchReset" style="margin-left:8px">重置</a-button>
      </a-form-model-item>
    </a-form-model>

    <a-table
      ref="table"
      size="middle"
      :columns="columns"
      :loading="loading"
      :dataSource="dataSource"
      >
      <!-- 显示头像 -->
      <template slot="avatarslot" slot-scope="text, record, index">
        <div class="anty-img-wrap">
          <a-avatar shape="square" :src="url.getAvatar(record.avatar)" icon="user"/>
        </div>
      </template>
      <div slot="contactSlot" slot-scope="text, record">
        <a-popover>
          <template slot="content">
            {{text}}
          </template>
          <div style="width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis">{{text}}</div>
        </a-popover>
      </div>
      <span slot="action" slot-scope="text, record">
        <a @click="enquiryDetail(record)"> 详情</a>
      </span>
    </a-table>
    <!--询盘详情-->
    <enquiry-detail ref="enquiryDetail"></enquiry-detail>
  </a-modal>
</template>

<script>
import { putAction, deleteAction, postAction, getAction } from '@/api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import enquiryDetail from '@views/adweb/enquiry/modules/enquiryDetail'

  export default {
    name: 'XpRecycleBinModal',
    mixins: [JeecgListMixin],
    components:{enquiryDetail},
    data() {
      return {
        title: '',
        loading: false,
        innerVisible: false,
        dataSource: [],
        visible:false,
        columns: [],
        url: {
          list: '/adweb/adwebEnquiry/getWastedEnquiry',
        },
        disableMixinCreated:true,
        email:'',
        type:'',
        siteId:'',
      }
    },

    methods: {
      init(email,type,siteId){
        let that = this
        that.columns = [
            { title: '站点名称', align: 'left', dataIndex: 'siteName', scopedSlots: { customRender: 'contactSlot' }},
            { title: '姓名', align: 'left', dataIndex: 'contact', scopedSlots: { customRender: 'contactSlot' }},
            { title: '邮箱', align: 'left', dataIndex: 'fromEmail', scopedSlots: { customRender: 'contactSlot' } },
            { title: '电话', align: 'left', dataIndex: 'phone' },
            { title: '询盘时间', align: 'left', dataIndex: 'recordCtime' },
            { title: '操作', align: 'center', dataIndex: 'action', scopedSlots: { customRender: 'action' } }
          ]
        that.email = email
        that.type = type
        that.siteId = siteId
        that.loadData(email,type,siteId);
        that.visible = true
      },

      //询盘详情
      enquiryDetail(record){
        this.$nextTick(() => {
          this.$refs.enquiryDetail.init(record)
        })
      },
      searchQuery() {
        this.loadData(this.email,this.type,this.siteId);
      },

      searchReset() {
        this.queryParam = {}
        this.loadData(this.email,this.type,this.siteId);
      },


      handleCancel() {
        this.queryParam = {}
        this.visible = false
      },

      loadData(email,type,siteId) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        params.email = email;
        params.type = type;
        params.siteId = siteId;
        params.wasteEnquiryType = 'email';
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },

    }
  }
</script>

<style lang="less" scoped></style>