myHome.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. <u-toast ref="uToast"></u-toast>
  70. </view>
  71. </template>
  72. <script>
  73. import uploadImage from '@/components/ossutil/uploadFile.js';
  74. export default {
  75. data() {
  76. return {
  77. companyData:{
  78. commonId:''
  79. },
  80. userInfo:{},
  81. fileList:[],
  82. fileList1:[],
  83. editstatus:false,
  84. id:''
  85. }
  86. },
  87. onLoad(options) {
  88. this.id=options.id
  89. uni.showLoading({
  90. title: '数据加载中'
  91. })
  92. this.getList()
  93. },
  94. onShow() {
  95. this.userInfo = uni.getStorageSync("userInfo")
  96. this.companyData.commonId=uni.getStorageSync("userInfo").id
  97. console.log(1111111111)
  98. // this.getList()
  99. },
  100. onUnload(){
  101. this.id=''
  102. },
  103. methods: {
  104. getList(){
  105. var data={}
  106. if(this.id){
  107. data={
  108. personalHomeId:this.id,
  109. page:1,
  110. limit:10,
  111. }
  112. }else{
  113. data={
  114. page:1,
  115. limit:10,
  116. commonId:uni.getStorageSync("userInfo").id
  117. }
  118. }
  119. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'list',data, failres => {
  120. console.log('res+++++', failres.errmsg)
  121. this.$refs.uToast.show({
  122. type: 'error',
  123. message: failres.errmsg,
  124. })
  125. uni.hideLoading()
  126. }).then(res => {
  127. console.log(res)
  128. if(res.data.items.length>0){
  129. this.companyData=res.data.items[0]
  130. if(res.data.items[0].addressUrl){
  131. var arr=res.data.items[0].addressUrl.split(',')
  132. this.fileList1=[]
  133. for(var i=0;i<arr.length;i++){
  134. if(arr[i]){
  135. this.fileList1.push({url:arr[i]})
  136. }
  137. }
  138. this.fileList=arr
  139. }
  140. console.log(this.fileList1)
  141. this.editstatus=false
  142. }else{
  143. this.editstatus=true
  144. }
  145. // if (res.errno == 200) {
  146. uni.hideLoading()
  147. // }
  148. })
  149. },
  150. edit(){
  151. this.editstatus=true
  152. },
  153. change(){
  154. },
  155. click(index){
  156. console.log(index)
  157. uni.previewImage({
  158. current: index, // 当前显示图片的索引值
  159. urls: this.fileList, // 需要预览的图片列表,photoList要求必须是数组
  160. loop:true, // 是否可循环预览
  161. })
  162. },
  163. buttonsubmit(){
  164. uni.showLoading({
  165. title: '数据加载中',
  166. mask:true
  167. })
  168. if(this.companyData.id){
  169. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'update',{
  170. personalHomepageInfo:JSON.stringify(this.companyData)
  171. }, failres => {
  172. console.log('res+++++', failres.errmsg)
  173. this.$refs.uToast.show({
  174. type: 'error',
  175. message: failres.errmsg,
  176. })
  177. uni.hideLoading()
  178. }).then(res => {
  179. // if (res.errno == 200) {
  180. uni.hideLoading()
  181. this.$refs.uToast.show({
  182. type: 'success',
  183. message: '编辑成功',
  184. })
  185. this.getList()
  186. // }
  187. })
  188. }else{
  189. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'add',{
  190. personalHomepageInfo:JSON.stringify(this.companyData)
  191. }, failres => {
  192. console.log('res+++++', failres.errmsg)
  193. this.$refs.uToast.show({
  194. type: 'error',
  195. message: failres.errmsg,
  196. })
  197. uni.hideLoading()
  198. }).then(res => {
  199. // if (res.errno == 200) {
  200. uni.hideLoading()
  201. this.$refs.uToast.show({
  202. type: 'success',
  203. message: '提交成功',
  204. })
  205. this.getList()
  206. // }
  207. })
  208. }
  209. },
  210. deletePic(event) {
  211. this[`fileList${event.name}`].splice(event.index, 1)
  212. this.companyData.addressUrl =this[`fileList${event.name}`].toString()
  213. },
  214. // 新增图片
  215. async afterRead(event) {
  216. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  217. let lists = [].concat(event.file)
  218. let fileListLen = this[`fileList${event.name}`].length
  219. lists.map((item) => {
  220. this[`fileList${event.name}`].push({
  221. ...item,
  222. status: 'uploading',
  223. message: '上传中'
  224. })
  225. })
  226. // console.log(event,111111,fileListLen)
  227. for (let i = 0; i < lists.length; i++) {
  228. const result = await this.uploadFilePromise(lists[i].url)
  229. this.companyData.addressUrl = this.companyData.addressUrl?this.companyData.addressUrl+','+result:result
  230. this[`fileList${event.name}`][fileListLen]={}
  231. let item = this[`fileList${event.name}`][fileListLen]
  232. console.log(item)
  233. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  234. status: 'success',
  235. message: '',
  236. url: result
  237. }))
  238. fileListLen++
  239. }
  240. console.log(this[`fileList${event.name}`])
  241. },
  242. uploadFilePromise(url) {
  243. console.log(url)
  244. return new Promise((resolve, reject) => {
  245. uploadImage(url, 'cardImages/',
  246. result => {
  247. console.log(result,22222)
  248. resolve(result)
  249. }
  250. )
  251. // let a = uni.uploadFile({
  252. // url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  253. // filePath: url,
  254. // name: 'file',
  255. // formData: {
  256. // user: 'test'
  257. // },
  258. // success: (res) => {
  259. // setTimeout(() => {
  260. // resolve(res.data.data)
  261. // }, 1000)
  262. // }
  263. // });
  264. })
  265. },
  266. }
  267. }
  268. </script>
  269. <style>
  270. </style>