<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-10-21 14:27:29
 * @LastEditors: 无尘
 * @LastEditTime: 2020-08-26 09:55:33
 -->

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

import materialRecord from '@/components/app/material/material-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">
        <el-tabs v-model="activeName" type="card" @tab-click="handleTab">
          <el-tab-pane label="点赞记录" name="first">
            <div class="m-b-20 flex">
              <el-input placeholder="请输入姓名/手机号/code" maxlength="50" prefix-icon="el-icon-search" v-model="conditionObj.searchInput" class="w-223" @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">
                  <div class="flex">
                    <div class="flex flex-align-center flex-pack-center bg-82C5FF table-head-pic">
                      <i v-if="!scope.row.headImg" class="iconfont icon-yewuduanmorentouxian"></i>
                      <img v-else :src="scope.row.headImg" alt="img" />
                    </div>
                    <div class="flex flex-column apply-info">
                      <span class="text-ellipsis">{{ scope.row.userName }}</span>
                      <span class="font-13 text-ellipsis">{{ scope.row.storeName }}</span>
                    </div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="手机号" show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.phoneNumber || '--' }}
                </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>
          </el-tab-pane>
          <el-tab-pane label="转发记录" name="second">
            <div class="m-b-20 flex">
              <el-input placeholder="请输入姓名/手机号/code" maxlength="50" prefix-icon="el-icon-search" v-model="conditionObj.searchInput" class="w-223" @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">
                  <div class="flex">
                    <div class="flex flex-align-center flex-pack-center bg-82C5FF table-head-pic">
                      <i v-if="!scope.row.headImg" class="iconfont icon-yewuduanmorentouxian"></i>
                      <img v-else :src="scope.row.headImg" alt="img" />
                    </div>
                    <div class="flex flex-column apply-info">
                      <span class="text-ellipsis">{{ scope.row.userName || '--' }}</span>
                      <span class="font-13 text-ellipsis">{{ scope.row.storeName || '--' }}</span>
                    </div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="手机号" show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.phoneNumber || '--' }}
                </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>
          </el-tab-pane>
        </el-tabs>
        <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: 'material-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: {
    /**
     *   切换tab
     */
    handleTab() {
      const that = this;
      that.conditionObj.searchInput = '';
      that.currentPage = 1;
      that.getTableList();
    },
    /**
     * 输入
     */
    toInput: _debounce(function(e, value) {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    }, 500),
    // 搜索清除
    clearInput() {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    },
    /**
     * 分页---页码变化
     * @param {Number} val
     */
    handleSizeChange(val) {
      const that = this;
      that.currentPage = 1;
      that.pageSize = val;
      that.getTableList();
    },

    /**
     * 分页---当前页变化
     * @param {Number} val
     */
    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 = {
        materialId: that.conditionObj.materialId,
        imgTextTitle: that.conditionObj.searchInput || '', // 搜索字段
        relatedType: that.activeName == 'first' ? 2 : 1,
        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="scss" scoped>
.bg-82C5FF {
  background: #82c5ff;
}

.w-223 {
  width: 223px;
}
.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 {
  >>> .el-dialog__body {
    padding: 25px 20px 17px 20px;
    min-height: 352px;
  }

  >>> .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>
