contentTab.vue 5.3 KB
Newer Older
乐宝呗666's avatar
乐宝呗666 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<template>
  <div class="learn-detail-content">
    <div class="page-wrapper">
      <form action="javascript:return true">
        <van-search
          type="search"
          v-model="searchVal"
          shape="round"
          placeholder="请输入学习内容名称"
          @search="onRefresh"
        />
      </form>
      <div class="detail-body">
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
乐宝呗666's avatar
乐宝呗666 committed
15 16 17 18 19 20 21 22 23 24 25 26 27
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
            offset="50"
          >
            <van-cell v-for="(item, index) in tableData" :key="index">
              <van-swipe-cell :stop-propagation="true">
                <van-card
                  :title="item.name"
                  :thumb="item.cover"
                  @click="goDetail(item)"
乐宝呗666's avatar
乐宝呗666 committed
28
                />
乐宝呗666's avatar
乐宝呗666 committed
29 30 31 32
                <template #right>
                  <van-button
                    @click="optFn(item)"
                    square
33
                    :disabled="item.auditStatus!=='APPROVED_FINAL' "
乐宝呗666's avatar
乐宝呗666 committed
34
                    :text="active ? '启用' : '禁用'"
乐宝呗666's avatar
乐宝呗666 committed
35 36 37 38 39 40 41 42 43 44 45
                    type="danger"
                    :class="{
                      'delete-button': active === 0,
                      'enable-button': active === 1,
                    }"
                  />
                </template>
              </van-swipe-cell>
            </van-cell>
          </van-list>
        </van-pull-refresh>
乐宝呗666's avatar
乐宝呗666 committed
46 47 48 49 50 51 52
      </div>
    </div>
  </div>
</template>

