index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <div id="famousTeacherManagement">
  3. <search-box :formList="formList" @search="search" @init="init" />
  4. <table-list
  5. :tableSets="tableSet"
  6. :tableData="tableData"
  7. :navText="navText"
  8. @addClick="addClick"
  9. :loading="loading"
  10. >
  11. <template slot="btn" slot-scope="props">
  12. <el-button type="text" @click="modify(props.scope.row)">修改</el-button>
  13. <el-button type="text" @click="del(props.scope.row)">删除</el-button>
  14. </template>
  15. </table-list>
  16. <pagination
  17. :total="total"
  18. :pageSize="pageSize"
  19. :currentPage="currentPage"
  20. @handleSizeChange="handleSizeChange"
  21. @handleCurrentChange="handleCurrentChange"
  22. />
  23. <el-dialog
  24. :visible.sync="dialogBox"
  25. width="920px"
  26. :show-close="false"
  27. :destroy-on-close="true"
  28. :fullscreen="fullscreen"
  29. :close-on-click-modal="false"
  30. >
  31. <div slot="title" class="hearders">
  32. <div class="leftTitle">{{ statusPop === 1 ? "添加" : "修改" }}</div>
  33. <div class="rightBoxs">
  34. <img
  35. src="@/assets/images/Max@2x.png"
  36. alt=""
  37. @click="fullscreen = !fullscreen"
  38. />
  39. <img src="@/assets/images/Close@2x.png" alt="" @click="closeBefore" />
  40. </div>
  41. </div>
  42. <el-row class="contentBox" :span="24">
  43. <el-col :span="12">
  44. <el-col :span="24">
  45. <header>名师姓名:</header>
  46. <el-input
  47. placeholder="请输入名师姓名:"
  48. v-model="poppleData.teacherName"
  49. /></el-col>
  50. <el-col :span="24">
  51. <header>简介:</header>
  52. <el-input placeholder="请输入简介" v-model="poppleData.introduce" />
  53. </el-col>
  54. <el-col :span="24">
  55. <header>是否启用:</header>
  56. <el-radio-group v-model="poppleData.status">
  57. <el-radio :label="1">是</el-radio>
  58. <el-radio :label="0">否</el-radio>
  59. </el-radio-group>
  60. </el-col>
  61. </el-col>
  62. <el-col :span="12">
  63. <el-col :span="24">
  64. <header>名师头像:</header>
  65. <div class="imgBox">
  66. <label class="imgLabel" for="inputs">
  67. <div class="msPhoto" v-if="poppleData.avatar">
  68. <img
  69. :src="$methodsTools.splitImgHost(poppleData.avatar)"
  70. alt="图片加载失败"
  71. />
  72. </div>
  73. <div class="imgbbx" v-else>
  74. <p style="margin-top: 49px">点击添加或将文件拖拽到这里上传</p>
  75. <i class="el-icon-plus"></i>
  76. <p style="margin-bottom: 37px">
  77. 图片格式:.jpg/.png/jpeg/bmp
  78. </p>
  79. </div>
  80. <input
  81. id="inputs"
  82. type="file"
  83. ref="file"
  84. style="display: none"
  85. @change="getImgFile"
  86. />
  87. </label>
  88. <p>请上传比例为16:9且小于2m的图片</p>
  89. </div>
  90. </el-col>
  91. </el-col>
  92. </el-row>
  93. <div slot="footer" class="dialog-footer">
  94. <el-button @click="closeBefore">取 消</el-button>
  95. <el-button type="primary" @click="submitTabel">确 定</el-button>
  96. </div>
  97. </el-dialog>
  98. </div>
  99. </template>
  100. <script>
  101. import searchBox from "@/components/searchBox";
  102. import tableList from "@/components/tableList";
  103. import pagination from "@/components/pagination";
  104. export default {
  105. components: { searchBox, tableList, pagination },
  106. data() {
  107. return {
  108. loading: false, //当前表单加载是否加载动画
  109. navText: {
  110. title: "名师合计",
  111. index: 0,
  112. ch: "人",
  113. num: true,
  114. choice: true,
  115. backFatherBtn: {
  116. status: false,
  117. title: "未定义",
  118. },
  119. },
  120. tableSet: [
  121. {
  122. label: "姓名",
  123. prop: "teacherName",
  124. hidden: true,
  125. },
  126. {
  127. label: "名师头像",
  128. prop: "avatar",
  129. hidden: true,
  130. scope: "img",
  131. width: "200px",
  132. },
  133. {
  134. label: "简介",
  135. prop: "introduce",
  136. hidden: true,
  137. },
  138. {
  139. label: "启用状态",
  140. prop: "status",
  141. hidden: true,
  142. scope: "status",
  143. },
  144. ], //表头信息
  145. tableData: [], //表单数据
  146. total: 0, //一共多少条
  147. pageSize: 10, //每页多少条数据
  148. currentPage: 1, //当前页码
  149. formList: [
  150. {
  151. label: "名师名称",
  152. prop: "teacherName",
  153. placeholder: "输入名师名称",
  154. },
  155. {
  156. label: "启用状态",
  157. prop: "status",
  158. scope: "select",
  159. placeholder: "选择启用状态",
  160. options: [
  161. {
  162. label: "启用",
  163. value: 1,
  164. },
  165. {
  166. label: "关闭",
  167. value: 0,
  168. },
  169. ],
  170. },
  171. ], //搜索栏
  172. poppleData: {},
  173. fullscreen: false,
  174. dialogBox: false,
  175. statusPop: 0,
  176. beif: "", //备份数据
  177. };
  178. },
  179. mounted() {
  180. this.search();
  181. },
  182. methods: {
  183. getImgFile() {
  184. var self = this;
  185. var file = self.$refs.file.files[0];
  186. if (file === undefined) {
  187. self.$set(self.poppleData, "avatar", "");
  188. return;
  189. }
  190. if (file.size > 2 * 1024 * 1024) {
  191. self.$message.error("图片不得大于2MB");
  192. return;
  193. }
  194. var type = self.$refs.file.value.toLowerCase().split(".").splice(-1);
  195. if (
  196. type[0] != "jpg" &&
  197. type[0] != "png" &&
  198. type[0] != "jpeg" &&
  199. type[0] != "bmp"
  200. ) {
  201. self.$message.error("上传格式需为:.jpg/.png/.jpeg/bmp");
  202. self.$refs.file.value = "";
  203. return;
  204. }
  205. var reader = new FileReader();
  206. reader.readAsDataURL(file);
  207. reader.onload = function (ev) {
  208. self.$set(self.poppleData, "avatar", ev.target.result);
  209. };
  210. },
  211. async submitTabel() {
  212. var self = this;
  213. if (!self.poppleData.teacherName) {
  214. self.$message.error("请输入名师姓名");
  215. return;
  216. }
  217. if (!self.poppleData.introduce) {
  218. self.$message.error("请输入简介");
  219. return;
  220. }
  221. if (self.poppleData.status !== 0 && self.poppleData.status !== 1) {
  222. self.$message.error("请选择是否启用");
  223. return;
  224. }
  225. if (self.poppleData.avatar.length === 0) {
  226. self.$message.error("请上传头像");
  227. return;
  228. }
  229. if (self.statusPop === 0) {
  230. if (self.poppleData.avatar !== self.beif.avatar) {
  231. const awtimg = await self.imgUpload(0);
  232. }
  233. } else {
  234. const awtimg = await self.imgUpload(0);
  235. }
  236. var data = {
  237. teacherName: self.poppleData.teacherName,
  238. status: self.poppleData.status,
  239. introduce: self.poppleData.introduce,
  240. avatar: self.poppleData.avatar,
  241. };
  242. if (self.statusPop === 1) {
  243. self.$api.addCourseTeacher(data).then((sult) => {
  244. self.$message.success("添加成功!");
  245. self.dialogBox = false;
  246. self.search();
  247. });
  248. } else {
  249. data.teacherId = self.poppleData.teacherId;
  250. self.$api.editCourseTeacher(data).then((sult) => {
  251. self.$message.success("修改成功!");
  252. self.dialogBox = false;
  253. self.search();
  254. });
  255. }
  256. },
  257. imgUpload(int) {
  258. var self = this;
  259. return new Promise((resolve, reject) => {
  260. self.$upload
  261. .upload(self.$refs.file.files[0], int)
  262. .then((res) => {
  263. self.$set(self.poppleData, "avatar", res);
  264. resolve();
  265. })
  266. .catch((err) => {
  267. self.$message.error("图片上传错误");
  268. });
  269. });
  270. },
  271. //添加
  272. addClick() {
  273. this.poppleData = {
  274. avatar: "",
  275. };
  276. this.statusPop = 1;
  277. this.dialogBox = true;
  278. },
  279. // 修改
  280. modify(options) {
  281. var self = this;
  282. this.$api.obtainCourseTeacher(options.teacherId).then((res) => {
  283. console.log(res)
  284. if (res.code === 200) {
  285. self.beif = JSON.parse(JSON.stringify(res.data));
  286. self.poppleData = res.data;
  287. self.statusPop = 0;
  288. self.dialogBox = true;
  289. }
  290. });
  291. },
  292. //删除
  293. del(options) {
  294. var self = this;
  295. this.$confirm("此操作将删除该专业分类, 是否继续?", "提示", {
  296. confirmButtonText: "确定",
  297. cancelButtonText: "取消",
  298. type: "warning",
  299. })
  300. .then(() => {
  301. var data = {
  302. teacherId: options.teacherId,
  303. avatar: options.avatar,
  304. introduce: options.introduce,
  305. status: -1,
  306. teacherName: options.teacherName,
  307. };
  308. self.$api
  309. .editCourseTeacher(data)
  310. .then((res) => {
  311. self.$message.success("删除成功");
  312. self.search();
  313. })
  314. .catch((error) => {
  315. self.$message.error("删除失败,失败原因:" + error);
  316. });
  317. })
  318. .catch(() => {});
  319. },
  320. search(v) {
  321. var self = this;
  322. if (v === undefined) {
  323. v = {
  324. status: "0,1",
  325. teacherName: "",
  326. pageSize: this.pageSize,
  327. pageNum: this.currentPage,
  328. };
  329. }
  330. var data = {
  331. status: v.status === undefined ? "0,1" : v.status,
  332. teacherName: v.teacherName || "",
  333. pageSize: this.pageSize,
  334. pageNum: this.currentPage,
  335. };
  336. self.loading = true;
  337. self.$api
  338. .inquireCourseTeacher(data)
  339. .then((res) => {
  340. res.rows.forEach((item, index) => {
  341. item.srcList = [item.avatar];
  342. });
  343. self.tableData = res.rows;
  344. self.total = res.total;
  345. self.navText.index = res.total;
  346. self.loading = false;
  347. })
  348. .catch((err) => {
  349. self.loading = false;
  350. });
  351. },
  352. init() {
  353. this.search();
  354. },
  355. //窗口关闭
  356. closeBefore() {
  357. this.dialogBox = false;
  358. this.fullscreen = false;
  359. this.poppleData = {};
  360. },
  361. handleSizeChange(v) {
  362. this.pageSize = v;
  363. this.currentPage = 1;
  364. this.search();
  365. },
  366. handleCurrentChange(v) {
  367. this.currentPage = v;
  368. this.search();
  369. },
  370. },
  371. };
  372. </script>
  373. <style lang="less" scoped>
  374. /deep/.el-button {
  375. border-radius: 8px;
  376. }
  377. /deep/.el-dialog {
  378. border-radius: 8px;
  379. .el-dialog__header {
  380. padding: 0;
  381. .hearders {
  382. height: 40px;
  383. display: flex;
  384. align-items: center;
  385. justify-content: space-between;
  386. padding: 0px 18px 0px 20px;
  387. border-bottom: 1px solid #e2e2e2;
  388. .leftTitle {
  389. font-size: 14px;
  390. font-weight: bold;
  391. color: #2f4378;
  392. }
  393. .rightBoxs {
  394. display: flex;
  395. align-items: center;
  396. img {
  397. width: 14px;
  398. height: 14px;
  399. margin-left: 13px;
  400. cursor: pointer;
  401. }
  402. }
  403. }
  404. }
  405. .el-dialog__body {
  406. padding: 0;
  407. .contentBox {
  408. padding: 20px 20px 5px;
  409. .el-col {
  410. padding: 0px 20px;
  411. margin-bottom: 30px;
  412. header {
  413. margin-bottom: 6px;
  414. color: #2f4378;
  415. font-size: 14px;
  416. }
  417. }
  418. }
  419. }
  420. .el-dialog__footer {
  421. padding: 0;
  422. .dialog-footer {
  423. padding: 0px 40px;
  424. height: 70px;
  425. border-top: 1px solid #e2e2e2;
  426. display: flex;
  427. align-items: center;
  428. justify-content: flex-end;
  429. }
  430. }
  431. }
  432. .imgBox {
  433. width: 100%;
  434. // height: 210px;
  435. border: 1px solid #e2e2e2;
  436. border-radius: 8px;
  437. padding: 8px 8px 3px;
  438. display: flex;
  439. flex-direction: column;
  440. align-items: center;
  441. .imgLabel {
  442. flex: 1;
  443. width: 100%;
  444. border: 1px dotted #e2e2e2;
  445. color: #999;
  446. font-size: 14px;
  447. cursor: pointer;
  448. border-radius: 8px;
  449. .msPhoto {
  450. display: flex;
  451. justify-content: center;
  452. align-items: center;
  453. max-width: 100%;
  454. max-height: 270px;
  455. img {
  456. max-width: 100%;
  457. max-height: 270px;
  458. }
  459. }
  460. .imgbbx {
  461. display: flex;
  462. flex-direction: column;
  463. align-items: center;
  464. justify-content: center;
  465. width: 100%;
  466. height: 100%;
  467. i {
  468. font-weight: bold;
  469. margin: 14px 0;
  470. font-size: 24px;
  471. }
  472. }
  473. }
  474. p {
  475. margin: 5px 0px;
  476. }
  477. }
  478. </style>