addStore.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. receiveAddress: {
  67. provinceName: '',// 省
  68. cityName: '',// 市
  69. districtName: '', // 区
  70. receiveAddress: '',// 详细地址
  71. receiveAreasName:'',
  72. lat:'',
  73. lng:''
  74. }
  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.form.receiveAddress.provinceName=res.data.receiveAddressVO?res.data.receiveAddressVO.provinceName:''
  98. this.form.receiveAddress.cityName=res.data.receiveAddressVO?res.data.receiveAddressVO.cityName:''
  99. this.form.receiveAddress.districtName=res.data.receiveAddressVO?res.data.receiveAddressVO.districtName:''
  100. this.form.receiveAddress.receiveAddress=res.data.receiveAddressVO?res.data.receiveAddressVO.receiveAddress:''
  101. this.form.receiveAddress.receiveAreasName=res.data.receiveAddressVO?res.data.receiveAddressVO.receiveAreasName:''
  102. this.photograph=res.data.receiveAddressVO?res.data.receiveAddressVO.headerImageList:[]
  103. }else{
  104. uni.showToast({
  105. title: res.message,
  106. icon:'none',
  107. })
  108. }
  109. })
  110. },
  111. // 选择通信地址
  112. selectAddress(){
  113. wx.chooseLocation({
  114. success:(res)=>{
  115. if(res){
  116. this.getArea(res.address)
  117. // this.form.contactAddress=res.address
  118. this.form.receiveAddress.lat=res.latitude
  119. this.form.receiveAddress.lng=res.longitude
  120. this.form.receiveAddress.receiveAreasName= res.address
  121. }
  122. }
  123. })
  124. },
  125. // 拍照或从相册选图片
  126. goPhotograph() {
  127. uni.chooseImage({
  128. count: 1, //默认9
  129. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  130. sourceType: ['album','camera'], //从相册选择
  131. success: (res) =>{
  132. if(res.tempFiles[0].size>10485760){
  133. uni.showToast({
  134. title: '图片过大无法上传!',
  135. icon: 'none'
  136. })
  137. return
  138. }
  139. uni.showLoading({
  140. title:'正在保存图片...',
  141. mask: true
  142. })
  143. saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
  144. this.photograph.push(ret.data)
  145. uni.hideLoading()
  146. })
  147. }
  148. });
  149. },
  150. // 预览图片
  151. previewPictures(item) {
  152. const photograph = [item];
  153. uni.previewImage({
  154. urls: photograph,
  155. });
  156. },
  157. // 删除图片
  158. cancelPhotograph(index) {
  159. setTimeout(() => {
  160. this.photograph.splice(index)
  161. }, 500);
  162. },
  163. //截取省市区
  164. getArea(str) {
  165. // let area = {}
  166. let index11 = 0
  167. let index1 = str.indexOf("省")
  168. if (index1 == -1) {
  169. index11 = str.indexOf("自治区")
  170. if (index11 != -1) {
  171. this.form.receiveAddress.provinceName = str.substring(0, index11 + 3)
  172. } else {
  173. this.form.receiveAddress.provinceName= str.substring(0, 0)
  174. }
  175. } else {
  176. this.form.receiveAddress.provinceName = str.substring(0, index1 + 1)
  177. }
  178. let index2 = str.indexOf("市")
  179. if (index11 == -1) {
  180. this.form.receiveAddress.cityName = str.substring(index11 + 1, index2 + 1)
  181. } else {
  182. if (index11 == 0) {
  183. this.form.receiveAddress.cityName = str.substring(index1 + 1, index2 + 1)
  184. } else {
  185. this.form.receiveAddress.cityName = str.substring(index11 + 3, index2 + 1)
  186. }
  187. }
  188. let index3 = str.lastIndexOf("区")
  189. if (index3 == -1) {
  190. index3 = str.indexOf("县")
  191. this.form.receiveAddress.districtName = str.substring(index2 + 1, index3 + 1)
  192. } else {
  193. this.form.receiveAddress.districtName = str.substring(index2 + 1, index3 + 1)
  194. }
  195. // return this.area;
  196. if(this.form.receiveAddress==''){
  197. this.form.receiveAddress.provinceName=this.form.receiveAddress.cityName
  198. }
  199. },
  200. // 保存
  201. submit(){
  202. const testVal=/^1[34578]\d{9}$/
  203. if (!testVal.test(this.form.mobile)) {
  204. uni.showToast({
  205. title: '请输入正确的联系电话',
  206. icon: 'none'
  207. })
  208. return false
  209. }
  210. const params=Object.assign(this.form,{sourceTypeReserve:'rider'})
  211. if(this.photograph.length>0){
  212. params.receiveAddress.headerImageList=this.photograph
  213. }
  214. if(this.itemId){
  215. params.id=this.itemId
  216. }
  217. console.log(params,'-----------提交参数')
  218. savShop(params).then(res=>{
  219. console.log(res)
  220. if(res.status==200){
  221. uni.navigateBack({})
  222. }
  223. uni.showToast({
  224. title:res.message,
  225. icon:'none'
  226. })
  227. })
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="less">
  233. .content-add{
  234. width: 100%;
  235. height: 100vh;
  236. background-color: #f5f5f5;
  237. display: flex;
  238. flex-direction: column;
  239. .add-body{
  240. width: 100%;
  241. padding: 20upx 30upx;
  242. flex: 1;
  243. overflow-y: scroll;
  244. .form-data{
  245. width: 100%;
  246. background-color: #fff;
  247. border-radius: 24upx;
  248. margin-bottom: 20upx;
  249. .data-item{
  250. margin: 0 32upx;
  251. padding: 36upx 0;
  252. border-bottom: 1px solid #e5e5e5;
  253. }
  254. .data-item>text:first-child{
  255. color:#666E75;
  256. }
  257. .last{
  258. border-bottom:none;
  259. }
  260. .headerImgTitle{
  261. padding-top:36upx;
  262. margin: 0 32upx;
  263. color:#666E75;
  264. }
  265. .info-main {
  266. margin:0 32upx;
  267. padding: 10upx 0 36upx;
  268. border-radius: 12upx;
  269. background-color: #fff;
  270. display: flex;
  271. .location-icon {
  272. padding-left: 10upx;
  273. vertical-align: sub;
  274. }
  275. .photograph-camera {
  276. border: 2upx dashed #bfbfbf;
  277. border-radius: 12upx;
  278. width: 140upx;
  279. height: 140upx;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. }
  284. .camera-btn{
  285. display: flex;
  286. flex-direction: column;
  287. align-items: center;
  288. color: #999999;
  289. font-size: 24upx;
  290. }
  291. .photograph-con {
  292. margin: 0 20upx;
  293. width: 140upx;
  294. height: 140upx;
  295. text-align: center;
  296. position: relative;
  297. .photograph-icon {
  298. display: inline-block;
  299. padding-top: 48upx;
  300. }
  301. .close-circle-icon {
  302. background-color: #fff;
  303. border-radius: 50%;
  304. position: absolute;
  305. right: -23upx;
  306. top: -23upx;
  307. z-index: 9;
  308. }
  309. }
  310. }
  311. }
  312. }
  313. .footer{
  314. width: 100%;
  315. padding: 14upx 32upx 32upx;
  316. background-color: #fff;
  317. color: #fff;
  318. font-weight: 500;
  319. .submit-btn{
  320. height: 84upx;
  321. background: #1995FF;
  322. opacity: 1;
  323. border-radius: 16upx;
  324. }
  325. }
  326. }
  327. </style>