acc50aed8d61a6e4d11e7689b838430541e51831.svn-base 12 KB

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