search.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <app-layout>
  3. <view class="search-mode">
  4. <view class="search-input">
  5. <input type="text"confirm-type='search' v-model='keyword' placeholder-style='color:#999999;font-size:13px;' placeholder='请输入订单号/商品名称/收货人姓名/联系电话'>
  6. <image v-if="keyword.length > 0" @click="clearSearch" class="search-clear" src="/static/image/icon/clear.png"></image>
  7. </view>
  8. <view class="search-time dir-left-nowrap cross-center">
  9. <view class="search-time-label">下单时间</view>
  10. <view @click="dialog=true;type=1" class="search-time-item main-between cross-center" :class="{'placeholder': !start}">
  11. <view>{{start != '' ? start : '请选择开始时间'}}</view>
  12. <image v-if="start" @click.stop="clearTime(1)" class="time-clear" src="/static/image/icon/clear.png"></image>
  13. </view>
  14. <view class="search-time-line"></view>
  15. <view @click="dialog=true;type=2" class="search-time-item main-between cross-center" :class="{'placeholder': !end}">
  16. <view>{{end != '' ? end : '请选择结束时间'}}</view>
  17. <image v-if="end" @click.stop="clearTime(2)" class="time-clear" src="/static/image/icon/clear.png"></image>
  18. </view>
  19. </view>
  20. <view>
  21. <app-iphone-x>
  22. <view class="search-menu main-center" slot="empty-area">
  23. <view @click="reset" class="box-grow-1 search-menu-item">重置</view>
  24. <view @click="toSearch" style="color: #fff" class="box-grow-1 search-menu-item" :class="getTheme + '-m-back ' + getTheme">搜索</view>
  25. </view>
  26. </app-iphone-x>
  27. </view>
  28. </view>
  29. <view class="dialog" v-if="dialog" @click="dialog=!dialog">
  30. <view class="picker-list" @click.stop="">
  31. <view class="main-between picker-header">
  32. <view @click="dialog=false">取消</view>
  33. <view @click="submitTime">确定</view>
  34. </view>
  35. <picker-view :value="timeVal" :indicator-style="indicatorStyle" @change="timeChange">
  36. <picker-view-column>
  37. <view v-for="(item,idx) in years" :key="item"
  38. :class="[`picker-view`,{
  39. 'sure-color': timeVal[0] === idx,
  40. 'cardinal-color': timeVal[0] === idx + 1 || timeVal[0] === idx - 1,
  41. 'even-color': timeVal[0] === idx + 2 || timeVal[0] === idx - 2,
  42. }]"><text>{{item}}</text>年</view>
  43. </picker-view-column>
  44. <picker-view-column>
  45. <view v-for="(item,idx) in months" :key="item"
  46. :class="[`picker-view`,{
  47. 'sure-color': timeVal[1] === idx,
  48. 'cardinal-color': timeVal[1] === idx + 1 || timeVal[1] === idx - 1,
  49. 'even-color': timeVal[1] === idx + 2 || timeVal[1] === idx - 2,
  50. }]"><text>{{item}}</text>月</view>
  51. </picker-view-column>
  52. <picker-view-column>
  53. <view v-for="(item,idx) in days" :key="item"
  54. :class="[`picker-view`,{
  55. 'sure-color': timeVal[2] === idx,
  56. 'cardinal-color': timeVal[2] === idx + 1 || timeVal[2] === idx - 1,
  57. 'even-color': timeVal[2] === idx + 2 || timeVal[2] === idx - 2,
  58. }]"><text>{{item}}</text>日</view>
  59. </picker-view-column>
  60. </picker-view>
  61. </view>
  62. </view>
  63. </app-layout>
  64. </template>
  65. <script>
  66. import { mapState,mapGetters } from "vuex";
  67. import appIphoneX from '../../../components/basic-component/app-iphone-x/app-iphone-x.vue';
  68. const date = new Date()
  69. const years = []
  70. const months = []
  71. const bigDays = []
  72. const smallDays = []
  73. const secDays = []
  74. const otherDays = []
  75. for (let i = 2015; i <= date.getFullYear(); i++) {
  76. years.push(i)
  77. }
  78. for (let i = 1; i <= 12; i++) {
  79. months.push(i)
  80. }
  81. for (let i = 1; i <= 31; i++) {
  82. bigDays.push(i)
  83. }
  84. for (let i = 1; i <= 30; i++) {
  85. smallDays.push(i)
  86. }
  87. for (let i = 1; i <= 28; i++) {
  88. secDays.push(i)
  89. }
  90. for (let i = 1; i <= 29; i++) {
  91. otherDays.push(i)
  92. }
  93. export default {
  94. data() {
  95. return {
  96. keyword: '',
  97. timeVal: [],
  98. time: '',
  99. start: '',
  100. end: '',
  101. years: years,
  102. months: months,
  103. days: bigDays,
  104. bigDays: bigDays,
  105. smallDays: smallDays,
  106. secDays: secDays,
  107. otherDays: otherDays,
  108. today: '',
  109. type: 1,
  110. dialog: false
  111. }
  112. },
  113. components: {
  114. 'app-iphone-x': appIphoneX,
  115. },
  116. computed: {
  117. ...mapGetters('mallConfig', {
  118. getTheme: 'getTheme',
  119. }),
  120. },
  121. methods: {
  122. clearSearch() {
  123. this.keyword = '';
  124. },
  125. clearTime(type) {
  126. if(type == 1) {
  127. this.start = '';
  128. }else {
  129. this.end = ''
  130. }
  131. },
  132. toSearch() {
  133. let search = {
  134. keyword: this.keyword,
  135. dateArr: []
  136. }
  137. if(this.start || this.end) {
  138. search.dateArr = [this.start,this.end]
  139. }
  140. uni.setStorage({
  141. key: "search",
  142. data: search,
  143. success(res) {
  144. uni.hideLoading();
  145. setTimeout(function() {
  146. uni.navigateBack();
  147. }, 500)
  148. },
  149. fail(res) {
  150. uni.hideLoading();
  151. uni.showToast({
  152. title: res.errMsg,
  153. icon: 'none',
  154. duration: 1000
  155. });
  156. }
  157. })
  158. },
  159. reset() {
  160. this.keyword = '';
  161. this.start = '';
  162. this.end = '';
  163. },
  164. submitTime() {
  165. let start,end;
  166. let time = new Date(this.time).getTime();
  167. if(this.type == 1) {
  168. if(this.end) {
  169. end = new Date(this.end).getTime();
  170. if(time > end) {
  171. uni.showToast({
  172. title: '时间区间选择有误,请确认选择的时间',
  173. icon: 'none',
  174. duration: 1000
  175. });
  176. return false
  177. }
  178. }
  179. this.start = this.time;
  180. }else {
  181. if(this.start) {
  182. start = new Date(this.start).getTime();
  183. if(time < start) {
  184. uni.showToast({
  185. title: '时间区间选择有误,请确认选择的时间',
  186. icon: 'none',
  187. duration: 1000
  188. });
  189. return false
  190. }
  191. }
  192. this.end = this.time
  193. }
  194. this.dialog = false;
  195. },
  196. timeChange: function(e) {
  197. const val = e.detail.value;
  198. this.timeVal = e.detail.value;
  199. let years = this.years;
  200. let year = this.years[val[0]];
  201. let month = this.months[val[1]];
  202. if(month == 2) {
  203. if(year%4 == 0 && year %400 != 0) {
  204. this.days = this.otherDays
  205. }else {
  206. this.days = this.secDays
  207. }
  208. }else if((month < 8 && month%2 == 1) || (month > 7 && month%2 == 0)) {
  209. this.days = this.bigDays
  210. }else {
  211. this.days = this.smallDays
  212. }
  213. let day = this.days[val[2]];
  214. if (month >= 1 && month <= 9) {
  215. month = "0" + month;
  216. }
  217. if (day >= 1 && day <= 9) {
  218. day = "0" + day;
  219. }
  220. this.time = year + '-' + month + '-' + day;
  221. },
  222. },
  223. onLoad(options) {
  224. let that = this;
  225. that.indicatorStyle = 'height: 36px;color:'+ that.color + ';font-size:14px;';
  226. var myDate = new Date();
  227. // 今天
  228. let year = myDate.getFullYear();
  229. let month = myDate.getMonth() + 1;
  230. if (month >= 1 && month <= 9) {
  231. month = "0" + month;
  232. }
  233. let now = myDate.getDate();
  234. that.today = year + "-" + month + "-" + now;
  235. that.time = that.today;
  236. for(let i in that.years) {
  237. if (that.today.substring(0, 4) == that.years[i]) {
  238. that.timeVal[0] = +i
  239. }
  240. }
  241. let chooseMonth = that.today.substring(5, 7);
  242. for(let i in that.months) {
  243. if (that.today.substring(5, 7) == that.months[i]) {
  244. that.timeVal[1] = +i
  245. }
  246. }
  247. if(chooseMonth == 2) {
  248. if(year%4 == 0 && year %400 != 0) {
  249. this.days = this.otherDays
  250. }else {
  251. this.days = this.secDays
  252. }
  253. }else if((chooseMonth < 8 && chooseMonth%2 == 1) || (chooseMonth > 7 && chooseMonth%2 == 0)) {
  254. this.days = this.bigDays
  255. }else {
  256. this.days = this.smallDays
  257. }
  258. for(let i in that.days) {
  259. if (that.today.substring(8, 10) == that.days[i]) {
  260. that.timeVal[2] = +i
  261. }
  262. }
  263. uni.getStorage({
  264. key: 'search',
  265. success(res) {
  266. that.keyword = res.data.keyword;
  267. if(res.data.dateArr[0]) {
  268. that.start = res.data.dateArr[0];
  269. }
  270. if(res.data.dateArr[1]) {
  271. that.end = res.data.dateArr[1];
  272. }
  273. }
  274. });
  275. }
  276. }
  277. </script>
  278. <style scoped lang="scss">
  279. .search-mode {
  280. position: fixed;
  281. z-index: 233;
  282. top: 0;
  283. left: 0;
  284. right: 0;
  285. width: 100%;
  286. height: 100%;
  287. background-color: #f7f7f7;
  288. .search-input {
  289. height: #{100rpx};
  290. background-color: #fff;
  291. padding: #{19rpx} #{18rpx};
  292. input {
  293. padding: 0 #{30rpx};
  294. background-color: #fff;
  295. border-radius: #{31rpx};
  296. height: #{62rpx};
  297. font-size: #{26rpx};
  298. color: #353535;
  299. width: 100%;
  300. background-color: #f7f7f7;
  301. }
  302. .search-clear {
  303. position: absolute;
  304. right: #{35rpx};
  305. top: #{35rpx};
  306. width: #{30rpx};
  307. height: #{30rpx};
  308. z-index: 235;
  309. }
  310. }
  311. .search-time {
  312. margin-top: #{20rpx};
  313. padding-left: #{24rpx};
  314. height: #{100rpx};
  315. background-color: #fff;
  316. .search-time-label {
  317. font-size: #{32rpx};
  318. color: #353535;
  319. margin-right: #{28rpx};
  320. }
  321. .search-time-item {
  322. height: #{48rpx};
  323. line-height: #{44rpx};
  324. width: #{250rpx};
  325. font-size: #{24rpx};
  326. color: #353535;
  327. border: #{2rpx} solid #e2e2e2;
  328. padding: 0 #{10rpx} 0 #{16rpx};
  329. border-radius: #{8rpx};
  330. &.placeholder {
  331. color: #999999;
  332. }
  333. .time-clear {
  334. width: #{30rpx};
  335. height: #{30rpx};
  336. margin-right: #{10rpx};
  337. }
  338. }
  339. .search-time-line {
  340. margin: 0 #{12rpx};
  341. width: #{24rpx};
  342. height: #{2rpx};
  343. background-color: #e2e2e2;
  344. }
  345. }
  346. .search-menu {
  347. height: #{110rpx};
  348. width: 100%;
  349. background-color: #fff;
  350. .search-menu-item {
  351. line-height: #{110rpx};
  352. text-align: center;
  353. font-size: #{32rpx};
  354. color: #353535;
  355. }
  356. }
  357. }
  358. .dialog {
  359. position: fixed;
  360. height: 100%;
  361. width: 100%;
  362. bottom: 0;
  363. left: 0;
  364. z-index: 240;
  365. background-color: rgba(0, 0, 0, .3);
  366. .picker-list {
  367. background-color: #fff;
  368. position: fixed;
  369. bottom: 0;
  370. left: 0;
  371. width: 100%;
  372. z-index: 242;
  373. .picker-header {
  374. padding: 0 #{24rpx};
  375. color: #446dfd;
  376. font-size: #{32rpx};
  377. line-height: #{100rpx};
  378. height: #{96rpx};
  379. border-bottom: #{2rpx} solid #e2e2e2;
  380. &>view:first-of-type {
  381. color: #353535;
  382. }
  383. }
  384. picker-view {
  385. width: 100%;
  386. height: #{440rpx};
  387. picker-view-column:first-of-type {
  388. flex: 1.75
  389. }
  390. }
  391. .picker-view {
  392. line-height: #{72rpx};
  393. text-align:center;
  394. font-size: #{32rpx};
  395. &.sure-color {
  396. font-size: #{36rpx};
  397. color: #353535;
  398. font-weight: 600;
  399. }
  400. &.cardinal-color {
  401. color: #999999;
  402. }
  403. &.even-color {
  404. color: #cdcdcd;
  405. }
  406. }
  407. }
  408. }
  409. </style>