open-time.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <app-layout>
  3. <view>
  4. <view @click="openTime(item, index)" class="attr" v-for="(item, index) in list" :key="index">
  5. <image @click.stop='toDelete(index)' class='low-attr' src='./../image/low.png'></image>
  6. <view class="attr-item main-between cross-center">
  7. <view v-if="item.value[0] && item.value[1]">{{item.value[0]}}-{{item.value[1]}}</view>
  8. <view v-else class="placeholder-text">请选择时间段</view>
  9. <image class="app-icon" src="../image/arrow-right.png"></image>
  10. </view>
  11. </view>
  12. </view>
  13. <view v-if="list.length < 3" class='add-attr' @click='add'>
  14. <view class='add-attr-btn main-center'>
  15. <image src='./../image/add.png'></image>
  16. <view>增加时间段</view>
  17. </view>
  18. </view>
  19. <view :class="['placeholder', `${iphone_x? 'iphone_x':''}`]"></view>
  20. <view :class="['add', `${iphone_x? 'iphone_x':''}`]">
  21. <view @click="save">保存</view>
  22. </view>
  23. <view @touchmove.stop.prevent="" class="time-bg cross-center" v-if="timeDialog">
  24. <view class="time-dialog">
  25. <view class="dialog-title">选择时间段</view>
  26. <view class="choose-time">
  27. <view class="time-title">起始时间</view>
  28. <view class="year-1">时</view>
  29. <view class="month-1">分</view>
  30. <view class="day-1">秒</view>
  31. <view class="year-2">时</view>
  32. <view class="month-2">分</view>
  33. <view class="day-2">秒</view>
  34. <picker-view :value="startVal" :indicator-style="indicatorStyle" class="picker-view" @change="startChange">
  35. <picker-view-column>
  36. <view v-for="(item,idx) in hour" :key="item"
  37. :class="[`${startVal[0] == idx ?`admin-m-text admin`: ''}`]"
  38. :style="{ color: startVal[0] == idx + 1 || startVal[0] == idx - 1 ? '#999999' : startVal[0] == idx + 2 || startVal[0] == idx - 2 ? '#cdcdcd': '' , lineHeight: lineHeight}">{{item}}</view>
  39. </picker-view-column>
  40. <picker-view-column>
  41. <view v-for="(item,idx) in minutes" :key="item"
  42. :class="[`${startVal[1] == idx ?`admin-m-text admin`: ''}`]"
  43. :style="{ color: startVal[1] == idx + 1 || startVal[1] == idx - 1 ? '#999999' : startVal[1] == idx + 2 || startVal[1] == idx - 2 ? '#cdcdcd': '' , lineHeight: lineHeight}">{{item}}</view>
  44. </picker-view-column>
  45. <picker-view-column>
  46. <view v-for="(item,idx) in minutes" :key="item"
  47. :class="[`${startVal[2] == idx ?`admin-m-text admin`: ''}`]"
  48. :style="{ color: startVal[2] == idx + 1 || startVal[2] == idx - 1 ? '#999999' : startVal[2] == idx + 2 || startVal[2] == idx - 2 ? '#cdcdcd': '' , lineHeight: lineHeight}">{{item}}</view>
  49. </picker-view-column>
  50. </picker-view>
  51. <view class="time-title">结束时间时间</view>
  52. <picker-view :value="endVal" :indicator-style="indicatorStyle" class="picker-view" @change="endChange">
  53. <picker-view-column>
  54. <view v-for="(item,idx) in hour" :key="item"
  55. :class="[`${endVal[0] == idx ?`admin-m-text admin`: ''}`]"
  56. :style="{ color: endVal[0] == idx + 1 || endVal[0] == idx - 1 ? '#999999' : endVal[0] == idx + 2 || endVal[0] == idx - 2 ? '#cdcdcd': '' , lineHeight: lineHeight}">{{item}}</view>
  57. </picker-view-column>
  58. <picker-view-column>
  59. <view v-for="(item,idx) in minutes" :key="item"
  60. :class="[`${endVal[1] == idx ?`admin-m-text admin`: ''}`]"
  61. :style="{ color: endVal[1] == idx + 1 || endVal[1] == idx - 1 ? '#999999' : endVal[1] == idx + 2 || endVal[1] == idx - 2 ? '#cdcdcd': '' , lineHeight: lineHeight}">{{item}}</view>
  62. </picker-view-column>
  63. <picker-view-column>
  64. <view v-for="(item,idx) in minutes" :key="item"
  65. :class="[`${endVal[2] == idx ?`admin-m-text admin`: ''}`]"
  66. :style="{ color: endVal[2] == idx + 1 || endVal[2] == idx - 1 ? '#999999' : endVal[2] == idx + 2 || endVal[2] == idx - 2 ? '#cdcdcd': '' , lineHeight: lineHeight}">{{item}}</view>
  67. </picker-view-column>
  68. </picker-view>
  69. </view>
  70. <view class="main-center btn-area">
  71. <view class="time-submit-btn" @click='cancel' style="color: #666;">取消</view>
  72. <view class="line"></view>
  73. <view class="time-submit-btn" style="color: #446dfd;" @click='submitTime'>确认</view>
  74. </view>
  75. </view>
  76. </view>
  77. </app-layout>
  78. </template>
  79. <script>
  80. import { mapState } from "vuex";
  81. export default {
  82. data() {
  83. return {
  84. lineHeight: '72rpx',
  85. iphone_x: false,
  86. list: [],
  87. detail: {},
  88. indicatorStyle: '',
  89. timeDialog: false,
  90. choose: 2,
  91. index: -1,
  92. hour: [],
  93. minutes: [],
  94. startVal: [0,0,0],
  95. endVal: [0,0,0],
  96. }
  97. },
  98. computed: {
  99. ...mapState({
  100. userInfo: state => state.user.info,
  101. adminImg: state => state.mallConfig.__wxapp_img.app_admin
  102. })
  103. },
  104. methods: {
  105. submitTime() {
  106. if(this.startVal[0] > this.endVal[0]) {
  107. uni.showToast({
  108. title: '结束时间不应早于开始时间',
  109. icon: 'none',
  110. duration: 1000
  111. })
  112. }else if(this.startVal[0] == this.endVal[0] && this.startVal[1] > this.endVal[1]) {
  113. uni.showToast({
  114. title: '结束时间不应早于开始时间',
  115. icon: 'none',
  116. duration: 1000
  117. })
  118. }else if(this.startVal[0] == this.endVal[0] && this.startVal[1] == this.endVal[1] && this.startVal[2] > this.endVal[2]) {
  119. uni.showToast({
  120. title: '结束时间不应早于开始时间',
  121. icon: 'none',
  122. duration: 1000
  123. })
  124. }else if(this.startVal[0] == this.endVal[0] && this.startVal[1] == this.endVal[1] && this.startVal[2] == this.endVal[2]) {
  125. uni.showToast({
  126. title: '结束时间不应等于开始时间',
  127. icon: 'none',
  128. duration: 1000
  129. })
  130. }else {
  131. this.list[this.index] = [];
  132. let start = this.hour[this.startVal[0]] + ':' + this.minutes[this.startVal[1]] + ':' + this.minutes[this.startVal[2]]
  133. let end = this.hour[this.endVal[0]] + ':' + this.minutes[this.endVal[1]] + ':' + this.minutes[this.endVal[2]]
  134. let para = {
  135. value : [start,end]
  136. }
  137. this.list[this.index] = para
  138. this.timeDialog = false;
  139. }
  140. },
  141. cancel() {
  142. this.timeDialog = false;
  143. this.index = -1;
  144. },
  145. openTime(item, index) {
  146. this.index = index;
  147. if(item.value[0]) {
  148. this.startVal = item.value[0].split(':').map(Number);
  149. }else {
  150. this.startVal = [0,0,0]
  151. }
  152. if(item.value[1]) {
  153. this.endVal = item.value[1].split(':').map(Number);
  154. }else {
  155. this.endVal = [0,0,0]
  156. }
  157. this.timeDialog = true;
  158. },
  159. startChange: function(e) {
  160. this.startVal = e.detail.value;
  161. },
  162. endChange: function(e) {
  163. this.endVal = e.detail.value;
  164. },
  165. add() {
  166. let para = {
  167. value: []
  168. }
  169. this.list.push(para);
  170. },
  171. toDelete(index) {
  172. this.list.splice(index,1);
  173. },
  174. save() {
  175. for(let item of this.list) {
  176. if(!item.value[0] || !item.value[1]) {
  177. uni.showToast({icon: 'none', title: '时间段请填写完整'});
  178. return false;
  179. }
  180. }
  181. uni.showLoading({
  182. mask: true,
  183. title: '保存中...'
  184. });
  185. this.detail.setting.time_list = this.list;
  186. let data = {
  187. name: this.detail.name,
  188. setting: JSON.stringify(this.detail.setting)
  189. };
  190. this.$request({
  191. url: this.$api.app_admin.setting,
  192. method: 'post',
  193. data: data,
  194. }).then(response => {
  195. if (response.code === 0) {
  196. uni.showToast({
  197. title: response.msg,
  198. icon: 'none',
  199. duration: 1000
  200. });
  201. setTimeout(function() {
  202. uni.navigateBack();
  203. }, 500)
  204. }
  205. })
  206. },
  207. },
  208. onLoad(options) { this.$commonLoad.onload(options);
  209. let that = this;
  210. let screenWidth = uni.getSystemInfoSync().windowWidth;
  211. let p = 375 / screenWidth;
  212. this.lineHeight = 72*p + 'rpx'
  213. this.indicatorStyle = 'height: 36px;font-size:14px;';
  214. this.$request({
  215. url: this.$api.app_admin.setting
  216. }).then(response => {
  217. this.detail = response.data.detail;
  218. })
  219. for(let i = 0;i < 60;i++) {
  220. if(i < 10) {
  221. i = '0' + i
  222. }
  223. if(i < 24) {
  224. this.hour.push(i)
  225. }
  226. this.minutes.push(i)
  227. }
  228. this.list = JSON.parse(options.time_list);
  229. if(this.list.length == 0) {
  230. let para = {
  231. value: ['','']
  232. }
  233. this.list.push(para)
  234. }
  235. uni.getSystemInfo({
  236. success: function (res) {
  237. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  238. that.iphone_x = true;
  239. }
  240. }
  241. })
  242. }
  243. }
  244. </script>
  245. <style scoped lang="scss">
  246. .attr {
  247. background-color: #fff;
  248. position: relative;
  249. padding-left: #{84rpx};
  250. padding-right: #{26rpx};
  251. .low-attr {
  252. position: absolute;
  253. z-index: 2;
  254. top: #{24rpx};
  255. height: #{40rpx};
  256. width: #{40rpx};
  257. left: #{24rpx};
  258. }
  259. .attr-item {
  260. height: #{88rpx};
  261. line-height: #{88rpx};
  262. border-top: #{2rpx} solid #e2e2e2;
  263. position: relative;
  264. font-size: #{28rpx};
  265. color: #353535;
  266. .placeholder-text {
  267. color: #e1e1e1;
  268. }
  269. .app-icon {
  270. width: #{12rpx};
  271. height: #{22rpx};
  272. }
  273. }
  274. &:first-of-type {
  275. .attr-item {
  276. border-top: 0;
  277. }
  278. }
  279. }
  280. .add-attr {
  281. height: #{120rpx};
  282. background-color: #fff;
  283. margin-top: #{20rpx};
  284. padding-top: #{24rpx};
  285. .add-attr-btn {
  286. height: #{72rpx};
  287. width: #{320rpx};
  288. border-radius: #{36rpx};
  289. border: #{1rpx} solid #446dfd;
  290. margin: 0 auto;
  291. color: #446dfd;
  292. font-size: #{26rpx};
  293. line-height: #{72rpx};
  294. image {
  295. height: #{28rpx};
  296. width: #{28rpx};
  297. margin-right: #{12rpx};
  298. margin-top: #{22rpx};
  299. }
  300. }
  301. }
  302. .add {
  303. position: fixed;
  304. bottom: 0;
  305. left: 0;
  306. height: #{120rpx};
  307. width: 100%;
  308. z-index: 15;
  309. background-color: #fff;
  310. view {
  311. width: #{702rpx};
  312. line-height: #{80rpx};
  313. height: #{80rpx};
  314. margin: #{20rpx} auto;
  315. border-radius: #{40rpx};
  316. background-color: #446dfd;
  317. color: #fff;
  318. font-size: #{32rpx};
  319. text-align: center;
  320. }
  321. }
  322. .add.iphone_x {
  323. height: #{170rpx};
  324. padding-bottom: #{50rpx};
  325. }
  326. .placeholder {
  327. height: #{120rpx};
  328. }
  329. .placeholder.iphone_x {
  330. height: #{170rpx};
  331. }
  332. .time-bg {
  333. background-color: rgba(0, 0, 0, 0.3);
  334. position: fixed;
  335. top: 0;
  336. left: 0;
  337. height: 100%;
  338. width: 100%;
  339. z-index: 100;
  340. .time-dialog {
  341. width: #{620rpx};
  342. border-radius: #{16rpx};
  343. margin: 0 auto;
  344. background-color: #fff;
  345. z-index: 20;
  346. .dialog-title {
  347. font-size: #{32rpx};
  348. color: #353535;
  349. width: #{620rpx};
  350. margin: #{32rpx} auto #{40rpx};
  351. text-align: center;
  352. }
  353. .time-area {
  354. margin-bottom: #{24rpx};
  355. padding: 0 #{32rpx};
  356. &.date-area {
  357. border-top: #{2rpx} solid #e2e2e2;
  358. padding: #{28rpx} #{32rpx};
  359. .dialog-choose-item {
  360. margin: #{12rpx} 0;
  361. }
  362. }
  363. .dialog-choose-item {
  364. margin: 0 12rpx;
  365. width: #{170rpx};
  366. height: #{68rpx};
  367. line-height: #{68rpx};
  368. text-align: center;
  369. border-radius: #{34rpx};
  370. border: #{2rpx} solid;
  371. font-size: #{28rpx};
  372. margin-bottom: #{16rpx};
  373. &.time-area-item {
  374. border-color: #ddd;
  375. color: #666;
  376. }
  377. }
  378. }
  379. .choose-time {
  380. position: relative;
  381. .time-title {
  382. margin-left: #{32rpx};
  383. color: #666;
  384. font-size: #{28rpx};
  385. margin-bottom: #{20rpx};
  386. }
  387. .year-1 {
  388. position: absolute;
  389. left: #{192rpx};
  390. top: #{146rpx};
  391. }
  392. .month-1 {
  393. position: absolute;
  394. left: #{380rpx};
  395. top: #{146rpx};
  396. }
  397. .day-1 {
  398. position: absolute;
  399. right: #{32rpx};
  400. top: #{146rpx};
  401. }
  402. .year-2 {
  403. position: absolute;
  404. left: #{192rpx};
  405. bottom: #{88rpx};
  406. }
  407. .month-2 {
  408. position: absolute;
  409. left: #{380rpx};
  410. bottom: #{88rpx};
  411. }
  412. .day-2 {
  413. position: absolute;
  414. right: #{32rpx};
  415. bottom: #{88rpx};
  416. }
  417. .picker-view {
  418. width: #{556rpx};
  419. height: #{216rpx};
  420. margin: 0 auto #{20rpx};
  421. text-align: center;
  422. view {
  423. line-height: #{68rpx};
  424. }
  425. }
  426. }
  427. .btn-area {
  428. height: #{88rpx};
  429. position: relative;
  430. border-top: #{2rpx} solid #e2e2e2;
  431. &.other-btn-area {
  432. margin-top: #{10rpx};
  433. }
  434. .line {
  435. height: #{32rpx};
  436. width: #{1rpx};
  437. background-color: #e2e2e2;
  438. position: absolute;
  439. top: #{28rpx};
  440. left: 0;
  441. right: 0;
  442. margin: 0 auto;
  443. }
  444. .time-submit-btn {
  445. height: #{88rpx};
  446. line-height: #{88rpx};
  447. font-size: #{32rpx};
  448. width: #{310rpx};
  449. text-align: center;
  450. }
  451. }
  452. }
  453. }
  454. </style>