myHome.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. }
  87. },
  88. onLoad() {
  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. methods: {
  101. getList(){
  102. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'list',{
  103. page:1,
  104. limit:10,
  105. commonId:uni.getStorageSync("userInfo").id
  106. }, failres => {
  107. console.log('res+++++', failres.errmsg)
  108. this.$refs.uToast.show({
  109. type: 'error',
  110. message: failres.errmsg,
  111. })
  112. uni.hideLoading()
  113. }).then(res => {
  114. console.log(res)
  115. if(res.data.items.length>0){
  116. this.companyData=res.data.items[0]
  117. if(res.data.items[0].addressUrl){
  118. var arr=res.data.items[0].addressUrl.split(',')
  119. this.fileList1=[]
  120. for(var i=0;i<arr.length;i++){
  121. if(arr[i]){
  122. this.fileList1.push({url:arr[i]})
  123. }
  124. }
  125. this.fileList=arr
  126. }
  127. console.log(this.fileList1)
  128. this.editstatus=false
  129. }else{
  130. this.editstatus=true
  131. }
  132. // if (res.errno == 200) {
  133. uni.hideLoading()
  134. // }
  135. })
  136. },
  137. edit(){
  138. this.editstatus=true
  139. },
  140. change(){
  141. },
  142. click(index){
  143. console.log(index)
  144. uni.previewImage({
  145. current: index, // 当前显示图片的索引值
  146. urls: this.fileList, // 需要预览的图片列表,photoList要求必须是数组
  147. loop:true, // 是否可循环预览
  148. })
  149. },
  150. buttonsubmit(){
  151. uni.showLoading({
  152. title: '数据加载中',
  153. mask:true
  154. })
  155. if(this.companyData.id){
  156. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'update',{
  157. personalHomepageInfo:JSON.stringify(this.companyData)
  158. }, failres => {
  159. console.log('res+++++', failres.errmsg)
  160. this.$refs.uToast.show({
  161. type: 'error',
  162. message: failres.errmsg,
  163. })
  164. uni.hideLoading()
  165. }).then(res => {
  166. // if (res.errno == 200) {
  167. uni.hideLoading()
  168. this.$refs.uToast.show({
  169. type: 'success',
  170. message: '编辑成功',
  171. })
  172. this.getList()
  173. // }
  174. })
  175. }else{
  176. this.$request.baseRequest('admin.unimall.personalHomepageInfo', 'add',{
  177. personalHomepageInfo:JSON.stringify(this.companyData)
  178. }, failres => {
  179. console.log('res+++++', failres.errmsg)
  180. this.$refs.uToast.show({
  181. type: 'error',
  182. message: failres.errmsg,
  183. })
  184. uni.hideLoading()
  185. }).then(res => {
  186. // if (res.errno == 200) {
  187. uni.hideLoading()
  188. this.$refs.uToast.show({
  189. type: 'success',
  190. message: '提交成功',
  191. })
  192. this.getList()
  193. // }
  194. })
  195. }
  196. },
  197. deletePic(event) {
  198. this[`fileList${event.name}`].splice(event.index, 1)
  199. this.companyData.addressUrl =this[`fileList${event.name}`].toString()
  200. },
  201. // 新增图片
  202. async afterRead(event) {
  203. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  204. let lists = [].concat(event.file)
  205. let fileListLen = this[`fileList${event.name}`].length
  206. lists.map((item) => {
  207. this[`fileList${event.name}`].push({
  208. ...item,
  209. status: 'uploading',
  210. message: '上传中'
  211. })
  212. })
  213. // console.log(event,111111,fileListLen)
  214. for (let i = 0; i < lists.length; i++) {
  215. const result = await this.uploadFilePromise(lists[i].url)
  216. this.companyData.addressUrl = this.companyData.addressUrl?this.companyData.addressUrl+','+result:result
  217. this[`fileList${event.name}`][fileListLen]={}
  218. let item = this[`fileList${event.name}`][fileListLen]
  219. console.log(item)
  220. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  221. status: 'success',
  222. message: '',
  223. url: result
  224. }))
  225. fileListLen++
  226. }
  227. console.log(this[`fileList${event.name}`])
  228. },
  229. uploadFilePromise(url) {
  230. console.log(url)
  231. return new Promise((resolve, reject) => {
  232. uploadImage(url, 'cardImages/',
  233. result => {
  234. console.log(result,22222)
  235. resolve(result)
  236. }
  237. )
  238. // let a = uni.uploadFile({
  239. // url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  240. // filePath: url,
  241. // name: 'file',
  242. // formData: {
  243. // user: 'test'
  244. // },
  245. // success: (res) => {
  246. // setTimeout(() => {
  247. // resolve(res.data.data)
  248. // }, 1000)
  249. // }
  250. // });
  251. })
  252. },
  253. }
  254. }
  255. </script>
  256. <style scoped lang="scss">
  257. /deep/.u-border {
  258. border-color: #E6E6E6!important;
  259. }
  260. .content{
  261. }
  262. .top{
  263. width: 100vw;
  264. height: 135rpx;
  265. background: #112253;
  266. border-radius: 0px 0px 20rpx 20rpx;
  267. }
  268. .content1{
  269. margin: 20rpx 0 120rpx 0;
  270. background-color: #fff;
  271. border-radius: 20rpx;
  272. padding: 20rpx;
  273. box-sizing: border-box;
  274. .row{
  275. padding-bottom: 24rpx;
  276. }
  277. .line{
  278. border-bottom: 1px solid #E6E6E6;
  279. }
  280. .top-m{
  281. margin-top: 24rpx;
  282. }
  283. .qyfc{
  284. margin: 24rpx 0;
  285. }
  286. }
  287. .content1-edit{
  288. position: relative;
  289. top: -135rpx;
  290. }
  291. .footer{
  292. position: fixed;
  293. bottom: 80rpx;
  294. width: calc(100% - 40rpx);
  295. padding: 0 20rpx;
  296. }
  297. .button{
  298. color: #fff;
  299. background-color: #112253;
  300. border-radius: 20rpx;
  301. }
  302. </style>