addStore.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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" v-if="!isView" :custom-style="inputClass" v-model="form.name" placeholder="请输入店铺名称" placeholder-style="color:'#bbb';font-size:18px"/>
  9. <view v-if="isView">{{form.name || '--'}}</view>
  10. </view>
  11. </view>
  12. <view class="flex flex_column data-item last">
  13. <view class="flex align_center">
  14. <view style="color:#666E75">电话</view>
  15. <u-image src="/static/billing_icon.png" width="24" height="24" style="margin:0 0 10rpx 10rpx;"></u-image>
  16. </view>
  17. <view class="list-item-right flex_1 flex justify_between">
  18. <u-input class="flex_1" :custom-style="inputClass" :disabled="isView" v-model="form.mobile" placeholder="请输入联系电话" placeholder-style="color:'#bbb';font-size:18px"/>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="form-data">
  23. <view class="flex flex_column data-item">
  24. <text>地址</text>
  25. <view class="list-item-right flex_1 flex justify_between" >
  26. <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"/>
  27. <view v-if="isView">{{reverseReceiveAddress.receiveAreasName || '--'}}</view>
  28. <u-icon class="back-img" name="arrow-right" color="#9DA8B5" @click="selectAddress" v-show="!isView"></u-icon>
  29. </view>
  30. </view>
  31. <view class="flex flex_column data-item last">
  32. <text>详细地址</text>
  33. <view class="list-item-right flex_1 flex justify_between" >
  34. <u-input class="flex_1" :custom-style="inputClass" v-if="!isView" v-model="reverseReceiveAddress.receiveAddress" placeholder="请输入详细地址" placeholder-style="color:'#bbb';font-size:18px"/>
  35. <view v-if="isView">{{reverseReceiveAddress.receiveAddress || '--'}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="form-data">
  40. <view class="headerImgTitle"> 门头照片 <text style="color: #bbbbbb;">(仅可上传1张,10MB以内)</text></view>
  41. <view class="info-main">
  42. <view class="camera-btn" v-if="photograph.length<1 ">
  43. <view class="photograph-camera" v-if="isView">
  44. <u-icon name="camera" color="#bfbfbf" size="60"></u-icon>
  45. </view>
  46. <view @click="goPhotograph" class="photograph-camera" v-if="!isView">
  47. <u-icon name="camera" color="#bfbfbf" size="60"></u-icon>
  48. </view>
  49. </view>
  50. <view v-show="photograph.length" v-for="(item,index) in photograph" :key="index" class="photograph-con">
  51. <u-icon v-show="!isView" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph(index)"></u-icon>
  52. <u-image width="100%" height="100%" :src="item" @click="previewPictures(item)"></u-image>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="footer">
  58. <view class="submit-btn flex justify_center align_center" v-if="!isView" @click="submit">保存</view>
  59. <view class="submit-btn flex justify_center align_center" v-if="isView" @click="isView=false">编辑</view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {saveImgToAliOss} from '@/libs/tools.js'
  65. import { shopDetails,savShop } from '@/api/shop.js'
  66. export default{
  67. data(){
  68. return{
  69. photograph: [],
  70. form:{
  71. name:'', // 名称
  72. mobile:'', // 手机号码
  73. },
  74. reverseReceiveAddress: {
  75. provinceName: '',// 省
  76. cityName: '',// 市
  77. districtName: '', // 区
  78. receiveAddress: '',// 详细地址
  79. receiveAreasName:'',
  80. lat:'',
  81. lng:''
  82. },
  83. itemId:'',// 店铺id
  84. pageInfo:null, // 页面数据
  85. isView: false ,// 是否是查看详情
  86. }
  87. },
  88. onLoad(option) {
  89. if(option.id){
  90. this.isView = true
  91. console.log(option,option.id)
  92. uni.setNavigationBarTitle({
  93. title: '修改店铺'
  94. });
  95. this.itemId=option.id
  96. this.getDetailInfo()
  97. }
  98. },
  99. methods:{
  100. // 获取详情信息
  101. getDetailInfo(){
  102. shopDetails({id:this.itemId}).then(res=>{
  103. if(res.status==200){
  104. this.form.name=res.data.name? res.data.name:''
  105. this.form.mobile=res.data.mobile
  106. this.reverseReceiveAddress=Object.assign(this.reverseReceiveAddress,res.data.reverseReceiveAddress?res.data.reverseReceiveAddress:null)
  107. this.photograph=res.data.reverseReceiveAddress && res.data.reverseReceiveAddress.headerImageList?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){
  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>