e97fbc48f20b55328e7d987a7a0b266a1209b714.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.pastureName" placeholder="牧场" style="width: 180px;" class="filter-item" clearable />
  5. <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  6. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  7. </el-select>
  8. <div ref="selectInput" class="filter-item selectInput">
  9. <el-input type="text" name="" value="" placeholder="请点击选择搜索条件" class="Input" />
  10. <i v-if="arrowDown" icon="el-icon-arrow-down" class="el-icon-arrow-down" />
  11. <i v-if="arrowUp" icon="el-icon-arrow-up" class="el-icon-arrow-up" />
  12. <ul v-if="arrowUp" class="selectUl">
  13. <li><a>地址</a><el-input v-model="table.getdataListParm.parammaps.address" type="text" style="width: 245px;" /></li>
  14. <li><a>联系人</a><el-input v-model="table.getdataListParm.parammaps.contact" type="text" style="width: 245px;" /></li>
  15. <li><a>联系电话</a><el-input v-model="table.getdataListParm.parammaps.phone" type="text" style="width: 245px;" /></li>
  16. <li>
  17. <div style="float: right;">
  18. <el-button class="downminCancel" @click="arrowUp=false;arrowDown=true;">取消</el-button>
  19. <el-button class="miniPrimary" @click="handleSearch">搜索</el-button>
  20. </div>
  21. </li>
  22. </ul>
  23. </div>
  24. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  25. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  26. </div>
  27. <div class="table">
  28. <el-table
  29. :key="table.tableKey"
  30. v-loading="table.listLoading"
  31. element-loading-text="给我一点时间"
  32. :data="table.list"
  33. border
  34. fit
  35. highlight-current-row
  36. style="width: 100%;"
  37. :row-style="rowStyle"
  38. :cell-style="cellStyle"
  39. class="elTable table-fixed"
  40. @selection-change="handleSelectionChange"
  41. >
  42. <el-table-column type="selection" align="center" width="50" />
  43. <el-table-column label="序号" align="center" type="index" width="50px">
  44. <template slot-scope="scope">
  45. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="集团名称" min-width="130px" align="center">
  49. <template slot-scope="scope">
  50. <span>{{ scope.row.groupsname }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="牧场名称" min-width="130px" align="center">
  54. <template slot-scope="scope">
  55. <span>{{ scope.row.pastureName }}</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="地址" min-width="150px" align="center">
  59. <template slot-scope="scope">
  60. <span v-if="scope.row.NoEdit">{{ scope.row.address }}</span>
  61. <el-input v-if="scope.row.Edit" v-model="scope.row.address" placeholder="1-255字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="255" style="width:95%;padding:10px 0;" />
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="联系人" min-width="150px" align="center">
  65. <template slot-scope="scope">
  66. <span v-if="scope.row.NoEdit">{{ scope.row.contact }}</span>
  67. <el-input v-if="scope.row.Edit" v-model="scope.row.contact" placeholder="1-32字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="联系电话" min-width="150px" align="center">
  71. <template slot-scope="scope">
  72. <span v-if="scope.row.NoEdit">{{ scope.row.phone }}</span>
  73. <el-input v-if="scope.row.Edit" v-model="scope.row.phone" placeholder="请输入11位手机号" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="11" style="width:95%;padding:10px 0;" />
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  77. <template slot-scope="{row}">
  78. <!-- 编辑 -->
  79. <el-button v-if="row.isUpdate && isRoleEdit" icon="el-icon-edit-outline" class="miniSuccess" @click="handleUpdate(row)" />
  80. <!-- 编辑保存 -->
  81. <el-button v-if="row.isUpdateSave && isRoleEdit" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData(row)" />
  82. <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
  83. <el-button v-if="row.isUpdateSave && isRoleEdit" icon="el-icon-close" class="minCancel" @click="updateCancel(row)" />
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import { GetDataByName, PostDataByName, failproccess, checkButtons } from '@/api/common'
  93. import Cookies from 'js-cookie'
  94. import Pagination from '@/components/Pagination'
  95. export default {
  96. name: 'RanchInformation',
  97. components: { Pagination },
  98. data() {
  99. return {
  100. isRoleEdit: [],
  101. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }],
  102. table: {
  103. getdataListParm: {
  104. name: 'getPastureList',
  105. page: 1,
  106. offset: 1,
  107. pagecount: 10,
  108. returntype: 'Map',
  109. parammaps: {
  110. 'pastureid': Cookies.get('pastureid'),
  111. 'phone': '',
  112. 'contact': '',
  113. 'address': '',
  114. 'pastureName': '',
  115. enable: ''
  116. }
  117. },
  118. tableKey: 0,
  119. list: [],
  120. total: 0,
  121. listLoading: true,
  122. temp: {}
  123. },
  124. requestParam: {},
  125. arrowDown: true,
  126. arrowUp: false,
  127. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  128. cellStyle: { padding: 0 + 'px' }
  129. }
  130. },
  131. created() {
  132. this.getList()
  133. this.getButtons()
  134. },
  135. mounted() {
  136. document.addEventListener('click', (e) => {
  137. if (this.$refs.selectInput !== undefined) {
  138. if (!this.$refs.selectInput.contains(e.target)) {
  139. this.arrowDown = true
  140. this.arrowUp = false
  141. } else {
  142. this.arrowDown = false
  143. this.arrowUp = true
  144. }
  145. }
  146. })
  147. },
  148. methods: {
  149. getButtons() {
  150. const Edit = 'RanchInformation'
  151. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  152. this.isRoleEdit = isRoleEdit
  153. },
  154. getList() {
  155. this.table.listLoading = true
  156. GetDataByName(this.table.getdataListParm).then(response => {
  157. console.log('table数据', response.data.list)
  158. if (response.data.list !== null) {
  159. for (let i = 0; i < response.data.list.length; i++) {
  160. response.data.list[i].enable = parseInt(response.data.list[i].enable)
  161. this.$set(response.data.list[i], 'Edit', false) // 编辑
  162. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  163. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  164. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  165. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  166. }
  167. this.table.list = response.data.list
  168. this.table.pageNum = response.data.pageNum
  169. this.table.pageSize = response.data.pageSize
  170. this.table.total = response.data.total
  171. } else {
  172. this.table.list = []
  173. }
  174. setTimeout(() => {
  175. this.table.listLoading = false
  176. }, 100)
  177. })
  178. },
  179. handleEnableChange() {
  180. console.log('点击了是否启用')
  181. },
  182. handleConfirmStartChange() {
  183. console.log('点击了确认开始')
  184. },
  185. handleSearch() {
  186. console.log('点击了查询')
  187. this.getList()
  188. this.table.getdataListParm.offset = 1
  189. this.arrowDown = true
  190. this.arrowUp = false
  191. },
  192. handleRefresh() {
  193. console.log('点击了重置')
  194. this.table.getdataListParm.parammaps.empCode = ''
  195. this.table.getdataListParm.parammaps.phone = ''
  196. this.table.getdataListParm.parammaps.enable = ''
  197. this.table.getdataListParm.parammaps.contact = ''
  198. this.table.getdataListParm.parammaps.address = ''
  199. this.table.getdataListParm.parammaps.pastureName = ''
  200. this.table.getdataListParm.offset = 1
  201. this.getList()
  202. },
  203. handleSelectionChange(val) {
  204. console.log('勾选数据', val)
  205. },
  206. handleUpdate(row) {
  207. console.log('点击了编辑')
  208. for (let i = 0; i < this.table.list.length; i++) {
  209. if (this.table.list[i].Edit == true) {
  210. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  211. return false
  212. }
  213. }
  214. // 编辑true,不可编辑false
  215. row.Edit = true
  216. row.NoEdit = false
  217. // 新增false,编辑false,编辑保存true
  218. row.isCreate = false
  219. row.isUpdate = false
  220. row.isUpdateSave = true
  221. },
  222. updateData(row) {
  223. console.log('点击了编辑保存', row)
  224. this.table.temp.pastureid = row.pastureid
  225. this.table.temp.phone = row.phone
  226. this.table.temp.enable = row.enable
  227. this.table.temp.contact = row.contact
  228. this.table.temp.address = row.address
  229. this.table.temp.pastureName = row.pastureName
  230. // 检验手机号是否为11位数字
  231. if (this.table.temp.phone !== undefined && this.table.temp.phone !== '') {
  232. const phone = /^\d{11}$/
  233. if (!phone.test(this.table.temp.phone)) {
  234. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  235. return false
  236. }
  237. }
  238. this.isokDisable = true
  239. setTimeout(() => {
  240. this.isokDisable = false
  241. }, 1000)
  242. this.requestParam.name = 'updatepastureinfo'
  243. this.requestParam.parammaps = this.table.temp
  244. PostDataByName(this.requestParam).then(response => {
  245. console.log('新增保存发送参数', this.requestParam)
  246. if (response.msg !== 'fail') {
  247. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  248. this.getList()
  249. } else {
  250. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  251. }
  252. })
  253. },
  254. updateCancel(row) {
  255. console.log('点击了编辑取消')
  256. // 编辑false,不可编辑true
  257. row.Edit = false
  258. row.NoEdit = true
  259. // 新增false,编辑true,编辑保存false
  260. row.isCreate = false
  261. row.isUpdate = true
  262. row.isUpdateSave = false
  263. this.getList()
  264. }
  265. }
  266. }
  267. </script>
  268. <style lang="scss" scoped>
  269. .search{margin-top:10px;}
  270. .table{margin-top:10px;}
  271. $width:350px;
  272. $left:325px;
  273. .selectInput{
  274. position: relative;
  275. display: inline-block;
  276. .Input{width: $width;position: relative;}
  277. .el-icon-arrow-down{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
  278. .el-icon-arrow-up{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
  279. .selectUl{
  280. 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;
  281. li{
  282. 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;
  283. a{float:left;width: 80px;}
  284. a:hover{color: rgba(0, 204, 102, 0.71); font-weight: 700;}
  285. }
  286. }
  287. }
  288. </style>