repairOrder.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <view class="cell">
  5. <view class="label required">产品图片</view>
  6. <view>
  7. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" :maxCount="9" name="1" multiple :previewFullImage="true" width="200rpx" height="200rpx">
  8. <image src="https://ship.shipcc.cn/common/add-img.png" style="width: 200rpx;height: 200rpx;"></image>
  9. </u-upload>
  10. </view>
  11. </view>
  12. <view class="cell">
  13. <view class="label required">维修时间</view>
  14. <view class="hflex acenter jbetween">
  15. <view @click="open(1)">
  16. <u-input v-model="startTime" disabled disabledColor="#fff" border="none" placeholder="开始时间"></u-input>
  17. </view>
  18. <u-datetime-picker title="开始时间" dis :show="show_time1" :minDate="newDate" v-model="newDate" ref="datetimePicker" @confirm="confirmTime1" @cancel="cancel" :formatter="formatter" mode="date"></u-datetime-picker>
  19. <view style="margin: 0 20rpx;">-</view>
  20. <view @click="open(2)">
  21. <u-input v-model="endTime" disabled disabledColor="#fff" border="none" placeholder="结束时间"></u-input>
  22. </view>
  23. <u-datetime-picker title="结束时间" :show="show_time2" :minDate="newDate" v-model="newDate" ref="datetimePicker" @confirm="confirmTime2" @cancel="cancel" :formatter="formatter" mode="date"></u-datetime-picker>
  24. </view>
  25. </view>
  26. <view class="cell" @click="selectmap">
  27. <view class="label required">维修地点</view>
  28. <view>
  29. <u-input v-model="addressObj.address" border="none" disabled disabledColor="#fff" placeholder="请选择" suffixIcon="arrow-right"></u-input>
  30. </view>
  31. </view>
  32. <view class="cell">
  33. <view class="label required">故障描述</view>
  34. <view>
  35. <u--textarea v-model="fault" maxlength="300" placeholder="请详细描述故障情况及原因,方便师傅带齐工具,并为您提供准确合理的维修" border="none" count></u--textarea>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="box">
  40. <view class="hflex acenter jbetween">
  41. <view class="label">是否快修</view>
  42. <u-switch v-model="is_quick" activeColor="#506dff" inactiveColor="rgb(230, 230, 230)" @change="change"></u-switch>
  43. </view>
  44. </view>
  45. <view class="bottom">
  46. <view class="bottom_btn" @click="release">立即发布</view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import $api from '@/static/js/api.js'
  52. var that = ''
  53. export default {
  54. data() {
  55. return {
  56. id: '',
  57. fileList1: [],
  58. imgs: '',
  59. fault: '',
  60. is_quick: false,
  61. startTime: '',
  62. endTime: '',
  63. address: '',
  64. show_time1: false,
  65. show_time2: false,
  66. newDate: Number(new Date()),
  67. addressObj: {},
  68. }
  69. },
  70. onLoad(options) {
  71. that = this
  72. if(options.data) {
  73. var data = JSON.parse(options.data)
  74. that.getData(data)
  75. console.log(data);
  76. }
  77. },
  78. onReady() {
  79. // 微信小程序需要用此写法
  80. this.$refs.datetimePicker.setFormatter(this.formatter)
  81. },
  82. methods: {
  83. getData(data) {
  84. that.id = data.id
  85. var imgs = data.imgs
  86. let obj = {}
  87. for(let key in imgs) {
  88. obj[key] = imgs[key]
  89. }
  90. var fileList1 = Object.keys(obj).map(item => ({
  91. url: obj[item]
  92. }))
  93. that.fileList1 = fileList1
  94. that.imgs = data.imgs
  95. that.fault = data.describe
  96. if(data.quick == 1) {
  97. that.is_quick = false
  98. } else {
  99. that.is_quick = true
  100. }
  101. that.startTime = data.start_time
  102. that.endTime = data.end_time
  103. that.address = data.address
  104. that.addressObj = {
  105. address: data.address,
  106. province: data.province,
  107. city:data.city,
  108. area:data.area,
  109. }
  110. },
  111. selectmap() {
  112. uni.getLocation({
  113. type: 'wgs84',
  114. success: (res)=>{
  115. console.log(res);
  116. if(res.longitude && res.latitude){
  117. $api.jump('/pages/user/map?lng='+res.longitude+'&lat='+res.latitude)
  118. }
  119. },
  120. fail:()=>{
  121. uni.getSetting({
  122. success: (res) => {
  123. console.log(res);
  124. var status = res.authSetting;
  125. if(!status['scope.userLocation']){
  126. uni.showModal({
  127. title:"是否授权当前位置",
  128. content:"需要获取您的地理位置,请确认授权,否则地图功能将无法使用",
  129. success:(tip)=>{
  130. if(tip.confirm){
  131. uni.openSetting({
  132. success:(data)=>{
  133. if(data.authSetting['scope.userLocation']===true){
  134. uni.showToast({
  135. title:"授权成功",
  136. icon:"success",
  137. duration:1000
  138. })
  139. uni.getLocation({
  140. type: 'wgs84',
  141. success: (res)=>{
  142. console.log('当前位置的经度:' + res.longitude);
  143. console.log('当前位置的纬度:' + res.latitude);
  144. $api.jump('/pages/user/map?lng='+res.longitude+'&lat='+res.latitude)
  145. }
  146. })
  147. }else{
  148. uni.showToast({
  149. title:"授权失败",
  150. icon:"none",
  151. duration:1000
  152. })
  153. }
  154. }
  155. })
  156. }
  157. }
  158. })
  159. }else{
  160. uni.getLocation({
  161. type: 'wgs84',
  162. success: (res)=>{
  163. console.log('当前位置的经度:' + res.longitude);
  164. console.log('当前位置的纬度:' + res.latitude);
  165. $api.jump('/pages/user/map?lng='+res.longitude+'&lat='+res.latitude)
  166. }
  167. })
  168. }
  169. },
  170. fail: (res) => {
  171. uni.showToast({
  172. title:"调用授权窗口失败",
  173. icon:"none",
  174. duration:1000
  175. })
  176. }
  177. })
  178. }
  179. })
  180. },
  181. // 格式化日期选择
  182. formatter(type, value) {
  183. if (type === 'year') {
  184. return `${value}年`
  185. }
  186. if (type === 'month') {
  187. return `${value}月`
  188. }
  189. if (type === 'day') {
  190. return `${value}日`
  191. }
  192. return value
  193. },
  194. // 删除图片
  195. deletePic(event) {
  196. this[`fileList${event.name}`].splice(event.index, 1)
  197. that.imgs = ''
  198. if(that[`fileList${event.name}`].length > 0) {
  199. for(var i=0;i<that[`fileList${event.name}`].length;i++) {
  200. if(i == that[`fileList${event.name}`].length -1) {
  201. that.imgs += that[`fileList${event.name}`][i].url
  202. } else {
  203. that.imgs += that[`fileList${event.name}`][i].url + ','
  204. }
  205. }
  206. }
  207. },
  208. // 新增图片
  209. async afterRead(event) {
  210. uni.showLoading({
  211. title: '上传中',
  212. mask: true
  213. })
  214. let lists = [].concat(event.file)
  215. let fileListLen = this[`fileList${event.name}`].length
  216. lists.map((item) => {
  217. this[`fileList${event.name}`].push({
  218. ...item,
  219. status: 'uploading',
  220. message: '上传中'
  221. })
  222. })
  223. for (let i = 0; i < lists.length; i++) {
  224. const result = await this.uploadFilePromise(lists[i].url)
  225. let item = this[`fileList${event.name}`][fileListLen]
  226. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  227. status: 'success',
  228. message: '',
  229. url: result.url
  230. }))
  231. fileListLen++
  232. if(lists.length - 1 == i) {
  233. uni.hideLoading()
  234. }
  235. }
  236. that.imgs = ''
  237. if(that[`fileList${event.name}`].length > 0) {
  238. for(var i=0;i<that[`fileList${event.name}`].length;i++) {
  239. if(i == that[`fileList${event.name}`].length -1) {
  240. that.imgs += that[`fileList${event.name}`][i].url
  241. } else {
  242. that.imgs += that[`fileList${event.name}`][i].url + ','
  243. }
  244. }
  245. }
  246. },
  247. uploadFilePromise(url) {
  248. return new Promise((resolve, reject) => {
  249. let a = uni.uploadFile({
  250. url: $api.config.baseUrl + '/data/api.auth.Center/upload',
  251. filePath: url,
  252. name: 'file',
  253. header: {
  254. 'content-type': 'application/x-www-form-urlencoded',
  255. 'api-token': uni.getStorageSync('token').token?uni.getStorageSync('token').token:'',
  256. 'api-name': 'wxapp'
  257. },
  258. formData: {
  259. user: 'test'
  260. },
  261. success: (res) => {
  262. setTimeout(() => {
  263. var data = JSON.parse(res.data)
  264. resolve(data.data)
  265. }, 1000)
  266. }
  267. });
  268. })
  269. },
  270. // 是否快修
  271. change(e) {
  272. that.is_quick = e
  273. },
  274. // 打开选择器
  275. open(index) {
  276. if(index == 1) {
  277. that.show_time1 = true
  278. } else {
  279. that.show_time2 = true
  280. }
  281. },
  282. cancel() {
  283. that.show_time1 = false
  284. that.show_time2 = false
  285. },
  286. confirmTime1(e) {
  287. that.startTime = $api.formatDate(e)
  288. that.cancel()
  289. },
  290. confirmTime2(e) {
  291. that.endTime = $api.formatDate(e)
  292. that.cancel()
  293. },
  294. // 立即发布
  295. release() {
  296. uni.showLoading({
  297. title: '发布中',
  298. mask:true
  299. })
  300. if($api.formCheck(that.fileList1,'required') &&$api.formCheck(that.fault,'required') && $api.formCheck(that.startTime,'required') && $api.formCheck(that.endTime,'required')&& $api.formCheck(that.endTime,'required') ) {
  301. $api.req({
  302. url: '/data/api.auth.ShipEngineMaintenance/subrepair',
  303. method: 'POST',
  304. data: {
  305. imgs: that.imgs,
  306. start_time: that.startTime,
  307. end_time: that.endTime,
  308. province: that.addressObj.province,
  309. city: that.addressObj.city,
  310. area: that.addressObj.area,
  311. address: that.addressObj.address,
  312. describe: that.fault,
  313. quick: that.is_quick?2:1,
  314. id: that.id
  315. }
  316. }, function(res) {
  317. uni.hideLoading()
  318. if(res.code == 1) {
  319. $api.info(res.info)
  320. $api.jump(-1)
  321. }
  322. })
  323. }
  324. }
  325. },
  326. }
  327. </script>
  328. <style lang="scss" scoped>
  329. .content {
  330. background: #F4F4F4;
  331. .box {
  332. width: 690rpx;
  333. margin: 20rpx 30rpx 0;
  334. background: #FFFFFF;
  335. border-radius: 10px;
  336. box-sizing: border-box;
  337. padding: 20rpx;
  338. .cell {
  339. padding: 32rpx 0 0;
  340. .label {
  341. font-size: 26rpx;
  342. font-weight: 400;
  343. color: #222222;
  344. padding-bottom: 28rpx;
  345. }
  346. .required {
  347. position: relative;
  348. padding-left: 15rpx;
  349. }
  350. .required::after {
  351. content: '*';
  352. position: absolute;
  353. top: 5rpx;
  354. left: 0;
  355. font-size: 26rpx;
  356. font-weight: 400;
  357. color: #FF3232;
  358. }
  359. }
  360. }
  361. .bottom {
  362. width: 100%;
  363. z-index: 9;
  364. position: fixed;
  365. bottom: 0;
  366. height: 166rpx;
  367. background: #FFFFFF;
  368. box-sizing: border-box;
  369. padding: 8rpx 40rpx 74rpx;
  370. .bottom_btn {
  371. width: 100%;
  372. height: 84rpx;
  373. background: #506DFF;
  374. border-radius: 42rpx;
  375. font-size: 36rpx;
  376. font-weight: 500;
  377. color: #FFFFFF;
  378. text-align: center;
  379. line-height: 84rpx;
  380. }
  381. }
  382. }
  383. </style>