index.vue 33 KB

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