You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
7.8 KiB

3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
  1. <template>
  2. <div class="box">
  3. <div style="width: 95%">
  4. <el-card>
  5. <el-table
  6. :data="tableData"
  7. style="width: 100%"
  8. row-key="id"
  9. class="el-table__body-wrapper tbody"
  10. border:stripe="true"
  11. @row-click="rowick"
  12. highlight-current-row
  13. >
  14. <el-table-column prop="id" label="编号" width=""> </el-table-column>
  15. <el-table-column prop="displayName" label="名称" width="">
  16. </el-table-column>
  17. <!-- <el-table-column prop="sexId" label="性别" width="">
  18. </el-table-column> -->
  19. <el-table-column prop="simpleCode" label="快捷码" width="">
  20. </el-table-column>
  21. <el-table-column label="操作" width="400">
  22. <template>
  23. <el-tag
  24. class="move"
  25. style="cursor: move; margin-left: 15px"
  26. draggable="true"
  27. >
  28. <i
  29. class="el-icon-d-caret"
  30. style="width: 1rem; height: 1rem"
  31. ></i>
  32. </el-tag>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. <div class="cancelorconfirm"></div>
  37. <!-- -->
  38. <el-dialog
  39. title="修改"
  40. :visible.sync="dialogVisible"
  41. width="40%"
  42. :before-close="handleClose"
  43. >
  44. <el-form ref="form" :model="form">
  45. <el-row>
  46. <el-col :span="12">
  47. <el-form-item label="性别" label-width="80px">
  48. <el-input
  49. v-model="form.displayName"
  50. style="width: 80%"
  51. ></el-input>
  52. </el-form-item>
  53. </el-col>
  54. <el-col :span="12">
  55. <el-form-item label="快捷码" label-width="80px">
  56. <el-input
  57. v-model="form.simpleCode"
  58. style="width: 80%"
  59. ></el-input>
  60. </el-form-item>
  61. </el-col>
  62. </el-row>
  63. </el-form>
  64. <span slot="footer" class="dialog-footer">
  65. <el-button @click="dialogVisible = false"> </el-button>
  66. <el-button type="primary" @click="confirmmodification"
  67. > </el-button
  68. >
  69. </span>
  70. </el-dialog>
  71. </el-card>
  72. </div>
  73. <!-- 按钮区域 -->
  74. <div style="margin-left: 10px; margin-top: 5%">
  75. <el-button type="primary" @click="eddte">编辑</el-button>
  76. <div style="margin-top: 10px">
  77. <el-button type="primary" @click="topping">置顶</el-button>
  78. </div>
  79. <div style="margin-top: 10px">
  80. <el-button type="primary" @click="setlow">置底</el-button>
  81. </div>
  82. <div style="margin-top: 10px">
  83. <el-button type="primary" :disabled="isshow" @click="assertion"
  84. >排序</el-button
  85. >
  86. </div>
  87. <div style="margin-top: 10px">
  88. <el-button type="primary" :disabled="isshow" @click="cancellation"
  89. >取消</el-button
  90. >
  91. </div>
  92. </div>
  93. </div>
  94. </template>
  95. <script>
  96. import Sortable from "sortablejs";
  97. import {
  98. examinationgender,
  99. modifygender,
  100. genderbottomtotop,
  101. modifydraganddrop,
  102. } from "../../request/systemapi";
  103. import { postapi } from "@/api/api";
  104. export default {
  105. data() {
  106. return {
  107. isshow: true,
  108. tableData: [],
  109. dialogVisible: false,
  110. form: {
  111. displayName: "",
  112. },
  113. initTableData: [],
  114. };
  115. },
  116. created() {
  117. this.getlist();
  118. },
  119. mounted() {
  120. this.rowDrop();
  121. },
  122. methods: {
  123. handleClose(done) {
  124. this.$confirm("确认关闭?")
  125. .then((_) => {
  126. done();
  127. })
  128. .catch((_) => {});
  129. },
  130. rowick(row) {
  131. this.form = row;
  132. },
  133. //取消按钮
  134. cancellation() {
  135. this.$message.info("取消操作");
  136. this.isshow = true;
  137. this.getlist();
  138. },
  139. //确定排序
  140. assertion() {
  141. const result = [];
  142. this.tableData.forEach((item, index) => {
  143. // index 从0开始的, 你的displayOrder从大到小排
  144. // const currentDisplayOrder = this.tableData.length -1
  145. const currentDisplayOrder = this.initTableData[index].displayOrder;
  146. console.log(currentDisplayOrder);
  147. if (item.displayOrder != currentDisplayOrder) {
  148. // 如果它的displayOrder和它当前所在的位置不同代表挪动过位置
  149. result.push({ id: item.id, displayOrder: currentDisplayOrder });
  150. }
  151. });
  152. modifydraganddrop({ itemList: result }).then((res) => {
  153. this.getlist();
  154. this.$message.success("操作成功");
  155. this.isshow = true;
  156. });
  157. },
  158. //初始化
  159. rowDrop() {
  160. this.$nextTick(() => {
  161. const tbody = document.querySelector(".el-table__body-wrapper tbody");
  162. const _this = this;
  163. Sortable.create(tbody, {
  164. handle: ".move",
  165. animation: 300,
  166. // 指定父元素下可被拖拽的子元素方法
  167. // draggable: ".module-manager .el-table__row",
  168. onEnd({ newIndex, oldIndex }) {
  169. // console.log(arr);
  170. _this.isshow = false;
  171. const currRow = _this.tableData.splice(oldIndex, 1)[0];
  172. _this.tableData.splice(newIndex, 0, currRow);
  173. _this.tableData.map((item, index) => {
  174. if (index == newIndex && index == oldIndex) {
  175. // console.log(item, "新数据");
  176. } else if (index == oldIndex) {
  177. } else if (index == newIndex) {
  178. }
  179. });
  180. console.log(_this.tableData.map((item) => item.displayOrder));
  181. },
  182. });
  183. });
  184. },
  185. //置底
  186. setlow(row) {
  187. console.log(this.form.id);
  188. if (this.form.id == undefined) {
  189. this.$message.warning("请选择操作的数据");
  190. } else {
  191. genderbottomtotop(this.form.id, 2).then((res) => {
  192. this.getlist();
  193. this.$message.success("操作成功");
  194. });
  195. }
  196. },
  197. //置顶
  198. topping() {
  199. if (this.form.id == undefined) {
  200. this.$message.warning("请选择操作的数据");
  201. } else {
  202. genderbottomtotop(this.form.id, 1).then((res) => {
  203. this.getlist();
  204. this.$message.success("操作成功");
  205. });
  206. }
  207. },
  208. //确定修改
  209. confirmmodification() {
  210. if (this.form.displayName == "") {
  211. this.$message.warning("请输入名称");
  212. } else if (this.form.simpleCode == "") {
  213. this.$message.warning("请输入快捷码");
  214. } else {
  215. // modifygender(this.form.id, {
  216. // displayName: this.form.displayName,
  217. // simpleCode: this.form.simpleCode,
  218. // }).then((res) => {
  219. // if (res.code == 1) {
  220. // this.$message.success("修改成功");
  221. // this.getlist();
  222. // this.dialogVisible = false;
  223. // }
  224. // });
  225. postapi(`/api/app/sex/update/${this.form.id}`, {
  226. displayName: this.form.displayName,
  227. simpleCode: this.form.simpleCode,
  228. }).then((res) => {
  229. if (res.code == 1) {
  230. this.$message.success("修改成功");
  231. this.getlist();
  232. this.dialogVisible = false;
  233. }
  234. });
  235. }
  236. },
  237. //编辑弹框
  238. eddte() {
  239. if (this.form.id == undefined) {
  240. this.$message.warning("请选择操作的数据");
  241. } else {
  242. let obj = Object.assign({}, this.form);
  243. console.log(obj);
  244. this.form = obj;
  245. this.dialogVisible = true;
  246. }
  247. },
  248. //
  249. getlist() {
  250. examinationgender().then((res) => {
  251. this.initTableData = [...res.data];
  252. this.tableData = res.data;
  253. console.log(res);
  254. });
  255. },
  256. },
  257. };
  258. </script>
  259. <style scoped>
  260. .box {
  261. display: flex;
  262. }
  263. .cancelorconfirm {
  264. display: flex;
  265. justify-content: flex-end;
  266. padding: 20px;
  267. }
  268. </style>