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.

255 lines
7.7 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
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
3 years ago
2 years ago
  1. <template>
  2. <div class="box">
  3. <div style="width: 95%">
  4. <el-card class="elcard" style="border-radius: 15px">
  5. <div class="publiccss">支付方式</div>
  6. <el-table
  7. :data="tableData"
  8. style="width: 100%; height: 500px;margin-top:20px"
  9. row-key="id"
  10. :height="tableHeight"
  11. class="el-table__body-wrapper tbody"
  12. @row-click="rowick"
  13. highlight-current-row
  14. >
  15. <el-table-column prop="id" label="编号" width="300">
  16. </el-table-column>
  17. <el-table-column prop="displayName" label="名称" width="300">
  18. </el-table-column>
  19. <el-table-column prop="simpleCode" label="快捷码" width="300">
  20. </el-table-column>
  21. <el-table-column label="操作">
  22. <template>
  23. <el-tag
  24. class="move"
  25. style="cursor: move; margin-left: 15px;background-color: rgb(245, 245, 245);border:none"
  26. draggable="true"
  27. >
  28. <i
  29. class="el-icon-d-caret"
  30. style="width: 1rem; height: 1rem;color: rgb(113, 113, 113)"
  31. ></i>
  32. </el-tag>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. <!-- 新增或者编辑 -->
  37. <el-dialog
  38. title="修改"
  39. :visible.sync="dialogVisible"
  40. width="40%"
  41. :close-on-click-modal="false"
  42. >
  43. <el-form ref="form" :model="form" label-width="80px">
  44. <el-row>
  45. <el-col :span="12">
  46. <el-form-item label="编号">
  47. <el-input v-model="form.id" disabled></el-input>
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="12">
  51. <el-form-item label="名称">
  52. <el-input v-model="form.displayName"></el-input>
  53. </el-form-item>
  54. </el-col>
  55. </el-row>
  56. </el-form>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button @click="dialogVisible = false"> </el-button>
  59. <el-button type="primary" @click="addoredit" class="bulletcommit"> </el-button>
  60. </span>
  61. </el-dialog>
  62. </el-card>
  63. </div>
  64. <!-- -->
  65. <div style="margin-left: 10px; margin-top: 5%">
  66. <el-button type="" @click="editpopup" class="commonbutton">编辑</el-button>
  67. <div style="margin-top: 10px">
  68. <el-button type="" @click="topping" class="commonbutton">置顶</el-button>
  69. </div>
  70. <div style="margin-top: 10px">
  71. <el-button type="" @click="toppings" class="commonbutton">置底</el-button>
  72. </div>
  73. <div style="margin-top: 10px">
  74. <el-button type="" :disabled="isshow" @click="assertion" class="commonbutton"
  75. >排序</el-button
  76. >
  77. </div>
  78. <div style="margin-top: 10px">
  79. <el-button type="" :disabled="isshow" @click="cancellation" class="commonbutton"
  80. >取消</el-button
  81. >
  82. </div>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import Sortable from "sortablejs";
  88. import {
  89. paymodelist,
  90. paymentediting,
  91. paytopandbottom,
  92. paymentdraganddrop,
  93. } from "@/request/commonapi";
  94. export default {
  95. data() {
  96. return {
  97. isshow: true,
  98. tableHeight: window.innerHeight - 180, //表格动态高度
  99. screenHeight: window.innerHeight, //内容区域高度 1
  100. initTableData: [],
  101. tableData: [],
  102. form: {
  103. displayName: "",
  104. },
  105. dialogVisible: false,
  106. };
  107. },
  108. created() {
  109. this.getlist();
  110. },
  111. mounted() {
  112. this.rowDrop();
  113. // window.onresize:浏览器尺寸变化响应事件
  114. window.onresize = () => {
  115. return (() => {
  116. // window.innerHeight:浏览器的可用高度
  117. window.screenHeight = window.innerHeight;
  118. this.screenHeight = window.screenHeight;
  119. })();
  120. };
  121. },
  122. watch: {
  123. // 监听screenHeight从而改变table的高度
  124. screenHeight(val) {
  125. this.screenHeight = val;
  126. this.tableHeight = this.screenHeight - 180;
  127. },
  128. },
  129. methods: {
  130. //取消排序
  131. cancellation() {
  132. this.$message.info("取消操作");
  133. this.isshow = true;
  134. this.getlist();
  135. },
  136. //确定拖拽
  137. assertion() {
  138. const result = [];
  139. this.tableData.forEach((item, index) => {
  140. // index 从0开始的, displayOrder从大到小排
  141. console.log(item.id);
  142. // const currentDisplayOrder = this.tableData.length -1
  143. const currentDisplayOrder = this.initTableData[index].displayOrder;
  144. if (item.displayOrder != currentDisplayOrder) {
  145. // 如果它的displayOrder和它当前所在的位置不同代表挪动过位置
  146. result.push({
  147. id: item.id,
  148. displayOrder: currentDisplayOrder,
  149. });
  150. }
  151. });
  152. paymentdraganddrop({ itemList: result }).then((res) => {
  153. this.$message.success("操作成功");
  154. this.isshow = true;
  155. this.getlist();
  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. onEnd({ newIndex, oldIndex }) {
  167. _this.isshow = false;
  168. const currRow = _this.tableData.splice(oldIndex, 1)[0];
  169. _this.tableData.splice(newIndex, 0, currRow);
  170. _this.tableData.map((item, index) => {
  171. if (index == newIndex && index == oldIndex) {
  172. // console.log(item, "新数据");
  173. } else if (index == oldIndex) {
  174. } else if (index == newIndex) {
  175. }
  176. });
  177. console.log(_this.tableData.map((item) => item.displayOrder));
  178. },
  179. });
  180. });
  181. },
  182. //置低
  183. toppings() {
  184. console.log(this.form.id);
  185. if (this.form.id == undefined) {
  186. this.$message.warning("请点击选择操作的数据");
  187. } else {
  188. paytopandbottom(this.form.id, 2).then((res) => {
  189. this.$message.success("操作成功");
  190. this.getlist();
  191. });
  192. }
  193. },
  194. //置顶
  195. topping() {
  196. if (this.form.id == undefined) {
  197. this.$message.warning("请点击选择操作的数据");
  198. } else {
  199. paytopandbottom(this.form.id, 1).then((res) => {
  200. this.$message.success("操作成功");
  201. this.getlist();
  202. });
  203. }
  204. },
  205. // 确定修改编辑
  206. addoredit() {
  207. if (this.form.displayName == "") {
  208. this.$message.warning("请输入名称");
  209. } else {
  210. paymentediting(this.form.id, {
  211. displayName: this.form.displayName,
  212. }).then((res) => {
  213. this.$message.success("修改成功");
  214. this.getlist();
  215. this.dialogVisible = false;
  216. });
  217. }
  218. },
  219. //编辑弹框
  220. editpopup() {
  221. if (this.form.id == undefined) {
  222. this.$message.warning("请点击选择操作的数据");
  223. } else {
  224. this.dialogVisible = true;
  225. let copy = Object.assign({}, this.form);
  226. this.form = copy;
  227. // invoiceidquery(this.form.payModeId).then((res) => {
  228. // console.log(res);
  229. // this.form = res.data;
  230. // });
  231. }
  232. },
  233. rowick(row) {
  234. this.form = row;
  235. },
  236. getlist() {
  237. paymodelist().then((res) => {
  238. this.initTableData = [...res.data];
  239. this.tableData = res.data;
  240. console.log(res);
  241. });
  242. },
  243. },
  244. };
  245. </script>
  246. <style scoped>
  247. ::v-deep .el-table__header th {
  248. /* font-size: px; */
  249. background-color: rgb(245, 245, 245); /* 设置表头背景颜色 */
  250. color: rgb(113, 113, 113); /* 设置表头文字颜色 */
  251. }
  252. .box {
  253. display: flex;
  254. }
  255. </style>