addStore.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <view class="content-add">
  3. <view class="add-body">
  4. <view class="form-data">
  5. <view class="flex flex_column data-item">
  6. <text>名称</text>
  7. <view class="list-item-right flex_1 flex justify_between">
  8. <u-input class="flex_1" v-if="!isView" :custom-style="inputClass" v-model="form.name" placeholder="请输入店铺名称" placeholder-style="color:'#bbb';font-size:18px"/>
  9. <view v-if="isView">{{form.name || ''}}</view>
  10. </view>
  11. </view>
  12. <view class="flex flex_column data-item last">
  13. <view class="flex align_center">
  14. <view style="color:#666E75">电话</view>
  15. <u-image src="/static/billing_icon.png" width="24" height="24" style="margin:0 0 10rpx 10rpx;"></u-image>
  16. </view>
  17. <view class="list-item-right flex_1 flex justify_between">
  18. <u-input class="flex_1" :custom-style="inputClass" :disabled="isView" v-model="form.mobile" placeholder="请输入联系电话" placeholder-style="color:'#bbb';font-size:18px"/>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="form-data">
  23. <view class="flex flex_column data-item">
  24. <text>地址</text>
  25. <view class="list-item-right flex_1 flex justify_between" >
  26. <u-input v-if="!isView" class="flex_1" :custom-style="inputClass" v-model="reverseReceiveAddress.receiveAreasName" @click="selectAddress" :disabled="true" placeholder="请选择通信地址" placeholder-style="color:'#bbb';font-size:18px"/>
  27. <view v-if="isView">{{reverseReceiveAddress.receiveAreasName || ''}}</view>
  28. <u-icon class="back-img" name="arrow-right" color="#9DA8B5" @click="selectAddress" v-show="!isView"></u-icon>
  29. </view>
  30. </view>
  31. <view class="flex flex_column data-item last">
  32. <text>详细地址</text>
  33. <view class="list-item-right flex_1 flex justify_between" >
  34. <u-input class="flex_1" :custom-style="inputClass" v-if="!isView" v-model="reverseReceiveAddress.receiveAddress" placeholder="请输入详细地址" placeholder-style="color:'#bbb';font-size:18px"/>
  35. <view v-if="isView">{{reverseReceiveAddress.receiveAddress || ''}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="form-data">
  40. <view class="headerImgTitle"> 门头照片 <text style="color: #bbbbbb;">(仅可上传1张,10MB以内)</text></view>
  41. <view class="info-main">
  42. <view class="camera-btn" v-if="photograph.length<1 ">
  43. <view class="photograph-camera" v-if="isView">
  44. <u-icon name="camera" color="#bfbfbf" size="60"></u-icon>
  45. </view>
  46. <view @click="goPhotograph" class="photograph-camera" v-if="!isView">
  47. <u-icon name="camera" color="#bfbfbf" size="60"></u-icon>
  48. </view>
  49. </view>
  50. <view v-show="photograph.length" v-for="(item,index) in photograph" :key="index" class="photograph-con">
  51. <u-icon v-show="!isView" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph(index)"></u-icon>
  52. <u-image width="100%" height="100%" :src="item" @click="previewPictures(item)"></u-image>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="footer">
  58. <view class="submit-btn flex justify_center align_center" v-if="!isView" @click="submit">保存</view>
  59. <view class="submit-btn flex justify_center align_center" v-if="isView" @click="edit">编辑</view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {saveImgToAliOss} from '@/libs/tools.js'
  65. import { shopDetails,saveShop } from '@/api/shop.js'
  66. export default{
  67. data(){
  68. return{
  69. photograph: [],
  70. form:{
  71. name:'', // 名称
  72. mobile:'', // 手机号码
  73. },
  74. reverseReceiveAddress: {
  75. provinceName: '',// 省
  76. cityName: '',// 市
  77. districtName: '', // 区
  78. receiveAddress: '',// 详细地址
  79. receiveAreasName:'',
  80. lat:'',
  81. lng:''
  82. },
  83. itemId:'',// 店铺id
  84. pageInfo:null, // 页面数据
  85. isView: false ,// 是否是查看详情
  86. }
  87. },
  88. onLoad(option) {
  89. if(option.id){
  90. this.isView = true
  91. console.log(option,option.id)
  92. uni.setNavigationBarTitle({
  93. title: '店铺信息'
  94. });
  95. this.itemId=option.id
  96. this.getDetailInfo()
  97. }
  98. },
  99. methods:{
  100. // 获取详情信息
  101. getDetailInfo(){
  102. shopDetails({id:this.itemId}).then(res=>{
  103. if(res.status==200){
  104. this.form.name=res.data.name? res.data.name:''
  105. this.form.mobile=res.data.mobile
  106. this.reverseReceiveAddress=Object.assign(this.reverseReceiveAddress,res.data.reverseReceiveAddress?res.data.reverseReceiveAddress:null)
  107. this.photograph=res.data.reverseReceiveAddress && res.data.reverseReceiveAddress.headerImageList?res.data.reverseReceiveAddress.headerImageList:[]
  108. }else{
  109. uni.showToast({
  110. title: res.message,
  111. icon:'none',
  112. })
  113. }
  114. })
  115. },
  116. // 选择通信地址
  117. selectAddress(){
  118. wx.chooseLocation({
  119. success:(res)=>{
  120. if(res){
  121. console.log(res.address,'==========编码')
  122. this.getArea(res.address)
  123. this.reverseReceiveAddress.lat=res.latitude
  124. this.reverseReceiveAddress.lng=res.longitude
  125. this.reverseReceiveAddress.receiveAreasName= res.address
  126. }
  127. }
  128. })
  129. },
  130. // 拍照或从相册选图片
  131. goPhotograph() {
  132. uni.chooseImage({
  133. count: 1, //默认9
  134. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  135. sourceType: ['album','camera'], //从相册选择
  136. success: (res) =>{
  137. if(res.tempFiles[0].size>10485760){
  138. uni.showToast({
  139. title: '图片过大无法上传!',
  140. icon: 'none'
  141. })
  142. return
  143. }
  144. uni.showLoading({
  145. title:'正在保存图片...',
  146. mask: true
  147. })
  148. saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
  149. this.photograph.push(ret.data)
  150. uni.hideLoading()
  151. })
  152. }
  153. });
  154. },
  155. // 预览图片
  156. previewPictures(item) {
  157. const photograph = [item];
  158. uni.previewImage({
  159. urls: photograph,
  160. });
  161. },
  162. // 删除图片
  163. cancelPhotograph(index) {
  164. setTimeout(() => {
  165. this.photograph.splice(index)
  166. }, 500);
  167. },
  168. //截取省市区
  169. getArea(str) {
  170. // let area = {}
  171. let index11 = 0
  172. let index1 = str.indexOf("省")
  173. if (index1 == -1) {
  174. index11 = str.indexOf("自治区")
  175. if (index11 != -1) {
  176. this.reverseReceiveAddress.provinceName = str.substring(0, index11 + 3)
  177. } else {
  178. this.reverseReceiveAddress.provinceName= str.substring(0, 0)
  179. }
  180. } else {
  181. this.reverseReceiveAddress.provinceName = str.substring(0, index1 + 1)
  182. }
  183. let index2 = str.indexOf("市")
  184. if (index11 == -1) {
  185. this.reverseReceiveAddress.cityName = str.substring(index11 + 1, index2 + 1)
  186. } else {
  187. if (index11 == 0) {
  188. this.reverseReceiveAddress.cityName = str.substring(index1 + 1, index2 + 1)
  189. } else {
  190. this.reverseReceiveAddress.cityName = str.substring(index11 + 3, index2 + 1)
  191. }
  192. }
  193. let index3 = str.lastIndexOf("区")
  194. if (index3 == -1) {
  195. index3 = str.indexOf("县")
  196. this.reverseReceiveAddress.districtName = str.substring(index2 + 1, index3 + 1)
  197. } else {
  198. this.reverseReceiveAddress.districtName = str.substring(index2 + 1, index3 + 1)
  199. }
  200. // return this.area;
  201. if(this.reverseReceiveAddress.provinceName==''){
  202. this.reverseReceiveAddress.provinceName=this.reverseReceiveAddress.cityName
  203. }
  204. },
  205. // 编辑
  206. edit(){
  207. this.isView = false
  208. uni.setNavigationBarTitle({
  209. title: '修改店铺'
  210. });
  211. },
  212. // 保存
  213. submit(){
  214. const testVal=/^1[34578]\d{9}$/
  215. if (!testVal.test(this.form.mobile)) {
  216. uni.showToast({
  217. title: '请输入正确的联系电话',
  218. icon: 'none'
  219. })
  220. return false
  221. }
  222. const params=Object.assign(this.form,{sourceTypeReserve:'rider'},{reverseReceiveAddress:this.reverseReceiveAddress})
  223. if(this.photograph){
  224. params.reverseReceiveAddress.headerImageList=this.photograph
  225. }
  226. if(this.itemId){
  227. params.id=this.itemId
  228. }
  229. console.log(params,'-----------提交参数')
  230. saveShop(params).then(res=>{
  231. console.log(res)
  232. if(res.status==200){
  233. uni.navigateBack({})
  234. }
  235. uni.showToast({
  236. title:res.message,
  237. icon:'none'
  238. })
  239. })
  240. }
  241. }
  242. }
  243. </script>
  244. <style lang="less">
  245. .content-add{
  246. width: 100%;
  247. height: 100vh;
  248. background-color: #f5f5f5;
  249. display: flex;
  250. flex-direction: column;
  251. .add-body{
  252. width: 100%;
  253. padding: 20upx 30upx;
  254. flex: 1;
  255. overflow-y: scroll;
  256. .form-data{
  257. width: 100%;
  258. background-color: #fff;
  259. border-radius: 24upx;
  260. margin-bottom: 20upx;
  261. .data-item{
  262. margin: 0 32upx;
  263. padding: 36upx 0;
  264. border-bottom: 1px solid #e5e5e5;
  265. }
  266. .data-item>text:first-child{
  267. color:#666E75;
  268. }
  269. .last{
  270. border-bottom:none;
  271. }
  272. .headerImgTitle{
  273. padding-top:36upx;
  274. margin: 0 32upx;
  275. color:#666E75;
  276. }
  277. .info-main {
  278. margin:0 32upx;
  279. padding: 10upx 0 36upx;
  280. border-radius: 12upx;
  281. background-color: #fff;
  282. display: flex;
  283. .location-icon {
  284. padding-left: 10upx;
  285. vertical-align: sub;
  286. }
  287. .photograph-camera {
  288. border: 2upx dashed #bfbfbf;
  289. border-radius: 12upx;
  290. width: 140upx;
  291. height: 140upx;
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. }
  296. .camera-btn{
  297. display: flex;
  298. flex-direction: column;
  299. align-items: center;
  300. color: #999999;
  301. font-size: 24upx;
  302. }
  303. .photograph-con {
  304. margin: 0 20upx;
  305. width: 140upx;
  306. height: 140upx;
  307. text-align: center;
  308. position: relative;
  309. .photograph-icon {
  310. display: inline-block;
  311. padding-top: 48upx;
  312. }
  313. .close-circle-icon {
  314. background-color: #fff;
  315. border-radius: 50%;
  316. position: absolute;
  317. right: -23upx;
  318. top: -23upx;
  319. z-index: 9;
  320. }
  321. }
  322. }
  323. }
  324. }
  325. .footer{
  326. width: 100%;
  327. padding: 14upx 32upx 32upx;
  328. background-color: #fff;
  329. color: #fff;
  330. font-weight: 500;
  331. .submit-btn{
  332. height: 84upx;
  333. background: #1995FF;
  334. opacity: 1;
  335. border-radius: 16upx;
  336. }
  337. }
  338. }
  339. </style>