e20bbdea53a83b131d6b207274dc4fa03a934eca.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div class="app-container">
  3. <div class="operation">
  4. <el-button class="success" style="float: left;" @click="handleCreate">新增车次</el-button>
  5. <el-button class="danger" style="float: left;" @click="handleDelete">减少车次</el-button>
  6. <el-button class="import" style="float: right;" @click="handleHistoryRecords">历史记录</el-button>
  7. </div>
  8. <div class="search" />
  9. <div class="table">
  10. <el-table
  11. id="table"
  12. :key="table.tableKey"
  13. v-loading="table.listLoading"
  14. element-loading-text="给我一点时间"
  15. :data="table.list"
  16. border
  17. fit
  18. highlight-current-row
  19. style="width: 100%;"
  20. :row-style="rowStyle"
  21. :cell-style="cellStyle"
  22. class="elTable table-fixed"
  23. row-key="id"
  24. @selection-change="handleSelect"
  25. >
  26. <el-table-column type="selection" min-width="50" />
  27. <el-table-column label="车次" min-width="130px" align="center">
  28. <template slot-scope="scope">
  29. <span v-if="scope.row.NoEdit">{{ scope.row.group }}</span>
  30. <el-input v-if="scope.row.Edit" v-model="scope.row.group" type="number" style="width:95%;padding:10px 0;" />
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="栏舍" min-width="130px" align="center">
  34. <template slot-scope="scope">
  35. <span v-if="scope.row.NoEdit">{{ scope.row.name }}</span>
  36. <el-select v-if="scope.row.Edit" v-model="scope.row.name" filterable placeholder="" class="filter-item" style="width:95%;padding:10px 0;">
  37. <el-option v-for="item in barnsList" :key="item.value" :label="item.label" :value="item.value" />
  38. </el-select>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="TMR编号" prop="weight" min-width="130px" align="center">
  42. <template slot-scope="scope">
  43. <span v-if="scope.row.NoEdit">{{ scope.row.weight }}</span>
  44. <el-select v-if="scope.row.Edit" v-model="scope.row.weight" filterable placeholder="" class="filter-item" style="width:95%;padding:10px 0;">
  45. <el-option v-for="item in TMRNumberList" :key="item.value" :label="item.label" :value="item.value" />
  46. </el-select>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="生效" min-width="130px" align="center">
  50. <template slot-scope="scope">
  51. <el-switch v-model="scope.row.enable" :disabled="scope.row.NoEdit==true" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="班次" min-width="130px" align="center">
  55. <template slot-scope="scope">
  56. <span v-if="scope.row.NoEdit">{{ scope.row.hour }}</span>
  57. <el-select v-if="scope.row.Edit" v-model="scope.row.hour" filterable placeholder="" class="filter-item" style="width:95%;padding:10px 0;">
  58. <el-option v-for="item in frequencyList" :key="item.value" :label="item.label" :value="item.value" />
  59. </el-select>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="发料计划车次跟随" min-width="130px" align="center">
  63. <template slot-scope="scope">
  64. <span v-if="scope.row.NoEdit">{{ scope.row.proportion }}</span>
  65. <el-select v-if="scope.row.Edit" v-model="scope.row.proportion" filterable placeholder="" class="filter-item" style="width:95%;padding:10px 0;">
  66. <el-option v-for="item in carFollowList" :key="item.value" :label="item.label" :value="item.value" />
  67. </el-select>
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="时间" min-width="180px" align="center">
  71. <template slot-scope="scope">
  72. <span v-if="scope.row.NoEdit">{{ scope.row.proportion }}</span>
  73. <el-time-picker v-if="scope.row.Edit" v-model="scope.row.proportion" :picker-options="{ selectableRange: '00:00:00 - 23:59:59' }" placeholder="选择时间" style="width:95%;padding:10px 0;" />
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="剩料处理方式" min-width="130px" align="center">
  77. <template slot-scope="scope">
  78. <span v-if="scope.row.NoEdit">{{ scope.row.proportion }}</span>
  79. <el-select v-if="scope.row.Edit" v-model="scope.row.proportion" filterable placeholder="" class="filter-item" style="width:95%;padding:10px 0;">
  80. <el-option v-for="item in residueDisposalList" :key="item.value" :label="item.label" :value="item.value" />
  81. </el-select>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="转投栏舍" min-width="130px" align="center">
  85. <template slot-scope="scope">
  86. <span v-if="scope.row.NoEdit">{{ scope.row.proportion }}</span>
  87. <el-select v-if="scope.row.Edit" v-model="scope.row.proportion" filterable placeholder="" class="filter-item" style="width:95%;padding:10px 0;">
  88. <el-option v-for="item in transferBarnsList" :key="item.value" :label="item.label" :value="item.value" />
  89. </el-select>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="操作" align="center" width="320" class-name="small-padding fixed-width" fixed="right">
  93. <template slot-scope="{row}">
  94. <!-- 新增 -->
  95. <el-button v-if="row.isCreate" class="miniSuccess" @click="createData(row)">保存</el-button>
  96. <el-button v-if="row.isCreate" class="minCancel" @click="createCancel(row)">取消</el-button>
  97. <!-- 编辑 -->
  98. <el-button v-if="row.isUpdate" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  99. <el-button v-if="row.isUpdate" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  100. <!-- 编辑保存 -->
  101. <el-button v-if="row.isUpdateSave" class="miniSuccess" @click="updateData(row)">保存</el-button>
  102. <el-button v-if="row.isUpdateSave" class="minCancel" @click="updateCancel(row)">取消</el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. </div>
  107. </div>
  108. </template>
  109. <script>
  110. import { GetDataByName } from '@/api/common'
  111. import Sortable from 'sortablejs'
  112. export default {
  113. name: 'SurplusMaterialPlan',
  114. data() {
  115. return {
  116. barnsList: [{ value: '0', label: '1-1' }, { value: '1', label: '1-2' }, { value: '2', label: '1-3' }], // 栏舍
  117. residueDisposalList: [{ value: '0', label: '转投剩料' }, { value: '1', label: '继续饲喂' }], // 剩料处理方式
  118. TMRNumberList: [{ value: '0', label: 'TMR编号01' }, { value: '1', label: 'TMR编号02' }, { value: '2', label: '任意车' }], // TMR编号
  119. frequencyList: [{ value: '0', label: '第一班' }, { value: '1', label: '第二班' }, { value: '2', label: '第三班' }], // 班次
  120. carFollowList: [{ value: '0', label: '01' }, { value: '1', label: '02' }, { value: '2', label: '03' }], // 发料计划车次跟随
  121. transferBarnsList: [{ value: '0', label: '1-1' }, { value: '1', label: '1-2' }, { value: '2', label: '1-3' }], // 转头栏舍
  122. table: {
  123. getdataListParm: {
  124. name: 'getAssetList',
  125. page: 1,
  126. offset: 1,
  127. pagecount: 10,
  128. returntype: 'Map',
  129. parammaps: {
  130. enable: ''
  131. }
  132. },
  133. tableKey: 0,
  134. list: [],
  135. total: 0,
  136. listLoading: true
  137. },
  138. selectList: [],
  139. isokDisable: false,
  140. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  141. cellStyle: { padding: 0 + 'px' }
  142. }
  143. },
  144. created() {
  145. this.getList()
  146. },
  147. methods: {
  148. getList() {
  149. this.table.listLoading = true
  150. GetDataByName(this.table.getdataListParm).then(response => {
  151. console.log('table数据', response.data.list)
  152. if (response.data.list !== null) {
  153. for (let i = 0; i < response.data.list.length; i++) {
  154. this.$set(response.data.list[i], 'Edit', false) // 编辑
  155. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  156. this.$set(response.data.list[i], 'groupEdit', false) // 饲料组编辑
  157. this.$set(response.data.list[i], 'groupNoEdit', true) // 饲料组不可编辑
  158. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  159. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  160. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  161. }
  162. this.table.list = response.data.list
  163. this.table.list = [
  164. { id: '0', group: '饲料组1', name: '饲料名称1', weight: '1', 'hour': '搅拌延时1', 'proportion': '是否锁定牛头数比例1', 'order': '0', 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true },
  165. { id: '1', group: '饲料组2', name: '饲料名称2', weight: '2', 'hour': '搅拌延时2', 'proportion': '是否锁定牛头数比例2', 'order': '1', 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true },
  166. { id: '2', group: '饲料组3', name: '饲料名称3', weight: '3', 'hour': '搅拌延时3', 'proportion': '是否锁定牛头数比例3', 'order': '2', 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true },
  167. { id: '3', group: '饲料组3', name: '饲料名称4', weight: '4', 'hour': '搅拌延时4', 'proportion': '是否锁定牛头数比例4', 'order': '2', 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true },
  168. { id: '4', group: '饲料组4', name: '饲料名称5', weight: '5', 'hour': '搅拌延时5', 'proportion': '是否锁定牛头数比例5', 'order': '3', 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true },
  169. { id: '5', group: '饲料组4', name: '饲料名称6', weight: '6', 'hour': '搅拌延时6', 'proportion': '是否锁定牛头数比例6', 'order': '3', 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true },
  170. { id: '6', group: '饲料组4', name: '饲料名称7', weight: '7', 'hour': '搅拌延时7', 'proportion': '是否锁定牛头数比例7', 'order': '3', 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true },
  171. { id: '7', group: '饲料组6', name: '饲料名称8', weight: '8', 'hour': '搅拌延时8', 'proportion': '是否锁定牛头数比例8', 'order': '5', 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true }
  172. ]
  173. this.table.pageNum = response.data.pageNum
  174. this.table.pageSize = response.data.pageSize
  175. this.rowDrop()
  176. this.table.total = response.data.total
  177. } else {
  178. this.table.list = []
  179. }
  180. setTimeout(() => {
  181. this.table.listLoading = false
  182. }, 100)
  183. })
  184. },
  185. handleEnableChange() {
  186. console.log('点击了生效')
  187. },
  188. // 行拖拽
  189. rowDrop() {
  190. console.log(document.querySelector('#table .el-table__body-wrapper tbody'))
  191. const tbody = document.querySelector('#table .el-table__body-wrapper tbody')
  192. const that = this
  193. Sortable.create(tbody, {
  194. onEnd({ newIndex, oldIndex }) {
  195. const currRow = that.table.list.splice(oldIndex, 1)[0]
  196. that.table.list.splice(newIndex, 0, currRow)
  197. console.log('索引', newIndex)
  198. console.log('拖动数据', currRow)
  199. console.log('上', that.table.list[newIndex - 1])
  200. console.log('下', that.table.list[newIndex + 1])
  201. }
  202. })
  203. },
  204. // 模板新增
  205. handleCreate() {
  206. console.log('点击了新增车次')
  207. // 编辑true/不可编辑false
  208. // 新增操true,编辑false,编辑保存false
  209. console.log(11)
  210. for (let i = 0; i < this.table.list.length; i++) {
  211. if (this.table.list[i].Edit === true) {
  212. console.log(123)
  213. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  214. return false
  215. }
  216. }
  217. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1 })
  218. },
  219. createData(row) {
  220. console.log('点击了新增保存', row)
  221. },
  222. createCancel(row) {
  223. console.log('点击了新增取消')
  224. for (let i = 0; i < this.table.list.length; i++) {
  225. if (row.myId === this.table.list[i].myId) {
  226. var listIndex = this.table.list.indexOf(this.table.list[i])
  227. }
  228. if (listIndex > -1) {
  229. this.table.list.splice(listIndex, 1)
  230. return
  231. }
  232. }
  233. },
  234. // 模板编辑
  235. handleUpdate(row) {
  236. for (let i = 0; i < this.table.list.length; i++) {
  237. if (this.table.list[i].Edit == true) {
  238. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  239. return false
  240. }
  241. }
  242. // 编辑true,不可编辑false
  243. row.Edit = true
  244. row.NoEdit = false
  245. // 新增false,编辑false,编辑保存true
  246. row.isCreate = false
  247. row.isUpdate = false
  248. row.isUpdateSave = true
  249. },
  250. updateData(row) {
  251. console.log('点击了编辑保存', row)
  252. },
  253. updateCancel(row) {
  254. console.log('点击了编辑取消')
  255. // 编辑false,不可编辑true
  256. row.Edit = false
  257. row.NoEdit = true
  258. // 新增false,编辑true,编辑保存false
  259. row.isCreate = false
  260. row.isUpdate = true
  261. row.isUpdateSave = false
  262. },
  263. handleSelect(val) {
  264. console.log('勾选数据', val)
  265. this.selectList = val
  266. },
  267. // 减少车次
  268. handleDelete() {
  269. if (this.selectList.length == 0) {
  270. this.$message({ type: 'error', message: '请选择车次', duration: 2000 })
  271. return false
  272. } else {
  273. console.log('点击了减少车次')
  274. }
  275. },
  276. // 历史记录
  277. handleHistoryRecords() {
  278. console.log('点击了历史记录')
  279. }
  280. }
  281. }
  282. </script>
  283. <style lang="scss" scoped>
  284. .search{clear: both;}
  285. .table{margin-top:10px;}
  286. </style>