<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-10-21 14:27:29
 * @LastEditors: 无尘
 * @LastEditTime: 2020-06-28 11:18:00
 -->

<!--
<use-record
  :detailShow="detailShow"
  @hideDetailDialog="hideDetailDialog">
</use-record>

import useRecord from '@/components/app/material/use-record.vue'
 -->
<template>
  <div v-show="customDialog">
    <el-dialog class="edit-dialog" title="记录" :visible.sync="customDialog" width="739px" :before-close="handleClose">
      <div class="edit-dialog-body">
        <div class="m-b-20 flex">
          <el-input placeholder="请输入标题" prefix-icon="el-icon-search" v-model="conditionObj.searchInput" class="w-203" @keyup.native="value => toInput(value, conditionObj.searchInput)" clearable @clear="clearInput"> </el-input>
          <!-- <span class="p-l-10 l-h-32">共{{ total }}条点赞记录</span> -->
        </div>
        <el-table :data="tableData" style="width: 100%" height="332">
          <el-table-column label="发布人" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.userName || '--' }}
            </template>
          </el-table-column>
          <el-table-column label="标题" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.imgTextTitle || '--' }}
            </template>
          </el-table-column>
          <el-table-column label="发布时间" show-overflow-tooltip>
            <template slot-scope="scope">
              <div class="color-606266 line-18">{{ scope.row.createTime | timeStampToYmd }}</div>
              <div class="color-606266 line-18">{{ scope.row.createTime | timeStampToHms }}</div>
            </template>
          </el-table-column>
        </el-table>
        <div class="block common-wrap__page text-right m-t-24" v-if="tableData.length != 0">
          <dm-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-size="pageSize" layout=" prev, pager, next" :total="total"> </dm-pagination>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getRequest } from '@/api/api';
import errMsg from '@/common/js/error';
import { _debounce } from '@/common/js/public';
export default {
  name: 'use-record',
  props: {
    detailShow: {
      type: Boolean,
      default: false
    },
    materialId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      customDialog: false, // 弹框显示
      activeName: 'first',
      tableData: [],
      conditionObj: {
        searchInput: '',
        materialId: this.materialId
      },
      // 分页参数
      currentPage: 1,
      pageSize: 5,
      total: 0
    };
  },
  methods: {
    /**
     * 输入
     */
    toInput: _debounce(function(e, value) {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    }, 500),
    // 搜索清除
    clearInput() {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    },
    /**
     * 分页---页码变化
     */
    handleSizeChange(val) {
      const that = this;
      that.currentPage = 1;
      that.pageSize = val;
      that.getTableList();
    },

    /**
     * 分页---当前页变化
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
      that.getTableList();
    },
    /**
     *   关闭
     */
    handleClose(done) {
      const that = this;
      done();
      that.hideDialog();
    },

    /**
     *  取消
     */
    customCancel() {
      const that = this;
      that.hideDialog();
    },

    hideDialog() {
      const that = this;
      that.customDialog = false;
      that.$emit('hideDetailDialog');
    },
    /**
     * 获取列表数据
     */
    getTableList(val) {
      const that = this;
      let para = {
        imgTextMaterialId: that.conditionObj.materialId,
        imgTextTitle: that.conditionObj.searchInput || '', // 搜索字段
        relatedType: 4,
        pageNum: that.currentPage, // 当前页
        pageSize: that.pageSize, // 一页显示个数
        brandId: that.activeBrand
      };
      getRequest('/haoban-app-material-web/material-log', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            that.tableData = resData.result.list || [];
            that.total = resData.result.total;
            return false;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    detailShow: function(newData, oldData) {
      const that = this;
      that.customDialog = newData;
    },
    materialId: function(newData, oldData) {
      const that = this;
      if (newData) {
        that.conditionObj.materialId = newData;
        that.currentPage = 1;
        that.getTableList();
      }
    }
  },

  /* 接收数据 */
  mounted() {
    const that = this;
    that.customDialog = that.detailShow;
    if (that.materialId) {
      that.conditionObj.materialId = that.materialId;
      that.currentPage = 1;
      that.getTableList();
    }
  }
};
</script>

<style lang="less" scoped>
.bg-82C5FF {
  background: #82c5ff;
}

.w-203 {
  width: 203px;
}
.l-h-32 {
  line-height: 32px;
}

.table-head-pic {
  width: 35px;
  height: 35px;
  padding: 10px;
  border-radius: 4px;
  i {
    font-size: 20px;
    color: #e5f3ff;
  }
  img {
    max-width: 35px;
    max-height: 35px;
  }
}

.apply-info {
  margin-left: 15px;
  line-height: 18px;
  .text-ellipsis {
    display: block;
    width: 96px;
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
.edit-dialog {
  /deep/ .el-dialog__body {
    padding: 25px 20px 17px 20px;
    min-height: 352px;
  }

  /deep/ .el-dialog__footer {
    border: none;
    padding-top: 3px;
  }

  &__title {
    width: 100%;
    height: 38px;
    padding: 12px 15px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    background: rgba(235, 238, 245, 1);
  }

  .el-alert--info {
    width: 400px;
    font-size: 14px;
    color: #606266;
    background: #e6f7ff;
    border: 1px solid rgba(145, 213, 255, 1);
  }
  .el-icon-info {
    width: 12px;
    font-size: 12px;
    color: #2f54eb;
  }
  .el-form {
    margin-top: 40px;
  }
}
</style>
