detail.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view class="content">
  3. <view class="box hflex acenter">
  4. <view class="img_box">
  5. <image :src="pageData.head_img" class="img"></image>
  6. <view class="img_bottom hflex acenter jcenter" @click="replace">点击替换</view>
  7. </view>
  8. <view class="vflex img_right">
  9. <view class="top_title">{{pageData.company}}</view>
  10. <view class="hflex acenter jbetween">
  11. <view class="addr">{{pageData.address}}</view>
  12. <image src="/static/images/mine/address_icon.png" style="width: 44rpx;height: 44rpx;"></image>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="box">
  17. <view class="box_top hflex acenter jbetween">
  18. <view class="title">商家信息</view>
  19. <view class="hflex acenter" @click="edit">
  20. <view class="top_text">可编辑</view>
  21. <image src="/static/images/mine/edit.png" style="width: 36rpx;height: 36rpx;"></image>
  22. </view>
  23. </view>
  24. <view class="cell hflex acenter">
  25. <view class="left">联系人</view>
  26. <u-input v-model="pageData.contact_name" border="none" :disabled="!is_edit" disabledColor="#fff"></u-input>
  27. </view>
  28. <view class="cell hflex acenter">
  29. <view class="left">联系电话</view>
  30. <u-input v-model="pageData.contact_phone" border="none" :disabled="!is_edit" disabledColor="#fff"></u-input>
  31. </view>
  32. <view class="cell">
  33. <view class="left">商家简介</view>
  34. <u-textarea v-model="pageData.intro" :disabled="!is_edit"></u-textarea >
  35. </view>
  36. <view class="cell">
  37. <view class="left">图片及视频</view>
  38. </view>
  39. <view class="imgs" v-if="!is_edit">
  40. <block v-for="(item,index) in pageData.imgs_videos" :key="index">
  41. <image :src="item.url" class="img" v-if="item.type == 'image'"></image>
  42. <video :src="item.url" class="img" v-if="item.type == 'video'"></video>
  43. </block>
  44. </view>
  45. <view class="imgs" v-else>
  46. <u-upload :fileList="pageData.imgs_videos" :accept='accept' @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="9" width="200rpx" height="200rpx">
  47. <image src="/static/images/common/upload_img.png" style="width: 200rpx;height: 200rpx;"></image>
  48. </u-upload>
  49. </view>
  50. </view>
  51. <view class="box">
  52. <view class="title">营业执照</view>
  53. <view class="cell">
  54. <image :src="pageData.business_img" class="bus_img"></image>
  55. </view>
  56. </view>
  57. <view class="btn hflex acenter jcenter" @click="save">
  58. 保存
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import $api from '@/static/js/api.js'
  64. var that = ''
  65. export default {
  66. data() {
  67. return {
  68. pageData: {},
  69. is_edit: false,
  70. accept: ['image','video'],
  71. }
  72. },
  73. onLoad() {
  74. that = this
  75. that.getData()
  76. },
  77. methods: {
  78. getData() {
  79. var pages = getCurrentPages()
  80. var prePage = pages[pages.length - 2]
  81. that.pageData = prePage.$vm.user.merchant
  82. for(var i=0;i<that.pageData.imgs_videos.length;i++) {
  83. if(!that.pageData.imgs_videos[i].type) {
  84. var img = that.pageData.imgs_videos[i].split('.')
  85. var type = ''
  86. console.log(img);
  87. if(img[img.length - 1] == 'mp4') {
  88. type = 'video'
  89. } else if(img[img.length - 1] == 'jpg' || img[img.length - 1] == 'png' || img[img.length - 1] == 'jpeg' || img[img.length - 1] == 'gif') {
  90. type = 'image'
  91. }
  92. var data = {
  93. type: type,
  94. url: that.pageData.imgs_videos[i]
  95. }
  96. that.pageData.imgs_videos.splice(i,1,data)
  97. }
  98. }
  99. console.log(that.pageData);
  100. },
  101. replace() {
  102. uni.chooseImage({
  103. count: 1, //默认9
  104. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  105. sourceType: ['album','camera'], //从相册选择
  106. success: function (res) {
  107. // console.log(JSON.stringify(res.tempFilePaths));
  108. const tempFilePaths = res.tempFilePaths
  109. uni.uploadFile({
  110. url: $api.config.baseUrl + '/data/api.auth.Center/upload',
  111. filePath: tempFilePaths[0],
  112. name: 'file',
  113. header: {
  114. 'token': uni.getStorageSync('token')?uni.getStorageSync('token'):'',
  115. 'api-name': 'iosapp'
  116. },
  117. formData: {
  118. 'user': 'test'
  119. },
  120. success: (res) => {
  121. const data = JSON.parse(res.data)
  122. if (data.code == 1) {
  123. that.pageData.head_img = data.data.url
  124. }
  125. }
  126. });
  127. }
  128. });
  129. },
  130. edit() {
  131. that.is_edit = true
  132. },
  133. // 删除图片
  134. deletePic(event) {
  135. that.pageData.imgs_videos.splice(event.index, 1)
  136. },
  137. // 新增图片
  138. async afterRead(event) {
  139. let lists = [].concat(event.file)
  140. let fileListLen = that.pageData.imgs_videos.length
  141. lists.map((item) => {
  142. that.pageData.imgs_videos.push({
  143. ...item,
  144. // status: 'uploading',
  145. // message: '上传中'
  146. })
  147. })
  148. for (let i = 0; i < lists.length; i++) {
  149. const result = await this.uploadFilePromise(lists[i].url)
  150. let item = that.pageData.imgs_videos[fileListLen]
  151. that.pageData.imgs_videos.splice(fileListLen, 1, Object.assign(item, {
  152. // status: 'success',
  153. type: result.type,
  154. url: result.url
  155. }))
  156. fileListLen++
  157. }
  158. },
  159. uploadFilePromise(url) {
  160. return new Promise((resolve, reject) => {
  161. let a = uni.uploadFile({
  162. url: $api.config.baseUrl + '/data/api.auth.Center/upload', // 仅为示例,非真实的接口地址
  163. filePath: url,
  164. name: 'file',
  165. header: {
  166. 'token': uni.getStorageSync('token')?uni.getStorageSync('token'):'',
  167. 'api-name': 'iosapp'
  168. },
  169. formData: {
  170. user: 'test'
  171. },
  172. success: (res) => {
  173. setTimeout(() => {
  174. var data = JSON.parse(res.data)
  175. console.log('data:',data);
  176. var type = data.data.key.split('.')
  177. if(type[1] == 'mp4') {
  178. that.$set(data.data,'type','video')
  179. } else {
  180. that.$set(data.data,'type','image')
  181. }
  182. resolve(data.data)
  183. }, 1000)
  184. }
  185. });
  186. })
  187. },
  188. save() {
  189. var imgs_videos = ""
  190. for(var i=0;i<that.pageData.imgs_videos.length;i++) {
  191. imgs_videos+=that.pageData.imgs_videos[i].url + ','
  192. }
  193. imgs_videos = imgs_videos.substr(0,imgs_videos.length - 1)
  194. $api.req({
  195. url: '/data/api.business.User/edit',
  196. method: 'POST',
  197. data: {
  198. head_img: that.pageData.head_img,
  199. contact_name: that.pageData.contact_name,
  200. contact_phone: that.pageData.contact_phone,
  201. intro: that.pageData.intro,
  202. imgs_videos: imgs_videos
  203. }
  204. }, function(res) {
  205. if(res.code == 1) {
  206. $api.info(res.info)
  207. $api.jump(-1)
  208. }
  209. })
  210. },
  211. },
  212. }
  213. </script>
  214. <style lang="scss" scoped>
  215. .content::v-deep {
  216. background: #F5F5F5;
  217. padding: 0 30rpx;
  218. .box {
  219. width: 100%;
  220. background: #FFFFFF;
  221. border-radius: 20rpx;
  222. box-sizing: border-box;
  223. padding: 28rpx 20rpx;
  224. margin-top: 20rpx;
  225. .img_box {
  226. width: 112rpx;
  227. height: 112rpx;
  228. border-radius: 16rpx;
  229. overflow: hidden;
  230. margin-right: 20rpx;
  231. position: relative;
  232. .img {
  233. width: 100%;
  234. height: 100%;
  235. }
  236. .img_bottom {
  237. position: absolute;
  238. bottom: 0;
  239. left: 0;
  240. width: 100%;
  241. height: 36rpx;
  242. background: rgba(0,0,0,0.5);
  243. border-radius: 0px 0px 16rpx 16rpx;
  244. font-size: 20rpx;
  245. font-weight: 400;
  246. color: #FFFFFF;
  247. line-height: 28rpx;
  248. }
  249. }
  250. .img_right {
  251. width: calc(100% - 132rpx);
  252. .top_title {
  253. width: 100%;
  254. font-size: 36rpx;
  255. font-weight: 600;
  256. color: #222222;
  257. line-height: 50px;
  258. }
  259. .addr {
  260. width: 424rpx;
  261. font-size: 24rpx;
  262. font-weight: 400;
  263. color: #777777;
  264. line-height: 28rpx;
  265. }
  266. }
  267. .box_top {
  268. padding: 0 0 24rpx;
  269. border-bottom: 1rpx solid #F5F5F5;
  270. .title {
  271. font-size: 32rpx;
  272. font-weight: 600;
  273. color: #222222;
  274. line-height: 44rpx;
  275. }
  276. .top_text {
  277. font-size: 22rpx;
  278. font-weight: 400;
  279. color: #656565;
  280. line-height: 32rpx;
  281. }
  282. }
  283. .cell {
  284. padding: 32rpx 0 0;
  285. .left {
  286. width: 150rpx;
  287. font-size: 28rpx;
  288. font-weight: 400;
  289. color: #333333;
  290. line-height: 40rpx;
  291. }
  292. .u-textarea {
  293. margin-top: 24rpx;
  294. background: #F5F5F5;
  295. border-radius: 24rpx;
  296. padding: 20rpx;
  297. box-sizing: border-box;
  298. }
  299. .bus_img {
  300. width: 100%;
  301. height: 348rpx;
  302. border-radius: 16rpx;
  303. }
  304. }
  305. .imgs {
  306. padding: 32rpx 0 0;
  307. .img {
  308. width: 200rpx;
  309. height: 200rpx;
  310. border-radius: 20rpx;
  311. margin: 0 14rpx 20rpx 0;
  312. }
  313. .img:nth-child(3n+3) {
  314. margin: 0 0 20rpx;
  315. }
  316. }
  317. }
  318. .btn {
  319. width: 100%;
  320. height: 84rpx;
  321. background: #506DFF;
  322. border-radius: 42rpx;
  323. margin: 56rpx 0 68rpx;
  324. font-size: 36rpx;
  325. font-weight: 600;
  326. color: #FFFFFF;
  327. line-height: 50rpx;
  328. }
  329. }
  330. </style>