myHome.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <view class="content">
  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="top" v-else>
  17. </view>
  18. <view class="content1" :class="editstatus?'content1-edit':''">
  19. <view class="company-title row flex flex-between line" >
  20. <view v-if='editstatus'>公司/机构名称</view>
  21. <u--input v-if='editstatus' v-model="companyData.companyName" placeholder="请输入公司名称" border="none" inputAlign='right'></u--input>
  22. <view v-else>{{companyData.companyName}}</view>
  23. </view>
  24. <view class="intro top-m">
  25. <view v-if='editstatus'class="row">公司/机构简介</view>
  26. <u--textarea v-if='editstatus' v-model="companyData.companyIntroduction" count placeholder="请输入公司/机构简介,不超过1000个字"></u--textarea>
  27. <view v-else>{{companyData.companyIntroduction}}</view>
  28. </view>
  29. <view class="scope top-m">
  30. <view class="row">业务范围</view>
  31. <u--textarea v-if='editstatus' v-model="companyData.scopeOfBusiness" count placeholder="输入业务范围,不超过500个字"></u--textarea>
  32. <view v-else>{{companyData.scopeOfBusiness}}</view>
  33. </view>
  34. <view class="row flex flex-between line top-m">
  35. <view v-if='editstatus'>公司地址</view>
  36. <u--input v-if='editstatus' v-model="companyData.companyAddress" placeholder="输入地址" border="none" inputAlign='right'></u--input>
  37. <view v-else>{{companyData.companyAddress}}</view>
  38. </view>
  39. <view class="row flex flex-between line top-m">
  40. <view v-if='editstatus'>联系电话</view>
  41. <u--input v-if='editstatus' v-model="companyData.phone" placeholder="输入联系电话" border="none" inputAlign='right'></u--input>
  42. <view v-else>{{companyData.phone}}</view>
  43. </view>
  44. <view class="row flex flex-between line top-m">
  45. <view v-if='editstatus'>传真</view>
  46. <u--input v-if='editstatus' v-model="companyData.portraiture" placeholder="输入传真号" border="none" inputAlign='right'></u--input>
  47. <view v-else>{{companyData.portraiture}}</view>
  48. </view>
  49. <view class="row flex flex-between line top-m">
  50. <view v-if='editstatus'>邮箱</view>
  51. <u--input v-if='editstatus' v-model="companyData.postbox" placeholder="输入邮箱" border="none" inputAlign='right'></u--input>
  52. <view v-else>{{companyData.postbox}}</view>
  53. </view>
  54. <view v-if='editstatus'>
  55. <view class="qyfc">企业风采</view>
  56. <!-- <image v-for='item in fileList' :src="item.url" mode=""></image> -->
  57. <u-upload
  58. @afterRead="afterRead"
  59. :fileList="fileList1"
  60. @delete="deletePic"
  61. name="1"
  62. multiple
  63. :maxCount="10"
  64. ></u-upload>
  65. </view>
  66. </view>
  67. <view class="footer">
  68. <button v-if='!editstatus' @click='edit' class='button' >编辑</button>
  69. <button v-else @click='$u.debounce(buttonsubmit, 500)' class='button' type="default">提交</button>
  70. </view>
  71. <u-toast ref="uToast"></u-toast>
  72. </view>
  73. </template>
  74. <script>
  75. import uploadImage from '@/components/ossutil/uploadFile.js';
  76. export default {
  77. data() {
  78. return {
  79. companyData:{
  80. commonId:''
  81. },
  82. userInfo:{},
  83. fileList:[],
  84. fileList1:[],
  85. editstatus:false,
  86. id:''
  87. }
  88. },
  89. onLoad(options) {
  90. this.id=options.id
  91. uni.showLoading({
  92. title: '数据加载中'
  93. })
  94. this.getList()
  95. },
  96. onShow() {
  97. this.userInfo = uni.getStorageSync("userInfo")
  98. this.companyData.commonId=uni.getStorageSync("userInfo").id
  99. console.log(1111111111)
  100. // this.getList()
  101. },
  102. onUnload(){
  103. this.id=''
  104. },
  105. methods: {
  106. getList(){
  107. var data={}
  108. if(this.id){
  109. data={
  110. personalHomeId:this.id,
  111. page:1,
  112. limit:10,
  113. }
  114. }else{
  115. data={
  116. page:1,
  117. limit:10,
  118. commonId:uni.getStorageSync("userInfo").id
  119. }
  120. }
  121. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'list',data, failres => {
  122. console.log('res+++++', failres.errmsg)
  123. this.$refs.uToast.show({
  124. type: 'error',
  125. message: failres.errmsg,
  126. })
  127. uni.hideLoading()
  128. }).then(res => {
  129. console.log(res)
  130. if(res.data.items.length>0){
  131. this.companyData=res.data.items[0]
  132. if(res.data.items[0].addressUrl){
  133. var arr=res.data.items[0].addressUrl.split(',')
  134. this.fileList1=[]
  135. for(var i=0;i<arr.length;i++){
  136. if(arr[i]){
  137. this.fileList1.push({url:arr[i]})
  138. }
  139. }
  140. this.fileList=arr
  141. }
  142. console.log(this.fileList1)
  143. this.editstatus=false
  144. }else{
  145. this.editstatus=true
  146. }
  147. // if (res.errno == 200) {
  148. uni.hideLoading()
  149. // }
  150. })
  151. },
  152. edit(){
  153. this.editstatus=true
  154. },
  155. change(){
  156. },
  157. click(index){
  158. console.log(index)
  159. uni.previewImage({
  160. current: index, // 当前显示图片的索引值
  161. urls: this.fileList, // 需要预览的图片列表,photoList要求必须是数组
  162. loop:true, // 是否可循环预览
  163. })
  164. },
  165. buttonsubmit(){
  166. uni.showLoading({
  167. title: '数据加载中',
  168. mask:true
  169. })
  170. if(this.companyData.id){
  171. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'update',{
  172. personalHomepageInfo:JSON.stringify(this.companyData)
  173. }, failres => {
  174. console.log('res+++++', failres.errmsg)
  175. this.$refs.uToast.show({
  176. type: 'error',
  177. message: failres.errmsg,
  178. })
  179. uni.hideLoading()
  180. }).then(res => {
  181. // if (res.errno == 200) {
  182. uni.hideLoading()
  183. this.$refs.uToast.show({
  184. type: 'success',
  185. message: '编辑成功',
  186. })
  187. this.getList()
  188. // }
  189. })
  190. }else{
  191. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'add',{
  192. personalHomepageInfo:JSON.stringify(this.companyData)
  193. }, failres => {
  194. console.log('res+++++', failres.errmsg)
  195. this.$refs.uToast.show({
  196. type: 'error',
  197. message: failres.errmsg,
  198. })
  199. uni.hideLoading()
  200. }).then(res => {
  201. // if (res.errno == 200) {
  202. uni.hideLoading()
  203. this.$refs.uToast.show({
  204. type: 'success',
  205. message: '提交成功',
  206. })
  207. this.getList()
  208. // }
  209. })
  210. }
  211. },
  212. deletePic(event) {
  213. this[`fileList${event.name}`].splice(event.index, 1)
  214. this.companyData.addressUrl =this[`fileList${event.name}`].toString()
  215. },
  216. // 新增图片
  217. async afterRead(event) {
  218. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  219. let lists = [].concat(event.file)
  220. let fileListLen = this[`fileList${event.name}`].length
  221. lists.map((item) => {
  222. this[`fileList${event.name}`].push({
  223. ...item,
  224. status: 'uploading',
  225. message: '上传中'
  226. })
  227. })
  228. // console.log(event,111111,fileListLen)
  229. for (let i = 0; i < lists.length; i++) {
  230. const result = await this.uploadFilePromise(lists[i].url)
  231. this.companyData.addressUrl = this.companyData.addressUrl?this.companyData.addressUrl+','+result:result
  232. this[`fileList${event.name}`][fileListLen]={}
  233. let item = this[`fileList${event.name}`][fileListLen]
  234. console.log(item)
  235. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  236. status: 'success',
  237. message: '',
  238. url: result
  239. }))
  240. fileListLen++
  241. }
  242. console.log(this[`fileList${event.name}`])
  243. },
  244. uploadFilePromise(url) {
  245. console.log(url)
  246. return new Promise((resolve, reject) => {
  247. uploadImage(url, 'cardImages/',
  248. result => {
  249. console.log(result,22222)
  250. resolve(result)
  251. }
  252. )
  253. // let a = uni.uploadFile({
  254. // url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  255. // filePath: url,
  256. // name: 'file',
  257. // formData: {
  258. // user: 'test'
  259. // },
  260. // success: (res) => {
  261. // setTimeout(() => {
  262. // resolve(res.data.data)
  263. // }, 1000)
  264. // }
  265. // });
  266. })
  267. },
  268. }
  269. }
  270. </script>
  271. <style scoped lang="scss">
  272. /deep/.u-border {
  273. border-color: #E6E6E6!important;
  274. }
  275. .content{
  276. }
  277. .top{
  278. width: 100vw;
  279. height: 135rpx;
  280. background: #112253;
  281. border-radius: 0px 0px 20rpx 20rpx;
  282. }
  283. .content1{
  284. margin: 20rpx 0 120rpx 0;
  285. background-color: #fff;
  286. border-radius: 20rpx;
  287. padding: 20rpx;
  288. box-sizing: border-box;
  289. .row{
  290. padding-bottom: 24rpx;
  291. }
  292. .line{
  293. border-bottom: 1px solid #E6E6E6;
  294. }
  295. .top-m{
  296. margin-top: 24rpx;
  297. }
  298. .qyfc{
  299. margin: 24rpx 0;
  300. }
  301. }
  302. .content1-edit{
  303. position: relative;
  304. top: -135rpx;
  305. }
  306. .footer{
  307. position: fixed;
  308. bottom: 80rpx;
  309. width: calc(100% - 40rpx);
  310. padding: 0 20rpx;
  311. }
  312. .button{
  313. color: #fff;
  314. background-color: #112253;
  315. border-radius: 20rpx;
  316. }
  317. </style>