myHome.vue 9.2 KB

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