modify.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <view class="main main-bg">
  3. <u-form :model="form" ref="uForm" :rules="rules">
  4. <u-form-item
  5. label="店铺名称"
  6. label-width="180"
  7. :label-position="labelPosition"
  8. prop="shopsName">
  9. <u-input
  10. v-model="form.shopsName"
  11. placeholder-style="color: #2E4F1C;"
  12. placeholder="请输入店铺名称" />
  13. </u-form-item>
  14. <u-form-item
  15. label="店铺电话"
  16. label-width="180"
  17. :label-position="labelPosition"
  18. prop="shopsTel">
  19. <view class="form-item">
  20. <u-input
  21. v-model="form.shopsTel"
  22. placeholder-style="color: #2E4F1C;"
  23. placeholder="请输入店铺电话" />
  24. </view>
  25. </u-form-item>
  26. <u-form-item
  27. :label-position="labelPosition"
  28. label="场景种类"
  29. prop="shopsType"
  30. label-width="180">
  31. <u-input placeholder-style="color: #2E4F1C;" type="select" :select-open="selectShow" v-model="form.type" placeholder="请选择场景种类" @click="selectShow = true"></u-input>
  32. <u-select mode="single-column" :list="selectList" v-model="selectShow" @confirm="selectConfirm"></u-select>
  33. </u-form-item>
  34. <!-- <u-form-item
  35. label="优惠"
  36. label-width="180"
  37. :label-position="labelPosition"
  38. prop="shopsDiscount">
  39. <u-input
  40. v-model="form.shopsDiscount"
  41. placeholder-style="color: #2E4F1C;"
  42. placeholder="请输入优惠" />
  43. </u-form-item> -->
  44. <view class="store-dis">
  45. <view class="store-address">
  46. <view class="select-address">
  47. <view class="font-color3 font-twenty">
  48. 店铺地址
  49. </view>
  50. <u-input
  51. v-model="form.shopsAddress"
  52. placeholder-style="color: #2E4F1C;"
  53. placeholder="请选择地址"/>
  54. </view>
  55. </view>
  56. <view class="map-icon" @click="chooseLocation()">
  57. <image src="../../../static/map.png" class="icon-img"></image>
  58. <!-- <u-icon name="map" color="#ffffff" size="56rpx"></u-icon> -->
  59. </view>
  60. </view>
  61. <u-form-item
  62. label-position="top"
  63. label="简介"
  64. prop="shopsIntroduce">
  65. <u-input type="textarea" placeholder="请填写店铺简介" v-model="form.shopsIntroduce" />
  66. </u-form-item>
  67. <view class="form-upload">
  68. <view class="upload-title font-twenty font-color2">
  69. 照片修改(重新上传一张新照片,否则默认之前)
  70. </view>
  71. <view style="display: flex;">
  72. <image v-if="flag" :src="image(form.shopsPic)" style="width:160rpx; height:160rpx"></image>
  73. <u-upload
  74. width="160"
  75. height="160"
  76. :action="action"
  77. max-count="1"
  78. @on-success="onSuccess">
  79. </u-upload>
  80. </view>
  81. </view>
  82. </u-form>
  83. <view @click="submit" class="form-submit">确认</view>
  84. <u-toast ref="uToast" />
  85. </view>
  86. </template>
  87. <script>
  88. import http from '@/common/http.js'
  89. import amap from '@/lib/amap-wx.130.js'
  90. import server from "@/api/index";
  91. export default {
  92. data() {
  93. return {
  94. action: http.webUrl+`/wx/common/upload`,
  95. labelPosition: 'left',
  96. addressName: '',
  97. flag: true,
  98. selectShow: false,
  99. form: {
  100. shopsName: '',
  101. shopsTel: '',
  102. // shopsDiscount: 1,
  103. shopsIntroduce: '',
  104. shopsPic: '',
  105. shopsAddress:'',
  106. shopsLat: null,
  107. shopsLng: null,
  108. shopsType: null
  109. },
  110. selectList: [],
  111. rules: {
  112. shopsTel: [
  113. {
  114. required: true,
  115. message: '手机号格式不正确!',
  116. trigger: ['change','blur'],
  117. },
  118. {
  119. validator: (rule, value, callback) => {
  120. return this.$u.test.rangeLength(value, [1, 11]);
  121. },
  122. message: '手机号最多输入11个字符!',
  123. trigger: ['change','blur'],
  124. }
  125. ],
  126. shopsIntroduce: [
  127. {
  128. validator: (rule, value, callback) => {
  129. return this.$u.test.rangeLength(value, [0, 50]);
  130. },
  131. message: '简介最多输入50个字符!',
  132. trigger: ['change','blur'],
  133. }
  134. ],
  135. shopsName: [
  136. {
  137. validator: (rule, value, callback) => {
  138. return this.$u.test.rangeLength(value, [1, 15]);
  139. },
  140. message: '名称最多输入15个字符!',
  141. trigger: ['change','blur'],
  142. }
  143. ],
  144. // shopsDiscount: [
  145. // {
  146. // required: true,
  147. // message: '请输入优惠!',
  148. // trigger: ['change','blur'],
  149. // },
  150. // {
  151. // validator: (rule, value, callback) => {
  152. // return this.$u.test.range(value, [0, 1]);
  153. // },
  154. // message: '优惠必须是小数!',
  155. // trigger: ['change','blur'],
  156. // }
  157. // ]
  158. },
  159. id: null,
  160. key:'1dc63f21c12985e199a715faf4c02f36',
  161. userInfo:{}
  162. }
  163. },
  164. onLoad(e) {
  165. this.userInfo = uni.getStorageSync('userInfo');
  166. this.id = e.id;
  167. if(this.userInfo.nickName !== "null"){
  168. this.getListFn();
  169. }
  170. this.amapPulgin = new amap.AMapWX({
  171. key: this.key
  172. })
  173. this.getDicFn()
  174. },
  175. onReady() {
  176. this.$refs.uForm.setRules(this.rules);
  177. },
  178. // onShow() {
  179. // this.getListFn();
  180. // },
  181. methods:{
  182. image(e) {
  183. return http.webUrl + e
  184. },
  185. selectConfirm(e) {
  186. console.log(e)
  187. this.form.shopsType = e[0].value
  188. this.form.type = e[0].label
  189. },
  190. getDicFn(){
  191. server.getDic({dictType: 'shops_type'}).then(res =>{
  192. console.log(res)
  193. this.selectList = res
  194. })
  195. },
  196. getListFn(){
  197. server.getYongJunDetails(this.userInfo.nickName).then(res =>{
  198. this.form = res
  199. })
  200. },
  201. onSuccess(data, index, lists, name){
  202. this.form.shopsPic = data.fileName
  203. this.flag = false;
  204. },
  205. submit() {
  206. console.log(this.form)
  207. let _this = this;
  208. let form = this.form
  209. form.shopsStatus = '1';
  210. if(this.userInfo.nickName === "null"){
  211. form.userId = _this.userInfo.userId;
  212. this.$refs.uForm.validate(valid => {
  213. if (valid) {
  214. server.getAddShops(form).then(res =>{
  215. _this.$refs.uToast.show({
  216. title: '添加店铺信息成功!',
  217. type: 'default',
  218. })
  219. setTimeout(function() {
  220. uni.redirectTo({
  221. url: '/pages/login/index'
  222. });
  223. }, 2000);
  224. })
  225. } else {
  226. }
  227. });
  228. }else{
  229. form.shopsId = _this.userInfo.nickName;
  230. this.$refs.uForm.validate(valid => {
  231. if (valid) {
  232. server.getIndexData(form).then(res =>{
  233. _this.$refs.uToast.show({
  234. title: '修改店铺信息成功!',
  235. type: 'default',
  236. })
  237. setTimeout(function() {
  238. uni.navigateBack({
  239. delta: 1
  240. });
  241. }, 2000);
  242. })
  243. } else {
  244. }
  245. });
  246. }
  247. },
  248. getLocation() {
  249. let that = this;
  250. that.amapPulgin.getRegeo({
  251. success: res => {
  252. console.log('当前定位', res);
  253. that.addressName = `${res[0].regeocodeData.addressComponent.city}`
  254. // uni.hideLoading();
  255. },
  256. fail: err => {
  257. console.log(err)
  258. }
  259. })
  260. },
  261. chooseLocation(e) {
  262. uni.chooseLocation({
  263. success: (res) => {
  264. console.log(res)
  265. this.form.shopsAddress = res.name
  266. this.form.shopsLat = res.latitude
  267. this.form.shopsLng = res.longitude
  268. // let result = res.address.substring(0, res.address.indexOf('市'))
  269. // if(result.indexOf('省') != -1){
  270. // this.form.address = result.match(/省(\S*)/)[1];
  271. // }else{
  272. // this.form.address = result
  273. // }
  274. }
  275. })
  276. }
  277. }
  278. }
  279. </script>
  280. <style lang="scss" scoped>
  281. /deep/ .u-list-item{
  282. margin: 0rpx 0rpx 0rpx 16rpx!important;
  283. }
  284. /deep/ .u-icon__icon{
  285. position: relative;
  286. // color: #2E4F1C!important;
  287. color: #FFFFFF!important;
  288. }
  289. /deep/ .u-form-item__message{
  290. padding-right: 0rpx!important;
  291. text-align: right;
  292. }
  293. /deep/ .u-input__input{
  294. color: #2E4F1C!important;
  295. font-size: 28rpx;
  296. font-family: PingFangSC-Regular, PingFang SC;
  297. font-weight: 400;
  298. text-align: right;
  299. }
  300. /deep/ .u-border, .u-border-bottom, .u-border-left, .u-border-right, .u-border-top, .u-border-top-bottom{
  301. }
  302. /deep/ .u-form-item{
  303. display: -webkit-box;
  304. display: -webkit-flex;
  305. display: flex;
  306. -webkit-box-orient: horizontal;
  307. -webkit-box-direction: normal;
  308. -webkit-flex-direction: row;
  309. flex-direction: row;
  310. box-sizing: border-box;
  311. line-height: 96rpx;
  312. -webkit-flex-direction: column;
  313. flex-direction: column;
  314. background: rgba(46, 79, 28, 0.13);
  315. border-radius: 24rpx;
  316. margin-bottom: 40rpx;
  317. padding-left: 30rpx!important;
  318. padding-right: 30rpx!important;
  319. }
  320. .main{
  321. width: 100%;
  322. height: auto;
  323. min-height: 100vh;
  324. padding: 60rpx 30rpx 30rpx;
  325. .store-dis{
  326. display: flex;
  327. margin-bottom: 30rpx;
  328. .store-address{
  329. width: 580rpx;
  330. padding: 16rpx 30rpx;
  331. background: rgba(46, 79, 28, 0.13);
  332. border-radius: 16rpx 0rpx 0rpx 16rpx;
  333. .select-address{
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. }
  338. }
  339. .map-icon{
  340. width: 110rpx;
  341. background: #2E4F1C;
  342. text-align: center;
  343. border-radius: 0rpx 16rpx 16rpx 0rpx;
  344. padding-top: 31rpx;
  345. .icon-img{
  346. width: 42rpx;
  347. height: 42rpx;
  348. }
  349. }
  350. }
  351. .form-upload{
  352. width: 100%;
  353. height: 300rpx;
  354. background: rgba(46, 79, 28, 0.13);
  355. border-radius: 16rpx;
  356. padding-left: 30rpx;
  357. .upload-title{
  358. height: 100rpx;
  359. line-height: 100rpx;
  360. }
  361. }
  362. .form-submit{
  363. margin: 60rpx auto;
  364. width: 570rpx;
  365. height: 96rpx;
  366. line-height: 96rpx;
  367. background: #2E4F1C;
  368. border-radius: 49rpx;
  369. font-size: 36rpx;
  370. text-align: center;
  371. font-family: PingFangSC-Medium, PingFang SC;
  372. font-weight: 500;
  373. color: #fff;
  374. }
  375. }
  376. </style>