orderadd.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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-forms>
  102. <view class="footer">
  103. <view class="control">
  104. <view class="view-flex-rc">
  105. <view class="block"
  106. style="width: 160px;height:32px;margin-left: 10px;margin-right: 10px;border-radius:7px;background-color:lightsalmon"
  107. @click="toSubmit()">
  108. <view class="view-flex-cc">
  109. <uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="#ffffff" />
  110. </view>
  111. <view class="view-flex-cc" style="padding-left:5px;">
  112. <text style="color:black;font-size:0.7rem">立即提交</text>
  113. </view>
  114. </view>
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. </template>
  120. <script>
  121. import {
  122. role
  123. } from "@/api/role.js";
  124. import http from '@/http/api.js';
  125. import {
  126. oss,
  127. imgPath,
  128. devUrl,
  129. prodUrl
  130. } from '@/common/setting';
  131. export default {
  132. components: {},
  133. data() {
  134. return {
  135. title: '创建工单',
  136. desc: '',
  137. styles: {
  138. color: '#333',
  139. borderColor: '#e5e5e5',
  140. disableColor: '#FFFFFF'
  141. },
  142. permission: {
  143. 'admin': false,
  144. 'orgAdmin': false,
  145. 'companyAdmin': false,
  146. 'companyServciePerson': false,
  147. },
  148. baseURL: '',
  149. baseOSS: '',
  150. videoImg: '/static/images/video.png',
  151. formData: {
  152. orderType: 0,
  153. orderDesc: ''
  154. },
  155. rules: {
  156. orderTypeOption: {
  157. rules: [{
  158. required: true,
  159. errorMessage: '必填项',
  160. }]
  161. },
  162. orderDesc: {
  163. rules: [{
  164. required: true,
  165. errorMessage: '必填项',
  166. }, ]
  167. },
  168. },
  169. orderTypeOption: {
  170. items: [{
  171. 'value': 1,
  172. 'text': '维修工单'
  173. }, {
  174. 'value': 2,
  175. 'text': '服务工单'
  176. }],
  177. current: 0,
  178. },
  179. orderPhotos: [],
  180. orderVideos: [],
  181. uuid: '',
  182. }
  183. },
  184. computed: {
  185. videoImage() {
  186. return imgPath + "logo_pc.png";
  187. }
  188. },
  189. onLoad(options) {
  190. this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
  191. console.log(this.baseURL)
  192. this.baseOSS = oss;
  193. this.permission.admin = false;
  194. this.permission.orgAdmin = false;
  195. this.permission.companyAdmin = false;
  196. this.permission.companyServciePerson = false;
  197. if (this.userInfo.role_name === role.admin) {
  198. this.permission.admin = true;
  199. } else if (this.userInfo.role_name === role.orgAdmin) {
  200. this.permission.orgAdmin = true;
  201. } else if (this.userInfo.role_name === role.companyAdmin) {
  202. this.permission.companyAdmin = true;
  203. } else if (this.userInfo.role_name === role.companyServciePerson) {
  204. this.permission.companyServciePerson = true;
  205. this.formData.orderType = 1;
  206. }
  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. this.permission.admin = false;
  216. this.permission.orgAdmin = false;
  217. this.permission.companyAdmin = false;
  218. this.permission.companyServciePerson = false;
  219. if (this.userInfo.role_name === role.admin) {
  220. this.permission.admin = true;
  221. } else if (this.userInfo.role_name === role.orgAdmin) {
  222. this.permission.orgAdmin = true;
  223. } else if (this.userInfo.role_name === role.companyAdmin) {
  224. this.permission.companyAdmin = true;
  225. } else if (this.userInfo.role_name === role.companyServciePerson) {
  226. this.permission.companyServciePerson = true;
  227. this.formData.orderType = 1;
  228. }
  229. this.uuid = this.getUuid();
  230. },
  231. methods: {
  232. getUuid() {
  233. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  234. var r = (Math.random() * 16) | 0,
  235. v = c == 'x' ? r : (r & 0x3) | 0x8;
  236. return v.toString(16);
  237. });
  238. },
  239. toOss(path) {
  240. return this.baseOSS + path;
  241. },
  242. toBack() {
  243. uni.navigateBack({
  244. delta: 1
  245. })
  246. },
  247. onCheckPhotoAdd() {
  248. let that = this;
  249. uni.chooseImage({
  250. sourceType: ['album ', 'camera'],
  251. sizeType: ['compressed'],
  252. success: (res) => {
  253. const len = res.tempFilePaths.length;
  254. if (len === 1) {
  255. res.tempFilePaths.forEach(path => {
  256. that.uploadPhoto(path);
  257. })
  258. } else {
  259. uni.showModal({
  260. content: '只能选择一张图片,请确认!',
  261. showCancel: false
  262. });
  263. }
  264. }
  265. })
  266. },
  267. uploadPhoto(imagePath) {
  268. let that = this;
  269. uni.showLoading({
  270. title: '上传中'
  271. });
  272. uni.uploadFile({
  273. url: this.baseURL + '/galaxy-resource/oss/endpoint/put-file-attach?Blade-Auth=' +
  274. uni.getStorageSync('accessToken'),
  275. fileType: 'image',
  276. filePath: imagePath,
  277. name: 'file',
  278. success: (uploadFileRes) => {
  279. if (uploadFileRes.statusCode == 200) {
  280. let data = JSON.parse(uploadFileRes.data);
  281. if (data.success) {
  282. let path = data.data['name'];
  283. that.orderPhotos.push(path);
  284. }
  285. }
  286. },
  287. fail: (err) => {
  288. console.log(err);
  289. reject('err')
  290. },
  291. complete() {
  292. uni.hideLoading()
  293. }
  294. });
  295. },
  296. onPhotoDel(index) {
  297. this.orderPhotos.splice(index, 1);
  298. },
  299. onCheckVideoAdd() {
  300. let that = this;
  301. uni.chooseVideo({
  302. sourceType: ['camera'],
  303. maxDuration: 10,
  304. success: (res) => {
  305. that.uploadVideo(res.tempFilePath);
  306. }
  307. })
  308. },
  309. uploadVideo(videoPath) {
  310. let that = this;
  311. uni.showLoading({
  312. title: '上传中'
  313. });
  314. uni.uploadFile({
  315. url: this.baseURL + '/galaxy-resource/oss/endpoint/put-file-attach?Blade-Auth=' +
  316. uni.getStorageSync('accessToken'),
  317. filePath: videoPath,
  318. name: 'file',
  319. success: (uploadFileRes) => {
  320. if (uploadFileRes.statusCode == 200) {
  321. let data = JSON.parse(uploadFileRes.data);
  322. if (data.success) {
  323. let path = data.data['name'];
  324. that.orderVideos.push(path);
  325. }
  326. }
  327. },
  328. fail: (err) => {
  329. console.log(err);
  330. reject('err')
  331. },
  332. complete() {
  333. uni.hideLoading()
  334. }
  335. });
  336. },
  337. onVideoDel(index) {
  338. this.orderVideos.splice(index, 1);
  339. },
  340. openVideo(item) {
  341. let url = '/pages/check-order/videoView?url=' + item;
  342. uni.navigateTo({
  343. url: url
  344. })
  345. },
  346. toSubmit() {
  347. let that = this;
  348. this.$refs.baseForm.validate().then(res => {
  349. that.submitData();
  350. }).catch(err => {
  351. //console.log('表单错误信息:', err);
  352. uni.showModal({
  353. content: "录入错误,请根据提示信息检查录入内容!",
  354. showCancel: false,
  355. success(res) {
  356. if (res.confirm) {
  357. //that.$refs.baseForm.clearValidate();
  358. }
  359. }
  360. });
  361. })
  362. },
  363. submitData() {
  364. let formdata = this.formData;
  365. formdata['batchId'] = this.uuid;
  366. if (this.orderPhotos.length > 0) {
  367. let photos = '';
  368. for (let i = 0; i < this.orderPhotos.length; i++) {
  369. if (photos.length > 0) {
  370. photos = photos + ',';
  371. }
  372. photos = photos + this.orderPhotos[i];
  373. }
  374. formdata['orderPhotos'] = photos;
  375. }
  376. if (this.orderVideos.length > 0) {
  377. let videos = '';
  378. for (let i = 0; i < this.orderVideos.length; i++) {
  379. if (videos.length > 0) {
  380. videos = videos + ',';
  381. }
  382. videos = videos + this.orderVideos[i];
  383. }
  384. formdata['orderVideos'] = videos;
  385. }
  386. let that = this;
  387. http.request({
  388. url: '/galaxy-business/order/save',
  389. method: 'POST',
  390. data: formdata
  391. }).then(res => {
  392. if (res.success) {
  393. uni.showModal({
  394. content: '已成功提交',
  395. showCancel: false,
  396. success(res) {
  397. that.toBack();
  398. }
  399. });
  400. } else {
  401. uni.showModal({
  402. content: '' + res.msg,
  403. showCancel: false
  404. });
  405. }
  406. }).catch(err => {
  407. console.log(err)
  408. })
  409. },
  410. }
  411. }
  412. </script>
  413. <style lang="scss" scoped>
  414. .container {
  415. padding: 0 0 100rpx;
  416. }
  417. .view-flex-rc {
  418. display: flex;
  419. flex-direction: row;
  420. justify-content: center;
  421. align-items: center;
  422. }
  423. .view-flex-cc {
  424. display: flex;
  425. flex-direction: column;
  426. justify-content: center;
  427. }
  428. </style>