| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- <template>
- <div id="famousTeacherManagement">
- <search-box :formList="formList" @search="search" @init="init" />
- <table-list
- :tableSets="tableSet"
- :tableData="tableData"
- :navText="navText"
- @addClick="addClick"
- :loading="loading"
- >
- <template slot="btn" slot-scope="props">
- <el-button type="text" @click="modify(props.scope.row)">修改</el-button>
- <el-button type="text" @click="del(props.scope.row)">删除</el-button>
- </template>
- </table-list>
- <pagination
- :total="total"
- :pageSize="pageSize"
- :currentPage="currentPage"
- @handleSizeChange="handleSizeChange"
- @handleCurrentChange="handleCurrentChange"
- />
- <el-dialog
- :visible.sync="dialogBox"
- width="920px"
- :show-close="false"
- :destroy-on-close="true"
- :fullscreen="fullscreen"
- :close-on-click-modal="false"
- >
- <div slot="title" class="hearders">
- <div class="leftTitle">{{ statusPop === 1 ? "添加" : "修改" }}</div>
- <div class="rightBoxs">
- <img
- src="@/assets/images/Max@2x.png"
- alt=""
- @click="fullscreen = !fullscreen"
- />
- <img src="@/assets/images/Close@2x.png" alt="" @click="closeBefore" />
- </div>
- </div>
- <el-row class="contentBox" :span="24">
- <el-col :span="12">
- <el-col :span="24">
- <header>名师姓名:</header>
- <el-input
- placeholder="请输入名师姓名:"
- v-model="poppleData.teacherName"
- /></el-col>
- <el-col :span="24">
- <header>简介:</header>
- <el-input placeholder="请输入简介" v-model="poppleData.introduce" />
- </el-col>
- <el-col :span="24">
- <header>是否启用:</header>
- <el-radio-group v-model="poppleData.status">
- <el-radio :label="1">是</el-radio>
- <el-radio :label="0">否</el-radio>
- </el-radio-group>
- </el-col>
- </el-col>
- <el-col :span="12">
- <el-col :span="24">
- <header>名师头像:</header>
- <div class="imgBox">
- <label class="imgLabel" for="inputs">
- <div class="msPhoto" v-if="poppleData.avatar">
- <img
- :src="$methodsTools.splitImgHost(poppleData.avatar)"
- alt="图片加载失败"
- />
- </div>
- <div class="imgbbx" v-else>
- <p style="margin-top: 49px">点击添加或将文件拖拽到这里上传</p>
- <i class="el-icon-plus"></i>
- <p style="margin-bottom: 37px">
- 图片格式:.jpg/.png/jpeg/bmp
- </p>
- </div>
- <input
- id="inputs"
- type="file"
- ref="file"
- style="display: none"
- @change="getImgFile"
- />
- </label>
- <p>请上传比例为16:9且小于2m的图片</p>
- </div>
- </el-col>
- </el-col>
- </el-row>
- <div slot="footer" class="dialog-footer">
- <el-button @click="closeBefore">取 消</el-button>
- <el-button type="primary" @click="submitTabel">确 定</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import searchBox from "@/components/searchBox";
- import tableList from "@/components/tableList";
- import pagination from "@/components/pagination";
- export default {
- components: { searchBox, tableList, pagination },
- data() {
- return {
- loading: false, //当前表单加载是否加载动画
- navText: {
- title: "名师合计",
- index: 0,
- ch: "人",
- num: true,
- choice: true,
- backFatherBtn: {
- status: false,
- title: "未定义",
- },
- },
- tableSet: [
- {
- label: "姓名",
- prop: "teacherName",
- hidden: true,
- },
- {
- label: "名师头像",
- prop: "avatar",
- hidden: true,
- scope: "img",
- width: "200px",
- },
- {
- label: "简介",
- prop: "introduce",
- hidden: true,
- },
- {
- label: "启用状态",
- prop: "status",
- hidden: true,
- scope: "status",
- },
- ], //表头信息
- tableData: [], //表单数据
- total: 0, //一共多少条
- pageSize: 10, //每页多少条数据
- currentPage: 1, //当前页码
- formList: [
- {
- label: "名师名称",
- prop: "teacherName",
- placeholder: "输入名师名称",
- },
- {
- label: "启用状态",
- prop: "status",
- scope: "select",
- placeholder: "选择启用状态",
- options: [
- {
- label: "启用",
- value: 1,
- },
- {
- label: "关闭",
- value: 0,
- },
- ],
- },
- ], //搜索栏
- poppleData: {},
- fullscreen: false,
- dialogBox: false,
- statusPop: 0,
- beif: "", //备份数据
- };
- },
- mounted() {
- this.search();
- },
- methods: {
- getImgFile() {
- var self = this;
- var file = self.$refs.file.files[0];
- if (file === undefined) {
- self.$set(self.poppleData, "avatar", "");
- return;
- }
- if (file.size > 2 * 1024 * 1024) {
- self.$message.error("图片不得大于2MB");
- return;
- }
- var type = self.$refs.file.value.toLowerCase().split(".").splice(-1);
- if (
- type[0] != "jpg" &&
- type[0] != "png" &&
- type[0] != "jpeg" &&
- type[0] != "bmp"
- ) {
- self.$message.error("上传格式需为:.jpg/.png/.jpeg/bmp");
- self.$refs.file.value = "";
- return;
- }
- var reader = new FileReader();
- reader.readAsDataURL(file);
- reader.onload = function (ev) {
- self.$set(self.poppleData, "avatar", ev.target.result);
- };
- },
- async submitTabel() {
- var self = this;
- if (!self.poppleData.teacherName) {
- self.$message.error("请输入名师姓名");
- return;
- }
- if (!self.poppleData.introduce) {
- self.$message.error("请输入简介");
- return;
- }
- if (self.poppleData.status !== 0 && self.poppleData.status !== 1) {
- self.$message.error("请选择是否启用");
- return;
- }
- if (self.poppleData.avatar.length === 0) {
- self.$message.error("请上传头像");
- return;
- }
- if (self.statusPop === 0) {
- if (self.poppleData.avatar !== self.beif.avatar) {
- const awtimg = await self.imgUpload(0);
- }
- } else {
- const awtimg = await self.imgUpload(0);
- }
- var data = {
- teacherName: self.poppleData.teacherName,
- status: self.poppleData.status,
- introduce: self.poppleData.introduce,
- avatar: self.poppleData.avatar,
- };
- if (self.statusPop === 1) {
- self.$api.addCourseTeacher(data).then((sult) => {
- self.$message.success("添加成功!");
- self.dialogBox = false;
- self.search();
- });
- } else {
- data.teacherId = self.poppleData.teacherId;
- self.$api.editCourseTeacher(data).then((sult) => {
- self.$message.success("修改成功!");
- self.dialogBox = false;
- self.search();
- });
- }
- },
- imgUpload(int) {
- var self = this;
- return new Promise((resolve, reject) => {
- self.$upload
- .upload(self.$refs.file.files[0], int)
- .then((res) => {
- self.$set(self.poppleData, "avatar", res);
- resolve();
- })
- .catch((err) => {
- self.$message.error("图片上传错误");
- });
- });
- },
- //添加
- addClick() {
- this.poppleData = {
- avatar: "",
- };
- this.statusPop = 1;
- this.dialogBox = true;
- },
- // 修改
- modify(options) {
- var self = this;
- this.$api.obtainCourseTeacher(options.teacherId).then((res) => {
- console.log(res)
- if (res.code === 200) {
- self.beif = JSON.parse(JSON.stringify(res.data));
- self.poppleData = res.data;
- self.statusPop = 0;
- self.dialogBox = true;
- }
- });
- },
- //删除
- del(options) {
- var self = this;
- this.$confirm("此操作将删除该专业分类, 是否继续?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- var data = {
- teacherId: options.teacherId,
- avatar: options.avatar,
- introduce: options.introduce,
- status: -1,
- teacherName: options.teacherName,
- };
- self.$api
- .editCourseTeacher(data)
- .then((res) => {
- self.$message.success("删除成功");
- self.search();
- })
- .catch((error) => {
- self.$message.error("删除失败,失败原因:" + error);
- });
- })
- .catch(() => {});
- },
- search(v) {
- var self = this;
- if (v === undefined) {
- v = {
- status: "0,1",
- teacherName: "",
- pageSize: this.pageSize,
- pageNum: this.currentPage,
- };
- }
- var data = {
- status: v.status === undefined ? "0,1" : v.status,
- teacherName: v.teacherName || "",
- pageSize: this.pageSize,
- pageNum: this.currentPage,
- };
- self.loading = true;
- self.$api
- .inquireCourseTeacher(data)
- .then((res) => {
- res.rows.forEach((item, index) => {
- item.srcList = [item.avatar];
- });
- self.tableData = res.rows;
- self.total = res.total;
- self.navText.index = res.total;
- self.loading = false;
- })
- .catch((err) => {
- self.loading = false;
- });
- },
- init() {
- this.search();
- },
- //窗口关闭
- closeBefore() {
- this.dialogBox = false;
- this.fullscreen = false;
- this.poppleData = {};
- },
- handleSizeChange(v) {
- this.pageSize = v;
- this.currentPage = 1;
- this.search();
- },
- handleCurrentChange(v) {
- this.currentPage = v;
- this.search();
- },
- },
- };
- </script>
- <style lang="less" scoped>
- /deep/.el-button {
- border-radius: 8px;
- }
- /deep/.el-dialog {
- border-radius: 8px;
- .el-dialog__header {
- padding: 0;
- .hearders {
- height: 40px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0px 18px 0px 20px;
- border-bottom: 1px solid #e2e2e2;
- .leftTitle {
- font-size: 14px;
- font-weight: bold;
- color: #2f4378;
- }
- .rightBoxs {
- display: flex;
- align-items: center;
- img {
- width: 14px;
- height: 14px;
- margin-left: 13px;
- cursor: pointer;
- }
- }
- }
- }
- .el-dialog__body {
- padding: 0;
- .contentBox {
- padding: 20px 20px 5px;
- .el-col {
- padding: 0px 20px;
- margin-bottom: 30px;
- header {
- margin-bottom: 6px;
- color: #2f4378;
- font-size: 14px;
- }
- }
- }
- }
- .el-dialog__footer {
- padding: 0;
- .dialog-footer {
- padding: 0px 40px;
- height: 70px;
- border-top: 1px solid #e2e2e2;
- display: flex;
- align-items: center;
- justify-content: flex-end;
- }
- }
- }
- .imgBox {
- width: 100%;
- // height: 210px;
- border: 1px solid #e2e2e2;
- border-radius: 8px;
- padding: 8px 8px 3px;
- display: flex;
- flex-direction: column;
- align-items: center;
- .imgLabel {
- flex: 1;
- width: 100%;
- border: 1px dotted #e2e2e2;
- color: #999;
- font-size: 14px;
- cursor: pointer;
- border-radius: 8px;
- .msPhoto {
- display: flex;
- justify-content: center;
- align-items: center;
- max-width: 100%;
- max-height: 270px;
- img {
- max-width: 100%;
- max-height: 270px;
- }
- }
- .imgbbx {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 100%;
- i {
- font-weight: bold;
- margin: 14px 0;
- font-size: 24px;
- }
- }
- }
- p {
- margin: 5px 0px;
- }
- }
- </style>
|