funcAdd.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <view class="appWrapper padding-top" style="height:calc(100vh - 250rpx);overflow:scroll">
  3. <form action="" class="funcAdd">
  4. <view class="form-item selectBox">
  5. <view class="title"><text class="necessary">*</text>报备类型:</view>
  6. <uni-data-select v-model="report_type" :localdata="skillsRange" >
  7. </uni-data-select>
  8. <!--
  9. <select name="" id="" placeholder="请选择" clearable v-model="report_type">
  10. <option value="">请选择</option>
  11. <option value="1">单位</option>
  12. <option value="2">类型</option>
  13. <option value="3">设备</option>
  14. </select> -->
  15. </view>
  16. <view class="form-item selectBox" v-if="report_type==2||report_type==3">
  17. <view class="title"><text class="necessary">*</text>设备类型:</view>
  18. <uni-data-select v-model="device_type" :localdata="deviceRange" >
  19. </uni-data-select>
  20. <!-- <select name="" id="" placeholder=""clearable v-model="device_type">
  21. <option value="">请选择</option>
  22. <option value="1">火系统</option>
  23. <option value="2">水系统</option>
  24. <option value="3">烟感系统</option>
  25. <option value="4">消防栓</option>
  26. <option value="5">液位</option>
  27. <option value="6">RTU</option>
  28. <option value="7">电气火灾</option>
  29. <option value="16">视频监控</option>
  30. <option value="128">井盖</option>
  31. <option value="131">可燃气体</option>
  32. <option value="130">门禁监测</option>
  33. <option value="129">地磁监测</option>
  34. <option value="17">电梯监测</option>
  35. </select> -->
  36. </view>
  37. <view class="form-item" v-if="report_type">
  38. <view class="title">
  39. <text class="necessary">*</text>
  40. 开始时间:
  41. </view>
  42. <view class="example-body">
  43. <uni-datetime-picker v-model="start_time" :start="this.id?'':now"/>
  44. </view>
  45. </view>
  46. <view class="form-item" v-if="report_type">
  47. <view class="title">
  48. <text class="necessary">*</text>
  49. 结束时间:
  50. </view>
  51. <view class="example-body">
  52. <uni-datetime-picker v-model="end_time" :start="start_time" />
  53. </view>
  54. </view>
  55. <view class="form-item " v-if="report_type==3&&device_type==6">
  56. <view class="title"><text class="necessary">*</text>端口号:</view>
  57. <input name="input" v-model="device_port"></input>
  58. </view>
  59. <view class="form-item selectBox" v-if="report_type==3&&device_type==6">
  60. <view class="title"><text class="necessary">*</text>端口类型:</view>
  61. <!-- <select name="" id="" placeholder=""clearable v-model="port_type">
  62. <option value="">请选择</option>
  63. <option value="1">数字量</option>
  64. <option value="2">模拟量</option>
  65. </select> -->
  66. <uni-data-select v-model="port_type" :localdata="portRange" >
  67. </uni-data-select>
  68. <!-- <text class="icon iconfont margin-right-sm margin-left">&#xe63d;</text> -->
  69. </view>
  70. <view class="form-item selectBox" v-if="report_type==3&&device_type">
  71. <view class="title"><text class="necessary">*</text>报备设备:</view>
  72. <!-- <select name="" id="" placeholder=""clearable v-model="device_code">
  73. <option value="">请选择</option>
  74. <option :value="item.owner_code" v-for="(item,index) in deviceListData" :key="index">{{item.owner_name}}
  75. </option>
  76. </select> -->
  77. <uni-data-select v-model="device_code" :localdata="deviceListData" >
  78. </uni-data-select>
  79. <!-- <text class="icon iconfont margin-right-sm margin-left">&#xe63d;</text> -->
  80. </view>
  81. <view class="form-item " v-if="report_type">
  82. <view class="title"><text class="necessary"></text>备注:</view>
  83. <input name="input" v-model="remarks"></input>
  84. </view>
  85. <view class="btn-area submitBottomBtn padding-lr-sm">
  86. <button class="bg-blue round margin-top" @tap="submit()">提 交 </button>
  87. </view>
  88. </form>
  89. </view>
  90. </template>
  91. <style scoped>
  92. /deep/ .funcAdd .uni-date-x--border, .uni-date-x{
  93. border-radius:0!important
  94. }
  95. .funcAdd .example-body{
  96. margin:0;
  97. width:calc(100% - 200rpx)
  98. }
  99. </style>
  100. <script>
  101. export default {
  102. data() {
  103. return {
  104. skillsRange: [{
  105. value: 1,
  106. text: "单位"
  107. },
  108. {
  109. value: 2,
  110. text: "类型"
  111. },
  112. {
  113. value: 3,
  114. text: "设备"
  115. },
  116. ],
  117. deviceRange:[{
  118. value: 1,
  119. text: "火系统"
  120. },
  121. {
  122. value: 2,
  123. text: "水系统"
  124. },
  125. {
  126. value: 3,
  127. text: "烟感系统"
  128. },{
  129. value: 4,
  130. text: "消防栓"
  131. },
  132. {
  133. value: 5,
  134. text: "液位"
  135. },
  136. {
  137. value: 6,
  138. text: "RTU"
  139. },{
  140. value: 7,
  141. text: "电气火灾"
  142. },
  143. {
  144. value: 16,
  145. text: "视频监控"
  146. },
  147. {
  148. value: 128,
  149. text: "井盖"
  150. },{
  151. value: 131,
  152. text: "可燃气体"
  153. },
  154. {
  155. value: 130,
  156. text: "门禁监测"
  157. },
  158. {
  159. value: 129,
  160. text: "地磁监测"
  161. },{
  162. value:17,
  163. text: "电梯监测"
  164. },],
  165. portRange: [{
  166. value: 1,
  167. text: "数字量"
  168. },
  169. {
  170. value: 2,
  171. text: "模拟量"
  172. },
  173. ],
  174. id:'',
  175. report_type:'',
  176. device_type:'',
  177. start_time:'',
  178. end_time:'',
  179. remarks:'',
  180. device_port:'',
  181. port_type:'',
  182. device_code:'',
  183. now:'',
  184. deviceListData:[],
  185. detailsData:''
  186. }
  187. },
  188. onLoad: function(option) {
  189. this.id=option.id;
  190. uni.setNavigationBarTitle({
  191. title: option.id?"编辑":"新增",
  192. });
  193. var nowTemp = new Date();
  194. this.now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
  195. if(option.id){
  196. this.getDetailsData({'id':option.id})
  197. }
  198. },
  199. watch: {
  200. start_time:function(){
  201. // alert(this.start_time)
  202. },
  203. report_type:function(newVal){
  204. if(newVal){
  205. var array123=['','1','2','3','4','5','6','7','16','128','131','130','129','17']
  206. if(array123.indexOf(this.device_type)==-1){
  207. this.device_type=''
  208. }
  209. }
  210. },
  211. device_type:function(newVal){
  212. if(newVal){
  213. this.deviceList({'company_code':uni.getStorageSync('selectedCode'),'device_type' :this.device_type });
  214. }
  215. }
  216. },
  217. methods: {
  218. // 回显信息请求
  219. async getDetailsData(params = {}) {
  220. const res = await this.$myRequest({
  221. url: 'AlarmReport/editData',
  222. data:params,
  223. showLoading: true
  224. })
  225. this.detailsData=res.data.data[0];
  226. this.report_type=parseInt(this.detailsData.report_type);
  227. this.device_type=parseInt(this.detailsData.device_type);
  228. this.start_time=this.detailsData.start_time;
  229. this.end_time=this.detailsData.end_time;
  230. this.remarks=this.detailsData.remarks;
  231. this.port_type=parseInt(this.detailsData.port_type);
  232. this.device_port=this.detailsData.device_port;
  233. this.device_code=parseInt(this.detailsData.device_code);
  234. },
  235. async submit() {
  236. //提交验证
  237. if (!this.report_type) {
  238. uni.showToast({
  239. title: "请输入报备类型",
  240. icon: "none"
  241. });
  242. return
  243. }
  244. if(this.report_type==1){
  245. if (!this.start_time.replace(/^\s*/g,'')) {
  246. uni.showToast({
  247. title: "请选择开始时间",
  248. icon: "none"
  249. });
  250. return
  251. }
  252. if (!this.end_time.replace(/^\s*/g,'')) {
  253. uni.showToast({
  254. title: "请选择结束时间",
  255. icon: "none"
  256. });
  257. return
  258. }
  259. }
  260. if(this.report_type==2||this.report_type==3){
  261. if (!this.device_type) {
  262. uni.showToast({
  263. title: "请选择设备类型",
  264. icon: "none"
  265. });
  266. return
  267. }
  268. if (!this.start_time.replace(/^\s*/g,'')) {
  269. uni.showToast({
  270. title: "请输入开始时间",
  271. icon: "none"
  272. });
  273. return
  274. }
  275. if (!this.end_time.replace(/^\s*/g,'')) {
  276. uni.showToast({
  277. title: "请输入结束时间",
  278. icon: "none"
  279. });
  280. return
  281. }
  282. }
  283. if(this.report_type==3&&this.device_type){
  284. if (this.device_type==6) {
  285. if (!this.device_port.replace(/^\s*/g,'')) {
  286. uni.showToast({
  287. title: "请输入端口号",
  288. icon: "none"
  289. });
  290. return
  291. }
  292. if (!this.port_type) {
  293. uni.showToast({
  294. title: "请选择端口类型",
  295. icon: "none"
  296. });
  297. return
  298. }
  299. if (!this.device_code) {
  300. uni.showToast({
  301. title: "请选择报备设备",
  302. icon: "none"
  303. });
  304. return
  305. }
  306. }
  307. if (!this.device_code) {
  308. uni.showToast({
  309. title: "请选择报备设备",
  310. icon: "none"
  311. });
  312. return
  313. }
  314. }
  315. let queryParam = {};
  316. if(this.id){
  317. queryParam.id=this.id
  318. }
  319. queryParam.report_type = this.report_type;
  320. queryParam.company_code=uni.getStorageSync('selectedCode');
  321. queryParam.remarks = this.remarks;
  322. queryParam.start_time = this.start_time;
  323. queryParam.end_time = this.end_time;
  324. if(this.id){
  325. queryParam.id = this.id;
  326. }
  327. if (this.report_type==1) {
  328. this.addDevice(queryParam)
  329. return;
  330. }
  331. if (this.report_type==2) {
  332. queryParam.device_type = this.device_type;
  333. this.addDevice(queryParam)
  334. return;
  335. }
  336. if (this.report_type==3) {
  337. queryParam.device_type = this.device_type;
  338. if(this.device_type==6){
  339. queryParam.port_type = this.port_type;
  340. queryParam.device_port = this.device_port;
  341. }
  342. queryParam.device_code = this.device_code;
  343. this.addDevice(queryParam)
  344. return;
  345. }
  346. this.addDevice(queryParam)
  347. },
  348. async addDevice(params = {}) {
  349. const res = await this.$myRequest({
  350. url: this.id?'AlarmReport/edit':'AlarmReport/add',
  351. data: params
  352. })
  353. uni.showToast({
  354. title:res.data.msg,
  355. icon: "none"
  356. });
  357. if (res.data.flag) {
  358. setTimeout(() => {
  359. uni.redirectTo({
  360. url: '/pages/setting/funReport/funReport',
  361. });
  362. }, 1000);
  363. }
  364. },
  365. radioChange(e) {
  366. console.log('type:' + e.detail.value);
  367. this.radioOne = e.detail.value;
  368. },
  369. //报备设备下拉请求数据
  370. async deviceList(params = {}) {
  371. const res = await this.$myRequest({
  372. url: 'AlarmReport/deviceList',
  373. data:params,
  374. })
  375. this.deviceListData = res.data.data;
  376. this.deviceListData=JSON.parse(JSON.stringify(this.deviceListData).replace(/owner_code/g,"value").replace(/owner_name/g,"text"))
  377. var arr=[]
  378. this.deviceListData.forEach(function(item){
  379. arr.push(item.owner_code)
  380. })
  381. if(arr.indexOf(this.device_code)==-1){
  382. this.device_code=''
  383. }
  384. },
  385. }
  386. }
  387. </script>
  388. <style lang="scss">
  389. input,
  390. select,
  391. option {
  392. line-height: 70rpx;
  393. padding: 0 20rpx;
  394. height: 70rpx;
  395. border: 1px solid #EDEDED;
  396. // width:500rpx!important;
  397. background-color: #fff;
  398. box-sizing: border-box;
  399. appearance: none;
  400. -moz-appearance: none;
  401. -webkit-appearance: none;
  402. color: #999;
  403. }
  404. /* 站点多选下拉样式end */
  405. </style>