index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <template>
  2. <div class="equipment-box">
  3. <moduleView :propConfig="config" ref="view" v-loading="load" @pagination="pagination" @modalHandle="modalHandle" @onRefresh="getList"
  4. @resert="queryList" @search="queryList" @clickHandle="clickHandle" @detail="detail" />
  5. <adModal ref="adModalView" @successHandle="queryList" />
  6. </div>
  7. </template>
  8. <script setup>
  9. import stateRadio from './components/stateRadio.vue';
  10. import adModal from './components/adModal.vue';
  11. import { list, add, adSetting, update,del,adList,adMove } from '@/api/base/equipment.js'
  12. import { computed,getCurrentInstance,ref,markRaw,shallowRef } from "vue";
  13. const { proxy } = getCurrentInstance();
  14. const load = ref(false)
  15. const isSearch = ref(false)
  16. const time= ref(null);
  17. const timeNum = ref(0);
  18. const config = ref({
  19. attr:{
  20. calculateH:true
  21. },
  22. search:{
  23. columns:[
  24. [{
  25. span:6,
  26. // label:'设备名称',
  27. labelWidth:1,
  28. prop:'searchText',
  29. component:'by-input',
  30. compConfig:{
  31. attr:{
  32. placeholder:'请输入设备编码、设备名称、维修人、维修电话',
  33. prefixIcon:'vxe-icon-search'
  34. }
  35. }
  36. },{
  37. span:6,
  38. labelWidth:80,
  39. label:'状态',
  40. prop:'state',
  41. component:'by-select',
  42. compConfig:{
  43. attr:{
  44. clearable:true,
  45. placeholder:'状态',
  46. data:[{
  47. label:'开启',
  48. value:1
  49. },{
  50. label:'关闭',
  51. value:0
  52. }]
  53. }
  54. }
  55. },
  56. {
  57. span:6,
  58. labelWidth:100,
  59. label:'在线状态',
  60. prop:'onState',
  61. component:'by-select',
  62. compConfig:{
  63. attr:{
  64. clearable:true,
  65. placeholder:'在线状态',
  66. data:[{
  67. label:'在线',
  68. value:1
  69. },{
  70. label:'休眠',
  71. value:0
  72. }]
  73. }
  74. }
  75. }
  76. ]
  77. ]
  78. },
  79. tool:{
  80. tools:{
  81. add:true,
  82. delete:true,
  83. search:true,
  84. refresh:true
  85. }
  86. },
  87. table:{
  88. attr:{
  89. size:'mini',
  90. // seq:true,
  91. align:'center',
  92. checkbox:true
  93. },
  94. columns:[{
  95. title:'设备编码',
  96. field:'equipmentCode',
  97. width:80
  98. },
  99. {
  100. title:'设备名称',
  101. field:'equipmentName',
  102. isDetail:true,
  103. width:100
  104. },
  105. {
  106. title:'状态',
  107. field:'state',
  108. component:'textChange',
  109. compConfig:{
  110. attr:{
  111. data:[{
  112. label:'开启',
  113. value:1,
  114. backgroundColor:'#f0f9eb',
  115. color:'#67c23a'
  116. },{
  117. label:'关闭',
  118. value:0,
  119. backgroundColor:'#fef0f0',
  120. color:'#f56c6c'
  121. }]
  122. }
  123. }
  124. },
  125. {
  126. title:'在线状态',
  127. field:'onState',
  128. component:'textChange',
  129. compConfig:{
  130. attr:{
  131. data:[{
  132. label:'在线',
  133. value:1,
  134. backgroundColor:'#f0f9eb',
  135. color:'#67c23a'
  136. },{
  137. label:'休眠',
  138. value:0,
  139. backgroundColor:'#fef0f0',
  140. color:'#f56c6c'
  141. }]
  142. }
  143. }
  144. },
  145. {
  146. title:'所属厂家',
  147. field:'manufacturers'
  148. },
  149. {
  150. title:'维修人',
  151. field:'maintainName'
  152. },
  153. {
  154. title:'维修电话',
  155. field:'maintainTelephone'
  156. },
  157. {
  158. title:'加入时间',
  159. field:'enterTime'
  160. },
  161. {
  162. title:'操作',
  163. action:true,
  164. plugins:[{
  165. name:'广告设置',
  166. audit:'',
  167. event:{
  168. click:item => {
  169. adSet(item)
  170. }
  171. }
  172. }]
  173. }]
  174. },
  175. modal:{
  176. tool:{
  177. tools:{
  178. return:true,
  179. add:true
  180. }
  181. },
  182. form:{
  183. attr:{
  184. width:'1000px',
  185. size:'small',
  186. labelWidth:'130px',
  187. rules:{
  188. equipmentCode:[
  189. {required: true, message: '请输入设备编码', trigger: 'blur'}
  190. ],
  191. equipmentName:[
  192. {required: true, message: '请输入设备名称', trigger: 'blur'}
  193. ],
  194. manufacturers:[
  195. {required: true, message: '请输入所属厂家', trigger: 'blur'}
  196. ],
  197. state:[
  198. {required: true, message: '请选择状态', trigger: 'blur'},
  199. ],
  200. addrCode:[
  201. {required: true, message: '请选择位置', trigger: 'blur'}
  202. ],
  203. addrInfo:[
  204. {required: true, message: '请输入详细地址', trigger: 'blur'}
  205. ],
  206. maintainName:[
  207. {required: true, message: '请输入维修人', trigger: 'blur'},
  208. ],
  209. onState:[
  210. {required: true, message: '请输入在线状态', trigger: 'blur'},
  211. ],
  212. maintainTelephone:[
  213. {required: true, message: '请输入维修人电话', trigger: 'blur'},
  214. { validator: (rule, value, callback) => {
  215. if (value) {
  216. if(!/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value)) {
  217. callback(new Error('手机号格式不正确!'));
  218. }else{
  219. callback();
  220. }
  221. } else {
  222. callback();
  223. }
  224. }, trigger: 'blur' }
  225. ]
  226. }
  227. },
  228. columns:[
  229. [{
  230. label:'设备编码',
  231. prop:'equipmentCode',
  232. component:'by-input',
  233. compConfig:{
  234. attr:{}
  235. }
  236. },{
  237. label:'设备名称',
  238. prop:'equipmentName',
  239. component:'by-input',
  240. compConfig:{
  241. attr:{}
  242. }
  243. }],
  244. [{
  245. label:'所属厂家',
  246. span:12,
  247. prop:'manufacturers',
  248. component:'by-input',
  249. compConfig:{
  250. attr:{}
  251. }
  252. }
  253. ,{
  254. label:'状态',
  255. prop:'state',
  256. component:'by-select',
  257. compConfig:{
  258. attr:{
  259. clearable:true,
  260. data:[{
  261. label:'开启',
  262. value:1
  263. },{
  264. label:'关闭',
  265. value:0
  266. }]
  267. }
  268. }
  269. }
  270. ],
  271. [{
  272. label:'在线状态',
  273. prop:'onState',
  274. component:shallowRef(stateRadio)
  275. }],
  276. [{
  277. label:'维修人',
  278. prop:'maintainName',
  279. component:'by-input'
  280. },{
  281. label:'维修电话',
  282. prop:'maintainTelephone',
  283. component:'by-input'
  284. }],
  285. // [{
  286. // label:'授权状态',
  287. // prop:'state',
  288. // component:shallowRef(stateRadio)
  289. // }],
  290. [{
  291. label:'位置',
  292. prop:'addrCode',
  293. component:'by-area',
  294. compConfig:{
  295. attr:{
  296. area:'addrCodeInfo',
  297. areaCode:'addrCode'
  298. }
  299. }
  300. }],
  301. [{
  302. label:'详细地址',
  303. prop:'addrInfo',
  304. component:'by-input'
  305. }],
  306. [{
  307. label:'标记',
  308. prop:'lnglat',
  309. component:'MapMaker',
  310. compConfig:{
  311. attr:{
  312. lng:'lng',
  313. lat:'lat'
  314. }
  315. }
  316. }],
  317. [{
  318. label:'备注',
  319. prop:'remark',
  320. component:'by-input',
  321. compConfig:{
  322. attr:{
  323. type:'textarea'
  324. }
  325. }
  326. }]
  327. ]
  328. }
  329. }
  330. })
  331. const adSet = row => {
  332. proxy.$refs.adModalView.setShow(true);
  333. proxy.$refs.adModalView.setValue(row)
  334. }
  335. const clickHandle = n => {
  336. if(n == 'onAdd'){
  337. config.value.modal.tool.tools.add = true;
  338. delete config.value.modal.tool.tools.save;
  339. proxy.$refs.view.initFormTool();
  340. }
  341. if(n == 'onDelete'){
  342. delHandle()
  343. }
  344. }
  345. const modalHandle = n =>{
  346. if(n == 'onAdd'){
  347. proxy.$refs.view.getFormValidate(addData)
  348. }
  349. if(n == 'onSave'){
  350. proxy.$refs.view.getFormValidate(onSave)
  351. }
  352. }
  353. //添加
  354. const addData = () => {
  355. let value = proxy.$refs.view.getFormValue();
  356. if(value){
  357. load.value = true;
  358. add(value).then(res =>{
  359. load.value = false;
  360. proxy.$message({
  361. message:res.msg,
  362. type:'success'
  363. });
  364. proxy.$refs.view.closeModal();
  365. getList();
  366. }).catch(()=>{
  367. load.value = false;
  368. })
  369. }
  370. }
  371. //保存
  372. const onSave = () => {
  373. let data = proxy.$refs.view.getFormValue();
  374. load.value = true;
  375. update(data).then(res => {
  376. proxy.$message({
  377. message:res.msg,
  378. type:'success'
  379. });
  380. load.value = false;
  381. proxy.$refs.view.closeModal();
  382. pagination();
  383. }).catch(() => {
  384. load.value = false;
  385. })
  386. }
  387. const delHandle = () => {
  388. let data = proxy.$refs.view.getSelectData();
  389. let ids = []
  390. if(!data && data.lenght == 0) {
  391. proxy.$message('请选择数据')
  392. return
  393. }
  394. for(const item of data) {
  395. ids.push(item.equipmentId)
  396. }
  397. proxy.$confirm('此操作将永久删除数据, 是否继续?', '提示', {
  398. confirmButtonText: '确定',
  399. cancelButtonText: '取消',
  400. type: 'warning'
  401. }).then(() => {
  402. load.value = true;
  403. del({
  404. equipmentIds:ids,
  405. }).then(()=>{
  406. proxy.$message({message:'删除成功!',type:'success'})
  407. load.value = false;
  408. getList();
  409. }).catch(()=>{
  410. load.value = false;
  411. })
  412. }).catch(()=>{})
  413. }
  414. const detail = () => {
  415. config.value.modal.tool.tools.save = true;
  416. delete config.value.modal.tool.tools.add;
  417. proxy.$refs.view.initFormTool();
  418. }
  419. const pagination = () => {
  420. if(isSearch.value){
  421. queryList();
  422. }else{
  423. getList()
  424. }
  425. }
  426. //列表请求(包含分页和搜素条件)
  427. const queryList = () => {
  428. isSearch.value = true;
  429. let data = proxy.$refs.view.getQuery();
  430. requestList(data);
  431. }
  432. const getList = () => {
  433. if(!proxy.$refs.view){
  434. if(timeNum.value > 5){
  435. return
  436. }
  437. setTimeout(()=>{
  438. getList()
  439. },500)
  440. timeNum.value ++;
  441. return
  442. }
  443. timeNum.value = 0;
  444. isSearch.value = false;
  445. let data = proxy.$refs.view.getPage();
  446. requestList(data);
  447. }
  448. const requestList = data => {
  449. load.value = true;
  450. list(data).then(res => {
  451. load.value = false;
  452. proxy.$refs.view.setTableValue(res.data.data);
  453. let page = {
  454. pageNo: res.data.page.current, //当前页
  455. pageSize: data.pageSize, //每页条数
  456. total: res.data.page.total //总条数
  457. };
  458. proxy.$refs.view.setPage(page)
  459. }).catch(()=>{
  460. load.value = false;
  461. })
  462. }
  463. nextTick(()=>{
  464. getList()
  465. })
  466. </script>
  467. <style lang="scss" scoped>
  468. .equipment-box{
  469. width: 100%;
  470. height: 100%;
  471. }
  472. .equip-info{
  473. padding: 8px 16px;
  474. width: 100%;
  475. box-sizing: border-box;
  476. background-color: rgba(255,240,184,0.95);
  477. font-size: 12px;
  478. margin-bottom: 16px;
  479. .equip-state{
  480. .norm{
  481. color: #00AE66;
  482. }
  483. .disa{
  484. color: red;
  485. }
  486. }
  487. }
  488. .page{
  489. width: 100%;
  490. display: flex;
  491. justify-content: flex-end;
  492. align-items: center;
  493. padding-top: 8px;
  494. }
  495. </style>