<template>
  <div class="upload_Link">
    <div class="upHead">
      <div class="topLeftTitle">针对论坛及其他平台链接上传</div>
      <button class="addButton" @click="addInfo()" v-if="editFlag == 'true'">新增反馈</button>
      <button class="addButton" style="cursor: not-allowed" v-else >新增反馈</button>
    </div>

    <div class="tableBox">
      <table class="feedbackTable">
        <thead class="theadStyle">
          <tr class="tableHeadStyle1">
            <td>论坛传播情况汇总</td>
          </tr>
          <tr class="tableHeadStyle2 tableHeadStyle3">
            <td v-for="(item, index) in tableHeader" :key="index">
              {{ item }}
            </td>
          </tr>
        </thead>
        <tbody class="bodyStyle">
          <tr
            class="bodyContent tableHeadStyle2"
            v-for="(obj, index) in tableData"
            :key="index"
            :class="{ table_gray: index % 2 === 0 }"
          >
            <td v-if="flag">{{ index + 1 }}</td>

            <td>
              {{ (obj.publishDate || "").replace(RegExp("-", "g"), "/") }}
            </td>
            <!-- 发布日期 -->
            <td>{{ obj.informationName }}</td>
            <!-- 资料名称 -->

            <td>{{ obj.publishPlatformName }}</td>
            <!-- 发布渠道 -->

            <td>{{ obj.publishSourceName }}</td>
            <!-- 平台板块 发布版块-->

            <td>{{ obj.readCount }}</td>
            <!-- 阅读量 -->
            <td>{{ obj.goodCount }}</td>
            <!-- 点赞 -->
            <td>{{ obj.bbsCount }}</td>
            <!-- 评论 -->
            <td>{{ obj.lookingCount }}</td>
            <!-- 在看/转发 -->

            <!--  <td>{{ obj.carTypeName }}</td> -->
            <!-- 车系 -->
            <!--  <td>{{ obj.projectTypeName }}</td> -->
            <!-- 项目分类 -->

            <!--<td>{{ obj.mediaTypeName }}</td>-->
            <!-- 稿件类别 内容分类1 -->
            <td>{{ obj.contentTypeName }}</td>
            <!-- 内容分类 内容分类2 -->
            <td>{{ obj.carPlatformName }}</td>
            <!-- 车型 -->
            <td :class="{ weiFanKui: !obj.id }">
              {{ obj.id ? "已反馈" : "未反馈" }}
            </td>
            <!-- 反馈状态  未定-->
            <td>{{ (obj.endDate || "").replace(RegExp("-", "g"), "/") }}</td>
            <!-- 反馈截止日期 -->
            <td>{{ obj.mediaTitle }}</td>
            <!-- 稿件标题 -->
            <td >
              <a :href="obj.mediaUrl" target="blank">{{ obj.mediaUrl }}</a>
            </td>
            <!-- 链接 -->

            <td
              class="operationStyle"
              style="cursor: pointer"
               v-if="editFlag == 'true'"
            >
              <span @click="toggleModal(index)" style="margin-right: 5px">编辑</span>
              <!-- :class="showItemOperation" -->
              <span @click="toggleModal2(index)">删除</span>
              <!-- :class="showItemOperation" -->
            </td>
            <td
              class="operationStyle"
              style="cursor: not-allowed"
              v-else
            >
              <span style="margin-right: 5px">编辑</span>
              <span>删除</span>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <!-- 弹窗： 编辑表格内容 -->
    <Modal
      v-if="showModal"
      v-on:closeme="closeme"
      :LinkData="modalData"
      @update="editTitle"
      :releaseMedia="releaseMedia"
    ></Modal>
    <!-- 弹窗： 新增内容 -->
    <AddModal
      v-if="showModalAdd"
      v-on:closeme="closemeAdd"
      @add_feedback="addFeedBack"
      :fileName="sfileName"
      :ziliaoId='ziliaoId'
      :userId="accountId"
    ></AddModal>
    <ResultModal
      v-show="isShowresultModal"
      :tipText="tipModalText"
      :flag="resultModalFlag"
      @close_result_modal="closeResultModal"
      @result_modal_submit="submit"
    ></ResultModal>
    <!-- 弹窗： 确定删除？ -->
    <deleteModal
      v-if="showModal2"
      @dataDel="toDel"
      @hide_modal="closeme2"
      :LinkData="modalData"
      :showModalFlag="showModal2"
    ></deleteModal>
    <div class="pageBottom">
      <TablePage
        :currentPage="currentPage"
        :totalPage="totalPage"
        @change_page="changePage"
        @jump_page="jumpPage"
      ></TablePage>
      <p style="margin-left: 16px">共{{ totalPage }}页，共{{ sum }}条数据</p>
    </div>
  </div>
