editShopImage.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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="mercharts_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. uni.showModal({
  60. title: '提示',
  61. content: '确定提交店铺图片?',
  62. success (res) {
  63. if (res.confirm) {
  64. that.$u.debounce(that.confirmSubmit, 500)
  65. } else if (res.cancel) {
  66. console.log('用户点击取消')
  67. }
  68. }
  69. })
  70. },
  71. confirmSubmit() {
  72. uni.showLoading({
  73. title: '加载中',
  74. mask: true
  75. })
  76. this.$request.baseRequest('admin.tourism.foodInfo', 'update', {
  77. foodInfo: JSON.stringify(this.currectData)
  78. }, failres => {
  79. uni.showToast({
  80. icon: "none",
  81. title: failres.errmsg,
  82. duration: 3000
  83. });
  84. uni.hideLoading()
  85. }).then(res => {
  86. this.isSubmit = false
  87. uni.showToast({
  88. icon: "success",
  89. title: '编辑店铺图片成功',
  90. duration: 2000
  91. });
  92. uni.setStorageSync('myCateringdustry',JSON.stringify(this.currectData))
  93. uni.navigateBack()
  94. })
  95. },
  96. // 删除图片
  97. deletePic(event,status) {
  98. this[`fileList${event.name}`].splice(event.index, 1)
  99. if(status==4){
  100. that.indoorImageArray.splice(event.index, 1)
  101. that.currectData.indoorImage =that.indoorImageArray.toString()
  102. }
  103. },
  104. // 新增图片
  105. async afterRead(event,status) {
  106. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  107. let lists = [].concat(event.file)
  108. let fileListLen = this[`fileList${event.name}`].length
  109. lists.map((item) => {
  110. this[`fileList${event.name}`].push({
  111. ...item,
  112. status: 'uploading',
  113. message: '上传中'
  114. })
  115. })
  116. for (let i = 0; i < lists.length; i++) {
  117. const result = await this.uploadFilePromise(lists[i].url,status)
  118. let item = this[`fileList${event.name}`][fileListLen]
  119. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  120. status: 'success',
  121. message: '',
  122. url: result
  123. }))
  124. fileListLen++
  125. console.log(that.currectData, this[`fileList${event.name}`])
  126. }
  127. },
  128. uploadFilePromise(res,status) {
  129. return new Promise((resolve, reject) => {
  130. uploadImage(res, 'cardImages/',
  131. result => {
  132. if(status==3){
  133. that.currectData.coverImage = result
  134. }else if(status==4){
  135. that.indoorImageArray.push(result)
  136. that.currectData.indoorImage =that.indoorImageArray.toString()
  137. }
  138. resolve(res)
  139. }
  140. )
  141. })
  142. },
  143. }
  144. }
  145. </script>
  146. <style>
  147. </style>