editShopImage.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class='content'>
  3. <view class='wrap'>
  4. <u--form ref="uForm">
  5. <u-form-item labelWidth='240' labelPosition='top' label="门面及门头照片(1张,店名文字清晰)">
  6. <u-upload :fileList="fileList4" @afterRead="afterRead($event,3)" @delete="deletePic($event,3)" name="4" multiple
  7. :maxCount="1">
  8. </u-upload>
  9. </u-form-item>
  10. <u-form-item labelWidth='120' labelPosition='top' label="室内照片(1-6张)">
  11. <u-upload :fileList="fileList5" @afterRead="afterRead($event,4)" @delete="deletePic($event,4)" name="5" multiple
  12. :maxCount="6">
  13. </u-upload>
  14. </u-form-item>
  15. </u--form>
  16. <view class="footer">
  17. <button @click='submit' class="submit">提交</button>
  18. </view>
  19. </view>
  20. <u-modal :show="isSubmit" content='确定提交店铺图片' @confirm="$u.debounce(confirmSubmit, 500)" showCancelButton
  21. @cancel="isSubmit=false" @close="isSubmit=false" closeOnClickOverlay></u-modal>
  22. </view>
  23. </template>
  24. <script>
  25. var that
  26. import uploadImage from '@/components/ossutil/uploadFile.js';
  27. export default {
  28. data() {
  29. return {
  30. isSubmit:false,
  31. indoorImageArray:[],
  32. fileList4:[],
  33. fileList5:[],
  34. currectData:{},
  35. }
  36. },
  37. onLoad() {
  38. that = this
  39. },
  40. onShow(){
  41. if(uni.getStorageSync('myCateringdustry')){
  42. this.currectData=JSON.parse(uni.getStorageSync('myCateringdustry'))
  43. if(this.currectData.coverImage){
  44. this.fileList4=[{url:this.currectData.coverImage}]
  45. }
  46. this.fileList5=[]
  47. if(this.currectData.indoorImage){
  48. this.indoorImageArray=this.currectData.indoorImage.split(',')
  49. for(var i=0;i<this.indoorImageArray.length;i++){
  50. if(this.indoorImageArray[i]){
  51. this.fileList5.push({url:this.indoorImageArray[i]})
  52. }
  53. }
  54. }
  55. }
  56. },
  57. methods: {
  58. submit(){
  59. this.isSubmit = true
  60. },
  61. confirmSubmit() {
  62. uni.showLoading({
  63. title: '加载中',
  64. mask: true
  65. })
  66. this.$request.baseRequest('admin.tourism.foodInfo', 'update', {
  67. foodInfo: JSON.stringify(this.currectData)
  68. }, failres => {
  69. uni.showToast({
  70. icon: "none",
  71. title: failres.errmsg,
  72. duration: 3000
  73. });
  74. uni.hideLoading()
  75. }).then(res => {
  76. this.isSubmit = false
  77. uni.showToast({
  78. icon: "success",
  79. title: '编辑店铺图片成功',
  80. duration: 2000
  81. });
  82. uni.setStorageSync('myCateringdustry',JSON.stringify(this.currectData))
  83. uni.navigateBack()
  84. })
  85. },
  86. // 删除图片
  87. deletePic(event,status) {
  88. this[`fileList${event.name}`].splice(event.index, 1)
  89. if(status==4){
  90. that.indoorImageArray.splice(event.index, 1)
  91. that.currectData.indoorImage =that.indoorImageArray.toString()
  92. }
  93. },
  94. // 新增图片
  95. async afterRead(event,status) {
  96. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  97. let lists = [].concat(event.file)
  98. let fileListLen = this[`fileList${event.name}`].length
  99. lists.map((item) => {
  100. this[`fileList${event.name}`].push({
  101. ...item,
  102. status: 'uploading',
  103. message: '上传中'
  104. })
  105. })
  106. for (let i = 0; i < lists.length; i++) {
  107. const result = await this.uploadFilePromise(lists[i].url,status)
  108. let item = this[`fileList${event.name}`][fileListLen]
  109. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  110. status: 'success',
  111. message: '',
  112. url: result
  113. }))
  114. fileListLen++
  115. console.log(that.currectData, this[`fileList${event.name}`])
  116. }
  117. },
  118. uploadFilePromise(res,status) {
  119. return new Promise((resolve, reject) => {
  120. uploadImage(res, 'cardImages/',
  121. result => {
  122. if(status==3){
  123. that.currectData.coverImage = result
  124. }else if(status==4){
  125. that.indoorImageArray.push(result)
  126. that.currectData.indoorImage =that.indoorImageArray.toString()
  127. }
  128. resolve(res)
  129. }
  130. )
  131. })
  132. },
  133. }
  134. }
  135. </script>
  136. <style>
  137. </style>