416e5f37b485a3947556fe81bb7203f22e6ae5fe.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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="minCancel" @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.group }}</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="是否启用" min-width="110px" align="center">
  77. <template slot-scope="scope">
  78. <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)" />
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
  82. <template slot-scope="{row}">
  83. <!-- 新增 -->
  84. <el-button v-if="row.isCreate && isRoleEdit" class="miniSuccess" @click="createData(row)">保存</el-button>
  85. <el-button v-if="row.isCreate && isRoleEdit" class="minCancel" @click="createCancel(row)">取消</el-button>
  86. <!-- 编辑 -->
  87. <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  88. <!-- 编辑保存 -->
  89. <el-button v-if="row.isUpdateSave && isRoleEdit" class="miniSuccess" @click="updateData(row)">保存</el-button>
  90. <el-button v-if="row.isUpdateSave && isRoleEdit" class="minCancel" @click="updateCancel(row)">取消</el-button>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  95. </div>
  96. </div>
  97. </template>
  98. <script>
  99. import { GetDataByName, PostDataByName, failproccess, checkButtons } from '@/api/common'
  100. import Cookies from 'js-cookie'
  101. import Pagination from '@/components/Pagination'
  102. export default {
  103. name: 'RanchInformation',
  104. components: { Pagination },
  105. data() {
  106. return {
  107. isRoleEdit: [],
  108. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }],
  109. table: {
  110. getdataListParm: {
  111. name: 'getPastureList',
  112. page: 1,
  113. offset: 1,
  114. pagecount: 10,
  115. returntype: 'Map',
  116. parammaps: {
  117. 'pastureid': Cookies.get('pastureid'),
  118. 'phone': '',
  119. 'contact': '',
  120. 'address': '',
  121. 'pastureName': '',
  122. enable: ''
  123. }
  124. },
  125. tableKey: 0,
  126. list: [],
  127. total: 0,
  128. listLoading: true,
  129. temp: {}
  130. },
  131. requestParam: {},
  132. arrowDown: true,
  133. arrowUp: false,
  134. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  135. cellStyle: { padding: 0 + 'px' }
  136. }
  137. },
  138. created() {
  139. this.getList()
  140. this.getButtons()
  141. },
  142. mounted() {
  143. document.addEventListener('click', (e) => {
  144. if (this.$refs.selectInput !== undefined) {
  145. if (!this.$refs.selectInput.contains(e.target)) {
  146. this.arrowDown = true
  147. this.arrowUp = false
  148. } else {
  149. this.arrowDown = false
  150. this.arrowUp = true
  151. }
  152. }
  153. })
  154. },
  155. methods: {
  156. getButtons() {
  157. const Edit = 'RanchInformation'
  158. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  159. this.isRoleEdit = isRoleEdit
  160. },
  161. getList() {
  162. this.table.listLoading = true
  163. GetDataByName(this.table.getdataListParm).then(response => {
  164. console.log('table数据', response.data.list)
  165. if (response.data.list !== null) {
  166. for (let i = 0; i < response.data.list.length; i++) {
  167. response.data.list[i].enable = parseInt(response.data.list[i].enable)
  168. this.$set(response.data.list[i], 'Edit', false) // 编辑
  169. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  170. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  171. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  172. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  173. }
  174. this.table.list = response.data.list
  175. this.table.pageNum = response.data.pageNum
  176. this.table.pageSize = response.data.pageSize
  177. this.table.total = response.data.total
  178. } else {
  179. this.table.list = []
  180. }
  181. setTimeout(() => {
  182. this.table.listLoading = false
  183. }, 100)
  184. })
  185. },
  186. handleEnableChange() {
  187. console.log('点击了是否启用')
  188. },
  189. handleConfirmStartChange() {
  190. console.log('点击了确认开始')
  191. },
  192. handleSearch() {
  193. console.log('点击了查询')
  194. this.getList()
  195. this.table.getdataListParm.offset = 1
  196. this.arrowDown = true
  197. this.arrowUp = false
  198. },
  199. handleRefresh() {
  200. console.log('点击了重置')
  201. this.table.getdataListParm.parammaps.empCode = ''
  202. this.table.getdataListParm.parammaps.phone = ''
  203. this.table.getdataListParm.parammaps.enable = ''
  204. this.table.getdataListParm.parammaps.contact = ''
  205. this.table.getdataListParm.parammaps.address = ''
  206. this.table.getdataListParm.parammaps.pastureName = ''
  207. this.table.getdataListParm.offset = 1
  208. this.getList()
  209. },
  210. handleSelectionChange(val) {
  211. console.log('勾选数据', val)
  212. },
  213. handleUpdate(row) {
  214. console.log('点击了编辑')
  215. for (let i = 0; i < this.table.list.length; i++) {
  216. if (this.table.list[i].Edit == true) {
  217. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  218. return false
  219. }
  220. }
  221. // 编辑true,不可编辑false
  222. row.Edit = true
  223. row.NoEdit = false
  224. // 新增false,编辑false,编辑保存true
  225. row.isCreate = false
  226. row.isUpdate = false
  227. row.isUpdateSave = true
  228. },
  229. updateData(row) {
  230. console.log('点击了编辑保存', row)
  231. this.table.temp.pastureid = row.pastureid
  232. this.table.temp.phone = row.phone
  233. this.table.temp.enable = row.enable
  234. this.table.temp.contact = row.contact
  235. this.table.temp.address = row.address
  236. this.table.temp.pastureName = row.pastureName
  237. // 检验手机号是否为11位数字
  238. if (this.table.temp.phone !== undefined && this.table.temp.phone !== '') {
  239. const phone = /^\d{11}$/
  240. if (!phone.test(this.table.temp.phone)) {
  241. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  242. return false
  243. }
  244. }
  245. this.isokDisable = true
  246. setTimeout(() => {
  247. this.isokDisable = false
  248. }, 1000)
  249. this.requestParam.name = 'updatepastureinfo'
  250. this.requestParam.parammaps = this.table.temp
  251. PostDataByName(this.requestParam).then(response => {
  252. console.log('新增保存发送参数', this.requestParam)
  253. if (response.msg !== 'fail') {
  254. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  255. this.getList()
  256. } else {
  257. failproccess(response, this.$notify)
  258. }
  259. })
  260. },
  261. updateCancel(row) {
  262. console.log('点击了编辑取消')
  263. // 编辑false,不可编辑true
  264. row.Edit = false
  265. row.NoEdit = true
  266. // 新增false,编辑true,编辑保存false
  267. row.isCreate = false
  268. row.isUpdate = true
  269. row.isUpdateSave = false
  270. this.getList()
  271. }
  272. }
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. .search{margin-top:10px;}
  277. .table{margin-top:10px;}
  278. $width:350px;
  279. $left:325px;
  280. .selectInput{
  281. position: relative;
  282. display: inline-block;
  283. .Input{width: $width;position: relative;}
  284. .el-icon-arrow-down{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
  285. .el-icon-arrow-up{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
  286. .selectUl{
  287. 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;
  288. li{
  289. 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;
  290. a{float:left;width: 80px;}
  291. a:hover{color: rgba(0, 204, 102, 0.71); font-weight: 700;}
  292. }
  293. }
  294. }
  295. </style>