addStore.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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="edit">编辑</view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {saveImgToAliOss} from '@/libs/tools.js'
  65. import { shopDetails,saveShop } 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. uni.authorize({
  119. scope: 'scope.userLocation',
  120. success:()=>{
  121. wx.chooseLocation({
  122. success:(res)=>{
  123. if(res){
  124. console.log(res.address,'==========编码')
  125. this.getArea(res.address)
  126. this.reverseReceiveAddress.lat=res.latitude
  127. this.reverseReceiveAddress.lng=res.longitude
  128. this.reverseReceiveAddress.receiveAreasName= res.address
  129. }
  130. }
  131. })
  132. },
  133. fail() {
  134. uni.getSetting({
  135. success(res) {
  136. console.log(res.authSetting, 'gggggggggg')
  137. if (!res.authSetting['scope.userLocation']) {
  138. uni.showModal({
  139. title: '提示',
  140. content: '无法选择通信地址,请开启定位功能!',
  141. success: (res) => {
  142. if (res.confirm) {
  143. uni.openSetting({
  144. success(res) {
  145. console.log(res.authSetting,
  146. 'res.authSetting')
  147. },
  148. fail(err) {
  149. console.log(err, 'eeeeeeeee')
  150. }
  151. })
  152. } else if (res.cancel) {
  153. console.log('用户点击取消');
  154. }
  155. }
  156. });
  157. }
  158. },
  159. fail() {
  160. console.log('获取失败')
  161. }
  162. })
  163. }
  164. })
  165. },
  166. // 拍照或从相册选图片
  167. goPhotograph() {
  168. uni.chooseImage({
  169. count: 1, //默认9
  170. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  171. sourceType: ['album','camera'], //从相册选择
  172. success: (res) =>{
  173. if(res.tempFiles[0].size>10485760){
  174. uni.showToast({
  175. title: '图片过大无法上传!',
  176. icon: 'none'
  177. })
  178. return
  179. }
  180. uni.showLoading({
  181. title:'正在保存图片...',
  182. mask: true
  183. })
  184. saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
  185. this.photograph.push(ret.data)
  186. uni.hideLoading()
  187. })
  188. }
  189. });
  190. },
  191. // 预览图片
  192. previewPictures(item) {
  193. const photograph = [item];
  194. uni.previewImage({
  195. urls: photograph,
  196. });
  197. },
  198. // 删除图片
  199. cancelPhotograph(index) {
  200. setTimeout(() => {
  201. this.photograph.splice(index)
  202. }, 500);
  203. },
  204. //截取省市区
  205. getArea(str) {
  206. // let area = {}
  207. let index11 = 0
  208. let index1 = str.indexOf("省")
  209. if (index1 == -1) {
  210. index11 = str.indexOf("自治区")
  211. if (index11 != -1) {
  212. this.reverseReceiveAddress.provinceName = str.substring(0, index11 + 3)
  213. } else {
  214. this.reverseReceiveAddress.provinceName= str.substring(0, 0)
  215. }
  216. } else {
  217. this.reverseReceiveAddress.provinceName = str.substring(0, index1 + 1)
  218. }
  219. let index2 = str.indexOf("市")
  220. if (index11 == -1) {
  221. this.reverseReceiveAddress.cityName = str.substring(index11 + 1, index2 + 1)
  222. } else {
  223. if (index11 == 0) {
  224. this.reverseReceiveAddress.cityName = str.substring(index1 + 1, index2 + 1)
  225. } else {
  226. this.reverseReceiveAddress.cityName = str.substring(index11 + 3, index2 + 1)
  227. }
  228. }
  229. let index3 = str.lastIndexOf("区")
  230. if (index3 == -1) {
  231. index3 = str.indexOf("县")
  232. this.reverseReceiveAddress.districtName = str.substring(index2 + 1, index3 + 1)
  233. } else {
  234. this.reverseReceiveAddress.districtName = str.substring(index2 + 1, index3 + 1)
  235. }
  236. // return this.area;
  237. if(this.reverseReceiveAddress.provinceName==''){
  238. this.reverseReceiveAddress.provinceName=this.reverseReceiveAddress.cityName
  239. }
  240. },
  241. // 编辑
  242. edit(){
  243. this.isView = false
  244. uni.setNavigationBarTitle({
  245. title: '修改店铺'
  246. });
  247. },
  248. // 保存
  249. submit(){
  250. const testVal=/^1[34578]\d{9}$/
  251. if (!testVal.test(this.form.mobile)) {
  252. uni.showToast({
  253. title: '请输入正确的联系电话',
  254. icon: 'none'
  255. })
  256. return false
  257. }
  258. const params=Object.assign(this.form,{sourceTypeReserve:'rider'},{reverseReceiveAddress:this.reverseReceiveAddress})
  259. if(this.photograph){
  260. params.reverseReceiveAddress.headerImageList=this.photograph
  261. }
  262. if(this.itemId){
  263. params.id=this.itemId
  264. }
  265. console.log(params,'-----------提交参数')
  266. saveShop(params).then(res=>{
  267. console.log(res)
  268. if(res.status==200){
  269. uni.navigateBack({})
  270. }
  271. uni.showToast({
  272. title:res.message,
  273. icon:'none'
  274. })
  275. })
  276. }
  277. }
  278. }
  279. </script>
  280. <style lang="less">
  281. .content-add{
  282. width: 100%;
  283. height: 100vh;
  284. background-color: #f5f5f5;
  285. display: flex;
  286. flex-direction: column;
  287. .add-body{
  288. width: 100%;
  289. padding: 20upx 30upx;
  290. flex: 1;
  291. overflow-y: scroll;
  292. .form-data{
  293. width: 100%;
  294. background-color: #fff;
  295. border-radius: 24upx;
  296. margin-bottom: 20upx;
  297. .data-item{
  298. margin: 0 32upx;
  299. padding: 36upx 0;
  300. border-bottom: 1px solid #e5e5e5;
  301. }
  302. .data-item>text:first-child{
  303. color:#666E75;
  304. }
  305. .last{
  306. border-bottom:none;
  307. }
  308. .headerImgTitle{
  309. padding-top:36upx;
  310. margin: 0 32upx;
  311. color:#666E75;
  312. }
  313. .info-main {
  314. margin:0 32upx;
  315. padding: 10upx 0 36upx;
  316. border-radius: 12upx;
  317. background-color: #fff;
  318. display: flex;
  319. .location-icon {
  320. padding-left: 10upx;
  321. vertical-align: sub;
  322. }
  323. .photograph-camera {
  324. border: 2upx dashed #bfbfbf;
  325. border-radius: 12upx;
  326. width: 140upx;
  327. height: 140upx;
  328. display: flex;
  329. align-items: center;
  330. justify-content: center;
  331. }
  332. .camera-btn{
  333. display: flex;
  334. flex-direction: column;
  335. align-items: center;
  336. color: #999999;
  337. font-size: 24upx;
  338. }
  339. .photograph-con {
  340. margin: 0 20upx;
  341. width: 140upx;
  342. height: 140upx;
  343. text-align: center;
  344. position: relative;
  345. .photograph-icon {
  346. display: inline-block;
  347. padding-top: 48upx;
  348. }
  349. .close-circle-icon {
  350. background-color: #fff;
  351. border-radius: 50%;
  352. position: absolute;
  353. right: -23upx;
  354. top: -23upx;
  355. z-index: 9;
  356. }
  357. }
  358. }
  359. }
  360. }
  361. .footer{
  362. width: 100%;
  363. padding: 14upx 32upx 32upx;
  364. background-color: #fff;
  365. color: #fff;
  366. font-weight: 500;
  367. .submit-btn{
  368. height: 84upx;
  369. background: #1995FF;
  370. opacity: 1;
  371. border-radius: 16upx;
  372. }
  373. }
  374. }
  375. </style>