order-add.vue 12 KB

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