index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <view class="wrap">
  5. <view class="form_wrap">
  6. <view class="form_item">
  7. <view class="item_l">开始时间</view>
  8. <view class="item_r">
  9. <van-field :value="begin_at" readonly placeholder="请选择开始时间" :border="false" @tap.native="beginTimeFun" />
  10. </view>
  11. </view>
  12. <view class="form_item">
  13. <view class="item_l">结束时间</view>
  14. <view class="item_r">
  15. <van-field :value="end_at" readonly placeholder="请选择结束时间" :border="false" @tap.native="endTimeFun" />
  16. </view>
  17. </view>
  18. <view class="form_item">
  19. <view class="item_l">可用状态</view>
  20. <view class="item_r">
  21. <van-switch :checked="status" size="40rpx" :active-value="1" :inactive-value="0" active-color="#295C56" inactive-color="#cccccc" @change="onChangeStatus" />
  22. </view>
  23. </view>
  24. </view>
  25. <view class="btn_wrap">
  26. <view class="btn" @tap="bindTijiao">提交</view>
  27. </view>
  28. </view>
  29. <!-- 开店时间 -->
  30. <van-popup :show="showBegin" position="bottom" @close="closeBeginTimePop">
  31. <van-datetime-picker type="time" title="选择开店时间" :value="currentBegin" @confirm="confirmBeginTime" @cancel="closeBeginTimePop" />
  32. </van-popup>
  33. <!-- 闭店时间 -->
  34. <van-popup :show="showEnd" position="bottom" @close="closeEndTimePop">
  35. <van-datetime-picker type="time" title="选择闭店时间" :value="currentEnd" @confirm="confirmEndTime" @cancel="closeEndTimePop" />
  36. </van-popup>
  37. <!-- loading -->
  38. <!-- <van-overlay show="{{ loading }}" z-index="100">
  39. <van-loading custom-class="custom_loading" />
  40. </van-overlay> -->
  41. </view>
  42. </template>
  43. <script>
  44. // index.js
  45. let myPro = require('../../../../utils/wxRequest.js');
  46. let util = require('../../../../utils/util.js');
  47. export default {
  48. data() {
  49. return {
  50. begin_at: null,
  51. end_at: null,
  52. status: 1,
  53. // 1正常 0禁用
  54. showBegin: false,
  55. showEnd: false,
  56. currentBegin: null,
  57. currentEnd: null,
  58. id: null
  59. };
  60. },
  61. onLoad: function (options) {
  62. // Do some initialize when page load.
  63. let that = this;
  64. if (options.id) {
  65. that.getDetail(options.id);
  66. that.setData({
  67. id: options.id
  68. });
  69. }
  70. },
  71. onShow: function () {
  72. // Do something when page show.
  73. let that = this;
  74. },
  75. onReady: function () {
  76. // Do something when page ready.
  77. },
  78. onHide: function () {
  79. // Do something when page hide.
  80. },
  81. onUnload: function () {
  82. // Do something when page close.
  83. },
  84. onPullDownRefresh: function () {
  85. // Do something when pull down.
  86. },
  87. onReachBottom: function () {
  88. // Do something when page reach bottom.
  89. },
  90. onShareAppMessage: function () {
  91. // return custom share data when user share.
  92. },
  93. onPageScroll: function () {
  94. // Do something when page scroll
  95. },
  96. onResize: function () {
  97. // Do something when page resize
  98. },
  99. methods: {
  100. // 详情
  101. getDetail(id) {
  102. let that = this;
  103. let params = {
  104. id: id
  105. };
  106. myPro
  107. .wxRequest('store/businessHours/detail', 'GET', params)
  108. .then((res) => {
  109. that.setData({
  110. begin_at: res.result.begin_at,
  111. end_at: res.result.end_at,
  112. status: res.result.status,
  113. currentBegin: res.result.begin_at,
  114. currentEnd: res.result.end_at
  115. });
  116. })
  117. .catch((err) => {
  118. console.log('报错信息', err);
  119. uni.showToast({
  120. title: err,
  121. icon: 'none'
  122. });
  123. });
  124. },
  125. // 开店时间
  126. beginTimeFun() {
  127. let that = this;
  128. that.setData({
  129. showBegin: true
  130. });
  131. },
  132. confirmBeginTime(event) {
  133. // console.log('开始时间',event)
  134. let that = this;
  135. that.setData({
  136. begin_at: event.detail,
  137. showBegin: false
  138. });
  139. },
  140. closeBeginTimePop() {
  141. let that = this;
  142. that.setData({
  143. showBegin: false
  144. });
  145. },
  146. // 闭店时间
  147. endTimeFun() {
  148. let that = this;
  149. that.setData({
  150. showEnd: true
  151. });
  152. },
  153. confirmEndTime(event) {
  154. // console.log('闭店时间',event)
  155. let that = this;
  156. that.setData({
  157. end_at: event.detail,
  158. showEnd: false
  159. });
  160. },
  161. closeEndTimePop() {
  162. let that = this;
  163. that.setData({
  164. showEnd: false
  165. });
  166. },
  167. // 状态
  168. onChangeStatus(event) {
  169. let that = this;
  170. that.setData({
  171. status: event.detail
  172. });
  173. },
  174. // 提交
  175. bindTijiao() {
  176. let that = this;
  177. if (!that.begin_at || !that.end_at) {
  178. uni.showToast({
  179. title: '请检查信息是否完整',
  180. icon: 'none'
  181. });
  182. return;
  183. } else {
  184. let params = {
  185. begin_at: that.begin_at,
  186. end_at: that.end_at,
  187. status: that.status
  188. }; // 编辑
  189. if (that.id) {
  190. params.id = that.id;
  191. myPro
  192. .wxRequest('store/businessHours/edit', 'POST', params)
  193. .then((res) => {
  194. uni.showToast({
  195. title: res.msg,
  196. icon: 'none'
  197. });
  198. uni.navigateBack();
  199. })
  200. .catch((err) => {
  201. console.log('报错信息', err);
  202. uni.showToast({
  203. title: err,
  204. icon: 'none'
  205. });
  206. });
  207. } else {
  208. // 新增
  209. myPro
  210. .wxRequest('store/businessHours/create', 'POST', params)
  211. .then((res) => {
  212. uni.showToast({
  213. title: res.msg,
  214. icon: 'none'
  215. });
  216. uni.navigateBack();
  217. })
  218. .catch((err) => {
  219. console.log('报错信息', err);
  220. uni.showToast({
  221. title: err,
  222. icon: 'none'
  223. });
  224. });
  225. }
  226. }
  227. }
  228. }
  229. };
  230. </script>
  231. <style>
  232. /**index.wxss**/
  233. .wrap {
  234. width: 690rpx;
  235. /* background:rgba(255,255,255,1);
  236. box-shadow:0rpx 0rpx 21rpx 0rpx rgba(0, 0, 0, 0.09); */
  237. margin: 0 auto;
  238. }
  239. .form_wrap {
  240. padding: 0 30rpx;
  241. }
  242. .form_item {
  243. font-size: 28rpx;
  244. color: #333333;
  245. min-height: 98rpx;
  246. display: flex;
  247. align-items: center;
  248. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  249. }
  250. .form_item .item_l {
  251. width: 150rpx;
  252. }
  253. .form_item .item_r {
  254. flex: 1;
  255. display: flex;
  256. align-items: center;
  257. justify-content: space-between;
  258. }
  259. .form_item van-field {
  260. width: 100%;
  261. }
  262. .form_item .van-cell {
  263. padding: 0 !important;
  264. }
  265. .btn_wrap {
  266. margin-top: 30rpx;
  267. }
  268. .btn_wrap .btn {
  269. width: 320rpx;
  270. height: 80rpx;
  271. margin: 0 auto;
  272. color: #fff;
  273. background: #295c56;
  274. border-radius: 40rpx;
  275. display: flex;
  276. align-items: center;
  277. justify-content: center;
  278. font-size: 28rpx;
  279. }
  280. </style>