addStore.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 class="flex_1" :custom-style="inputClass" :disabled="isView" v-model="reverseReceiveAddress.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" v-show="!isView"></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" :disabled="isView" v-model="reverseReceiveAddress.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 && !isView">
  40. <view @click="goPhotograph" class="photograph-camera">
  41. <u-icon name="camera" color="#bfbfbf" size="60" v-show="!isView"></u-icon>
  42. </view>
  43. </view>
  44. <view v-if="isView" style="margin-top: 10rpx;">暂无门头照</view>
  45. <view v-show="photograph.length" v-for="(item,index) in photograph" :key="index" class="photograph-con">
  46. <u-icon name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph(index)"></u-icon>
  47. <u-image width="100%" height="100%" :src="item" @click="previewPictures(item)"></u-image>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="footer">
  53. <view class="submit-btn flex justify_center align_center" v-if="!isView" @click="submit">保存</view>
  54. <view class="submit-btn flex justify_center align_center" v-if="isView" @click="isView=false">编辑</view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import {saveImgToAliOss} from '@/libs/tools.js'
  60. import { shopDetails,savShop } from '@/api/shop.js'
  61. export default{
  62. data(){
  63. return{
  64. photograph: [],
  65. form:{
  66. name:'', // 名称
  67. mobile:'', // 手机号码
  68. },
  69. reverseReceiveAddress: {
  70. provinceName: '',// 省
  71. cityName: '',// 市
  72. districtName: '', // 区
  73. receiveAddress: '',// 详细地址
  74. receiveAreasName:'',
  75. lat:'',
  76. lng:''
  77. },
  78. itemId:'',// 店铺id
  79. pageInfo:null, // 页面数据
  80. isView: false ,// 是否是查看详情
  81. }
  82. },
  83. onLoad(option) {
  84. if(option.id){
  85. this.isView = true
  86. console.log(option,option.id)
  87. uni.setNavigationBarTitle({
  88. title: '修改店铺'
  89. });
  90. this.itemId=option.id
  91. this.getDetailInfo()
  92. }
  93. },
  94. methods:{
  95. // 获取详情信息
  96. getDetailInfo(){
  97. shopDetails({id:this.itemId}).then(res=>{
  98. if(res.status==200){
  99. this.form.name=res.data.name? res.data.name:''
  100. this.form.mobile=res.data.mobile
  101. this.reverseReceiveAddress=Object.assign(this.reverseReceiveAddress,res.data.reverseReceiveAddress?res.data.reverseReceiveAddress:null)
  102. // this.form.receiveAddress.provinceName=res.data.receiveAddressVO?res.data.receiveAddressVO.provinceName:''
  103. // this.form.receiveAddress.cityName=res.data.receiveAddressVO?res.data.receiveAddressVO.cityName:''
  104. // this.form.receiveAddress.districtName=res.data.receiveAddressVO?res.data.receiveAddressVO.districtName:''
  105. // this.form.receiveAddress.receiveAddress=res.data.receiveAddressVO?res.data.receiveAddressVO.receiveAddress:''
  106. // this.form.receiveAddress.receiveAreasName=res.data.receiveAddressVO?res.data.receiveAddressVO.receiveAreasName:''
  107. this.photograph=res.data.reverseReceiveAddress?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. this.getArea(res.address)
  122. // this.form.contactAddress=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. submit(){
  207. const testVal=/^1[34578]\d{9}$/
  208. if (!testVal.test(this.form.mobile)) {
  209. uni.showToast({
  210. title: '请输入正确的联系电话',
  211. icon: 'none'
  212. })
  213. return false
  214. }
  215. const params=Object.assign(this.form,{sourceTypeReserve:'rider'},{reverseReceiveAddress:this.reverseReceiveAddress})
  216. if(this.photograph.length>0){
  217. params.reverseReceiveAddress.headerImageList=this.photograph
  218. }
  219. if(this.itemId){
  220. params.id=this.itemId
  221. }
  222. console.log(params,'-----------提交参数')
  223. savShop(params).then(res=>{
  224. console.log(res)
  225. if(res.status==200){
  226. uni.navigateBack({})
  227. }
  228. uni.showToast({
  229. title:res.message,
  230. icon:'none'
  231. })
  232. })
  233. }
  234. }
  235. }
  236. </script>
  237. <style lang="less">
  238. .content-add{
  239. width: 100%;
  240. height: 100vh;
  241. background-color: #f5f5f5;
  242. display: flex;
  243. flex-direction: column;
  244. .add-body{
  245. width: 100%;
  246. padding: 20upx 30upx;
  247. flex: 1;
  248. overflow-y: scroll;
  249. .form-data{
  250. width: 100%;
  251. background-color: #fff;
  252. border-radius: 24upx;
  253. margin-bottom: 20upx;
  254. .data-item{
  255. margin: 0 32upx;
  256. padding: 36upx 0;
  257. border-bottom: 1px solid #e5e5e5;
  258. }
  259. .data-item>text:first-child{
  260. color:#666E75;
  261. }
  262. .last{
  263. border-bottom:none;
  264. }
  265. .headerImgTitle{
  266. padding-top:36upx;
  267. margin: 0 32upx;
  268. color:#666E75;
  269. }
  270. .info-main {
  271. margin:0 32upx;
  272. padding: 10upx 0 36upx;
  273. border-radius: 12upx;
  274. background-color: #fff;
  275. display: flex;
  276. .location-icon {
  277. padding-left: 10upx;
  278. vertical-align: sub;
  279. }
  280. .photograph-camera {
  281. border: 2upx dashed #bfbfbf;
  282. border-radius: 12upx;
  283. width: 140upx;
  284. height: 140upx;
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. }
  289. .camera-btn{
  290. display: flex;
  291. flex-direction: column;
  292. align-items: center;
  293. color: #999999;
  294. font-size: 24upx;
  295. }
  296. .photograph-con {
  297. margin: 0 20upx;
  298. width: 140upx;
  299. height: 140upx;
  300. text-align: center;
  301. position: relative;
  302. .photograph-icon {
  303. display: inline-block;
  304. padding-top: 48upx;
  305. }
  306. .close-circle-icon {
  307. background-color: #fff;
  308. border-radius: 50%;
  309. position: absolute;
  310. right: -23upx;
  311. top: -23upx;
  312. z-index: 9;
  313. }
  314. }
  315. }
  316. }
  317. }
  318. .footer{
  319. width: 100%;
  320. padding: 14upx 32upx 32upx;
  321. background-color: #fff;
  322. color: #fff;
  323. font-weight: 500;
  324. .submit-btn{
  325. height: 84upx;
  326. background: #1995FF;
  327. opacity: 1;
  328. border-radius: 16upx;
  329. }
  330. }
  331. }
  332. </style>