2968ac15f42d84e5478d672fc756793ecf8ee26c.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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.sort }}</span>
  30. <el-input v-if="scope.row.Edit" v-model="scope.row.sort" 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.ftname }}</span>
  36. <el-select v-if="scope.row.Edit" v-model="scope.row.ftname" filterable 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.tmrcode }}</span>
  44. <el-select v-if="scope.row.Edit" v-model="scope.row.tmrcode" filterable placeholder="" class="filter-item" style="width:80%;padding:10px 0;">
  45. <el-option v-for="item in TMRNumberList" :key="item.id" :label="item.tname" :value="item.tname" />
  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.times }}</span>
  52. <el-select v-if="scope.row.Edit" v-model="scope.row.times" filterable 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.lppcode }}</span>
  60. <el-select v-if="scope.row.Edit" v-model="scope.row.lppid" filterable 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.ptime }}</span>
  73. <el-time-picker v-if="scope.row.Edit" v-model="scope.row.ptime" type="datetime" placeholder="选择时间" format="HH:mm" value-format="HH:mm" style="display: inline-block;width: 95%;" />
  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.maxweight }}</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.operateweight }}</span>
  84. <el-input v-if="scope.row.Edit" v-model="scope.row.operateweight" 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, GetDataByNames } from '@/api/common'
  106. import Sortable from 'sortablejs'
  107. import Cookies from 'js-cookie'
  108. export default {
  109. name: 'PremixedPlan',
  110. data() {
  111. return {
  112. requestParams: [
  113. { name: 'getTMRYHList', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
  114. ],
  115. formulaNameList: [{ id: 0, name: '泌乳牛高产' }, { id: 1, name: '高产日粮' }, { id: 2, name: '青年牛' }, { id: 3, name: '低产牛' }, { id: 4, name: '新产牛' }], // 配方名称
  116. TMRNumberList: [], // TMR编号
  117. frequencyList: [{ id: 0, name: '早班' }, { id: 1, name: '中班' }, { id: 2, name: '晚班' }], // 班次
  118. carFollowList: [{ id: 0, name: '01' }, { id: 1, name: '02' }, { id: 2, name: '03' }], // 发料计划车次跟随
  119. table: {
  120. getdataListParm: {
  121. name: 'getPremixplanList',
  122. page: 1,
  123. offset: 1,
  124. pagecount: 10,
  125. returntype: 'Map',
  126. parammaps: {
  127. pastureid: Cookies.get('pastureid')
  128. }
  129. },
  130. tableKey: 0,
  131. list: [],
  132. total: 0,
  133. listLoading: true
  134. },
  135. selectList: [],
  136. isokDisable: false,
  137. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  138. cellStyle: { padding: 0 + 'px' }
  139. }
  140. },
  141. created() {
  142. this.getList()
  143. this.getDownList()
  144. },
  145. methods: {
  146. getDownList() {
  147. GetDataByNames(this.requestParams).then(response => {
  148. this.TMRNumberList = response.data.getTMRYHList.list
  149. })
  150. },
  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], 'groupEdit', false) // 饲料组编辑
  160. this.$set(response.data.list[i], 'groupNoEdit', true) // 饲料组不可编辑
  161. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  162. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  163. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  164. }
  165. this.table.list = response.data.list
  166. // this.table.list = [
  167. // { 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 },
  168. // { 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 },
  169. // { 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 },
  170. // { 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 },
  171. // { 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 },
  172. // { 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 },
  173. // { 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 },
  174. // { 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 }
  175. // ]
  176. this.table.pageNum = response.data.pageNum
  177. this.table.pageSize = response.data.pageSize
  178. this.rowDrop()
  179. this.table.total = response.data.total
  180. } else {
  181. this.table.list = []
  182. }
  183. setTimeout(() => {
  184. this.table.listLoading = false
  185. }, 100)
  186. })
  187. },
  188. handleEnableChange() {
  189. console.log('点击了生效')
  190. },
  191. // 行拖拽
  192. rowDrop() {
  193. console.log(document.querySelector('#table .el-table__body-wrapper tbody'))
  194. const tbody = document.querySelector('#table .el-table__body-wrapper tbody')
  195. const that = this
  196. Sortable.create(tbody, {
  197. onEnd({ newIndex, oldIndex }) {
  198. const currRow = that.table.list.splice(oldIndex, 1)[0]
  199. that.table.list.splice(newIndex, 0, currRow)
  200. console.log('索引', newIndex)
  201. console.log('拖动数据', currRow)
  202. console.log('上', that.table.list[newIndex - 1])
  203. console.log('下', that.table.list[newIndex + 1])
  204. }
  205. })
  206. },
  207. // 模板新增
  208. handleCreate() {
  209. console.log('点击了新增车次')
  210. // 编辑true/不可编辑false
  211. // 新增操true,编辑false,编辑保存false
  212. console.log(11)
  213. for (let i = 0; i < this.table.list.length; i++) {
  214. if (this.table.list[i].Edit === true) {
  215. console.log(123)
  216. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  217. return false
  218. }
  219. }
  220. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1 })
  221. },
  222. createData(row) {
  223. console.log('点击了新增保存', row)
  224. },
  225. createCancel(row) {
  226. console.log('点击了新增取消')
  227. for (let i = 0; i < this.table.list.length; i++) {
  228. if (row.myId === this.table.list[i].myId) {
  229. var listIndex = this.table.list.indexOf(this.table.list[i])
  230. }
  231. if (listIndex > -1) {
  232. this.table.list.splice(listIndex, 1)
  233. return
  234. }
  235. }
  236. },
  237. // 模板编辑
  238. handleUpdate(row) {
  239. for (let i = 0; i < this.table.list.length; i++) {
  240. if (this.table.list[i].Edit == true) {
  241. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  242. return false
  243. }
  244. }
  245. // 编辑true,不可编辑false
  246. row.Edit = true
  247. row.NoEdit = false
  248. // 新增false,编辑false,编辑保存true
  249. row.isCreate = false
  250. row.isUpdate = false
  251. row.isUpdateSave = true
  252. },
  253. updateData(row) {
  254. console.log('点击了编辑保存', row)
  255. },
  256. updateCancel(row) {
  257. console.log('点击了编辑取消')
  258. // 编辑false,不可编辑true
  259. row.Edit = false
  260. row.NoEdit = true
  261. // 新增false,编辑true,编辑保存false
  262. row.isCreate = false
  263. row.isUpdate = true
  264. row.isUpdateSave = false
  265. },
  266. handleSelect(val) {
  267. console.log('勾选数据', val)
  268. this.selectList = val
  269. },
  270. // 减少车次
  271. handleDelete() {
  272. if (this.selectList.length == 0) {
  273. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  274. return false
  275. } else {
  276. console.log('点击了减少车次')
  277. }
  278. },
  279. // 历史记录
  280. handleHistoryRecords() {
  281. console.log('点击了历史记录')
  282. }
  283. }
  284. }
  285. </script>
  286. <style lang="scss" scoped>
  287. .search{clear: both;}
  288. .table{margin-top:10px;}
  289. </style>