myHome.vue 10 KB

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