orderSearch.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <!-- 订单中心 - 搜索弹窗 -->
  3. <div class="orderSearch flex-col">
  4. <van-popup v-model:show="sheetShow" round class="orderSearchPopup">
  5. <div class="content">
  6. <van-form @submit="onSubmit">
  7. <van-field v-model="userName" name="userName" :label="$t('orderCenter.userNameLabel')"
  8. :placeholder="$t('orderCenter.userNamePlaceholder')" />
  9. <van-field v-model="sn" name="sn" :label="$t('orderCenter.orderNo')"
  10. :placeholder="$t('orderCenter.orderNoPlaceholder')" />
  11. <van-field v-model="trxNo" name="trxNo" :label="$t('orderCenter.orderSerialNumberLabel')"
  12. :placeholder="$t('orderCenter.orderSerialNumberPlaceholder')" />
  13. <van-field v-model="clientId" name="clientId" :label="$t('orderCenter.equipmentNo')"
  14. :placeholder="$t('orderCenter.equipmentNoPlaceholder')" />
  15. <!-- <div class="van-cell van-field">
  16. <div class="van-cell__title van-field__label">
  17. <label id="van-field-4-label" for="van-field-4-input">{{ $t('orderCenter.orderDate') }}</label>
  18. </div>
  19. <div class="van-cell__value van-field__value">
  20. <div class="van-field__body">
  21. <input type="text" class="van-field__control" :placeholder="$t('orderCenter.startTime')"
  22. style="text-align: center; width: 50%;" v-model="startTime" @click="startTimeClick()" />
  23. <span>{{ $t('orderCenter.to') }}</span>
  24. <input type="text" class="van-field__control" :placeholder="$t('orderCenter.endTime')"
  25. style="text-align: center; width: 50%;" v-model="endTime" @click="endTimeClick()" />
  26. </div>
  27. </div>
  28. </div> -->
  29. <van-field v-model="queryDateValue" is-link readonly :label="$t('orderCenter.orderDate')"
  30. :placeholder="$t('orderCenter.orderDatePlaceholder')" @click="showOrderDate = true" />
  31. <!-- 操作 -->
  32. <van-row justify="space-around" style="padding: 2em;">
  33. <van-button class="clearBtn" span="5" round plain type="primary" style="height: 2em; padding: 0 2em;"
  34. @click="registerClick">{{ $t('device.emptyingConditions') }}</van-button>
  35. <van-button span="5" round type="primary" style="height: 2em; padding: 0 2em;" native-type="submit">
  36. {{ $t('orderCenter.clickSearch') }}
  37. </van-button>
  38. </van-row>
  39. </van-form>
  40. </div>
  41. </van-popup>
  42. <van-popup v-model:show="startDateShow" position="bottom">
  43. <van-date-picker v-model="startDateValue" :title="$t('orderCenter.selectFullTime')"
  44. @confirm="startDateConFirm($event)" @cancel="startDateCancel()" :min-date="minDate" :max-date="maxDate" />
  45. </van-popup>
  46. <van-popup v-model:show="endDateShow" position="bottom">
  47. <van-date-picker v-model="endDateValue" :title="$t('orderCenter.selectFullTime')"
  48. @confirm="endDateConFirm($event)" @cancel="endDateCancel()" :min-date="minDate" :max-date="maxDate" />
  49. </van-popup>
  50. <van-calendar color="#4d6add" v-model:show="showOrderDate" @confirm="calendarConfirm" type="range"
  51. :show-confirm="false" :allow-same-day="true" :min-date="minDate" :max-date="maxDate" :max-range="31" />
  52. </div>
  53. </template>
  54. <script>
  55. import { ref } from 'vue';
  56. import { showToast } from 'vant';
  57. import { useI18n } from "vue-i18n";
  58. import dateUtil from "@/utils/dateUtil";
  59. export default {
  60. name: 'orderSearch',
  61. setup(prop, context) {
  62. const { t } = useI18n();
  63. const sheetShow = ref(false);
  64. const startDateShow = ref(false);
  65. const endDateShow = ref(false);
  66. const minDate = new Date(2022, 0, 1);
  67. const maxDate = new Date();
  68. // 创建一个Date对象,表示当前时间
  69. const dateTime = new Date();
  70. // 获取当前时间的年份
  71. const currentYear = dateTime.getFullYear();
  72. // 获取当前时间的月份(注意,月份是从0开始的,所以要加1)
  73. const currentMonth = dateTime.getMonth() + 1;
  74. // 获取当前时间的日期
  75. const currentDate = dateTime.getDate();
  76. const startDateValue = ref([currentYear, currentMonth, currentDate])
  77. const endDateValue = ref([currentYear, currentMonth, currentDate])
  78. // 订单日期弹窗显示
  79. const showOrderDate = ref(false);
  80. // 订单日期弹窗确认
  81. const calendarConfirm = (value) => {
  82. showOrderDate.value = false;
  83. queryDateValue.value = dateUtil.formateDate(value[0], "yyyy/MM/dd") + "——" + dateUtil.formateDate(value[1], "yyyy/MM/dd");
  84. startDate.value = dateUtil.formateDate(value[0], "yyyy-MM-dd") + " 00:00:00";
  85. endDate.value = dateUtil.formateDate(value[1], "yyyy-MM-dd") + " 23:59:59";
  86. console.log(startDate, endDate);
  87. }
  88. const queryDateValue = ref(''); // 订单时间
  89. const userName = ref(''); // 用户名
  90. const sn = ref(''); // 订单编号
  91. const trxNo = ref(''); // 订单流水号
  92. const clientId = ref(''); // 设备唯一码_设备编号
  93. const startDate = ref(''); // 订单时间-起始时间
  94. const endDate = ref('');
  95. const startTime = ref('');
  96. const endTime = ref('');
  97. // 父组件页面触发展示及初始化
  98. const showSearch = () => { sheetShow.value = true; };
  99. const startTimeClick = () => {
  100. startDateShow.value = true;
  101. }
  102. const startDateConFirm = ({ selectedValues }) => {
  103. startDate.value = selectedValues.join("-") + " 00:00:00";
  104. startDateShow.value = false;
  105. startTime.value = selectedValues.join("-");
  106. }
  107. const startDateCancel = () => {
  108. startDateShow.value = false;
  109. }
  110. const endTimeClick = () => {
  111. endDateShow.value = true;
  112. }
  113. const endDateConFirm = ({ selectedValues }) => {
  114. endDate.value = selectedValues.join("-") + " 23:59:59";
  115. endDateShow.value = false;
  116. endTime.value = selectedValues.join("-");
  117. }
  118. const endDateCancel = () => {
  119. endDateShow.value = false;
  120. }
  121. // 提交搜索表单触发搜索
  122. const onSubmit = () => {
  123. if (userName.value == '' && sn.value == '' && trxNo.value == '' && clientId.value == '') {
  124. showToast(t('orderCenter.searchCriteria'));
  125. return;
  126. }
  127. if (queryDateValue.value == '') {
  128. showToast(t('orderCenter.searchDate'));
  129. return;
  130. }
  131. // if (clientId.value != '' || userName.value != '') {
  132. // if (startTime.value == '' || endTime.value == '') {
  133. // showToast(t('orderCenter.searchDate'));
  134. // return;
  135. // } else {
  136. // let start = new Date(startTime.value);
  137. // let end = new Date(endTime.value);
  138. // let diff = (end - start) / 1000 / 60 / 60 / 24;
  139. // if (diff > 30) {
  140. // showToast(t('orderCenter.searchDateTips'));
  141. // return;
  142. // }
  143. // }
  144. // }
  145. const searchParam = {
  146. userName: userName.value,
  147. sn: sn.value,
  148. trxNo: trxNo.value,
  149. clientId: clientId.value,
  150. startDate: startDate.value,
  151. endDate: endDate.value,
  152. };
  153. context.emit('search', searchParam);
  154. sheetShow.value = false;
  155. }
  156. // 清空条件
  157. const registerClick = () => {
  158. userName.value = '';
  159. sn.value = '';
  160. trxNo.value = '';
  161. clientId.value = '';
  162. startDate.value = '';
  163. endDate.value = '';
  164. queryDateValue.value = '';
  165. };
  166. return {
  167. sheetShow,
  168. startDateShow,
  169. startDateConFirm,
  170. startDateCancel,
  171. endDateShow,
  172. endDateConFirm,
  173. endDateCancel,
  174. minDate,
  175. userName,
  176. sn,
  177. trxNo,
  178. clientId,
  179. startDate,
  180. endDate,
  181. showSearch,
  182. startTimeClick,
  183. endTimeClick,
  184. onSubmit,
  185. startTime,
  186. endTime,
  187. maxDate,
  188. startDateValue,
  189. endDateValue,
  190. showOrderDate,
  191. calendarConfirm,
  192. queryDateValue,
  193. registerClick
  194. };
  195. },
  196. components: {},
  197. };
  198. </script>
  199. <style lang="less" scoped>
  200. .orderSearch {
  201. width: 100%;
  202. .clearBtn {
  203. border-color: #4d6add;
  204. background-color: #fff;
  205. }
  206. :deep(.orderSearchPopup) {
  207. width: 90%;
  208. }
  209. .content {
  210. padding-top: 1em;
  211. }
  212. .field .van-field__label {
  213. width: auto;
  214. }
  215. }
  216. </style>