funcAdd.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. device_type:function(newVal){
  127. if(newVal){
  128. this.deviceList({'company_code':uni.getStorageSync('selectedCode'),'device_type' :this.device_type });
  129. }
  130. }
  131. },
  132. methods: {
  133. // 回显信息请求
  134. async getDetailsData(params = {}) {
  135. const res = await this.$myRequest({
  136. url: 'AlarmReport/editData',
  137. data:params,
  138. showLoading: true
  139. })
  140. this.detailsData=res.data.data[0];
  141. console.log(this.detailsData)
  142. this.report_type=this.detailsData.report_type;
  143. this.device_type=this.detailsData.device_type;
  144. this.start_time=this.detailsData.start_time;
  145. this.end_time=this.detailsData.end_time;
  146. this.remarks=this.detailsData.remarks;
  147. this.port_type=this.detailsData.port_type;
  148. this.device_port=this.detailsData.device_port;
  149. this.device_code=this.detailsData.device_code;
  150. },
  151. async submit() {
  152. //提交验证
  153. if (!this.report_type) {
  154. uni.showToast({
  155. title: "请输入报备类型",
  156. icon: "none"
  157. });
  158. return
  159. }
  160. if(this.report_type==1){
  161. if (!this.start_time.replace(/^\s*/g,'')) {
  162. uni.showToast({
  163. title: "请选择开始时间",
  164. icon: "none"
  165. });
  166. return
  167. }
  168. if (!this.end_time.replace(/^\s*/g,'')) {
  169. uni.showToast({
  170. title: "请选择结束时间",
  171. icon: "none"
  172. });
  173. return
  174. }
  175. }
  176. if(this.report_type==2||this.report_type==3){
  177. if (!this.device_type) {
  178. uni.showToast({
  179. title: "请选择设备类型",
  180. icon: "none"
  181. });
  182. return
  183. }
  184. if (!this.start_time.replace(/^\s*/g,'')) {
  185. uni.showToast({
  186. title: "请输入开始时间",
  187. icon: "none"
  188. });
  189. return
  190. }
  191. if (!this.end_time.replace(/^\s*/g,'')) {
  192. uni.showToast({
  193. title: "请输入结束时间",
  194. icon: "none"
  195. });
  196. return
  197. }
  198. }
  199. if(this.report_type==3&&this.device_type){
  200. if (this.device_type==6) {
  201. if (!this.device_port.replace(/^\s*/g,'')) {
  202. uni.showToast({
  203. title: "请输入端口号",
  204. icon: "none"
  205. });
  206. return
  207. }
  208. if (!this.port_type) {
  209. uni.showToast({
  210. title: "请选择端口类型",
  211. icon: "none"
  212. });
  213. return
  214. }
  215. if (!this.device_code) {
  216. uni.showToast({
  217. title: "请选择报备设备",
  218. icon: "none"
  219. });
  220. return
  221. }
  222. }
  223. if (!this.device_code) {
  224. uni.showToast({
  225. title: "请选择报备设备",
  226. icon: "none"
  227. });
  228. return
  229. }
  230. }
  231. let queryParam = {};
  232. if(this.id){
  233. queryParam.id=this.id
  234. }
  235. queryParam.report_type = this.report_type;
  236. queryParam.company_code=uni.getStorageSync('selectedCode');
  237. queryParam.remarks = this.remarks;
  238. queryParam.start_time = this.start_time;
  239. queryParam.end_time = this.end_time;
  240. if(this.id){
  241. queryParam.id = this.id;
  242. }
  243. if (this.report_type==1) {
  244. this.addDevice(queryParam)
  245. return;
  246. }
  247. if (this.report_type==2) {
  248. queryParam.device_type = this.device_type;
  249. this.addDevice(queryParam)
  250. return;
  251. }
  252. if (this.report_type==3) {
  253. queryParam.device_type = this.device_type;
  254. if(this.device_type==6){
  255. queryParam.port_type = this.port_type;
  256. queryParam.device_port = this.device_port;
  257. }
  258. queryParam.device_code = this.device_code;
  259. this.addDevice(queryParam)
  260. return;
  261. }
  262. this.addDevice(queryParam)
  263. },
  264. async addDevice(params = {}) {
  265. const res = await this.$myRequest({
  266. url: this.id?'AlarmReport/edit':'AlarmReport/add',
  267. data: params
  268. })
  269. if (res.data.flag) {
  270. uni.showToast({
  271. title: "提交成功",
  272. });
  273. setTimeout(() => {
  274. uni.navigateTo({
  275. url: '/pages/accountManage/success/success',
  276. });
  277. }, 1000);
  278. }
  279. },
  280. radioChange(e) {
  281. console.log('type:' + e.detail.value);
  282. this.radioOne = e.detail.value;
  283. },
  284. //报备设备下拉请求数据
  285. async deviceList(params = {}) {
  286. const res = await this.$myRequest({
  287. url: 'AlarmReport/deviceList',
  288. data:params,
  289. })
  290. this.deviceListData = res.data.data;
  291. var arr=[]
  292. this.deviceListData.forEach(function(item){
  293. arr.push(item.owner_code)
  294. })
  295. if(arr.indexOf(this.device_code)==-1){
  296. this.device_code=''
  297. }
  298. },
  299. }
  300. }
  301. </script>
  302. <style lang="scss">
  303. input,
  304. select,
  305. option {
  306. line-height: 70rpx;
  307. padding: 0 20rpx;
  308. height: 70rpx;
  309. border: 1px solid #EDEDED;
  310. // width:500rpx!important;
  311. background-color: #fff;
  312. box-sizing: border-box;
  313. appearance: none;
  314. -moz-appearance: none;
  315. -webkit-appearance: none;
  316. color: #999;
  317. }
  318. /* 站点多选下拉样式end */
  319. </style>