addStore.vue 11 KB

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