addStore.vue 9.6 KB

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