funcAdd.vue 9.8 KB

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