orderadd.vue 15 KB

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