indexcopy.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <ay-container :showSpac="false">
  3. <ay-sticky relativeTo="#orderList" targetSelector="#top">
  4. <div class="center pt-spac pb-spac" id="top">
  5. <uni-datetime-picker
  6. v-model="data.range"
  7. type="daterange"
  8. :clearIcon="false"
  9. @change="methods.changeDate"
  10. />
  11. <button
  12. type="primary"
  13. plain="true"
  14. size="mini"
  15. class="ml-spac"
  16. @click="methods.showFilters"
  17. >
  18. 筛选{{ data.checkCount ? ` · ${data.checkCount}` : '' }}
  19. </button>
  20. <!-- <uni-badge type="primary" :text="data.checkCount" absolute="rightTop" :offset="[-3, 3]">
  21. <uni-icons
  22. class="ml-spacd2"
  23. type="settings"
  24. color=""
  25. size="24"
  26. @click="methods.showFilters"
  27. />
  28. </uni-badge> -->
  29. </div>
  30. </ay-sticky>
  31. <div class="center justify-between s-fz tags">
  32. <div
  33. class="text-center chunk tag"
  34. v-for="(t, i) in data.tags"
  35. :key="i"
  36. :class="{ odd: i % 2 === 0 }"
  37. >
  38. <div>{{ t.title }}</div>
  39. <div>{{ t.unit }}</div>
  40. <div class="font-bold p-fz">
  41. {{ func.convert.nullView(t.value, 1) }}
  42. <!-- <ay-numer :value="func.convert.nullView(t.value, 1)" /> -->
  43. </div>
  44. </div>
  45. </div>
  46. <div id="orderList">
  47. <div
  48. class="chunk childs-fcjb-mbd2"
  49. :class="{ 'm-b-0': i === data.orderList.length - 1 }"
  50. v-for="(o, i) in data.orderList"
  51. :key="i"
  52. @click="methods.goDetail(o)"
  53. >
  54. <div>
  55. <div class="font-bold p-fz">{{ o.nickName }}</div>
  56. <div>{{ func.convert.getOrderStatusStr(o.settleStatus) }}</div>
  57. </div>
  58. <div>
  59. <div>加气量(公斤)</div>
  60. <div>{{ o.gasQty }}</div>
  61. </div>
  62. <div>
  63. <div>小计(元)</div>
  64. <div class="font-bold bs-fz">{{ o.allAmount }}</div>
  65. </div>
  66. <div>
  67. <div class="gray-color">{{ func.getDate(o.createDate).format() }}</div>
  68. </div>
  69. </div>
  70. </div>
  71. <ay-drawer
  72. ref="drawer"
  73. mode="right"
  74. :maskClick="true"
  75. :width="config.common.SystemInfo.windowWidth"
  76. :top="topHeightPX"
  77. @change="methods.drawerChange"
  78. >
  79. <div class="m-spac">
  80. <div class="center b-fz mb-spac">
  81. <div class="font-bold">
  82. <span>筛选</span>
  83. <span v-if="checkCount">
  84. <span>·</span>
  85. <span class="p-color">{{ checkCount }}</span>
  86. </span>
  87. </div>
  88. <uni-icons
  89. type="closeempty"
  90. color=""
  91. size="24"
  92. class="abs-right"
  93. @click="methods.closeFilters"
  94. />
  95. </div>
  96. <div>
  97. <div>
  98. <div v-for="(f, i) in filtersView" :key="i" :class="{ 'nmt-spac': f.type === 1 }">
  99. <div
  100. class="section"
  101. :class="{
  102. 'font-bold': !f.type,
  103. 'ml-spacd2': f.type === 1,
  104. 's-fz': f.type === 1,
  105. }"
  106. >
  107. {{ f.label }}
  108. </div>
  109. <div class="center justify-between flex-wrap s-fz">
  110. <div
  111. class="center whitespace-nowrap p-spacd2 chunk f-item"
  112. :class="{
  113. 'checked-full': item.checked,
  114. isall: item.value === staticData.nullValue,
  115. }"
  116. v-for="(item, ii) in f.items"
  117. :key="ii"
  118. @click="methods.filterCheck(f, item)"
  119. >
  120. <!-- <div class="tag-rb" v-if="item.isPerson">个人支付</div> -->
  121. {{ item.label }}
  122. </div>
  123. <div class="f-item" v-if="f.items.length % 3 === 2"></div>
  124. </div>
  125. </div>
  126. </div>
  127. </div>
  128. <div class="btns">
  129. <button @click="methods.clearFilters">清除</button>
  130. <button type="primary" @click="methods.saveFilters">确定</button>
  131. </div>
  132. </div>
  133. </ay-drawer>
  134. </ay-container>
  135. </template>
  136. <script lang="ts" setup>
  137. const staticData = {
  138. /** 缓存筛选条件key名 */
  139. fcn: 'filterCheckeds',
  140. /** 全部选项的value值 */
  141. nullValue: '-1',
  142. payTypeGroups: [
  143. { label: '支付方式', type: 0, hasStatus: ['-1', '10'] },
  144. { label: '个人支付', type: 1, hasStatus: ['3'] },
  145. { label: '所属物流', type: 1, hasStatus: ['0', '1', '2'] },
  146. ],
  147. }
  148. const drawer = ref()
  149. const topHeight = computed(() => config.common.safeAreaTopHeight)
  150. const topHeightPX = computed(() => `${topHeight.value}px`)
  151. const data = ay.initData({
  152. /** 确定选中条件数量 */
  153. checkCount: 0,
  154. filters: [
  155. {
  156. label: '结算状态',
  157. value: 'settleStatus',
  158. items: func.convert.getCheckItem(config.common.settleStatus),
  159. },
  160. {
  161. label: '支付方式',
  162. value: 'payType',
  163. items: func.convert.getCheckItem(config.common.payTypes),
  164. },
  165. {
  166. label: '交易模式',
  167. value: 'tradeTypes',
  168. items: func.convert.getCheckItem(config.common.tradeType),
  169. },
  170. ] as any[],
  171. range: [],
  172. orderList: [] as 订单详情[],
  173. tags: [
  174. {
  175. field: 'allValue',
  176. title: '加气总额',
  177. unit: '(元)',
  178. value: '',
  179. },
  180. {
  181. field: 'allQty',
  182. title: '加气总量',
  183. unit: '(公斤)',
  184. value: '',
  185. },
  186. {
  187. field: 'count',
  188. title: '订单总数',
  189. unit: '(笔)',
  190. value: '',
  191. },
  192. {
  193. field: 'allPrefer',
  194. title: '优惠总额',
  195. unit: '(元)',
  196. value: '',
  197. },
  198. ],
  199. })
  200. const filtersView = computed(() => {
  201. const rv = [...data.filters]
  202. const payTypeIndex = rv.findIndex((f) => f.value === 'payType')
  203. const payTypeItem = rv[payTypeIndex]
  204. const groups = staticData.payTypeGroups.map((m) => {
  205. return {
  206. label: m.label,
  207. type: m.type,
  208. items: payTypeItem.items.filter((f) => m.hasStatus.includes(f.value)),
  209. target: payTypeItem,
  210. }
  211. })
  212. rv.splice(payTypeIndex, 1, ...groups)
  213. return rv
  214. })
  215. /** 选中的条件 */
  216. const filterCheckeds = computed(() => {
  217. const fcs: Record<string, string[]> = {}
  218. data.filters.forEach((f) => {
  219. const curItems = f.items
  220. .filter((ff) => ff.checked && ff.value !== staticData.nullValue)
  221. .map((m) => m.value)
  222. if (curItems.length) {
  223. fcs[f.value] = curItems
  224. }
  225. })
  226. return fcs
  227. })
  228. /** 临时选中条件数量 */
  229. const checkCount = computed(() =>
  230. Object.values(filterCheckeds.value)
  231. .map((m) => m.length + (m.includes(staticData.nullValue) ? -1 : 0))
  232. .reduce((a, b) => a + b, 0),
  233. )
  234. const methods = {
  235. goDetail(od) {
  236. ay.goPage(config.pages.order_orderDetail, { params: od })
  237. },
  238. /** 从缓存 初始化查询条件选中状态 */
  239. getStoreFilterCheckeds() {
  240. return uni.getStorageSync(staticData.fcn) || {}
  241. },
  242. /** 从缓存 初始化查询条件选中状态 */
  243. initFiltersCheck() {
  244. const filterCheckeds: any = methods.getStoreFilterCheckeds()
  245. if (Object.keys(filterCheckeds).length) {
  246. data.filters.forEach((f) => {
  247. if (filterCheckeds[f.value]) {
  248. f.items.forEach((ff) => {
  249. ff.checked = filterCheckeds[f.value]?.includes(ff.value)
  250. })
  251. } else {
  252. f.items[0].checked = true
  253. }
  254. })
  255. }
  256. },
  257. /** 计算条件选中数量 */
  258. setCheckCount() {
  259. const filterCheckeds = methods.getStoreFilterCheckeds()
  260. if (filterCheckeds) {
  261. data.checkCount = Object.values<string[]>(filterCheckeds)
  262. .map((m) => m.length + (m.includes(staticData.nullValue) ? -1 : 0))
  263. .reduce((a, b) => a + b, 0)
  264. }
  265. },
  266. drawerChange(args) {
  267. // 打开抽屉初始化条件选择状态
  268. if (args) {
  269. methods.initFiltersCheck()
  270. } else {
  271. // 关闭抽屉计算选中数量
  272. methods.setCheckCount()
  273. }
  274. },
  275. saveFilters() {
  276. // 有选中的条件
  277. if (Object.keys(filterCheckeds.value).length) {
  278. uni.setStorageSync(staticData.fcn, filterCheckeds.value)
  279. } else {
  280. uni.removeStorageSync(staticData.fcn)
  281. }
  282. methods.closeFilters()
  283. methods.getOrderList()
  284. },
  285. clearFilters() {
  286. data.filters.forEach((f) => {
  287. f.items.forEach((ff) => {
  288. ff.checked = false
  289. if (ff.value === staticData.nullValue) {
  290. ff.checked = true
  291. }
  292. })
  293. })
  294. },
  295. filterCheck(fg, item) {
  296. // 点击全部
  297. const realfg = fg.target ? fg.target : fg
  298. if (item.value === staticData.nullValue) {
  299. realfg.items.forEach((f) => (f.checked = false))
  300. item.checked = true
  301. } else {
  302. item.checked = !item.checked
  303. realfg.items[0].checked = false
  304. }
  305. },
  306. getOrderList(cras = store.curPage.getDefAyContainerRefreshArgs()) {
  307. const paramFilters: Record<string, string> = {}
  308. const storeFilterCheckeds = methods.getStoreFilterCheckeds()
  309. Object.keys(storeFilterCheckeds).forEach(
  310. (f) => (paramFilters[f] = storeFilterCheckeds[f].toString()),
  311. )
  312. webapi.strategy
  313. .get_order_list<{ param: { gasstationId?: string } }>(
  314. {
  315. page: cras.page,
  316. size: cras.size,
  317. param: {
  318. startCreateDate: data.range[0] + ' 00:00:00',
  319. endCreateDate: data.range[1] + ' 23:59:59',
  320. ...paramFilters,
  321. },
  322. },
  323. { showLoading: !cras.isAdd },
  324. )
  325. .then((res) => {
  326. data.tags.forEach((f) => {
  327. f.value = res[f.field]
  328. })
  329. if (cras.isAdd) {
  330. data.orderList.push(...res.page.records)
  331. } else {
  332. data.orderList = res.page.records
  333. }
  334. })
  335. },
  336. changeDate(e) {
  337. methods.getOrderList()
  338. },
  339. showFilters() {
  340. drawer.value.open()
  341. },
  342. closeFilters() {
  343. drawer.value.close()
  344. },
  345. }
  346. ay.entrance((args) => {
  347. if (args.loadType === enums.LoadType.onLoad) {
  348. // 初始化日期范围
  349. const endDate = func.getDate(Date.now())
  350. const startDate = endDate.add(-30, 'day')
  351. data.range = [
  352. func.getDate(startDate).format(enums.FormatType.YMD),
  353. func.getDate(endDate).format(enums.FormatType.YMD),
  354. ]
  355. methods.setCheckCount()
  356. }
  357. methods.getOrderList(args.cras)
  358. })
  359. </script>
  360. <style lang="scss" scoped>
  361. .abs-right {
  362. position: absolute;
  363. right: $p-spac;
  364. }
  365. .f-item {
  366. box-sizing: border-box;
  367. width: 31%;
  368. &.isall {
  369. background: #fff;
  370. }
  371. &.checked {
  372. color: $p-color;
  373. }
  374. }
  375. .tags {
  376. > .tag {
  377. min-width: 20%;
  378. max-width: 25%;
  379. padding: $p-spacd2 0;
  380. background-color: #d5f8e9;
  381. }
  382. .odd {
  383. background-color: #d5e9fa;
  384. }
  385. // > div:nth-child(odd) {
  386. // background-color: #d5e9fa;
  387. // }
  388. // > div:nth-child(even) {
  389. // background-color: #d5f8e9;
  390. // }
  391. }
  392. </style>