d0478857db8c9f0cd27e9ccca6cd47d37d9e6624.svn-base 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div style="width:800px">
  3. <el-table
  4. id="table1"
  5. :data="table2.list"
  6. border
  7. row-key="id"
  8. align="left"
  9. >
  10. <el-table-column label="饲料组" min-width="130px" align="center">
  11. <template slot-scope="scope">
  12. <span>{{ scope.row.groud }}</span>
  13. </template>
  14. </el-table-column>
  15. <el-table-column label="饲料名称" min-width="130px" align="center">
  16. <template slot-scope="scope">
  17. <span>{{ scope.row.name }}</span>
  18. </template>
  19. </el-table-column>
  20. <el-table-column label="重量(KG)" min-width="130px" align="center">
  21. <template slot-scope="scope">
  22. <span>{{ scope.row.weight }}</span>
  23. </template>
  24. </el-table-column>
  25. <el-table-column label="搅拌延时(min)" min-width="130px" align="center">
  26. <template slot-scope="scope">
  27. <span>{{ scope.row.hour }}</span>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="是否锁定牛头数比例" min-width="130px" align="center">
  31. <template slot-scope="scope">
  32. <span>{{ scope.row.proportion }}</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="顺序" min-width="130px" align="center">
  36. <template slot-scope="scope">
  37. <span>{{ scope.row.order }}</span>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. </div>
  42. </template>
  43. <script>
  44. import Sortable from 'sortablejs'
  45. import { GetDataByName } from '@/api/common'
  46. export default {
  47. name: 'MaterialIssuancePlan',
  48. data() {
  49. return {
  50. table: {
  51. getdataListParm: {
  52. name: 'getAssetList',
  53. page: 1,
  54. offset: 1,
  55. pagecount: 10,
  56. returntype: 'Map',
  57. parammaps: {
  58. enable: ''
  59. }
  60. },
  61. tableKey: 0,
  62. list: [],
  63. total: 0,
  64. listLoading: true
  65. },
  66. table2: {
  67. list: [
  68. {
  69. id: '0',
  70. groud: '饲料组1',
  71. name: '饲料名称1',
  72. weight: '重量1',
  73. 'hour': '搅拌延时1',
  74. 'proportion': '是否锁定牛头数比例1',
  75. 'order': '0'
  76. },
  77. {
  78. id: '1',
  79. groud: '饲料组2',
  80. name: '饲料名称2',
  81. weight: '重量2',
  82. 'hour': '搅拌延时2',
  83. 'proportion': '是否锁定牛头数比例2',
  84. 'order': '1'
  85. },
  86. {
  87. id: '2',
  88. groud: '饲料组3',
  89. name: '饲料名称3',
  90. weight: '重量3',
  91. 'hour': '搅拌延时3',
  92. 'proportion': '是否锁定牛头数比例3',
  93. 'order': '2'
  94. },
  95. {
  96. id: '3',
  97. groud: '饲料组3',
  98. name: '饲料名称4',
  99. weight: '重量4',
  100. 'hour': '搅拌延时4',
  101. 'proportion': '是否锁定牛头数比例4',
  102. 'order': '2'
  103. },
  104. {
  105. id: '4',
  106. groud: '饲料组4',
  107. name: '饲料名称5',
  108. weight: '重量5',
  109. 'hour': '搅拌延时5',
  110. 'proportion': '是否锁定牛头数比例5',
  111. 'order': '3'
  112. },
  113. {
  114. id: '5',
  115. groud: '饲料组4',
  116. name: '饲料名称6',
  117. weight: '重量6',
  118. 'hour': '搅拌延时6',
  119. 'proportion': '是否锁定牛头数比例6',
  120. 'order': '3'
  121. },
  122. {
  123. id: '6',
  124. groud: '饲料组4',
  125. name: '饲料名称7',
  126. weight: '重量7',
  127. 'hour': '搅拌延时7',
  128. 'proportion': '是否锁定牛头数比例7',
  129. 'order': '3'
  130. },
  131. {
  132. id: '7',
  133. groud: '饲料组6',
  134. name: '饲料名称8',
  135. weight: '重量8',
  136. 'hour': '搅拌延时8',
  137. 'proportion': '是否锁定牛头数比例8',
  138. 'order': '5'
  139. }
  140. ]
  141. }
  142. }
  143. },
  144. mounted() {
  145. // this.rowDrop()
  146. },
  147. created() {
  148. this.getList()
  149. },
  150. methods: {
  151. getList() {
  152. this.table.listLoading = true
  153. GetDataByName(this.table.getdataListParm).then(response => {
  154. console.log('table数据', response.data.list)
  155. if (response.data.list !== null) {
  156. for (let i = 0; i < response.data.list.length; i++) {
  157. this.$set(response.data.list[i], 'Edit', false) // 编辑
  158. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  159. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  160. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  161. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  162. }
  163. this.table.list = response.data.list
  164. this.table.pageNum = response.data.pageNum
  165. this.table.pageSize = response.data.pageSize
  166. this.table.total = response.data.total
  167. this.rowDrop()
  168. } else {
  169. this.table.list = []
  170. }
  171. setTimeout(() => {
  172. this.table.listLoading = false
  173. }, 100)
  174. })
  175. },
  176. // 行拖拽
  177. rowDrop() {
  178. console.log(123)
  179. const tbody = document.querySelector('#table1 .el-table__body-wrapper tbody')
  180. const that = this
  181. Sortable.create(tbody, {
  182. onEnd({ newIndex, oldIndex }) {
  183. const currRow = that.table2.list.splice(oldIndex, 1)[0]
  184. that.table2.list.splice(newIndex, 0, currRow)
  185. console.log('索引', newIndex)
  186. console.log('拖动数据', currRow)
  187. console.log('上', that.table2.list[newIndex - 1])
  188. console.log('下', that.table2.list[newIndex + 1])
  189. if (that.table2.list[newIndex - 1] === undefined) { // 拖动至最上方无值 // 顺序等于0,其他+1 // 饲料组等于饲料名称
  190. for (let i = 0; i < that.table2.list.length; i++) {
  191. that.table2.list[i].order = parseInt(that.table2.list[i].order) + 1 // 其他的顺序+1
  192. }
  193. currRow.order = 0
  194. currRow.groud = currRow.name
  195. console.log('拖动至最上方无值')
  196. } else if (currRow.order == that.table2.list[newIndex - 1].order) { // 拖动值顺序等于上值顺序
  197. currRow.order = that.table2.list[newIndex - 1].order
  198. console.log('拖动值顺序等于上值顺序')
  199. } else if (that.table2.list[newIndex + 1] == undefined) { // 拖动至最下方无值 // 顺序等于上方顺序+1 // 饲料组等于饲料名称
  200. currRow.order = parseInt(that.table2.list[newIndex - 1].order) + 1
  201. currRow.groud = currRow.name
  202. console.log('拖动至最下方无值')
  203. } else if (currRow.order == that.table2.list[newIndex + 1].order) { // 拖动值顺序等于下值顺序
  204. currRow.order == that.table2.list[newIndex + 1].order
  205. console.log('拖动值顺序等于下值顺序')
  206. } else if (that.table2.list[newIndex - 1].order == that.table2.list[newIndex + 1].order) { // 拖动至上下顺序一致,顺序/饲料组与上下保持一致
  207. currRow.order = that.table2.list[newIndex - 1].order
  208. currRow.groud = that.table2.list[newIndex - 1].groud
  209. console.log('拖动至上下顺序一致')
  210. } else if (that.table2.list[newIndex - 1].order !== undefined && that.table2.list[newIndex + 1].order !== undefined) { // 拖动至上下都有值
  211. console.log('上下')
  212. if (parseInt(that.table2.list[newIndex - 1].order) + 1 == that.table2.list[newIndex + 1].order) {
  213. console.log(newIndex)
  214. for (let i = newIndex; i < that.table2.list.length; i++) {
  215. that.table2.list[i].order = parseInt(that.table2.list[i].order) + 1
  216. }
  217. }
  218. currRow.order = parseInt(that.table2.list[newIndex - 1].order) + 1
  219. currRow.groud = currRow.name
  220. console.log(that.table2.list[newIndex + 1].order)
  221. }
  222. }
  223. })
  224. }
  225. }
  226. }
  227. </script>
  228. <style scoped>
  229. </style>