<template>
  <a-modal
    :width="1200"
    :title="title"
    :visible="visible"
    :destroyOnClose="true"
    @cancel="handleCancel"
    cancelText="关闭"
    :okButtonProps="{ style: { display: 'none' } }"
  >
    <a-form layout="inline" @keyup.enter.native="searchQuery" style="margin-bottom: 15px">
      <a-form-item>
        <a-input placeholder="邮箱/姓名" v-model="queryParam.searchText" />
      </a-form-item>
      <a-form-item>
        <a-button type="primary" @click="searchQuery">查询</a-button>
        <a-button @click="searchReset" style="margin-left: 8px">重置</a-button>
      </a-form-item>
    </a-form>

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

<script lang="js">
  import { putAction, deleteAction, postAction, getAction } from '/@/api/manage/manage';

  import enquiryDetail from '/@/views/adweb/enquiry/modules/enquiryDetail.vue';

  export default {
    name: 'XpRecycleBinModal',
    components: { enquiryDetail },

    data() {
      return {
        title: '',
        loading: false,
        innerVisible: false,
        dataSource: [],
        visible: false,
        columns: [],
        url: {
          list: '/adweb/adwebEnquiry/getWastedEnquiry',
        },
        disableMixinCreated: true,
        keyword: '',
        siteCode: '',
      };
    },

    methods: {
      init(keyword, 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.keyword = keyword;
        that.siteId = siteId;
        that.loadData(keyword, siteId);
        console.log(keyword);
        that.visible = true;
      },

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

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

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

      loadData(keyword, siteId) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!');
          return;
        }
        var params = this.getQueryParams(); //查询条件
        this.loading = true;
        params.keyword = keyword;
        params.siteId = siteId;
        params.wasteEnquiryType = 'keyword';
        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>
