index.vue 10 KB

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