<script>
export default {
乐宝呗666's avatar
乐宝呗666 committed
53
  props: ["active", "proId"],
乐宝呗666's avatar
乐宝呗666 committed
54 55
  data() {
    return {
乐宝呗666's avatar
乐宝呗666 committed
56
      searchVal: "",
乐宝呗666's avatar
乐宝呗666 committed
57 58
      pageNum: 1,
      pageSize: 8,
乐宝呗666's avatar
乐宝呗666 committed
59
      tableData: [],
乐宝呗666's avatar
乐宝呗666 committed
60 61 62
      loading: false,
      finished: false,
      refreshing: false,
乐宝呗666's avatar
乐宝呗666 committed
63
      flag: true,
乐宝呗666's avatar
乐宝呗666 committed
64 65
    };
  },
乐宝呗666's avatar
乐宝呗666 committed
66 67 68 69
  watch: {
    active() {
      this.onRefresh();
    },
乐宝呗666's avatar
乐宝呗666 committed
70 71
  },
  mounted() {
乐宝呗666's avatar
乐宝呗666 committed
72
    this.getList();
乐宝呗666's avatar
乐宝呗666 committed
73 74 75 76 77 78
  },
  methods: {
    // 获得数据接口
    getList() {
      let vm = this;
      let param = {
乐宝呗666's avatar
乐宝呗666 committed
79 80 81 82 83
        _index: this.pageNum,
        _size: this.pageSize,
        isPublished: this.active !== 1,
        learningProjectId: this.proId,
        nameOrCode: this.searchVal,
乐宝呗666's avatar
乐宝呗666 committed
84 85 86 87 88
      };
      vm.$https(
        {
          url: "learningContent/getPageList",
          method: "post",
乐宝呗666's avatar
乐宝呗666 committed
89
          authType: this.backToken,
乐宝呗666's avatar
乐宝呗666 committed
90 91
        },
        vm.$qs.stringify(param)
乐宝呗666's avatar
乐宝呗666 committed
92 93 94 95
      )
        .then((res) => {
          if (res.data.resultCode === "200") {
            vm.loading = false;
乐宝呗666's avatar
乐宝呗666 committed
96
            let data = res.data.data;
乐宝呗666's avatar
乐宝呗666 committed
97 98 99 100
            vm.tableData = vm.flag
              ? data.records
              : vm.tableData.concat(data.records);
            vm.flag = false;
乐宝呗666's avatar
乐宝呗666 committed
101
            vm.refreshing = false;
乐宝呗666's avatar
乐宝呗666 committed
102 103 104 105 106
            vm.pageNum = vm.pageNum + 1;
            vm.finished = data.records.length < vm.pageSize;
            vm.tableData = [...vm.tableData];
          } else {
            vm.$toast( res.data.message );
乐宝呗666's avatar
乐宝呗666 committed
107 108
          }
        })
乐宝呗666's avatar
乐宝呗666 committed
109
        .catch(function (err) {
乐宝呗666's avatar
乐宝呗666 committed
110
          console.log(err);
乐宝呗666's avatar
乐宝呗666 committed
111
        });
乐宝呗666's avatar
乐宝呗666 committed
112 113 114
    },
    // 列表的load上拉加载事件
    onLoad() {
乐宝呗666's avatar
乐宝呗666 committed
115
      if (!this.flag) {
乐宝呗666's avatar
乐宝呗666 committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
        console.log("加载数据");
        this.loading = true;
        this.flag = false;
        this.getList();
      }
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;
      this.flag = true;
      this.loading = true;
      this.pageNum = 1;
      this.getList();
    },
    optFn(item) {
      if (this.active === 1) {
乐宝呗666's avatar
乐宝呗666 committed
132
        this.changeStatus(true, item.id);
乐宝呗666's avatar
乐宝呗666 committed
133
      } else {
乐宝呗666's avatar
乐宝呗666 committed
134
        this.changeStatus(false, item.id);
乐宝呗666's avatar
乐宝呗666 committed
135 136 137
      }
    },
    // 启用 禁用
乐宝呗666's avatar
乐宝呗666 committed
138
    changeStatus(flag, id) {
乐宝呗666's avatar
乐宝呗666 committed
139 140
      let vm = this;
      let param = {
乐宝呗666's avatar
乐宝呗666 committed
141 142
        id: id,
        isPublish: flag,
乐宝呗666's avatar
乐宝呗666 committed
143 144 145 146 147
      };
      vm.$https(
        {
          url: `learningContent/enable/${id}`,
          method: "put",
乐宝呗666's avatar
乐宝呗666 committed
148 149 150 151 152 153 154 155 156 157
          authType: this.backToken,
        },
        vm.$qs.stringify(param)
      )
        .then((res) => {
          if (res.data.resultCode === "200") {
            this.$toast(res.data.message);
            this.onRefresh();
          } else {
            this.$toast(res.data.message);
乐宝呗666's avatar
乐宝呗666 committed
158 159
          }
        })
乐宝呗666's avatar
乐宝呗666 committed
160
        .catch(function (err) {
乐宝呗666's avatar
乐宝呗666 committed
161 162 163 164
          console.log(err);
        });
    },
    goDetail(item) {
乐宝呗666's avatar
乐宝呗666 committed
165 166 167
      this.$router.push({ path: "/learnDetail", query: { id: item.id } });
    },
  },
乐宝呗666's avatar
乐宝呗666 committed
168 169 170 171 172 173
};
</script>

<style lang="scss" scoped>
.learn-detail-content {
  height: calc(100vh - 100px);
乐宝呗666's avatar
乐宝呗666 committed
174
  .page-wrapper {
乐宝呗666's avatar
乐宝呗666 committed
175 176 177 178 179 180 181 182
    height: 100%;
  }
  .van-search {
    padding: 20px 0;
    .van-cell {
      line-height: 30px;
    }
  }
183
  ::v-deep .van-field__left-icon {
乐宝呗666's avatar
乐宝呗666 committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
    color: #ac9374;
    .van-icon {
      font-size: 20px;
    }
  }
  .detail-body {
    height: calc(100% - 80px);
    overflow-y: auto;
    .van-pull-refresh {
      height: 100%;
    }
    .van-cell {
      padding: 0;
    }
    .van-cell::after {
      border-bottom: none;
    }
  }
  .delete-button {
    height: 100%;
    background: #a4151d;
    font-size: 16px;
  }
  .enable-button {
    height: 100%;
    background: #6bc20b;
    font-size: 16px;
  }
  .van-button--danger {
    border: none;
  }
  .van-card {
    padding: 16px;
    background-color: transparent;
    border-bottom: 1px solid #eee;
    .van-card__thumb {
      width: 64px;
      height: 40px;
    }
    .van-card__content {
      min-height: 40px;
      .van-card__title {
        line-height: 40px;
        font-size: 16px;
        color: #333;
      }
    }
  }
}
</style>