addStore.vue 9.9 KB

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