</template>

<script>
import Modal from "../../../components/Modal";
import AddModal from "../components/addFeedbackMoal";
import TablePage from "../../../components/TablePage";
import deleteModal from "../../data/components/UploadLinkModalDelete";
import { env_url, php_url } from "../../../config/env";
import axiosTest from "axios";
import ResultModal from "../components/UploadResultModal";
export default {
  props: {},
  components: {
    Modal,
    TablePage,
    deleteModal,
    AddModal,
    ResultModal
  },
  data() {
    return {
      sfileName: this.$route.query.informationName,
      publishCount: "",
      platform: [],
      platformVal: "",

      releaseMedia: [],
      selectedPlatform: "",
      selectedPlatformId: "",
      /* modal */
      feedbackTimeLimit: 0,
      showModal: false,
      showModalAdd: false,
      showModal2: false,
      showModal3: false,
      showModal4: false,
      // 表格配置
      sum: 0, // 一共有多少条数据
      pageSize: 20, // 每页展示的数据
      currentPage: 1,
      tableHeader: [
        "NO.",
        "发布日期",
        "资料名称",
        "发布渠道",
        "平台板块",
        "阅读量",
        "点赞",
        "评论",
        "在看/转发",
        // "稿件类别",
        "内容分类",
        "涉及车型",
        "反馈状态",
        "反馈截止日期",
        "标题",
        "链接",
        "操作",
      ],
      tableData: [],
      flag: true,
      modalData: {}, //17:44
      file: "",
      dictList: [],
      onlineUrl: env_url, //'http://8.140.188.129:8080'线上 //http://8.136.230.133:8080 //测试
      accountId: "",
      informationName: this.$route.query.informationName || "",
      ziliaoId: this.$route.query.informationId || "",
      editFlag: this.$route.query.editFlag || "",
      php_url: php_url,
      isShowresultModal: false,
      resultModalFlag: true,
      tipModalText: "",
      addReportConfig: {}
    };
  },
  computed: {
    // 表格总页数
    totalPage() {
      return Math.ceil(this.sum / this.pageSize);
    },
    //是否隐藏编辑按钮 时间判断
    showItemOperation: function () {
      if (!this.endTime) {
        return { showItemOperationStyle: true };
      } else {
        return { showItemOperationStyle: false };
      }
    },
  },
  methods: {
    /*toggleModal：点击编辑后弹窗； toggleModal2：点击删除后弹窗； toggleModal3：点击导入后弹窗；  */
    toggleModal: function (i) {
      this.modalData = this.tableData[i];
      this.showModal = !this.showModal;
    },
    closeme: function () {
      this.showModal = !this.showModal;
    },

    //新增弹窗关闭
    closemeAdd: function () {
      this.showModalAdd = !this.showModalAdd;
    },
    //删除
    toggleModal2: function (i) {
      this.showModal2 = !this.showModal2;
      this.modalData = this.tableData[i];
    },
    closeme2: function () {
      this.showModal2 = !this.showModal2;
    },
    /* 编辑内容，，Modal传参 */
    editTitle: function (val) {
      axiosTest({
        url: this.php_url + val.url,
        method: "post",
        data: val.data,
      })
        .then((res) => {
          if (res.data && res.data.code == 200) {
            //更新数据
            let config = {
              Page: this.currentPage,
              Rows: this.pageSize,
              agentId: this.userId,
            };
            this.getDataList(config);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 新增反馈接口
    add_report: function () {
       axiosTest({
        method: "post",
        url: this.php_url + "/lexus_php/api/add_report.php",
        data: this.addReportConfig.data,
      }).then((res) => {
        if(res.data && res.data.code === 0) {
          this.isShowresultModal = true;
          this.tipModalText = res.data.message;
        } else {
          this.getDataList();
        }
      }).catch((err) => {
        console.log(err);
      })
    },
    // 新增
    addFeedBack: function (val) {
      this.addReportConfig = val;
      this.addReportConfig.data.add_times = 1
      this.add_report();
    },
    // 关闭导入结果弹窗
    closeResultModal: function () {
      this.isShowresultModal = false;
    },
    // 导入结果返回结果是code是0
    submit: function () {
      this.addReportConfig.data.add_times = 2
      this.add_report();
    },
    toDel: function () {
      this.showModal2 = !this.showModal2;
      //更新数据

      //this.choosePlatform();
      this.newGetDataList();
    },
    /* 表格翻页 */
    changePage: function (page) {
      this.currentPage = page;
      this.getDataList();
    },
    // 点击上一页，下一页，首页，尾页
    jumpPage: function (item) {
      switch (item) {
        case 1:
          this.currentPage = 1;
          break;
        case 2:
          this.currentPage = this.currentPage - 1;
          break;
        case 3:
          this.currentPage = this.currentPage + 1;
          break;
        case 4:
          this.currentPage = this.totalPage;
          break;
      }
      this.getDataList();
    },
    getDataList: function () {
      axiosTest({
        method: "post",
        url: this.php_url + "/lexus_php/api/myreport.php",
        data: {
          agentId: this.accountId,
          informationId: this.$route.query.informationId,
          Page: this.currentPage,
          Rows: this.pageSize,
        },
      })
        .then((res) => {
          if (res.data.code === 200) {
            this.tableData = [];
            let data = res.data.data;
            this.sum = res.data.count;
            for (let i = 0, j = 0; j < data.length; i++, j++) {
              this.$set(this.tableData, i, data[j]);
            }
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    newGetDataList: function () {
      axiosTest({
        method: "post",
        url: this.php_url + "/lexus_php/api/myreport.php",
        data: {
          agentId: this.accountId,
          informationId: this.$route.query.informationId,
          Page: this.currentPage,
          Rows: this.pageSize,
        },
      })
        .then((res) => {
          if (res.data.code === 200) {
            this.tableData = [];
            let data = res.data.data;
            this.sum = res.data.count;
            for (let i = 0, j = 0; j < data.length; i++, j++) {
              this.$set(this.tableData, i, data[j]);
            }
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //新增反馈
    addInfo: function () {
      this.showModalAdd = !this.showModalAdd;
    },
  },
  mounted() {
    let userId = localStorage.getItem("userId");
    if (userId) {
      this.accountId = userId;
      this.getDataList();
    } else {
      this.accountId = "";
      this.getDataList();
    }
  },
  created() {},
  beforeRouteEnter(to, from, next) {
    console.log(from)
    let meta = to.meta;
    meta[2].name = (to.query.informationName || '') + '详情'
    next()
  }
};
</script>

<style scoped lang="less">
.contentHead {
  height: 55px;
  display: flex;
  align-items: center;
}
.contentHead span {
  margin-right: 15px;
}
.tableBox {
  width: 1030px;
  overflow-y: hidden;
}
.tableBox {
  text-align: center;
  .table {
    table-layout: fixed;
    background-color: #fff;
    border-collapse: collapse;
    border: none;
    td {
      border: 1px solid #ccc;
    }
    span {
      &:hover {
        cursor: pointer;
      }
    }
  }
}
.table_gray td {
  background-color: #eeeeee;
}
.tableBox table {
  border-collapse: collapse;
  border: 0;
}
.tableBox table td {
  border: 1px solid #ccc;
  border-right: 0;
  border-bottom: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  display:block!important;
}
// 表头样式
.theadStyle tr td {
  color: white;
}
.tableHeadStyle1 {
  background: #848484;
  height: 30px;
  color: #fff;
  display: flex;
  align-items: center;
}
.tableHeadStyle1 td {
  width: 100%;
  padding: 7px 5px;
}
.tableHeadStyle2 {
  color: #333;
  display: flex;
  align-items: center;
  line-height: 20px;
}
.tableHeadStyle2 td {
  width: 100px;
  padding: 7px 5px;
}
.tableHeadStyle3 td {
  background: #848484;
}
.tableHeadStyle2 td:nth-child(1) {
  width: 60px;
}
.tableHeadStyle2 td:nth-child(10) {
  width: 100px;
  padding: 7px 5px;
}
.tableHeadStyle2 td:nth-child(11) {
  width: 100px;
  padding: 7px 5px;
}
.tableHeadStyle2 td:nth-child(12) {
  width: 100px;
  padding: 7px 5px;
}
.tableHeadStyle2 td:nth-child(2) {
  width: 100px;
  padding: 7px 5px;
}
.tableHeadStyle2 td:nth-child(3) {
  width: 100px;
  padding: 7px 5px;
}
.bodyStyle {
  display: block;
  background-color: #fff;
}
.bodyStyle tr > td:nth-last-child(2) {
  color: #0000ff;
}
.bodyContent td {
  //background-color: #fff;
  height: 20px;
}
.bodyContent td:nth-last-child(2) a {
  color: #0000ff;
}
.operationStyle {
  color: #0000ff;
  display: flex;
  justify-content: space-around;
}
.xiahuaxian {
  text-decoration: underline;
}
.operationStyle span {
  color: #0000ff;
}
.fileOperation {
  display: flex;
  justify-content: flex-start;
  margin: 10px;
  align-items: center;
}
.fileOperation button {
  border-radius: 4px;
}
.fileOperation span {
  margin-right: 16px;
}
.fileOperation {
  border-radius: 4px;
  label {
    margin-right: 16px;
    height: 30px;
    line-height: 30px;
    width: 56px;
    background-color: #0056a0;
    color: #fff;
    text-align: center;
    font-size: 14px;
    input {
      display: none;
    }
  }
}

.timeLimitStyle {
  padding: 10px;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.3);
  display: flex;
  justify-content: center;
  align-items: center;
}
.modal {
  background-color: #ffffff;
  box-shadow: 2px 2px 20px 1px;
  overflow-x: auto;
  display: flex;
  flex-direction: column;
  width: 500px;
  border-radius: 0px;
  height: 230px;
}
.modal-footer {
  border-top: 1px solid #eee;
  position: relative;
  top: 124px;
  left: 232px;
  width: 208px;
  display: flex;
  justify-content: space-between;
  padding: 0px;
}
.modal-footer button {
  border-radius: 4px;
  margin-left: 0px;
  width: 80px;
  font-size: 14px;
}

.modal-footer button:nth-child(1) {
  background-color: #0056a0;
}
.modal-footer button:nth-child(2) {
  background-color: #eeeeee;
}
.modal-body {
  position: relative;
  top: 64px;
  margin-left: 50px;
  padding: 0px;
}
.btn-close,
.btn-confirm {
  margin-left: 16px;
  width: 56px;
  height: 36px;
  border: none;
  cursor: pointer;
}
.btn-close {
  color: #313131;
  background-color: gray;
}
.btn-confirm {
  color: #fff;
  background-color: #2d8cf0;
}
.bodyRow {
  font-size: 16px;
  font-family: Arial;
}

.pageBottom {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.topLeftTitle {
  height: 50px;
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}
.addButton {
  color: white;
  width: 80px;
  border-radius: 4px;
}
.upHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.showItemOperationStyle {
  display: none;
}
</style>
