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.

409 lines
12 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="box">
  3. <div style="width: 200%">
  4. <el-card>
  5. <el-row style="margin-top: 20px">
  6. <el-col :span="4">
  7. <el-input
  8. v-model="pages.Filter"
  9. @clear="getlist"
  10. clearable
  11. ></el-input>
  12. </el-col>
  13. <el-col :span="4">
  14. <el-button type="primary" style="margin-left: 5%" @click="getlist"
  15. >查询</el-button
  16. >
  17. </el-col>
  18. </el-row>
  19. <el-table
  20. :data="tableData"
  21. style="width: 100%; height: 500px"
  22. row-key="id"
  23. class="el-table__body-wrapper tbody"
  24. @row-click="rowick"
  25. highlight-current-row
  26. >
  27. <el-table-column prop="id" label="编号" width="300">
  28. </el-table-column>
  29. <el-table-column prop="displayName" label="名称" width="">
  30. </el-table-column>
  31. <el-table-column prop="creatorName" label="创建者" width="">
  32. </el-table-column>
  33. <el-table-column prop="creationTime" label="创建时间" width="200">
  34. <template slot-scope="scope">
  35. {{ scope.row.creationTime | dateFormat }}
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="lastModifierName" label="修改者" width="">
  39. </el-table-column>
  40. <el-table-column
  41. prop="lastModificationTime"
  42. label="修改时间"
  43. width="200"
  44. >
  45. <template slot-scope="scope">
  46. {{ scope.row.lastModificationTime | dateFormat }}
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="操作">
  50. <template>
  51. <el-tag
  52. class="move"
  53. style="cursor: move; margin-left: 15px"
  54. draggable="true"
  55. >
  56. <i
  57. class="el-icon-d-caret"
  58. style="width: 1rem; height: 1rem"
  59. ></i>
  60. </el-tag>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. <!-- 新增或者编辑弹框 -->
  65. <el-dialog
  66. :title="title == 1 ? '新增' : '编辑'"
  67. :visible.sync="dialogVisible"
  68. width="75%"
  69. >
  70. <el-form ref="form" :model="form" label-width="80px" :rules="rules">
  71. <el-row>
  72. <el-col :span="8">
  73. <el-form-item label="编号" prop="displayName">
  74. <el-input v-model="form.id" disabled></el-input>
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="5">
  78. <el-form-item label="名称" prop="displayName">
  79. <el-input
  80. v-model="form.displayName"
  81. ref="refinput"
  82. ></el-input>
  83. </el-form-item>
  84. </el-col>
  85. <el-col :span="6">
  86. <el-color-picker
  87. v-model="form.containerColor"
  88. @change="colorchange"
  89. ></el-color-picker>
  90. <el-form-item
  91. label="颜色"
  92. prop="containerColor"
  93. style="width: 90%; margin-top: -40px"
  94. >
  95. <el-input v-model="form.containerColor"></el-input>
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="5">
  99. <el-form-item label="容器名称" prop="containerColorName">
  100. <el-input v-model="form.containerColorName"></el-input>
  101. </el-form-item>
  102. </el-col>
  103. <div style="margin-top: 70px"><el-divider></el-divider></div>
  104. <el-col :span="4" style="margin-left: 15px">
  105. <el-form-item label="创建者">
  106. <el-input
  107. v-model="form.creatorName"
  108. disabled
  109. style="width: 110%"
  110. ></el-input>
  111. </el-form-item>
  112. </el-col>
  113. <el-col :span="6">
  114. <el-form-item label="创建时间">
  115. <el-input
  116. :value="form.creationTime | dateFormat"
  117. disabled
  118. style="width: 95%"
  119. ></el-input>
  120. </el-form-item>
  121. </el-col>
  122. <el-col :span="4">
  123. <el-form-item label="修改者">
  124. <el-input
  125. v-model="form.lastModifierName"
  126. disabled
  127. style="width: 110%"
  128. ></el-input>
  129. </el-form-item>
  130. </el-col>
  131. <el-col :span="6">
  132. <el-form-item label="修改时间">
  133. <el-input
  134. :value="form.lastModificationTime | dateFormat"
  135. disabled
  136. style="width: 95%"
  137. ></el-input>
  138. </el-form-item>
  139. </el-col>
  140. </el-row>
  141. </el-form>
  142. <span slot="footer" class="dialog-footer">
  143. <el-button @click="dialogVisible = false"> </el-button>
  144. <el-button type="primary" @click="addoredit"> </el-button>
  145. </span>
  146. </el-dialog>
  147. </el-card>
  148. </div>
  149. <!-- //ann按钮区域 -->
  150. <div style="margin-left: 10px; margin-top: 7%">
  151. <el-button type="primary" @click="add">新增</el-button>
  152. <el-button
  153. type="primary"
  154. @click="editpopup"
  155. style="margin-left: 0; margin-top: 10px"
  156. >编辑</el-button
  157. >
  158. <div>
  159. <div style="margin-top: 10px">
  160. <el-button type="danger" @click="delsrts">删除</el-button>
  161. </div>
  162. <div style="margin-top: 10px">
  163. <el-button type="primary" @click="topping">置顶</el-button>
  164. </div>
  165. <div style="margin-top: 10px">
  166. <el-button type="primary" @click="toppings">置底</el-button>
  167. </div>
  168. <div style="margin-top: 10px">
  169. <el-button type="primary" :disabled="isshow" @click="assertion"
  170. >排序</el-button
  171. >
  172. </div>
  173. <div style="margin-top: 5px">
  174. <el-button type="primary" :disabled="isshow" @click="cancellation"
  175. >取消</el-button
  176. >
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. </template>
  182. <script>
  183. import Sortable from "sortablejs";
  184. import {
  185. containerlist,
  186. newlyspecimen,
  187. Containerid,
  188. specimenediting,
  189. detecontainer,
  190. specimentopbottom,
  191. specimensort,
  192. } from "../../request/systemapi";
  193. export default {
  194. data() {
  195. return {
  196. isshow: true,
  197. rules: {
  198. displayName: [
  199. { required: true, message: "请输入名称", trigger: "blur" },
  200. ],
  201. containerColorName: [
  202. { required: true, message: "请输入容器名称", trigger: "blur" },
  203. ],
  204. containerColor: [
  205. { required: true, message: "请输入容器颜色", trigger: "blur" },
  206. ],
  207. },
  208. pages: {
  209. Filter: "",
  210. SkipCount: 0,
  211. MaxResultCount: 100,
  212. Sorting: "displayOrder desc",
  213. },
  214. tableData: [],
  215. initTableData: [],
  216. title: 1,
  217. dialogVisible: false,
  218. form: {
  219. displayName: "",
  220. containerColorName: "",
  221. containerColor: "",
  222. },
  223. };
  224. },
  225. created() {
  226. this.getlist();
  227. },
  228. mounted() {
  229. this.rowDrop();
  230. },
  231. methods: {
  232. colorchange(v) {
  233. this.form.containerColor = parseInt(v)
  234. console.log(this.form.containerColor);
  235. },
  236. //取消排序
  237. cancellation() {
  238. this.$message.info("取消操作");
  239. this.isshow = true;
  240. this.getlist();
  241. },
  242. //确定拖拽
  243. assertion() {
  244. const result = [];
  245. this.tableData.forEach((item, index) => {
  246. // index 从0开始的, displayOrder从大到小排
  247. console.log(item.id);
  248. // const currentDisplayOrder = this.tableData.length -1
  249. const currentDisplayOrder = this.initTableData[index].displayOrder;
  250. if (item.displayOrder != currentDisplayOrder) {
  251. // 如果它的displayOrder和它当前所在的位置不同代表挪动过位置
  252. result.push({ id: item.id, displayOrder: currentDisplayOrder });
  253. }
  254. });
  255. specimensort({ itemList: result }).then((res) => {
  256. this.$message.success("操作成功");
  257. this.isshow = true;
  258. this.getlist();
  259. });
  260. },
  261. //初始化
  262. rowDrop() {
  263. this.$nextTick(() => {
  264. const tbody = document.querySelector(".el-table__body-wrapper tbody");
  265. const _this = this;
  266. Sortable.create(tbody, {
  267. handle: ".move",
  268. animation: 300,
  269. onEnd({ newIndex, oldIndex }) {
  270. _this.isshow = false;
  271. const currRow = _this.tableData.splice(oldIndex, 1)[0];
  272. _this.tableData.splice(newIndex, 0, currRow);
  273. _this.tableData.map((item, index) => {
  274. if (index == newIndex && index == oldIndex) {
  275. // console.log(item, "新数据");
  276. } else if (index == oldIndex) {
  277. } else if (index == newIndex) {
  278. }
  279. });
  280. console.log(_this.tableData.map((item) => item.displayOrder));
  281. },
  282. });
  283. });
  284. },
  285. //置低
  286. toppings() {
  287. if (this.form.id == undefined) {
  288. this.$message.success("请点击选择操作的数据");
  289. } else {
  290. specimentopbottom(this.form.id, 2).then((res) => {
  291. this.$message.success("操作成功");
  292. this.getlist();
  293. });
  294. }
  295. },
  296. //置顶
  297. topping() {
  298. if (this.form.id == undefined) {
  299. this.$message.warning("请点击选择操作的数据");
  300. } else {
  301. specimentopbottom(this.form.id, 1).then((res) => {
  302. this.$message.success("操作成功");
  303. this.getlist();
  304. });
  305. }
  306. },
  307. //删除
  308. delsrts() {
  309. if (this.form.id == undefined) {
  310. this.$message.warning("请选择删除的数据");
  311. } else {
  312. this.$confirm("是否确认删除,是否继续?", "提示", {
  313. confirmButtonText: "确定",
  314. cancelButtonText: "取消",
  315. type: "warning",
  316. })
  317. .then(() => {
  318. detecontainer(this.form.id).then((res) => {
  319. this.$message.success("删除成功");
  320. this.getlist();
  321. this.form = {};
  322. });
  323. })
  324. .catch(() => {});
  325. // detecontainer(this.form.id).then((res) => {
  326. // this.$message.success("删除成功");
  327. // this.form = {};
  328. // this.getlist();
  329. // });
  330. }
  331. },
  332. //编辑弹框
  333. editpopup() {
  334. if (this.form.id == undefined) {
  335. this.$message.warning("请点击选择操作的数据");
  336. } else {
  337. this.dialogVisible = true;
  338. this.title = 2;
  339. Containerid(this.form.id).then((res) => {
  340. console.log(res);
  341. this.form = res.data;
  342. });
  343. }
  344. },
  345. //点击列表通过id查询
  346. rowick(row) {
  347. Containerid(row.id).then((res) => {
  348. console.log(res);
  349. this.form = res.data;
  350. });
  351. console.log(row);
  352. },
  353. //确定新增或者编辑
  354. addoredit() {
  355. this.$refs.form.validate((v) => {
  356. if (v) {
  357. if (this.title == 1) {
  358. newlyspecimen({
  359. displayName: this.form.displayName,
  360. containerColorName: this.form.containerColorName,
  361. containerColor: Number(this.form.containerColor),
  362. }).then((res) => {
  363. this.$message.success("新增成功");
  364. this.getlist();
  365. this.dialogVisible = false;
  366. });
  367. } else if (this.title == 2) {
  368. specimenediting(this.form.id, {
  369. displayName: this.form.displayName,
  370. containerColorName: this.form.containerColorName,
  371. containerColor: Number(this.form.containerColor),
  372. }).then((res) => {
  373. this.$message.success("修改成功");
  374. this.getlist();
  375. this.dialogVisible = false;
  376. });
  377. }
  378. }
  379. });
  380. },
  381. //新增弹框
  382. add() {
  383. this.title = 1;
  384. this.dialogVisible = true;
  385. this.form = {};
  386. this.$nextTick(() => {
  387. this.$refs.refinput.focus();
  388. });
  389. },
  390. getlist() {
  391. containerlist(this.pages).then((res) => {
  392. this.initTableData = [...res.data.items];
  393. this.tableData = res.data.items;
  394. console.log(res);
  395. });
  396. },
  397. },
  398. };
  399. </script>
  400. <style lang="scss" scoped>
  401. ::v-deep .el-input.is-disabled .el-input__inner {
  402. width: 88%;
  403. }
  404. .box {
  405. display: flex;
  406. }
  407. </style>