8c8b31d13fcecb76457fdf63af852706d206d06d.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div class="app-container">
  3. <div class="operation">
  4. <el-button v-if="isRoleEdit" class="success" @click="handleCreate">新增</el-button>
  5. <el-button v-if="isRoleEdit" class="danger" @click="handleDelete">删除</el-button>
  6. </div>
  7. <div class="search">
  8. <el-select v-model="table.getdataListParm.parammaps.enable" filterable placeholder="标签类别" class="filter-item" style="width: 120px;" clearable>
  9. <el-option v-for="item in labelCategoryList" :key="item.id" :label="item.name" :value="item.id" />
  10. </el-select>
  11. <el-select v-model="table.getdataListParm.parammaps.enable" filterable placeholder="标签值" class="filter-item" style="width: 120px;" clearable>
  12. <el-option v-for="item in tagValueList" :key="item.id" :label="item.name" :value="item.id" />
  13. </el-select>
  14. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  15. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  16. </div>
  17. <div class="table">
  18. <el-table
  19. :key="table.tableKey"
  20. v-loading="table.listLoading"
  21. element-loading-text="给我一点时间"
  22. :data="table.list"
  23. border
  24. fit
  25. highlight-current-row
  26. style="width: 100%;"
  27. :row-style="rowStyle"
  28. :cell-style="cellStyle"
  29. class="elTable table-fixed"
  30. @selection-change="handleSelectionChange"
  31. >
  32. <el-table-column type="selection" align="center" width="50" />
  33. <el-table-column label="序号" align="center" type="index" width="50px">
  34. <template slot-scope="scope">
  35. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="标签类别" min-width="130px" align="center">
  39. <template slot-scope="scope">
  40. <span v-if="scope.row.NoEdit">{{ scope.row.drivercode }}</span>
  41. <el-input v-if="scope.row.Edit" v-model="scope.row.drivercode" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="标签值" min-width="130px" align="center">
  45. <template slot-scope="scope">
  46. <span v-if="scope.row.NoEdit">{{ scope.row.drivername }}</span>
  47. <el-input v-if="scope.row.Edit" v-model="scope.row.drivername" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="备注" min-width="130px" align="center">
  51. <template slot-scope="scope">
  52. <span v-if="scope.row.NoEdit">{{ scope.row.drivername }}</span>
  53. <el-input v-if="scope.row.Edit" v-model="scope.row.drivername" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="创建人" min-width="130px" align="center">
  57. <template slot-scope="scope">
  58. <span v-if="scope.row.NoEdit">{{ scope.row.drivername }}</span>
  59. <el-input v-if="scope.row.Edit" v-model="scope.row.drivername" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  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.drivername }}</span>
  65. <el-input v-if="scope.row.Edit" v-model="scope.row.drivername" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
  69. <template slot-scope="{row}">
  70. <!-- 新增 -->
  71. <el-button v-if="row.isCreate" :disabled="isokDisable" class="miniSuccess" @click="createData(row)">保存</el-button>
  72. <el-button v-if="row.isCreate" class="minCancel" @click="createCancel(row)">取消</el-button>
  73. <!-- 编辑 -->
  74. <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  75. <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  76. <!-- 编辑保存 -->
  77. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" class="miniSuccess" @click="updateData(row)">保存</el-button>
  78. <el-button v-if="row.isUpdateSave" class="minCancel" @click="updateCancel(row)">取消</el-button>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <pagination v-show="table.total>0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, checkButtons } from '@/api/common'
  88. import Cookies from 'js-cookie'
  89. import Pagination from '@/components/Pagination'
  90. import { MessageBox } from 'element-ui'
  91. export default {
  92. name: 'LabelManagement',
  93. components: { Pagination },
  94. data() {
  95. return {
  96. isRoleEdit: [],
  97. labelCategoryList: [], // 标签类别
  98. tagValueList: [], // 标签值
  99. table: {
  100. getdataListParm: {
  101. name: 'getDriverList',
  102. page: 1,
  103. offset: 1,
  104. pagecount: 10,
  105. returntype: 'Map',
  106. parammaps: {
  107. pastureid: Cookies.get('pastureid'),
  108. enable: '',
  109. drivername: '',
  110. drivercode: ''
  111. }
  112. },
  113. tableKey: 0,
  114. list: [],
  115. total: 0,
  116. listLoading: true,
  117. temp: {}
  118. },
  119. requestParam: {},
  120. isokDisable: false,
  121. selectList: [],
  122. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  123. cellStyle: { padding: 0 + 'px' }
  124. }
  125. },
  126. created() {
  127. this.getList()
  128. this.getButtons()
  129. },
  130. methods: {
  131. getButtons() {
  132. const Edit = 'Driver'
  133. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  134. this.isRoleEdit = isRoleEdit
  135. },
  136. getList() {
  137. this.table.listLoading = true
  138. GetDataByName(this.table.getdataListParm).then(response => {
  139. console.log('table数据', response.data.list)
  140. if (response.data.list !== null) {
  141. for (let i = 0; i < response.data.list.length; i++) {
  142. this.$set(response.data.list[i], 'Edit', false) // 编辑
  143. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  144. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  145. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  146. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  147. }
  148. this.table.list = response.data.list
  149. this.table.pageNum = response.data.pageNum
  150. this.table.pageSize = response.data.pageSize
  151. this.table.total = response.data.total
  152. } else {
  153. this.table.list = []
  154. }
  155. setTimeout(() => {
  156. this.table.listLoading = false
  157. }, 100)
  158. })
  159. },
  160. handleEnableChange() {
  161. console.log('点击了是否启用')
  162. },
  163. handleSearch() {
  164. console.log('点击了查询')
  165. this.table.getdataListParm.offset = 1
  166. this.getList()
  167. },
  168. handleRefresh() {
  169. console.log('点击了重置')
  170. this.table.getdataListParm.parammaps.drivername = ''
  171. this.table.getdataListParm.parammaps.enable = ''
  172. this.table.getdataListParm.parammaps.drivercode = ''
  173. this.table.getdataListParm.offset = 1
  174. this.getList()
  175. },
  176. handleCreate() {
  177. // 编辑true/不可编辑false
  178. // 新增操true,编辑false,编辑保存false
  179. for (let i = 0; i < this.table.list.length; i++) {
  180. if (this.table.list[i].Edit === true) {
  181. console.log(123)
  182. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  183. return false
  184. }
  185. }
  186. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'drivercode': '', 'drivername': '' })
  187. },
  188. createData(row) {
  189. console.log('点击了新增保存', row)
  190. this.table.temp.pastureid = Cookies.get('pastureid')
  191. this.table.temp.drivercode = row.drivercode
  192. this.table.temp.drivername = row.drivername
  193. this.table.temp.enable = row.enable
  194. // 检验用户名称/角色是否为空
  195. if (this.table.temp.drivercode == '' && this.table.temp.drivername == '') {
  196. this.$message({ type: 'error', message: '驾驶员编号/驾驶员名称不能为空', duration: 2000 })
  197. return false
  198. } else if (this.table.temp.drivercode == '') {
  199. this.$message({ type: 'error', message: '驾驶员编号不能为空', duration: 2000 })
  200. return false
  201. } else if (this.table.temp.drivername == '') {
  202. this.$message({ type: 'error', message: '驾驶员名称不能为空', duration: 2000 })
  203. return false
  204. }
  205. this.isokDisable = true
  206. setTimeout(() => {
  207. this.isokDisable = false
  208. }, 1000)
  209. this.requestParam.name = 'insertDriver'
  210. this.requestParam.parammaps = this.table.temp
  211. PostDataByName(this.requestParam).then(response => {
  212. console.log('新增保存发送参数', this.requestParam)
  213. if (response.msg !== 'fail') {
  214. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  215. this.getList()
  216. } else {
  217. failproccess(response, this.$notify)
  218. }
  219. })
  220. },
  221. createCancel(row) {
  222. console.log('点击了新增取消')
  223. for (let i = 0; i < this.table.list.length; i++) {
  224. if (row.myId === this.table.list[i].myId) {
  225. var listIndex = this.table.list.indexOf(this.table.list[i])
  226. }
  227. if (listIndex > -1) {
  228. this.table.list.splice(listIndex, 1)
  229. return
  230. }
  231. }
  232. },
  233. handleUpdate(row) {
  234. for (let i = 0; i < this.table.list.length; i++) {
  235. if (this.table.list[i].Edit == true) {
  236. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  237. return false
  238. }
  239. }
  240. // 编辑true,不可编辑false
  241. row.Edit = true
  242. row.NoEdit = false
  243. // 新增false,编辑false,编辑保存true
  244. row.isCreate = false
  245. row.isUpdate = false
  246. row.isUpdateSave = true
  247. },
  248. updateData(row) {
  249. console.log('点击了编辑保存', row)
  250. this.table.temp.pastureid = row.pastureid
  251. this.table.temp.drivercode = row.drivercode
  252. this.table.temp.drivername = row.drivername
  253. this.table.temp.enable = row.enable
  254. this.table.temp.id = row.id
  255. // 检验用户名称/角色是否为空
  256. console.log(this.table.temp.drivercode)
  257. console.log(this.table.temp.drivername)
  258. if (this.table.temp.drivercode == '' && this.table.temp.drivername == '') {
  259. this.$message({ type: 'error', message: '驾驶员编号/驾驶员名称不能为空', duration: 2000 })
  260. return false
  261. } else if (this.table.temp.drivercode == undefined || this.table.temp.drivercode == '') {
  262. this.$message({ type: 'error', message: '驾驶员编号不能为空', duration: 2000 })
  263. return false
  264. } else if (this.table.temp.drivername == undefined || this.table.temp.drivername == '') {
  265. this.$message({ type: 'error', message: '驾驶员名称不能为空', duration: 2000 })
  266. return false
  267. }
  268. this.isokDisable = true
  269. setTimeout(() => {
  270. this.isokDisable = false
  271. }, 1000)
  272. this.requestParam.name = 'updateDriver'
  273. this.requestParam.parammaps = this.table.temp
  274. PostDataByName(this.requestParam).then(response => {
  275. console.log('编辑保存发送参数', this.requestParam)
  276. if (response.msg !== 'fail') {
  277. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  278. this.getList()
  279. } else {
  280. failproccess(response, this.$notify)
  281. }
  282. })
  283. },
  284. updateCancel(row) {
  285. console.log('点击了编辑取消')
  286. // 编辑false,不可编辑true
  287. row.Edit = false
  288. row.NoEdit = true
  289. // 新增false,编辑true,编辑保存false
  290. row.isCreate = false
  291. row.isUpdate = true
  292. row.isUpdateSave = false
  293. this.getList()
  294. },
  295. handleRowDelete(row) {
  296. console.log('点击了行内删除')
  297. MessageBox.confirm('是否确认删除此信息?', {
  298. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  299. }).then(() => {
  300. this.selectList = []
  301. this.requestParam.name = 'deleteDriver'
  302. this.requestParam.parammaps = {}
  303. this.requestParam.parammaps.pastureid = row.pastureid
  304. this.requestParam.parammaps.id = row.id
  305. PostDataByName(this.requestParam).then(response => {
  306. if (response.msg === 'fail') {
  307. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  308. } else {
  309. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  310. this.getList()
  311. }
  312. })
  313. }).catch(() => {
  314. this.$message({ type: 'info', message: '已取消删除' })
  315. })
  316. },
  317. handleSelectionChange(val) {
  318. console.log('勾选数据', val)
  319. this.selectList = val
  320. },
  321. handleDelete() {
  322. console.log('点击了删除')
  323. if (this.selectList.length == 0) {
  324. this.$message({ type: 'error', message: '请选择驾驶员信息', duration: 2000 })
  325. } else {
  326. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  327. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  328. }).then(() => {
  329. console.log(this.selectList)
  330. this.requestParam.common = { 'returnmap': '0' }
  331. this.requestParam.data = []
  332. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  333. this.requestParam.data[0].children = []
  334. this.requestParam.data[0].children[0] = { 'name': 'deleteDriver', 'type': 'e', 'parammaps': {
  335. id: '@insertSpotList.id',
  336. pastureid: '@insertSpotList.pastureid'
  337. }}
  338. ExecDataByConfig(this.requestParam).then(response => {
  339. console.log('删除保存发送参数', this.requestParam)
  340. if (response.msg === 'fail') {
  341. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  342. } else {
  343. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  344. this.getList()
  345. }
  346. })
  347. })
  348. }
  349. }
  350. }
  351. }
  352. </script>
  353. <style lang="scss" scoped>
  354. .search{margin-top:10px;}
  355. .table{margin-top:10px;}
  356. </style>