index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.parammaps.name" placeholder="请输入牧场名称" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.parammaps.manager_user" placeholder="请输入负责人姓名" style="width: 180px;" class="filter-item" clearable />
  6. <el-input v-model="table.parammaps.manager_phone" placeholder="请输入手机号" style="width: 180px;" class="filter-item" clearable />
  7. <el-date-picker v-model="table.parammaps.inputDatetime" :clearable="false" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;margin-right: 10px;" />
  8. <el-select v-model="table.parammaps.is_show" placeholder="状态" class="filter-item" style="width: 120px;" clearable>
  9. <el-option v-for="item in enableList" :key="item.value" :label="item.label" :value="item.value" />
  10. </el-select>
  11. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  12. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  13. </div>
  14. <div class="operation">
  15. <el-button v-if="isAdd" icon="el-icon-plus" class="success" @click="handleCreate">添加牧场</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. >
  31. <el-table-column type="selection" align="center" width="50" />
  32. <el-table-column label="序号" min-width="130px" align="center" prop="id" />
  33. <el-table-column label="牧场名称" min-width="100px" align="center" prop="name" />
  34. <el-table-column label="登录账号" min-width="100px" align="center" prop="account" />
  35. <el-table-column label="负责人姓名" min-width="100px" align="center" prop="manager_user" />
  36. <el-table-column label="手机号" min-width="100px" align="center" prop="manager_phone" />
  37. <el-table-column label="牧场地址" min-width="100px" align="center" prop="address" />
  38. <el-table-column label="添加时间" min-width="100px" align="center" prop="created_at_format" />
  39. <el-table-column label="状态" min-width="110px" align="center">
  40. <template slot-scope="scope">
  41. <el-switch v-model="scope.row.is_show" :disabled="!isEnable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="2" @change="handleEnableChange(scope.$index, scope.row)" />
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width" fixed="right">
  45. <template slot-scope="{row}">
  46. <a v-if="isResetpassword" class="correcting" size="mini" style="width: 80px;" @click="handleResetPassword(row)">重置密码</a>
  47. <span v-if="isResetpassword && isEdit" class="centerSpan">|</span>
  48. <a v-if="isEdit" class="correcting" @click="handleUpdate(row)">编辑</a>
  49. <span v-if="isEdit && isDelete" class="centerSpan">|</span>
  50. <a v-if="isDelete" class="correcting" @click="handleRowDelete(row)">删除</a>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.page" :limit.sync="table.page_size" @pagination="getList" />
  55. </div>
  56. <!-- 新增/编辑 -->
  57. <el-dialog :title="textMap[edit.dialogStatus]" :visible.sync="edit.dialogFormVisible" :close-on-click-modal="false"
  58. width="50%">
  59. <div class="edit">
  60. <div class="content">
  61. <el-form ref="editTemp" :rules="rules" :model="edit.temp" label-position="right" label-width="115px" style="width: 90%;margin:0 auto 30px">
  62. <el-row v-if="edit.dialogStatus == 'add'">
  63. <el-col :span="12">
  64. <el-form-item label="牧场ID:" prop="pasture_id">
  65. <el-input ref="pasture_id" type="number" v-model="edit.temp.pasture_id" placeholder="请输入牧场ID" />
  66. </el-form-item>
  67. </el-col>
  68. </el-row>
  69. <el-row>
  70. <el-col :span="12">
  71. <el-form-item label="牧场名称:" prop="name">
  72. <el-input ref="name" v-model="edit.temp.name" placeholder="请输入牧场名称" />
  73. </el-form-item>
  74. </el-col>
  75. </el-row>
  76. <el-row>
  77. <el-col :span="12">
  78. <el-form-item label="登录账号:" prop="account">
  79. <el-input ref="account" v-model="edit.temp.account" placeholder="请输入登录账号" />
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. <el-row>
  84. <el-col :span="12">
  85. <el-form-item label="初始密码" prop="username">
  86. <span>123456</span>
  87. </el-form-item>
  88. </el-col>
  89. </el-row>
  90. <el-row>
  91. <el-col :span="12">
  92. <el-form-item label="负责人姓名:" prop="manager_user">
  93. <el-input ref="manager_user" v-model="edit.temp.manager_user" placeholder="请输入负责人姓名" />
  94. </el-form-item>
  95. </el-col>
  96. </el-row>
  97. <el-row>
  98. <el-col :span="12">
  99. <el-form-item label="手机号:" prop="manager_phone">
  100. <el-input ref="manager_phone" v-model="edit.temp.manager_phone" placeholder="请输入手机号" />
  101. </el-form-item>
  102. </el-col>
  103. </el-row>
  104. <el-row>
  105. <el-col :span="12">
  106. <el-form-item label="牧场地址:" prop="address">
  107. <el-input ref="address" v-model="edit.temp.address" placeholder="请输入牧场地址" />
  108. </el-form-item>
  109. </el-col>
  110. </el-row>
  111. <el-row>
  112. <el-col :span="12">
  113. <el-form-item label="域名或IP地址:" prop="domain">
  114. <el-input ref="domain" v-model="edit.temp.domain" placeholder="请联系技术人员索要牧场端域名或者服务器IP地址" />
  115. </el-form-item>
  116. </el-col>
  117. </el-row>
  118. </el-form>
  119. </div>
  120. <div slot="footer" class="dialog-footer" style="right:30px;position:absolute;bottom: 40px;">
  121. <el-button class="cancelClose cancelClose" @click="edit.dialogFormVisible = false;getList(); ">关闭</el-button>
  122. <el-button class="save" :disabled="isokDisable"
  123. @click="edit.dialogStatus == 'add' ? createData():updateData()">确认</el-button>
  124. </div>
  125. </div>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import { postJson,getJson,delJson,checkButtons } from '@/api/common'
  131. import Cookies from 'js-cookie'
  132. import { MessageBox } from 'element-ui'
  133. import { validatePhone } from '@/utils/validate'
  134. import Pagination from '@/components/Pagination'
  135. export default {
  136. name: 'PastureList',
  137. components: { Pagination },
  138. data() {
  139. return {
  140. enableList: JSON.parse(sessionStorage.downlist).confirm_start,
  141. table: {
  142. page: 1,
  143. page_size: parseInt(Cookies.get('pageCount')),
  144. tableKey: 0,
  145. list: [],
  146. total: 0,
  147. listLoading: true,
  148. parammaps: {
  149. name: '',manager_user:'',manager_phone:'',is_show:'',inputDatetime:[],end_time:'',start_time:''
  150. }
  151. },
  152. edit: {
  153. dialogStatus: '',
  154. dialogFormVisible: false,
  155. temp: {
  156. pasture_id:0,
  157. name:'',
  158. account:'',
  159. username:'',
  160. manager_user:'',
  161. manager_phone:'',
  162. address:''
  163. }
  164. },
  165. rules: {
  166. name: [{
  167. required: true,
  168. message: '必填',
  169. trigger: 'blur'
  170. }],
  171. account: [{
  172. required: true,
  173. message: '必填',
  174. trigger: 'blur'
  175. }],
  176. manager_user: [{
  177. required: true,
  178. message: '必填',
  179. trigger: 'blur'
  180. }],
  181. manager_phone: [{ validator: validatePhone,required: true, trigger: 'blur' }],
  182. address: [{
  183. required: true,
  184. message: '必填',
  185. trigger: 'blur'
  186. }],
  187. domain: [{
  188. required: true,
  189. message: '必填',
  190. trigger: 'blur'
  191. }],
  192. },
  193. create:{
  194. dialogStatus:'',
  195. dialogFormVisible: false,
  196. temp:{},
  197. rules:{}
  198. },
  199. isokDisable: false,
  200. textMap: {
  201. add: '添加牧场',
  202. update:'编辑牧场'
  203. },
  204. isAdd:'',isEdit:'',isResetpassword:'',isDelete:'',isEnable:'',
  205. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  206. cellStyle: { padding: 0 + 'px' }
  207. }
  208. },
  209. created() {
  210. this.getButton()
  211. this.getList()
  212. },
  213. methods: {
  214. getButton(){
  215. const add = 'rangeManagement:pastureList:add'
  216. this.isAdd = checkButtons(add)
  217. const edit = 'rangeManagement:pastureList:edit'
  218. this.isEdit = checkButtons(edit)
  219. const resetpassword = 'rangeManagement:pastureList:resetpassword'
  220. this.isResetpassword = checkButtons(resetpassword)
  221. const del = 'rangeManagement:pastureList:delete'
  222. this.isDelete = checkButtons(del)
  223. const enable = 'rangeManagement:pastureList:enable'
  224. this.isEnable = checkButtons(enable)
  225. },
  226. getList(){
  227. this.table.listLoading = true
  228. let page = this.table.page
  229. let page_size = this.table.page_size
  230. let url = 'api/v1/ops/pasture/list' + '?page=' + page + '&page_size=' + page_size
  231. let data = {
  232. "name":this.table.parammaps.name,
  233. "manager_user":this.table.parammaps.manager_user,
  234. "manager_phone":this.table.parammaps.manager_phone
  235. }
  236. if(this.table.parammaps.is_show !== ''){
  237. data.is_show = this.table.parammaps.is_show
  238. }
  239. if(this.table.parammaps.inputDatetime !== null && this.table.parammaps.inputDatetime.length > 0){
  240. data.created_start_time = this.table.parammaps.inputDatetime[0].getTime() / 1000
  241. data.created_end_time = this.table.parammaps.inputDatetime[1].getTime() / 1000 + 86400
  242. }
  243. postJson(url, data).then(response => {
  244. if (response.code == 200) {
  245. this.table.list = response.data.list
  246. this.table.total = response.data.total
  247. this.table.pageNum = response.data.page
  248. this.table.pageSize = response.data.page_size
  249. } else {
  250. this.table.list = []
  251. }
  252. setTimeout(() => {
  253. this.table.listLoading = false
  254. }, 1000)
  255. })
  256. },
  257. handleSearch() {
  258. this.table.page = 1
  259. this.getList()
  260. },
  261. handleRefresh() {
  262. this.table.parammaps.name = ''
  263. this.table.parammaps.manager_user = ''
  264. this.table.parammaps.manager_phone = ''
  265. this.table.parammaps.is_show = ''
  266. this.table.parammaps.inputDatetime = []
  267. this.table.parammaps.created_start_time = ''
  268. this.table.parammaps.created_end_time = ''
  269. this.table.page = 1
  270. this.getList()
  271. },
  272. handleEnableChange(index, row) {
  273. let url = 'api/v1/ops/pasture/is_show'
  274. let data = {
  275. "pasture_id":row.id,
  276. "is_show":row.is_show
  277. }
  278. postJson(url,data).then(response => {
  279. if(response.code == 200){
  280. this.$notify({ title: '成功', message: '成功', type: 'success', duration: 2000 })
  281. this.getList()
  282. }
  283. })
  284. },
  285. handleCreate(){
  286. this.edit.dialogStatus = 'add'
  287. this.edit.dialogFormVisible = true
  288. this.edit.temp= {
  289. pasture_id:0,
  290. name:'',
  291. account:'',
  292. username:'',
  293. manager_user:'',
  294. manager_phone:'',
  295. address:'',
  296. domain:''
  297. }
  298. },
  299. createData(){
  300. this.$refs['editTemp'].validate((valid) => {
  301. if (valid) {
  302. this.isokDisable = true
  303. setTimeout(() => {
  304. this.isokDisable = false
  305. }, 1000)
  306. let url = 'api/v1/ops/pasture/add'
  307. let data = {
  308. 'pasture_id':his.edit.temp.pasture_id,
  309. 'name': this.edit.temp.name,
  310. "account": this.edit.temp.account,
  311. "manager_user": this.edit.temp.manager_user,
  312. "manager_phone": this.edit.temp.manager_phone,
  313. "address": this.edit.temp.address,
  314. "is_show": this.edit.temp.is_show,
  315. "domain":this.edit.temp.domain,
  316. // "create_user": Cookies.get('username')
  317. }
  318. console.log(data)
  319. postJson(url, data).then(response => {
  320. if (response.code == 200) {
  321. this.$notify({
  322. title: '',
  323. message: '成功',
  324. type: 'success',
  325. duration: 2000
  326. })
  327. this.edit.dialogFormVisible = false
  328. this.getList()
  329. }
  330. })
  331. }
  332. })
  333. },
  334. handleUpdate(row) {
  335. console.log('点击了编辑')
  336. this.edit.dialogStatus = 'update'
  337. this.edit.dialogFormVisible = true
  338. this.edit.temp = Object.assign({},row)
  339. },
  340. updateData() {
  341. this.$refs['editTemp'].validate((valid) => {
  342. if (valid) {
  343. this.isokDisable = true
  344. setTimeout(() => {
  345. this.isokDisable = false
  346. }, 1000)
  347. let url = 'api/v1/ops/pasture/edit'
  348. let data = {
  349. "id":this.edit.temp.id,
  350. 'name': this.edit.temp.name,
  351. "manager_user": this.edit.temp.manager_user,
  352. "address": this.edit.temp.address,
  353. "manager_phone": this.edit.temp.manager_phone,
  354. "account": this.edit.temp.account,
  355. "domain":this.edit.temp.domain,
  356. }
  357. postJson(url, data).then(response => {
  358. if (response.code == 200) {
  359. this.$notify({
  360. title: '',
  361. message: '成功',
  362. type: 'success',
  363. duration: 2000
  364. })
  365. this.edit.dialogFormVisible = false
  366. this.getList()
  367. }
  368. })
  369. }
  370. })
  371. },
  372. handleRowDelete(row){
  373. MessageBox.confirm('确定删除吗?', {
  374. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  375. }).then(() => {
  376. let url = 'api/v1/ops/pasture/'
  377. // let data = 10011
  378. let data = row.id
  379. delJson(url, data).then(response => {
  380. if (response.code == 200) {
  381. this.$notify({
  382. title: '',
  383. message: '成功',
  384. type: 'success',
  385. duration: 2000
  386. })
  387. this.getList()
  388. }
  389. })
  390. })
  391. },
  392. handleResetPassword(row) {
  393. MessageBox.confirm('是否确认将此牧场密码重置为默认密码123456?', {
  394. confirmButtonText: '确认',
  395. cancelButtonText: '取消',
  396. type: 'warning'
  397. }).then(() => {
  398. let url = 'api/v1/ops/pasture/rest_password/' + row.id
  399. let data = {}
  400. postJson(url, data).then(response => {
  401. if (response.code == 200) {
  402. this.$notify({
  403. title: '',
  404. message: '成功',
  405. type: 'success',
  406. duration: 2000
  407. })
  408. this.getList()
  409. }
  410. })
  411. })
  412. },
  413. }
  414. }
  415. </script>
  416. <style lang="scss" scoped>
  417. .search{margin-top:10px;}
  418. $width:350px;
  419. $left:325px;
  420. .selectInput{
  421. position: relative;
  422. display: inline-block;
  423. .Input{width: $width;position: relative;}
  424. .el-icon-arrow-down{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
  425. .el-icon-arrow-up{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
  426. .selectUl{
  427. 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;
  428. li{
  429. 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;
  430. a{float:left;width: 80px;}
  431. a:hover{color: rgba(0, 204, 102, 0.71); font-weight: 700;}
  432. }
  433. }
  434. }
  435. </style>