open-time.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. title: '保存中...'
  183. });
  184. this.detail.setting.time_list = this.list;
  185. let data = {
  186. name: this.detail.name,
  187. setting: JSON.stringify(this.detail.setting)
  188. };
  189. this.$request({
  190. url: this.$api.app_admin.setting,
  191. method: 'post',
  192. data: data,
  193. }).then(response => {
  194. if (response.code === 0) {
  195. uni.showToast({
  196. title: response.msg,
  197. icon: 'none',
  198. duration: 1000
  199. });
  200. setTimeout(function() {
  201. uni.navigateBack();
  202. }, 500)
  203. }
  204. })
  205. },
  206. },
  207. onLoad(options) {
  208. let that = this;
  209. let screenWidth = uni.getSystemInfoSync().windowWidth;
  210. let p = 375 / screenWidth;
  211. this.lineHeight = 72*p + 'rpx'
  212. this.indicatorStyle = 'height: 36px;font-size:14px;';
  213. this.$request({
  214. url: this.$api.app_admin.setting
  215. }).then(response => {
  216. this.detail = response.data.detail;
  217. })
  218. for(let i = 0;i < 60;i++) {
  219. if(i < 10) {
  220. i = '0' + i
  221. }
  222. if(i < 24) {
  223. this.hour.push(i)
  224. }
  225. this.minutes.push(i)
  226. }
  227. this.list = JSON.parse(options.time_list);
  228. if(this.list.length == 0) {
  229. let para = {
  230. value: ['','']
  231. }
  232. this.list.push(para)
  233. }
  234. uni.getSystemInfo({
  235. success: function (res) {
  236. 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) {
  237. that.iphone_x = true;
  238. }
  239. }
  240. })
  241. }
  242. }
  243. </script>
  244. <style scoped lang="scss">
  245. .attr {
  246. background-color: #fff;
  247. position: relative;
  248. padding-left: #{84rpx};
  249. padding-right: #{26rpx};
  250. .low-attr {
  251. position: absolute;
  252. z-index: 2;
  253. top: #{24rpx};
  254. height: #{40rpx};
  255. width: #{40rpx};
  256. left: #{24rpx};
  257. }
  258. .attr-item {
  259. height: #{88rpx};
  260. line-height: #{88rpx};
  261. border-top: #{2rpx} solid #e2e2e2;
  262. position: relative;
  263. font-size: #{28rpx};
  264. color: #353535;
  265. .placeholder-text {
  266. color: #e1e1e1;
  267. }
  268. .app-icon {
  269. width: #{12rpx};
  270. height: #{22rpx};
  271. }
  272. }
  273. &:first-of-type {
  274. .attr-item {
  275. border-top: 0;
  276. }
  277. }
  278. }
  279. .add-attr {
  280. height: #{120rpx};
  281. background-color: #fff;
  282. margin-top: #{20rpx};
  283. padding-top: #{24rpx};
  284. .add-attr-btn {
  285. height: #{72rpx};
  286. width: #{320rpx};
  287. border-radius: #{36rpx};
  288. border: #{1rpx} solid #446dfd;
  289. margin: 0 auto;
  290. color: #446dfd;
  291. font-size: #{26rpx};
  292. line-height: #{72rpx};
  293. image {
  294. height: #{28rpx};
  295. width: #{28rpx};
  296. margin-right: #{12rpx};
  297. margin-top: #{22rpx};
  298. }
  299. }
  300. }
  301. .add {
  302. position: fixed;
  303. bottom: 0;
  304. left: 0;
  305. height: #{120rpx};
  306. width: 100%;
  307. z-index: 15;
  308. background-color: #fff;
  309. view {
  310. width: #{702rpx};
  311. line-height: #{80rpx};
  312. height: #{80rpx};
  313. margin: #{20rpx} auto;
  314. border-radius: #{40rpx};
  315. background-color: #446dfd;
  316. color: #fff;
  317. font-size: #{32rpx};
  318. text-align: center;
  319. }
  320. }
  321. .add.iphone_x {
  322. height: #{170rpx};
  323. padding-bottom: #{50rpx};
  324. }
  325. .placeholder {
  326. height: #{120rpx};
  327. }
  328. .placeholder.iphone_x {
  329. height: #{170rpx};
  330. }
  331. .time-bg {
  332. background-color: rgba(0, 0, 0, 0.3);
  333. position: fixed;
  334. top: 0;
  335. left: 0;
  336. height: 100%;
  337. width: 100%;
  338. z-index: 100;
  339. .time-dialog {
  340. width: #{620rpx};
  341. border-radius: #{16rpx};
  342. margin: 0 auto;
  343. background-color: #fff;
  344. z-index: 20;
  345. .dialog-title {
  346. font-size: #{32rpx};
  347. color: #353535;
  348. width: #{620rpx};
  349. margin: #{32rpx} auto #{40rpx};
  350. text-align: center;
  351. }
  352. .time-area {
  353. margin-bottom: #{24rpx};
  354. padding: 0 #{32rpx};
  355. &.date-area {
  356. border-top: #{2rpx} solid #e2e2e2;
  357. padding: #{28rpx} #{32rpx};
  358. .dialog-choose-item {
  359. margin: #{12rpx} 0;
  360. }
  361. }
  362. .dialog-choose-item {
  363. margin: 0 12rpx;
  364. width: #{170rpx};
  365. height: #{68rpx};
  366. line-height: #{68rpx};
  367. text-align: center;
  368. border-radius: #{34rpx};
  369. border: #{2rpx} solid;
  370. font-size: #{28rpx};
  371. margin-bottom: #{16rpx};
  372. &.time-area-item {
  373. border-color: #ddd;
  374. color: #666;
  375. }
  376. }
  377. }
  378. .choose-time {
  379. position: relative;
  380. .time-title {
  381. margin-left: #{32rpx};
  382. color: #666;
  383. font-size: #{28rpx};
  384. margin-bottom: #{20rpx};
  385. }
  386. .year-1 {
  387. position: absolute;
  388. left: #{192rpx};
  389. top: #{146rpx};
  390. }
  391. .month-1 {
  392. position: absolute;
  393. left: #{380rpx};
  394. top: #{146rpx};
  395. }
  396. .day-1 {
  397. position: absolute;
  398. right: #{32rpx};
  399. top: #{146rpx};
  400. }
  401. .year-2 {
  402. position: absolute;
  403. left: #{192rpx};
  404. bottom: #{88rpx};
  405. }
  406. .month-2 {
  407. position: absolute;
  408. left: #{380rpx};
  409. bottom: #{88rpx};
  410. }
  411. .day-2 {
  412. position: absolute;
  413. right: #{32rpx};
  414. bottom: #{88rpx};
  415. }
  416. .picker-view {
  417. width: #{556rpx};
  418. height: #{216rpx};
  419. margin: 0 auto #{20rpx};
  420. text-align: center;
  421. view {
  422. line-height: #{68rpx};
  423. }
  424. }
  425. }
  426. .btn-area {
  427. height: #{88rpx};
  428. position: relative;
  429. border-top: #{2rpx} solid #e2e2e2;
  430. &.other-btn-area {
  431. margin-top: #{10rpx};
  432. }
  433. .line {
  434. height: #{32rpx};
  435. width: #{1rpx};
  436. background-color: #e2e2e2;
  437. position: absolute;
  438. top: #{28rpx};
  439. left: 0;
  440. right: 0;
  441. margin: 0 auto;
  442. }
  443. .time-submit-btn {
  444. height: #{88rpx};
  445. line-height: #{88rpx};
  446. font-size: #{32rpx};
  447. width: #{310rpx};
  448. text-align: center;
  449. }
  450. }
  451. }
  452. }
  453. </style>