myHome.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <view>
  3. <view v-if='!editstatus&&fileList.length>0' class="swiper-wrap">
  4. <u-swiper :list="fileList" indicator indicatorMode="dot"
  5. autoplay
  6. imgMode='aspectFit'
  7. height='300'
  8. @change="change" @click="click">
  9. </u-swiper>
  10. </view>
  11. <!-- <u-skeleton
  12. rows="3"
  13. title
  14. loading
  15. ></u-skeleton> -->
  16. <view class="company-title">
  17. <view v-if='editstatus'>公司/机构名称</view>
  18. <u--input v-if='editstatus' v-model="companyData.companyName" placeholder="请输入公司名称" border="none" ></u--input>
  19. <view v-else>{{companyData.companyName}}</view>
  20. </view>
  21. <view class="intro">
  22. <view v-if='editstatus'>公司/机构简介</view>
  23. <u--input type='textarea' v-if='editstatus' v-model="companyData.companyIntroduction" placeholder="请输入公司简介" border="none" ></u--input>
  24. <view v-else>{{companyData.companyIntroduction}}</view>
  25. </view>
  26. <view class="scope">
  27. <view>业务范围</view>
  28. <u--input type='textarea' v-if='editstatus' v-model="companyData.scopeOfBusiness" placeholder="输入业务范围,不超过500个字" border="none" ></u--input>
  29. <view v-else>{{companyData.scopeOfBusiness}}</view>
  30. </view>
  31. <u-list>
  32. <u-list-item>
  33. <view v-if='editstatus'>公司地址</view>
  34. <u--input v-if='editstatus' v-model="companyData.companyAddress" placeholder="输入地址" border="none" ></u--input>
  35. <view v-else>{{companyData.companyAddress}}</view>
  36. </u-list-item>
  37. <u-list-item>
  38. <view v-if='editstatus'>联系电话</view>
  39. <u--input v-if='editstatus' v-model="companyData.phone" placeholder="输入联系电话" border="none" ></u--input>
  40. <view v-else>{{companyData.phone}}</view>
  41. </u-list-item>
  42. <u-list-item>
  43. <view v-if='editstatus'>传真</view>
  44. <u--input v-if='editstatus' v-model="companyData.portraiture" placeholder="输入传真号" border="none" ></u--input>
  45. <view v-else>{{companyData.portraiture}}</view>
  46. </u-list-item>
  47. <u-list-item>
  48. <view v-if='editstatus'>邮箱</view>
  49. <u--input v-if='editstatus' v-model="companyData.postbox" placeholder="输入邮箱" border="none" ></u--input>
  50. <view v-else>{{companyData.postbox}}</view>
  51. </u-list-item>
  52. </u-list>
  53. <view v-if='editstatus'>
  54. <view>企业风采</view>
  55. <!-- <image v-for='item in fileList' :src="item.url" mode=""></image> -->
  56. <u-upload
  57. @afterRead="afterRead"
  58. :fileList="fileList1"
  59. @delete="deletePic"
  60. name="1"
  61. multiple
  62. :maxCount="10"
  63. ></u-upload>
  64. </view>
  65. <view class="footer">
  66. <view v-if='!editstatus' @click='edit' class='button'>编辑</view>
  67. <view v-else @click='$u.debounce(buttonsubmit, 500)' class='button'>提交</view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import uploadImage from '@/components/ossutil/uploadFile.js';
  73. export default {
  74. data() {
  75. return {
  76. companyData:{
  77. commonId:''
  78. },
  79. userInfo:{},
  80. fileList:[],
  81. fileList1:[],
  82. editstatus:false,
  83. }
  84. },
  85. onLoad() {
  86. uni.showLoading({
  87. title: '数据加载中'
  88. })
  89. this.getList()
  90. },
  91. onShow() {
  92. this.userInfo = uni.getStorageSync("userInfo")
  93. this.companyData.commonId=uni.getStorageSync("userInfo").id
  94. console.log(1111111111)
  95. // this.getList()
  96. },
  97. methods: {
  98. getList(){
  99. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'list',{
  100. page:1,
  101. limit:10,
  102. commonId:uni.getStorageSync("userInfo").id
  103. }, failres => {
  104. console.log('res+++++', failres.errmsg)
  105. this.$refs.uToast.show({
  106. type: 'error',
  107. message: failres.errmsg,
  108. })
  109. uni.hideLoading()
  110. }).then(res => {
  111. console.log(res)
  112. if(res.data.items.length>0){
  113. this.companyData=res.data.items[0]
  114. if(res.data.items[0].addressUrl){
  115. var arr=res.data.items[0].addressUrl.split(',')
  116. this.fileList1=[]
  117. for(var i=0;i<arr.length;i++){
  118. if(arr[i]){
  119. this.fileList1.push({url:arr[i]})
  120. }
  121. }
  122. this.fileList=arr
  123. }
  124. console.log(this.fileList1)
  125. this.editstatus=false
  126. }else{
  127. this.editstatus=true
  128. }
  129. // if (res.errno == 200) {
  130. uni.hideLoading()
  131. // }
  132. })
  133. },
  134. edit(){
  135. this.editstatus=true
  136. },
  137. change(){
  138. },
  139. click(index){
  140. console.log(index)
  141. uni.previewImage({
  142. current: index, // 当前显示图片的索引值
  143. urls: this.fileList, // 需要预览的图片列表,photoList要求必须是数组
  144. loop:true, // 是否可循环预览
  145. })
  146. },
  147. buttonsubmit(){
  148. uni.showLoading({
  149. title: '数据加载中',
  150. mask:true
  151. })
  152. if(this.companyData.id){
  153. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'update',{
  154. personalHomepageInfo:JSON.stringify(this.companyData)
  155. }, failres => {
  156. console.log('res+++++', failres.errmsg)
  157. this.$refs.uToast.show({
  158. type: 'error',
  159. message: failres.errmsg,
  160. })
  161. uni.hideLoading()
  162. }).then(res => {
  163. // if (res.errno == 200) {
  164. uni.hideLoading()
  165. uni.showToast({
  166. title: '编辑成功',
  167. icon: 'none',
  168. duration: 2000
  169. })
  170. this.getList()
  171. // }
  172. })
  173. }else{
  174. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'add',{
  175. personalHomepageInfo:JSON.stringify(this.companyData)
  176. }, failres => {
  177. console.log('res+++++', failres.errmsg)
  178. this.$refs.uToast.show({
  179. type: 'error',
  180. message: failres.errmsg,
  181. })
  182. uni.hideLoading()
  183. }).then(res => {
  184. // if (res.errno == 200) {
  185. uni.hideLoading()
  186. uni.showToast({
  187. title: '提交成功',
  188. icon: 'none',
  189. duration: 2000
  190. })
  191. this.getList()
  192. // }
  193. })
  194. }
  195. },
  196. deletePic(event) {
  197. this[`fileList${event.name}`].splice(event.index, 1)
  198. this.companyData.addressUrl =this[`fileList${event.name}`].toString()
  199. },
  200. // 新增图片
  201. async afterRead(event) {
  202. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  203. let lists = [].concat(event.file)
  204. let fileListLen = this[`fileList${event.name}`].length
  205. lists.map((item) => {
  206. this[`fileList${event.name}`].push({
  207. ...item,
  208. status: 'uploading',
  209. message: '上传中'
  210. })
  211. })
  212. // console.log(event,111111,fileListLen)
  213. for (let i = 0; i < lists.length; i++) {
  214. const result = await this.uploadFilePromise(lists[i].url)
  215. this.companyData.addressUrl = this.companyData.addressUrl?this.companyData.addressUrl+','+result:result
  216. this[`fileList${event.name}`][fileListLen]={}
  217. let item = this[`fileList${event.name}`][fileListLen]
  218. console.log(item)
  219. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  220. status: 'success',
  221. message: '',
  222. url: result
  223. }))
  224. fileListLen++
  225. }
  226. console.log(this[`fileList${event.name}`])
  227. },
  228. uploadFilePromise(url) {
  229. console.log(url)
  230. return new Promise((resolve, reject) => {
  231. uploadImage(url, 'cardImages/',
  232. result => {
  233. console.log(result,22222)
  234. resolve(result)
  235. }
  236. )
  237. // let a = uni.uploadFile({
  238. // url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  239. // filePath: url,
  240. // name: 'file',
  241. // formData: {
  242. // user: 'test'
  243. // },
  244. // success: (res) => {
  245. // setTimeout(() => {
  246. // resolve(res.data.data)
  247. // }, 1000)
  248. // }
  249. // });
  250. })
  251. },
  252. }
  253. }
  254. </script>
  255. <style>
  256. </style>