fillTable.vue 7.1 KB

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