storeMessage.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="content">
  3. <view class="item">
  4. <view class="item-tit">店铺名称</view>
  5. <input type="text" v-model="store.name" placeholder="请输入店铺名称" />
  6. </view>
  7. <view class="item">
  8. <view class="item-tit">商家电话</view>
  9. <input type="number" v-model="store.phone" placeholder="请输入商家电话" />
  10. </view>
  11. <view class="item" @click="getLocation" v-if="type == 'add'">
  12. <view class="item-tit">经纬度</view>
  13. <input type="text" v-model="store.latlng" placeholder="请选择经纬度" />
  14. </view>
  15. <view class="item" >
  16. <view class="item-tit">详细地址</view>
  17. <input type="text" v-model="store.detailed_address" placeholder="请输入详细地址" />
  18. </view>
  19. <view class="item">
  20. <view class="item-tit">营业时间</view>
  21. <picker mode="time" :value="bgtime" @change="bindBgtimeChange" class="picker">
  22. <view class="uni-input">{{ bgtime }}</view>
  23. </picker>
  24. <view class="line">至</view>
  25. <picker mode="time" :value="edtime" @change="bindEdtimeChange" class="picker prcker-t">
  26. <view class="uni-input">{{ edtime }}</view>
  27. </picker>
  28. </view>
  29. <view class="item">
  30. <view class="item-tit">商户简介</view>
  31. <textarea v-model="store.introduction" placeholder="请输入商家简介" />
  32. </view>
  33. <view class="item">
  34. <view class="item-tit">门户头像</view>
  35. <view class="up-wrapper">
  36. <image :src="store.image" mode="" v-if="store.image" @click.stop="upImg"></image>
  37. <image src="../../static/img/add.png" mode="" v-else @click.stop="upImg"></image>
  38. </view>
  39. </view>
  40. <view class="sub" @click="sub" v-if="type == 'edit'">确认修改</view>
  41. <view class="sub" @click="add" v-if="type == 'add'">提交</view>
  42. </view>
  43. </template>
  44. <script>
  45. import { upload, editStore } from '@/api/user.js';
  46. export default {
  47. data() {
  48. return {
  49. store: {
  50. name: '',
  51. phone: '',
  52. id: '',
  53. introduction: '',
  54. image: '',
  55. id: '',
  56. detailed_address: '',
  57. day_time: '',
  58. latlng: ''
  59. },
  60. bgtime: '',
  61. edtime: '',
  62. detailed_address: '',
  63. type: 'edit',
  64. };
  65. },
  66. onLoad(opt) {
  67. if(opt.type == 'edit') {
  68. this.store = JSON.parse(opt.item);
  69. console.log(this.store, 'this.store++++++++++++');
  70. let time = this.store.day_time.split(' - ');
  71. this.bgtime = time[0].substring(0, 5);
  72. this.edtime = time[1].substring(0, 5);
  73. }
  74. if(opt.type == 'add') {
  75. this.type = 'add'
  76. this.bgtime = '00:00'
  77. this.edtime = '00:00'
  78. }
  79. },
  80. methods: {
  81. // 选择当前位置
  82. getLocation() {
  83. console.log('选择当前位置');
  84. let obj = this;
  85. uni.chooseLocation({
  86. success: function(res) {
  87. // obj.addressData.area = res.name;
  88. console.log('位置名称:' + res.name);
  89. console.log('详细地址:' + res.address);
  90. console.log('纬度:' + res.latitude);
  91. console.log('经度:' + res.longitude);
  92. // obj.addressData.latitude = res.latitude;
  93. // obj.addressData.longitude = res.longitude;
  94. obj.$set(obj.store,'latlng',res.latitude + ',' + res.longitude)
  95. // obj.store.latlng = res.latitude + ',' + res.longitude
  96. }
  97. });
  98. },
  99. bindBgtimeChange(e) {
  100. console.log(e);
  101. this.bgtime = e.detail.value;
  102. },
  103. bindEdtimeChange(e) {
  104. console.log(e);
  105. this.edtime = e.detail.value;
  106. },
  107. indicatorStyle() {},
  108. // 修改logo
  109. upImg() {
  110. let obj = this;
  111. upload({
  112. filename: ''
  113. }).then(res => {
  114. console.log(res[0].url);
  115. obj.store.image = res[0].url;
  116. });
  117. },
  118. //提交
  119. sub() {
  120. let obj = this;
  121. let store = obj.store;
  122. if (store.name == '') {
  123. obj.$api.msg('请输入店铺名称');
  124. return;
  125. }
  126. if (store.phone == '') {
  127. obj.$api.msg('请输入店铺电话');
  128. return;
  129. }
  130. if (store.image == '') {
  131. obj.$api.msg('请选择店铺头像');
  132. return;
  133. }
  134. if (store.day_time == '') {
  135. obj.$api.msg('请输入营业时间');
  136. return;
  137. }
  138. if (store.introduction == '') {
  139. obj.$api.msg('请输入店铺简介');
  140. return;
  141. }
  142. if (store.detailed_address == '') {
  143. obj.$api.msg('请输入店铺地址');
  144. return;
  145. }
  146. uni.showLoading({
  147. title: '提交中...',
  148. mask: true
  149. });
  150. let day_time = obj.bgtime + ':00 - ' + obj.edtime + ':00';
  151. editStore({
  152. id: store.id,
  153. name: store.name,
  154. introduction: store.introduction,
  155. detailed_address: store.detailed_address,
  156. image: store.image,
  157. phone: store.phone,
  158. day_time: day_time,
  159. latlng: store.latitude + ',' + store.longitude,
  160. // is_show: 0
  161. })
  162. .then(res => {
  163. uni.hideLoading();
  164. uni.showToast({
  165. title: '提交成功',
  166. duration: 2000
  167. });
  168. obj.$api.prePage().refreshList();
  169. setTimeout(function() {
  170. uni.navigateBack();
  171. }, 800);
  172. })
  173. .catch(err => {
  174. uni.hideLoading();
  175. console.log(err);
  176. });
  177. },
  178. add() {
  179. let obj = this;
  180. let store = obj.store;
  181. if (store.name == '') {
  182. obj.$api.msg('请输入店铺名称');
  183. return;
  184. }
  185. if (store.phone == '') {
  186. obj.$api.msg('请输入店铺电话');
  187. return;
  188. }
  189. if (store.image == '') {
  190. obj.$api.msg('请选择店铺头像');
  191. return;
  192. }
  193. // if (store.day_time == '') {
  194. // obj.$api.msg('请输入营业时间');
  195. // return;
  196. // }
  197. if (store.introduction == '') {
  198. obj.$api.msg('请输入店铺简介');
  199. return;
  200. }
  201. if (store.detailed_address == '') {
  202. obj.$api.msg('请输入店铺地址');
  203. return;
  204. }
  205. let day_time = obj.bgtime + ':00 - ' + obj.edtime + ':00';
  206. editStore({
  207. id: 0,
  208. name: store.name,
  209. introduction: store.introduction,
  210. image: store.image,
  211. phone: store.phone,
  212. day_time: day_time,
  213. latlng: store.latlng,
  214. detailed_address: store.detailed_address,
  215. is_show: 0
  216. })
  217. .then(res => {
  218. uni.hideLoading();
  219. uni.showToast({
  220. title: '提交成功',
  221. duration: 2000
  222. });
  223. obj.$api.prePage().refreshList();
  224. setTimeout(function() {
  225. uni.navigateBack();
  226. }, 800);
  227. })
  228. .catch(err => {
  229. uni.hideLoading();
  230. console.log(err);
  231. });
  232. }
  233. }
  234. };
  235. </script>
  236. <style lang="scss" scoped>
  237. page {
  238. height: 100%;
  239. background-color: #f8f6f6;
  240. }
  241. .item {
  242. background-color: #fff !important;
  243. min-height: 100rpx;
  244. display: flex;
  245. width: 750px;
  246. border: 1px #f4f4f4 solid;
  247. .line {
  248. display: inline-block;
  249. line-height: 100rpx;
  250. }
  251. .item-tit {
  252. height: 100rpx;
  253. line-height: 100rpx;
  254. padding-left: 30rpx;
  255. width: 200rpx;
  256. font-size: 30rpx;
  257. font-family: PingFang SC;
  258. font-weight: 500;
  259. color: #666666;
  260. flex-shrink: 0;
  261. }
  262. input {
  263. width: 550rpx;
  264. height: 100rpx;
  265. line-height: 100rpx;
  266. font-size: 30rpx;
  267. font-family: PingFang SC;
  268. font-weight: 500;
  269. color: #333333;
  270. }
  271. textarea {
  272. width: 550rpx;
  273. height: 257rpx;
  274. padding-top: 25rpx;
  275. padding-right: 30rpx;
  276. line-height: 50rpx;
  277. font-size: 30rpx;
  278. font-family: PingFang SC;
  279. font-weight: 500;
  280. color: #333333;
  281. }
  282. .up-wrapper {
  283. height: 352rpx;
  284. width: 550rpx;
  285. position: relative;
  286. image {
  287. position: absolute;
  288. height: 160rpx;
  289. width: 160rpx;
  290. top: 0;
  291. bottom: 0;
  292. left: 94rpx;
  293. margin: auto;
  294. }
  295. }
  296. }
  297. .sub {
  298. width: 674rpx;
  299. height: 88rpx;
  300. background: #ff4c4c;
  301. border-radius: 44rpx;
  302. line-height: 88rpx;
  303. text-align: center;
  304. font-size: 36rpx;
  305. font-family: PingFang SC;
  306. font-weight: 500;
  307. color: #ffffff;
  308. position: absolute;
  309. bottom: 35rpx;
  310. left: 0;
  311. right: 0;
  312. margin: auto;
  313. }
  314. .picker {
  315. display: inline-block;
  316. padding-right: 40rpx;
  317. height: 100rpx;
  318. line-height: 100rpx;
  319. }
  320. .prcker-t {
  321. padding-left: 40rpx;
  322. }
  323. </style>