index.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.bname" placeholder="栏舍名称" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.getdataListParm.parammaps.bcode" placeholder="栏舍编号" style="width: 180px;" class="filter-item" clearable />
  6. <el-select v-model="table.getdataListParm.parammaps.enable" filterable placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  7. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  8. </el-select>
  9. <div ref="selectInput" class="filter-item selectInput">
  10. <el-input type="text" name="" value="" placeholder="请点击选择搜索条件" class="Input" />
  11. <i v-if="arrowDown" icon="el-icon-arrow-down" class="el-icon-arrow-down" />
  12. <i v-if="arrowUp" icon="el-icon-arrow-up" class="el-icon-arrow-up" />
  13. <ul v-if="arrowUp" class="selectUl">
  14. <li><a>允许误差数</a><el-input v-model="table.getdataListParm.parammaps.allowratio" type="text" style="width: 245px;" /></li>
  15. <li><a>跳转重量域</a><el-input v-model="table.getdataListParm.parammaps.autozone" type="text" style="width: 245px;" /></li>
  16. <li>
  17. <a>跳转延时</a>
  18. <el-select v-model="table.getdataListParm.parammaps.autosecond" filterable class="filter-item" style="width: 245px;" clearable>
  19. <el-option v-for="item in jumpDelayList" :key="item.value" :label="item.label" :value="item.value" />
  20. </el-select>
  21. </li>
  22. <li>
  23. <div style="float: right;">
  24. <el-button class="downminCancel" @click="arrowUp=false;arrowDown=true;">取消</el-button>
  25. <el-button class="miniPrimary" @click="handleSearch">搜索</el-button>
  26. </div>
  27. </li>
  28. </ul>
  29. </div>
  30. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  31. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  32. </div>
  33. <div class="operation">
  34. <el-button v-if="isRoleEdit" style="float:left;" class="success" icon="el-icon-plus" @click="handleCreate">新增</el-button>
  35. <el-button v-if="isRoleEdit" style="float:left;" class="danger" icon="el-icon-delete" @click="handleDelete">删除</el-button>
  36. <el-button v-if="isOrder && isRoleEdit" style="float:left;" icon="el-icon-sort" class="success" @click="handleChangeOrder">更改顺序</el-button>
  37. <div v-else style="float:left;margin-left: 10px;">
  38. <el-button v-if="isRoleEdit" icon="el-icon-folder-checked" class="success" @click="saveChangeOrder">保存</el-button>
  39. <el-button v-if="isRoleEdit" icon="el-icon-close" class="sortCancel" @click="cancelChangeOrder">取消</el-button>
  40. </div>
  41. </div>
  42. <div class="table">
  43. <u-table
  44. id="table"
  45. :key="table.tableKey"
  46. ref="table"
  47. v-loading="table.listLoading"
  48. element-loading-text="给我一点时间"
  49. :data="table.list"
  50. border
  51. fit
  52. highlight-current-row
  53. style="width: 100%;"
  54. :row-style="rowStyle"
  55. :cell-style="cellStyle"
  56. class="elTable table-fixed"
  57. row-key="id"
  58. @selection-change="handleSelectionChange"
  59. >
  60. <el-table-column type="selection" align="center" width="50" />
  61. <el-table-column label="序号" type="index" align="center" width="50" />
  62. <el-table-column label="栏舍名称" min-width="130px" align="center">
  63. <template slot-scope="scope">
  64. <span v-if="scope.row.NoEdit">{{ scope.row.bname }}</span>
  65. <el-input v-if="scope.row.Edit" v-model="scope.row.bname" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:10px 0;" maxlength="32" />
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="栏舍编号" min-width="130px" align="center">
  69. <template slot-scope="scope">
  70. <span v-if="scope.row.NoEdit">{{ scope.row.bcode }}</span>
  71. <el-input v-if="scope.row.Edit" v-model="scope.row.bcode" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="允许误差数(kg)" min-width="150px" align="center">
  75. <template slot-scope="scope">
  76. <span v-if="scope.row.NoEdit">{{ scope.row.allowratio }}</span>
  77. <el-input v-if="scope.row.Edit" v-model="scope.row.allowratio" style="width:95%;padding:10px 0;" />
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="跳转重量域(kg)" min-width="150px" align="center">
  81. <template slot-scope="scope">
  82. <span v-if="scope.row.NoEdit">{{ scope.row.autozone }}</span>
  83. <el-input v-if="scope.row.Edit" v-model="scope.row.autozone" :disabled="scope.row.autosecond=='0'" style="width:95%;padding:10px 0;" />
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="跳转延时(s)" min-width="150px" align="center">
  87. <template slot-scope="scope">
  88. <span v-if="scope.row.NoEdit">{{ scope.row.autosecondname }}</span>
  89. <el-select v-if="scope.row.Edit" v-model="scope.row.autosecond" filterable class="filter-item" style="width: 95%;padding:10px 0;" @change="changeAutosecond">
  90. <el-option v-for="item in jumpDelayList" :key="item.value" :label="item.label" :value="item.value" />
  91. <!-- <el-option v-for="item in jumpDelayList" :key="item.label" :label="item.label" :value="item.label" /> -->
  92. </el-select>
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="确认开始" min-width="110px" align="center">
  96. <template slot-scope="scope">
  97. <el-switch v-model="scope.row.isstart" :disabled="scope.row.NoEdit==true" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleConfirmStartChange(scope.$index, scope.row)" />
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="是否启用" min-width="110px" align="center">
  101. <template slot-scope="scope">
  102. <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)" />
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  106. <template slot-scope="{row}">
  107. <!-- 新增 -->
  108. <el-button v-if="row.isCreate" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData(row)" />
  109. <span v-if="row.isCreate" class="centerSpan">|</span>
  110. <el-button v-if="row.isCreate" class="minCancel" icon="el-icon-close" @click="createCancel(row)" />
  111. <!-- 编辑 -->
  112. <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  113. <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
  114. <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete(row)" />
  115. <!-- 编辑保存 -->
  116. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData(row)" />
  117. <span v-if="row.isUpdateSave" class="centerSpan">|</span>
  118. <el-button v-if="row.isUpdateSave" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />
  119. </template>
  120. </el-table-column>
  121. </u-table>
  122. <!-- <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" /> -->
  123. </div>
  124. </div>
  125. </template>
  126. <script>
  127. import { GetDataByName, GetDataByNames, PostDataByName, failproccess, ExecDataByConfig, checkButtons } from '@/api/common'
  128. import Cookies from 'js-cookie'
  129. import draggable from 'vuedraggable'
  130. import Sortable from 'sortablejs'
  131. import Pagination from '@/components/Pagination'
  132. import { MessageBox } from 'element-ui'
  133. export default {
  134. name: 'GroupColumn',
  135. components: { Pagination,draggable },
  136. data() {
  137. return {
  138. isRoleEdit: [],
  139. requestParams: [
  140. { name: 'getDictByName', offset: 0, pagecount: 0, params: ['跳转延时'] }
  141. ],
  142. enableList: [{ id: '1', name: '是' }, { id: '0', name: '否' }],
  143. jumpDelayList: [],
  144. table: {
  145. getdataListParm: {
  146. name: 'getBarList',
  147. page: 1,
  148. offset: 1,
  149. pagecount: '',
  150. returntype: 'Map',
  151. parammaps: {
  152. pastureid: Cookies.get('pastureid'),
  153. bcode: '',
  154. bname: '',
  155. allowratio: '',
  156. autozone: '',
  157. autosecond: '',
  158. enable: ''
  159. }
  160. },
  161. tableKey: 0,
  162. list: [],
  163. total: 0,
  164. listLoading: true,
  165. temp: {}
  166. },
  167. requestParam: {},
  168. isokDisable: false,
  169. selectList: [],
  170. arrowDown: true,
  171. arrowUp: false,
  172. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  173. cellStyle: { padding: 0 + 'px' },
  174. dropState: false,
  175. isOrder: true,
  176. }
  177. },
  178. created() {
  179. this.getList()
  180. this.getDownList()
  181. this.getButtons()
  182. },
  183. mounted() {
  184. document.addEventListener('click', (e) => {
  185. if (this.$refs.selectInput !== undefined) {
  186. if (!this.$refs.selectInput.contains(e.target)) {
  187. this.arrowDown = true
  188. this.arrowUp = false
  189. } else {
  190. this.arrowDown = false
  191. this.arrowUp = true
  192. }
  193. }
  194. })
  195. },
  196. methods: {
  197. getButtons() {
  198. const Edit = 'GroupColumn'
  199. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  200. this.isRoleEdit = isRoleEdit
  201. },
  202. getDownList() {
  203. GetDataByNames(this.requestParams).then(response => {
  204. this.jumpDelayList = response.data.getDictByName.list
  205. })
  206. },
  207. getList() {
  208. this.table.listLoading = true
  209. GetDataByName(this.table.getdataListParm).then(response => {
  210. console.log('table数据', response.data.list)
  211. if (response.data.list !== null) {
  212. for (let i = 0; i < response.data.list.length; i++) {
  213. this.$set(response.data.list[i], 'Edit', false) // 编辑
  214. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  215. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  216. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  217. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  218. }
  219. this.table.list = response.data.list
  220. this.table.pageNum = response.data.pageNum
  221. this.table.pageSize = response.data.pageSize
  222. this.table.total = response.data.total
  223. } else {
  224. this.table.list = []
  225. }
  226. setTimeout(() => {
  227. this.table.listLoading = false
  228. }, 100)
  229. })
  230. },
  231. handleEnableChange() {
  232. console.log('点击了是否启用')
  233. },
  234. handleConfirmStartChange() {
  235. console.log('点击了确认开始')
  236. },
  237. handleSearch() {
  238. console.log('点击了查询')
  239. this.table.getdataListParm.offset = 1
  240. this.getList()
  241. this.arrowDown = true
  242. this.arrowUp = false
  243. },
  244. handleRefresh() {
  245. console.log('点击了重置')
  246. this.table.getdataListParm.parammaps.bcode = ''
  247. this.table.getdataListParm.parammaps.bname = ''
  248. this.table.getdataListParm.parammaps.allowratio = ''
  249. this.table.getdataListParm.parammaps.autozone = ''
  250. this.table.getdataListParm.parammaps.autosecond = ''
  251. this.table.getdataListParm.parammaps.enable = ''
  252. this.table.getdataListParm.offset = 1
  253. this.getList()
  254. },
  255. changeAutosecond(item) {
  256. this.table.temp.autosecondname = this.jumpDelayList.find(obj => obj.value === item).label
  257. console.log(this.table.temp.autosecondname)
  258. },
  259. handleCreate() {
  260. console.log('点击了新增')
  261. // 编辑true/不可编辑false
  262. // 新增操true,编辑false,编辑保存false
  263. for (let i = 0; i < this.table.list.length; i++) {
  264. if (this.table.list[i].Edit == true) {
  265. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  266. return false
  267. }
  268. }
  269. this.table.temp.autosecondname = ''
  270. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'isstart': 1, 'bname': '', 'bcode': '', 'allowratio': '', 'autozone': '', 'autosecond': '0', 'autosecondname': '禁用' })
  271. },
  272. createData(row) {
  273. console.log('点击了新增保存', row)
  274. this.table.temp.pastureid = Cookies.get('pastureid')
  275. this.table.temp.bcode = row.bcode
  276. this.table.temp.bname = row.bname
  277. this.table.temp.allowratio = row.allowratio
  278. this.table.temp.autozone = row.autozone
  279. this.table.temp.autosecond = row.autosecond
  280. if (this.table.temp.autosecondname == '') {
  281. this.table.temp.autosecondname = row.autosecondname
  282. } else {
  283. this.table.temp.autosecondname = this.table.temp.autosecondname
  284. }
  285. this.table.temp.isstart = row.isstart
  286. this.table.temp.enable = row.enable
  287. // 检验用户名称/角色是否为空
  288. if (this.table.temp.bname == '' && this.table.temp.bcode == '') {
  289. this.$message({ type: 'error', message: '栏舍名称/栏舍编号不能为空', duration: 2000 })
  290. return false
  291. } else if (this.table.temp.bname == '') {
  292. this.$message({ type: 'error', message: '栏舍名称不能为空', duration: 2000 })
  293. return false
  294. } else if (this.table.temp.bcode == '') {
  295. this.$message({ type: 'error', message: '栏舍编号不能为空', duration: 2000 })
  296. return false
  297. }
  298. // if (this.table.temp.bcode.length > 8) {
  299. // this.$message({ type: 'error', message: '栏舍编号请输入1-8位数字', duration: 2000 })
  300. // return false
  301. // }
  302. if (this.table.temp.allowratio !== '') {
  303. console.log(this.table.temp.allowratio)
  304. const allowratio = /^[0-9]\d*$/
  305. if (!allowratio.test(parseFloat(this.table.temp.allowratio))) {
  306. this.$message({ type: 'error', message: '允许误差数请输入大于等于0的整数', duration: 2000 })
  307. return false
  308. }
  309. } else {
  310. this.table.temp.allowratio = '0'
  311. }
  312. if (this.table.temp.autozone !== '') {
  313. console.log(this.table.temp.autozone)
  314. const autozone = /^(\d|[1-9]\d|1[0-1]\d|120)$/
  315. if (!autozone.test(parseFloat(this.table.temp.autozone))) {
  316. this.$message({ type: 'error', message: '跳转重量域请输入大于等于0小于等于120的整数', duration: 2000 })
  317. return false
  318. }
  319. } else {
  320. this.table.temp.autozone = '0'
  321. }
  322. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  323. if (pattern.test(this.table.temp.eqcode)) {
  324. this.$message({ type: 'error', message: 'TMR设备编号不可输入特殊字符', duration: 2000 })
  325. return false
  326. }
  327. if (pattern.test(this.table.temp.tname)) {
  328. this.$message({ type: 'error', message: 'TMR设备名称不可输入特殊字符', duration: 2000 })
  329. return false
  330. }
  331. this.isokDisable = true
  332. setTimeout(() => {
  333. this.isokDisable = false
  334. }, 1000)
  335. this.requestParam.name = 'insertBar'
  336. this.requestParam.parammaps = this.table.temp
  337. PostDataByName(this.requestParam).then(response => {
  338. console.log('新增保存发送参数', this.requestParam)
  339. if (response.msg !== 'fail') {
  340. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  341. this.getList()
  342. } else {
  343. const isRepeat = new RegExp('Duplicate entry :bar_bcode')
  344. if (isRepeat.test(response.data)) {
  345. this.$notify({ type: 'error', message: '栏舍编号不可重复,请重新录入', duration: 2000 })
  346. return false
  347. }
  348. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  349. }
  350. })
  351. },
  352. createCancel(row) {
  353. console.log('点击了新增取消')
  354. for (let i = 0; i < this.table.list.length; i++) {
  355. if (row.myId === this.table.list[i].myId) {
  356. var listIndex = this.table.list.indexOf(this.table.list[i])
  357. }
  358. if (listIndex > -1) {
  359. this.table.list.splice(listIndex, 1)
  360. return
  361. }
  362. }
  363. },
  364. handleUpdate(row) {
  365. console.log('点击了编辑', row)
  366. for (let i = 0; i < this.table.list.length; i++) {
  367. if (this.table.list[i].Edit == true) {
  368. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  369. return false
  370. }
  371. }
  372. // 编辑true,不可编辑false
  373. row.Edit = true
  374. row.NoEdit = false
  375. // 新增false,编辑false,编辑保存true
  376. row.isCreate = false
  377. row.isUpdate = false
  378. row.isUpdateSave = true
  379. row.autosecond = String(row.autosecond)
  380. this.table.temp.autosecondname = row.autosecondname
  381. this.table.temp.autosecond = row.autosecond
  382. },
  383. updateData(row) {
  384. console.log('点击了编辑保存', row)
  385. this.table.temp.pastureid = Cookies.get('pastureid')
  386. this.table.temp.bcode = row.bcode
  387. this.table.temp.bname = row.bname
  388. this.table.temp.allowratio = row.allowratio
  389. this.table.temp.autozone = row.autozone
  390. this.table.temp.autosecond = row.autosecond
  391. this.table.temp.autosecondname = this.table.temp.autosecondname
  392. this.table.temp.isstart = row.isstart
  393. this.table.temp.enable = row.enable
  394. this.table.temp.id = row.id
  395. // 检验用户名称/角色是否为空
  396. if (this.table.temp.bname == '' && this.table.temp.bcode == '') {
  397. this.$message({ type: 'error', message: '栏舍名称/栏舍编号不能为空', duration: 2000 })
  398. return false
  399. } else if (this.table.temp.bname == '') {
  400. this.$message({ type: 'error', message: '栏舍名称不能为空', duration: 2000 })
  401. return false
  402. } else if (this.table.temp.bcode == '') {
  403. this.$message({ type: 'error', message: '栏舍编号不能为空', duration: 2000 })
  404. return false
  405. }
  406. // if (this.table.temp.bcode.length > 8) {
  407. // this.$message({ type: 'error', message: '栏舍编号请输入1-8位数字', duration: 2000 })
  408. // return false
  409. // }
  410. if (this.table.temp.allowratio !== '') {
  411. console.log(this.table.temp.allowratio)
  412. const allowratio = /^[0-9]\d*$/
  413. if (!allowratio.test(parseFloat(this.table.temp.allowratio))) {
  414. this.$message({ type: 'error', message: '允许误差数请输入大于等于0的整数', duration: 2000 })
  415. return false
  416. }
  417. } else {
  418. this.table.temp.allowratio = '0'
  419. }
  420. if (this.table.temp.autozone !== '') {
  421. console.log(this.table.temp.autozone)
  422. const autozone = /^(\d|[1-9]\d|1[0-1]\d|120)$/
  423. if (!autozone.test(parseFloat(this.table.temp.autozone))) {
  424. this.$message({ type: 'error', message: '跳转重量域请输入大于等于0小于等于120的整数', duration: 2000 })
  425. return false
  426. }
  427. } else {
  428. this.table.temp.autozone = '0'
  429. }
  430. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  431. if (pattern.test(this.table.temp.eqcode)) {
  432. this.$message({ type: 'error', message: 'TMR设备编号不可输入特殊字符', duration: 2000 })
  433. return false
  434. }
  435. if (pattern.test(this.table.temp.tname)) {
  436. this.$message({ type: 'error', message: 'TMR设备名称不可输入特殊字符', duration: 2000 })
  437. return false
  438. }
  439. this.isokDisable = true
  440. setTimeout(() => {
  441. this.isokDisable = false
  442. }, 1000)
  443. this.requestParam.name = 'updateBar'
  444. this.requestParam.parammaps = this.table.temp
  445. PostDataByName(this.requestParam).then(response => {
  446. console.log('新增保存发送参数', this.requestParam)
  447. if (response.msg !== 'fail') {
  448. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  449. this.getList()
  450. } else {
  451. const isRepeat = new RegExp('Duplicate entry :bar_bcode')
  452. if (isRepeat.test(response.data)) {
  453. this.$notify({ type: 'error', message: '栏舍编号不可重复,请重新录入', duration: 2000 })
  454. return false
  455. }
  456. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  457. }
  458. })
  459. },
  460. updateCancel(row) {
  461. console.log('点击了编辑取消')
  462. // 编辑false,不可编辑true
  463. row.Edit = false
  464. row.NoEdit = true
  465. // 新增false,编辑true,编辑保存false
  466. row.isCreate = false
  467. row.isUpdate = true
  468. row.isUpdateSave = false
  469. this.getList()
  470. },
  471. handleRowDelete(row) {
  472. console.log('点击了行内删除')
  473. MessageBox.confirm('是否确认删除此信息?', {
  474. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  475. }).then(() => {
  476. this.selectList = []
  477. this.requestParam = {}
  478. this.requestParam.common = { 'returnmap': '0' }
  479. this.requestParam.data = []
  480. this.requestParam.data[0] = { 'name': 'checkDeleteBar', 'type': 'v', 'parammaps': {
  481. 'pastureid': row.pastureid,
  482. 'id': row.id
  483. }}
  484. this.requestParam.data[1] = { 'name': 'deleteBar', 'type': 'e', 'parammaps': {
  485. 'pastureid': row.pastureid,
  486. 'id': row.id
  487. }}
  488. ExecDataByConfig(this.requestParam).then(response => {
  489. console.log('删除保存发送参数', this.requestParam)
  490. if (response.msg === 'fail') {
  491. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  492. } else {
  493. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  494. this.getList()
  495. }
  496. })
  497. }).catch(() => {
  498. this.$message({ type: 'info', message: '已取消删除' })
  499. })
  500. },
  501. handleSelectionChange(val) {
  502. console.log('勾选数据', val)
  503. this.selectList = val
  504. },
  505. handleDelete() {
  506. console.log('点击了删除')
  507. if (this.selectList.length == 0) {
  508. this.$message({ type: 'error', message: '请选择舍组栏信息', duration: 2000 })
  509. } else {
  510. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  511. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  512. }).then(() => {
  513. console.log(this.selectList)
  514. this.requestParam = {}
  515. this.requestParam.common = { 'returnmap': '0' }
  516. this.requestParam.data = []
  517. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  518. this.requestParam.data[0].children = []
  519. this.requestParam.data[0].children[0] = { 'name': 'checkDeleteBar', 'type': 'v', 'parammaps': {
  520. id: '@insertSpotList.id',
  521. pastureid: '@insertSpotList.pastureid'
  522. }}
  523. this.requestParam.data[0].children[1] = { 'name': 'deleteBar', 'type': 'e', 'parammaps': {
  524. id: '@insertSpotList.id',
  525. pastureid: '@insertSpotList.pastureid'
  526. }}
  527. ExecDataByConfig(this.requestParam).then(response => {
  528. console.log('删除保存发送参数', this.requestParam)
  529. if (response.msg === 'fail') {
  530. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  531. } else {
  532. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  533. this.getList()
  534. }
  535. })
  536. })
  537. }
  538. },
  539. handleChangeOrder() {
  540. this.isOrder = false
  541. this.rowDrop()
  542. },
  543. saveChangeOrder() {
  544. // 保存顺序
  545. var sortArr = []
  546. for (let i = 0; i < this.table.list.length; i++) {
  547. var obj = {}
  548. obj.sort = i + 1
  549. obj.id = this.table.list[i].id
  550. obj.pastureid = this.table.list[i].pastureid
  551. sortArr.push(obj)
  552. }
  553. this.requestParam = {}
  554. this.requestParam.common = { 'returnmap': '0' }
  555. this.requestParam.data = []
  556. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': sortArr }}
  557. this.requestParam.data[0].children = []
  558. this.requestParam.data[0].children[0] = { 'name': 'updateBarSort', 'type': 'e', 'parammaps': {
  559. id: '@insertSpotList.id',
  560. pastureid: '@insertSpotList.pastureid',
  561. sort: '@insertSpotList.sort'
  562. }}
  563. this.table.listLoading = true
  564. ExecDataByConfig(this.requestParam).then(response => {
  565. console.log('顺序切换保存发送参数', this.requestParam)
  566. this.table.listLoading = false
  567. if (response.msg === 'fail') {
  568. this.$notify({ title: '顺序切换失败', message: response.data, type: 'warning', duration: 2000 })
  569. } else {
  570. this.$notify({ title: '', message: '顺序切换成功', type: 'success', duration: 2000 })
  571. this.getList()
  572. this.isOrder = true
  573. }
  574. })
  575. },
  576. cancelChangeOrder() {
  577. // 取消顺序
  578. this.getList()
  579. this.isOrder = true
  580. },
  581. // 行拖拽
  582. rowDrop() {
  583. console.log(document.querySelector('#table .el-table__body-wrapper tbody'))
  584. const tbody = document.querySelector('#table .el-table__body-wrapper tbody')
  585. const that = this
  586. var sortable = Sortable.create(tbody, {
  587. disabled: that.dropState,
  588. onChoose({ newIndex, oldIndex }) {
  589. console.log(that.isOrder, 'that.isOrder == false')
  590. console.log(that.dropState, 'that.dropState')
  591. if (that.dropState == true || that.isOrder == true) {
  592. sortable.destroy()
  593. }
  594. },
  595. onEnd({ newIndex, oldIndex }) {
  596. const currRow = that.table.list.splice(oldIndex, 1)[0]
  597. that.table.list.splice(newIndex, 0, currRow)
  598. console.log('currRow', currRow)
  599. console.log('oldIndex', oldIndex)
  600. console.log('索引newIndex', newIndex)
  601. console.log('拖动数据', currRow)
  602. console.log('上', that.table.list[newIndex - 1])
  603. console.log('下', that.table.list[newIndex + 1])
  604. }
  605. })
  606. },
  607. }
  608. }
  609. </script>
  610. <style lang="scss" scoped>
  611. .search{margin-top:10px;}
  612. .table{margin-top:10px;}
  613. $width:350px;
  614. $left:325px;
  615. .selectInput{
  616. position: relative;
  617. display: inline-block;
  618. .Input{width: $width;position: relative;}
  619. .el-icon-arrow-down{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
  620. .el-icon-arrow-up{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
  621. .selectUl{
  622. z-index: 111;width: $width;background: #fff;border: 1px solid #E4E7ED;box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);margin: -1px 0 0 0;padding: 6px 0; margin: 0;box-sizing: border-box;position: absolute;
  623. li{
  624. list-style: none;font-size: 14px; padding: 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #606266; height: 50px; line-height: 50px; box-sizing: border-box; cursor: pointer;
  625. a{float:left;width: 80px;}
  626. a:hover{color: rgba(0, 204, 102, 0.71); font-weight: 700;}
  627. }
  628. }
  629. }
  630. </style>