d73db767528c401dab9ba4a412e6c825ea6e8ff9.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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:80%;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" placeholder="" class="filter-item" style="width:80%;padding:10px 0;">
  37. <el-option v-for="item in formulaNameList" :key="item.id" :label="item.name" :value="item.name" />
  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" placeholder="" class="filter-item" style="width:80%;padding:10px 0;">
  45. <el-option v-for="item in TMRNumberList" :key="item.id" :label="item.name" :value="item.name" />
  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. <span v-if="scope.row.NoEdit">{{ scope.row.hour }}</span>
  52. <el-select v-if="scope.row.Edit" v-model="scope.row.hour" placeholder="" class="filter-item" style="width:80%;padding:10px 0;">
  53. <el-option v-for="item in frequencyList" :key="item.id" :label="item.name" :value="item.name" />
  54. </el-select>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="发料计划车次跟随" min-width="130px" align="center">
  58. <template slot-scope="scope">
  59. <span v-if="scope.row.NoEdit">{{ scope.row.proportion }}</span>
  60. <el-select v-if="scope.row.Edit" v-model="scope.row.proportion" placeholder="" class="filter-item" style="width:80%;padding:10px 0;">
  61. <el-option v-for="item in carFollowList" :key="item.id" :label="item.name" :value="item.name" />
  62. </el-select>
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="生效" min-width="130px" align="center">
  66. <template slot-scope="scope">
  67. <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)" />
  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="选择时间" />
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="单车操作重量" min-width="130px" align="center">
  77. <template slot-scope="scope">
  78. <span>{{ scope.row.proportion }}</span>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="作料重量" min-width="130px" align="center">
  82. <template slot-scope="scope">
  83. <span v-if="scope.row.NoEdit">{{ scope.row.group }}</span>
  84. <el-input v-if="scope.row.Edit" v-model="scope.row.group" type="number" style="width:80%;padding:10px 0;" />
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" align="center" width="320" class-name="small-padding fixed-width" fixed="right">
  88. <template slot-scope="{row}">
  89. <!-- 新增 -->
  90. <el-button v-if="row.isCreate" class="miniSuccess" @click="createData(row)">保存</el-button>
  91. <el-button v-if="row.isCreate" class="minCancel" @click="createCancel(row)">取消</el-button>
  92. <!-- 编辑 -->
  93. <el-button v-if="row.isUpdate" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  94. <el-button v-if="row.isUpdate" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  95. <!-- 编辑保存 -->
  96. <el-button v-if="row.isUpdateSave" class="miniSuccess" @click="updateData(row)">保存</el-button>
  97. <el-button v-if="row.isUpdateSave" class="minCancel" @click="updateCancel(row)">取消</el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. import { GetDataByName } from '@/api/common'
  106. import Sortable from 'sortablejs'
  107. export default {
  108. name: 'PremixedPlan',
  109. data() {
  110. return {
  111. formulaNameList: [{ id: 0, name: '泌乳牛高产' }, { id: 1, name: '高产日粮' }, { id: 2, name: '青年牛' }, { id: 3, name: '低产牛' }, { id: 4, name: '新产牛' }], // 配方名称
  112. TMRNumberList: [{ id: 0, name: 'TMR编号01' }, { id: 1, name: 'TMR编号02' }, { id: 2, name: '任意车' }], // TMR编号
  113. frequencyList: [{ id: 0, name: '早班' }, { id: 1, name: '中班' }, { id: 2, name: '晚班' }], // 班次
  114. carFollowList: [{ id: 0, name: '01' }, { id: 1, name: '02' }, { id: 2, name: '03' }], // 发料计划车次跟随
  115. table: {
  116. getdataListParm: {
  117. name: 'getAssetList',
  118. page: 1,
  119. offset: 1,
  120. pagecount: 10,
  121. returntype: 'Map',
  122. parammaps: {
  123. enable: ''
  124. }
  125. },
  126. tableKey: 0,
  127. list: [],
  128. total: 0,
  129. listLoading: true
  130. },
  131. selectList: [],
  132. isokDisable: false,
  133. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  134. cellStyle: { padding: 0 + 'px' }
  135. }
  136. },
  137. created() {
  138. this.getList()
  139. },
  140. methods: {
  141. getList() {
  142. this.table.listLoading = true
  143. GetDataByName(this.table.getdataListParm).then(response => {
  144. console.log('table数据', response.data.list)
  145. if (response.data.list !== null) {
  146. for (let i = 0; i < response.data.list.length; i++) {
  147. this.$set(response.data.list[i], 'Edit', false) // 编辑
  148. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  149. this.$set(response.data.list[i], 'groupEdit', false) // 饲料组编辑
  150. this.$set(response.data.list[i], 'groupNoEdit', true) // 饲料组不可编辑
  151. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  152. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  153. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  154. }
  155. this.table.list = response.data.list
  156. this.table.list = [
  157. { 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 },
  158. { 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 },
  159. { 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 },
  160. { 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 },
  161. { 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 },
  162. { 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 },
  163. { 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 },
  164. { 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 }
  165. ]
  166. this.table.pageNum = response.data.pageNum
  167. this.table.pageSize = response.data.pageSize
  168. this.rowDrop()
  169. this.table.total = response.data.total
  170. } else {
  171. this.table.list = []
  172. }
  173. setTimeout(() => {
  174. this.table.listLoading = false
  175. }, 100)
  176. })
  177. },
  178. handleEnableChange() {
  179. console.log('点击了生效')
  180. },
  181. // 行拖拽
  182. rowDrop() {
  183. console.log(document.querySelector('#table .el-table__body-wrapper tbody'))
  184. const tbody = document.querySelector('#table .el-table__body-wrapper tbody')
  185. const that = this
  186. Sortable.create(tbody, {
  187. onEnd({ newIndex, oldIndex }) {
  188. const currRow = that.table.list.splice(oldIndex, 1)[0]
  189. that.table.list.splice(newIndex, 0, currRow)
  190. console.log('索引', newIndex)
  191. console.log('拖动数据', currRow)
  192. console.log('上', that.table.list[newIndex - 1])
  193. console.log('下', that.table.list[newIndex + 1])
  194. }
  195. })
  196. },
  197. // 模板新增
  198. handleCreate() {
  199. console.log('点击了新增车次')
  200. // 编辑true/不可编辑false
  201. // 新增操true,编辑false,编辑保存false
  202. console.log(11)
  203. for (let i = 0; i < this.table.list.length; i++) {
  204. if (this.table.list[i].Edit === true) {
  205. console.log(123)
  206. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  207. return false
  208. }
  209. }
  210. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1 })
  211. },
  212. createData(row) {
  213. console.log('点击了新增保存', row)
  214. },
  215. createCancel(row) {
  216. console.log('点击了新增取消')
  217. for (let i = 0; i < this.table.list.length; i++) {
  218. if (row.myId === this.table.list[i].myId) {
  219. var listIndex = this.table.list.indexOf(this.table.list[i])
  220. }
  221. if (listIndex > -1) {
  222. this.table.list.splice(listIndex, 1)
  223. return
  224. }
  225. }
  226. },
  227. // 模板编辑
  228. handleUpdate(row) {
  229. for (let i = 0; i < this.table.list.length; i++) {
  230. if (this.table.list[i].Edit == true) {
  231. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  232. return false
  233. }
  234. }
  235. // 编辑true,不可编辑false
  236. row.Edit = true
  237. row.NoEdit = false
  238. // 新增false,编辑false,编辑保存true
  239. row.isCreate = false
  240. row.isUpdate = false
  241. row.isUpdateSave = true
  242. },
  243. updateData(row) {
  244. console.log('点击了编辑保存', row)
  245. },
  246. updateCancel(row) {
  247. console.log('点击了编辑取消')
  248. // 编辑false,不可编辑true
  249. row.Edit = false
  250. row.NoEdit = true
  251. // 新增false,编辑true,编辑保存false
  252. row.isCreate = false
  253. row.isUpdate = true
  254. row.isUpdateSave = false
  255. },
  256. handleSelect(val) {
  257. console.log('勾选数据', val)
  258. this.selectList = val
  259. },
  260. // 减少车次
  261. handleDelete() {
  262. if (this.selectList.length == 0) {
  263. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  264. return false
  265. } else {
  266. console.log('点击了减少车次')
  267. }
  268. },
  269. // 历史记录
  270. handleHistoryRecords() {
  271. console.log('点击了历史记录')
  272. }
  273. }
  274. }
  275. </script>
  276. <style lang="scss" scoped>
  277. .search{clear: both;}
  278. .table{margin-top:10px;}
  279. </style>