addStore.vue 9.9 KB

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