Newer
Older
smartKitchenFront / src / views / move / hotAndNews.vue
liyaguang on 22 Dec 2022 8 KB fix(*): 修改服务管理
<!--热门推荐与新闻配置列表-->
<template>
  <div class="product_container">
    <div class="productFun">
      <div class="productInput">
        标题
        <div class="inputBox" style="width: 120px">
          <el-input v-model="selectInfo.recommendTitle" placeholder="请输入标题" clearable class="product-input" />
        </div>
        类型
        <div class="inputBox" style="width: 140px">
          <el-select v-model="selectInfo.recommendType" filterable placeholder="类型">
            <el-option v-for="item in typeList" :key="item.key" :label="item.value" :value="item.key" />
          </el-select>
        </div>
      </div>
      <div class="productBtn">
        <el-button type="primary" icon="el-icon-search" class="btnItem" @click="selectData">
          查询
        </el-button>
        <el-button type="primary" icon="el-icon-refresh-right" class="btnItem" @click="reset">
          重置
        </el-button>
        <el-button type="success" icon="el-icon-circle-plus-outline" class="btnItem bggreen" @click="addCategory">
          新增
        </el-button>
        <el-button type="danger" icon="el-icon-delete-solid" class="btnItem bgred" @click="BatchDelete">
          删除
        </el-button>
      </div>
    </div>
    <el-table ref="multipleTable" :data="tableData.rows" :row-class-name="tableRowClassName" :header-cell-style="{
      'text-align': 'center',
      background: '  #2483b3',
      color: 'white',
    }" :row-style="{ 'text-align': 'center' }" style="width: 100%">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="index" label="序号" width="60" />
      <el-table-column prop="recommendCode" label="编号" />
      <el-table-column prop="recommendModuleName" label="所属模块" />
      <el-table-column prop="recommendTypeName" label="类型" />
      <el-table-column prop="recommendTitle" label="标题" />
      <el-table-column prop="recommendPicture" label="图片">
        <template slot-scope="scope">
          <img v-if="scope.row.recommendPicture != ''" :src="scope.row.recommendPicture" width="100" height="100px"
            alt="" />
        </template>
      </el-table-column>
      <el-table-column prop="recommendContent" label="内容">
        <template slot-scope="scope">
          <span v-html="scope.row.recommendContent"></span>
        </template>
   </el-table-column>
      <el-table-column prop="recommendPublisher" label="发布人" />
      <el-table-column prop="publishTime" label="发布时间" />
      <el-table-column prop="recommendSort" label="排序" />
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="updata(scope.row)">
            编辑
          </el-button>
          <el-button type="text" size="small" @click="Bdelete(scope.row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <group-page v-model="isFristPage" :limit="limit" :total="total" :offset="offset" :count="tableData.total"
      @setOffset="setOffset" @setLimit="setLimit" />
    <!-- 新增弹框 -->
    <hotand-news-dialog :is-show-info="isShowAdd" :title="title" :data-info="rowInfo" @close="closeAdd" />
  </div>
</template>

<script>
// 组件
import GroupPage from "../../components/mycomponent/groupPage.vue";
import HotandNewsDialog from "../../components/mycomponent/dialog/move/hotandNewsDialog.vue";
// 逻辑
import { tableRowClassName } from "../../utils/myUtils/changeTableTr";
import { listMixin } from "../../utils/myUtils/mixins/listPage";
import { listPage, batchDelete, bdelete } from "../../api/move/hotAndNews";
import { list } from "../../api/move/bannerConfig";
export default {
  // 加入分页逻辑
  components: {
    HotandNewsDialog,
    GroupPage,
  },
  mixins: [listMixin],
  data() {
    return {
      title: "",
      isShowAdd: false, // 显示新增功能
      selectInfo: {
        recommendType: "",
        recommendTitle: "",
      },
      rowInfo: "",
      typeList: [],
    };
  },
  mounted() {
    list().then((res) => {
      console.log(res)
      const str2 = res[26].detail;
      this.typeList = this.dealAry(str2);
    });
  },
  methods: {
    tableRowClassName: tableRowClassName,
    dealAry(str) {
      const Ary = [];
      const strAry = str.split(";");
      for (let i = 0; i < strAry.length; i++) {
        const temp = strAry[i].split(":");
        Ary.push({
          key: temp[2],
          value: temp[1],
        });
      }
      return Ary;
    },
    closeAdd() {
      this.isShowAdd = false;
      this.refresh();
    },
    addCategory() {
      this.isShowAdd = true;
      this.title = "新增";
      this.rowInfo = "";
    },
    updata(row) {
      this.isShowAdd = true;
      this.title = "编辑";
      this.rowInfo = row;
    },
    getListPage(limit, offset) {
      listPage(`limit=${limit}&offset=${offset}`, this.queryInfo).then(
        (res) => {
          // 得到相关数据
          res.rows.forEach((item, index) => {
            item.index = index + 1 + (offset - 1) * 10;
          });
          res.rows = res.rows.map((item, index) => {
            return {
              ...item,
              recommendPicture: item.recommendPicture ? "http://111.198.10.15:21403/static/" + item.recommendPicture : '',
              publishTime: item.publishTime.split(' ')[0],

            }
          })
          this.tableData = res;
        }
      );
    },
    reset() {
      this.selectInfo = {
        recommendType: "",
        recommendTitle: "",
      };
      listPage(`limit=${10}&offset=${1}`, this.selectInfo).then((res) => {
        // 得到相关数据
        res.rows.forEach((item, index) => {
          item.index = index + 1 + (1 - 1) * 10;
        });
        res.rows = res.rows.map((item, index) => {
          return {
            ...item,
            recommendPicture: item.recommendPicture ? "http://111.198.10.15:21403/static/" + item.recommendPicture : '',
            publishTime: item.publishTime.split(' ')[0],
            recommendContent: item.recommendContent.substr(2, item.recommendContent.length - 3)
          }
        })
        this.tableData = res;
      });
    },
    BatchDelete() {
      if (this.$refs.multipleTable.selection.length) {
        this.$confirm(`确认删除选中的这些数据吗?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            //  得到选中行
            const dle_ary = this.$refs.multipleTable.selection;
            const ids = [];
            dle_ary.forEach((ele) => {
              ids.push(ele.id);
            });
            batchDelete({ ids: ids }).then((res) => {
              this.$message({
                message: "删除成功",
                type: "success",
              });
              this.refresh();
            });
          })
          .catch(() => { });
      } else {
        this.$message.error("请选择需要删除的数据");
      }
    },
    // 删除
    Bdelete(row) {
      this.$confirm(`确认删除选中的这些数据吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        const id = row.id;
        bdelete({ id: id }).then((res) => {
          // 删除成功跟新数据
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.refresh();
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.product_container {
  position: relative;
  width: 100%;
  min-height: 700px;
  overflow: auto;

  .productData {
    width: 100%;
    display: flex;
    justify-content: center;

    .middle {
      margin: 0 30px;
    }
  }

  .productFun {
    margin: 0px 0px 30px;
    display: flex;
    justify-content: space-between;

    .productInput {
      display: flex;
      align-items: center;

      .inputBox {
        margin: 0 50px 0 10px;
      }
    }

    .productBtn {
      .btnItem {
        margin-right: 10px;
        border-radius: 5px;
        // height: 32px;
        // width: 84px;
        font-size: 16px;
      }
    }
  }

  .footer {
    display: flex;
    justify-content: space-between;
    color: #6666;
    margin: 30px 10px;
  }
}
</style>