inspection-plan.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <!--
  2. * @Title:
  3. * @Description: 巡检计划创建
  4. * @Author: swp
  5. * @Date: 2022-08-24 10:49:21
  6. * @LastEditors:
  7. * @LastEditTime: 2022-08-24 10:49:21
  8. -->
  9. <template>
  10. <view class="container">
  11. <uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
  12. @clickLeft="toBack">
  13. <view style="width: 100%;display: flex;flex-direction: row;justify-content: center;align-items: center;">
  14. <text style="color: white;font-size: 1rem;">{{title}}</text>
  15. </view>
  16. </uni-nav-bar>
  17. <uni-forms ref="baseForm" :model="formData" :rules="rules">
  18. <uni-card title="巡检标题" :is-shadow="false">
  19. <uni-forms-item name='planTitle' label-width="0px" required>
  20. <uni-easyinput :styles="styles" v-model="formData.planTitle" placeholder="录入巡检标题" />
  21. </uni-forms-item>
  22. </uni-card>
  23. <uni-card title="巡检内容" :is-shadow="false">
  24. <uni-forms-item name='planDesc' label-width="0px" required>
  25. <uni-easyinput :styles="styles" type="textarea" :autoHeight="true" v-model="formData.planDesc"
  26. placeholder="录入巡检内容" />
  27. </uni-forms-item>
  28. </uni-card>
  29. <uni-card title="巡检设定" :is-shadow="false">
  30. <uni-forms-item name="planScheduledType" label="计划类型" label-width="100px" required>
  31. <uni-data-checkbox v-model="formData.planScheduledType"
  32. :localdata="planScheduledTypeItems.items"></uni-data-checkbox>
  33. </uni-forms-item>
  34. <view v-if="formData.planScheduledType==1">
  35. <uni-forms-item name='inspectionCompleteTime' label="截止时间" label-width="100px" required>
  36. <uni-datetime-picker type="date" v-model="formData.inspectionCompleteTime"
  37. @change="completeDateTimeChange" />
  38. </uni-forms-item>
  39. </view>
  40. <view v-else-if="formData.planScheduledType==2">
  41. <!-- <uni-forms-item name='inspectionStartTime' label="开始时间" label-width="100px" required>
  42. <uni-datetime-picker type="date" v-model="formData.inspectionStartTime"
  43. @change="completeDateTimeChange" />
  44. </uni-forms-item>
  45. <uni-forms-item name='inspectionEndTime' label="结束时间" label-width="100px" required>
  46. <uni-datetime-picker type="date" v-model="formData.inspectionEndTime"
  47. @change="completeDateTimeChange" />
  48. </uni-forms-item> -->
  49. <uni-forms-item name='timeType' label="执行周期" label-width="100px">
  50. <uni-data-checkbox v-model="formData.timeType"
  51. :localdata="timeTypeItems.items"></uni-data-checkbox>
  52. </uni-forms-item>
  53. </view>
  54. </uni-card>
  55. </uni-forms>
  56. <view class="footer">
  57. <view class="control">
  58. <view class="view-flex-inline-center">
  59. <view class="block"
  60. style="width: 160px;height:32px;margin-left: 10px;margin-right: 10px;border-radius:7px;background-color:lightsalmon"
  61. @click="toSubmit()">
  62. <view class="view-flex-cc">
  63. <uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="#ffffff" />
  64. </view>
  65. <view class="view-flex-cc" style="padding-left:5px;">
  66. <text style="color:black;font-size:0.7rem">立即提交</text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import {
  76. role
  77. } from "@/api/role.js";
  78. import http from '@/http/api.js';
  79. import {
  80. oss,
  81. imgPath,
  82. devUrl,
  83. prodUrl
  84. } from '@/common/setting';
  85. export default {
  86. components: {},
  87. data() {
  88. return {
  89. title: '巡检保养计划',
  90. desc: '',
  91. styles: {
  92. color: '#333',
  93. borderColor: '#e5e5e5',
  94. disableColor: '#FFFFFF'
  95. },
  96. baseURL: '',
  97. baseOSS: '',
  98. videoImg: '/static/images/video.png',
  99. formData: {
  100. planTitle:'',
  101. planDesc:'',
  102. planScheduledType: 1,
  103. timeType: 1,
  104. inspectionCompleteTime:'',
  105. // inspectionStartTime:'',
  106. // inspectionEndTime:'',
  107. },
  108. rules: {
  109. planTitle: {
  110. rules: [{
  111. required: true,
  112. errorMessage: '必填项',
  113. }]
  114. },
  115. planDesc: {
  116. rules: [{
  117. required: true,
  118. errorMessage: '必填项',
  119. }, ]
  120. },
  121. planScheduledType: {
  122. rules: [{
  123. required: true,
  124. errorMessage: '必填项',
  125. }, ]
  126. },
  127. timeType: {
  128. rules: [{
  129. required: true,
  130. errorMessage: '必填项',
  131. }, ]
  132. },
  133. inspectionCompleteTime: {
  134. rules: [{
  135. required: true,
  136. errorMessage: '选择巡检截止时间',
  137. }, ]
  138. },
  139. // inspectionStartTime: {
  140. // rules: [{
  141. // required: true,
  142. // errorMessage: '必填项',
  143. // }, ]
  144. // },
  145. // inspectionEndTime: {
  146. // rules: [{
  147. // required: true,
  148. // errorMessage: '必填项',
  149. // }, ]
  150. // },
  151. },
  152. uuid: '',
  153. planScheduledTypeItems: {
  154. items: [{
  155. 'value': 1,
  156. 'text': '仅一次'
  157. }, {
  158. 'value': 2,
  159. 'text': '定期'
  160. }],
  161. current: 1,
  162. },
  163. timeTypeItems: {
  164. items: [{
  165. 'value': 1,
  166. 'text': '按天'
  167. }, {
  168. 'value': 2,
  169. 'text': '按周'
  170. }, {
  171. 'value': 3,
  172. 'text': '按月'
  173. }],
  174. current: 1,
  175. },
  176. }
  177. },
  178. computed: {
  179. },
  180. onLoad(options) {
  181. this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
  182. this.baseOSS = oss;
  183. this.uuid = this.getUuid();
  184. },
  185. onReady() {
  186. //console.log("onReady++++++++++++++")
  187. // 需要在onReady中设置规则
  188. this.$refs.baseForm.setRules(this.rules)
  189. },
  190. onShow() {
  191. let that = this;
  192. this.uuid = this.getUuid();
  193. // uni.$once("lngLat", function(data) {
  194. // let p = JSON.parse(data)
  195. // that.formData.longitude = p.lng;
  196. // that.formData.latitude = p.lat;
  197. // that.formData.address = p.add;
  198. // })
  199. // uni.$once("taskOwnerInfo", function(data) {
  200. // let p = JSON.parse(data)
  201. // that.formData.taskOwnerId = p.taskOwnerId;
  202. // that.formData.taskOwnerName = p.taskOwnerName;
  203. // })
  204. },
  205. methods: {
  206. toOss(path) {
  207. return this.baseOSS + path;
  208. },
  209. toBack() {
  210. uni.navigateBack({
  211. delta: 1
  212. })
  213. },
  214. getUuid() {
  215. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  216. var r = (Math.random() * 16) | 0,
  217. v = c == 'x' ? r : (r & 0x3) | 0x8;
  218. return v.toString(16);
  219. });
  220. },
  221. completeDateTimeChange(e) {
  222. console.log('change事件:', e);
  223. },
  224. onTaskOwnerSelectClick() {
  225. var url = '/pages/serviceperson/taskOwnerSelect';
  226. uni.navigateTo({
  227. url: url
  228. })
  229. },
  230. onMapAddClick() {
  231. var url = '/pages/map/maplocation';
  232. uni.navigateTo({
  233. url: url
  234. })
  235. },
  236. onCheckPhotoAdd() {
  237. let that = this;
  238. uni.chooseImage({
  239. sourceType: ['album ', 'camera'],
  240. sizeType: ['compressed'],
  241. success: (res) => {
  242. const len = res.tempFilePaths.length;
  243. if (len === 1) {
  244. res.tempFilePaths.forEach(path => {
  245. that.uploadPhoto(path);
  246. })
  247. } else {
  248. uni.showModal({
  249. content: '只能选择一张图片,请确认!',
  250. showCancel: false
  251. });
  252. }
  253. }
  254. })
  255. },
  256. uploadPhoto(imagePath) {
  257. let that = this;
  258. uni.showLoading({
  259. title: '上传中'
  260. });
  261. uni.uploadFile({
  262. url: this.baseURL + '/galaxy-resource/oss/endpoint/put-file-attach?Blade-Auth=' +
  263. uni.getStorageSync('accessToken'),
  264. fileType: 'image',
  265. filePath: imagePath,
  266. name: 'file',
  267. success: (uploadFileRes) => {
  268. if (uploadFileRes.statusCode == 200) {
  269. let data = JSON.parse(uploadFileRes.data);
  270. if (data.success) {
  271. let path = data.data['name'];
  272. that.orderPhotos.push(path);
  273. }
  274. }
  275. },
  276. fail: (err) => {
  277. console.log(err);
  278. reject('err')
  279. },
  280. complete() {
  281. uni.hideLoading()
  282. }
  283. });
  284. },
  285. onPhotoDel(index) {
  286. this.orderPhotos.splice(index, 1);
  287. },
  288. onCheckVideoAdd() {
  289. let that = this;
  290. uni.chooseVideo({
  291. sourceType: ['camera'],
  292. maxDuration: 10,
  293. success: (res) => {
  294. that.uploadVideo(res.tempFilePath);
  295. }
  296. })
  297. },
  298. uploadVideo(videoPath) {
  299. let that = this;
  300. uni.showLoading({
  301. title: '上传中'
  302. });
  303. uni.uploadFile({
  304. url: this.baseURL + '/galaxy-resource/oss/endpoint/put-file-attach?Blade-Auth=' +
  305. uni.getStorageSync('accessToken'),
  306. filePath: videoPath,
  307. name: 'file',
  308. success: (uploadFileRes) => {
  309. if (uploadFileRes.statusCode == 200) {
  310. let data = JSON.parse(uploadFileRes.data);
  311. if (data.success) {
  312. let path = data.data['name'];
  313. that.orderVideos.push(path);
  314. }
  315. }
  316. },
  317. fail: (err) => {
  318. console.log(err);
  319. reject('err')
  320. },
  321. complete() {
  322. uni.hideLoading()
  323. }
  324. });
  325. },
  326. onVideoDel(index) {
  327. this.orderVideos.splice(index, 1);
  328. },
  329. openVideo(item) {
  330. let url = '/pages/check-order/videoView?url=' + item;
  331. uni.navigateTo({
  332. url: url
  333. })
  334. },
  335. toSubmit() {
  336. let that = this;
  337. this.$refs.baseForm.validate().then(res => {
  338. that.submitData();
  339. //console.log('提交');
  340. }).catch(err => {
  341. console.log('表单错误信息:', JSON.stringify(err));
  342. uni.showModal({
  343. content: "录入错误,请检查录入内容!",
  344. showCancel: false,
  345. success(res) {
  346. if (res.confirm) {
  347. //that.$refs.baseForm.clearValidate();
  348. }
  349. }
  350. });
  351. })
  352. },
  353. submitData() {
  354. let formdata = this.formData;
  355. formdata['batchId'] = this.uuid;
  356. // if (this.orderPhotos.length > 0) {
  357. // let photos = '';
  358. // for (let i = 0; i < this.orderPhotos.length; i++) {
  359. // if (photos.length > 0) {
  360. // photos = photos + ',';
  361. // }
  362. // photos = photos + this.orderPhotos[i];
  363. // }
  364. // formdata['orderPhotos'] = photos;
  365. // }
  366. // if (this.orderVideos.length > 0) {
  367. // let videos = '';
  368. // for (let i = 0; i < this.orderVideos.length; i++) {
  369. // if (videos.length > 0) {
  370. // videos = videos + ',';
  371. // }
  372. // videos = videos + this.orderVideos[i];
  373. // }
  374. // formdata['orderVideos'] = videos;
  375. // }
  376. let that = this;
  377. http.request({
  378. url: '/galaxy-business/equipment/inspection/plan/save',
  379. method: 'POST',
  380. data: formdata
  381. }).then(res => {
  382. if (res.success) {
  383. uni.showModal({
  384. content: '已成功提交',
  385. showCancel: false,
  386. success(res) {
  387. that.toBack();
  388. }
  389. });
  390. } else {
  391. uni.showModal({
  392. content: '' + res.msg,
  393. showCancel: false
  394. });
  395. }
  396. }).catch(err => {
  397. console.log(err)
  398. })
  399. },
  400. }
  401. }
  402. </script>
  403. <style lang="scss" scoped>
  404. .container {
  405. padding: 0 0 100rpx;
  406. }
  407. .view-flex-cc {
  408. display: flex;
  409. flex-direction: column;
  410. justify-content: center;
  411. }
  412. </style>