orderListByDist.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view class="app-main app-content">
  3. <view class="input-wrap_box">
  4. <view class="select-dn_bx">
  5. <DateSelect class="bar" top="0" @selectDateFn="selectDateFn" defaultShowName="今天" :isShowMonth="false" :customDateOption="myCustomDateOption" :maxDays="7" />
  6. </view>
  7. </view>
  8. <view class="list-wrap">
  9. <view class="table-header">
  10. <text class="col-index-header">序号</text>
  11. <text class="col-name">名称</text>
  12. <text class="col-phone">电话</text>
  13. <text class="col-address">地址</text>
  14. </view>
  15. <block v-if="!$util.isEmpty(distList)">
  16. <view class="dist-block" v-for="distItem in distList" :key="distItem.distKey">
  17. <view class="dist-title">{{ distItem.distName }}</view>
  18. <view class="custom-row" v-for="(customItems, index) in distItem.orderList" :key="index" @click="handleRowClick(customItems)">
  19. <view class="row-content">
  20. <block v-if="customItems.length === 1">
  21. <text class="col-index">{{ index + 1 }}</text>
  22. <text class="col-name">{{ customItems[0].name }}</text>
  23. <text class="col-phone">{{ customItems[0].phone }}</text>
  24. <text class="col-address">{{ customItems[0].address }}</text>
  25. </block>
  26. <block v-else-if="customItems.length > 1">
  27. <text class="col-index">{{ index + 1 }}</text>
  28. <text class="col-name" style="color: #3385FF;">{{ customItems[0].name }}</text>
  29. <text class="col-phone" style="color: #3385FF;">{{ customItems[0].phone }}</text>
  30. <text class="col-address" style="color: #3385FF;">{{ customItems[0].address }}</text>
  31. </block>
  32. </view>
  33. <block v-if="getRemarks(customItems).length > 0">
  34. <view class="row-remark" v-for="(remarkItem, rIndex) in getRemarks(customItems)" :key="'remark-' + rIndex" style="font-weight:bold;">
  35. <text style="font-size:28upx;">{{ remarkItem.label }}:</text>{{ remarkItem.text }}
  36. </view>
  37. </block>
  38. </view>
  39. </view>
  40. </block>
  41. <block v-else>
  42. <app-wrapper-empty title="暂无数据" :is-empty="$util.isEmpty(distList)" />
  43. </block>
  44. </view>
  45. <NotLogin></NotLogin>
  46. <!-- 弹窗 -->
  47. <view class="popup-mask" v-if="showPopup" @click="closePopup">
  48. <view class="popup-content" @click.stop>
  49. <view class="popup-header">
  50. <text class="popup-title">{{ popupList.length }}条订单</text>
  51. <view class="popup-close" @click="closePopup">×</view>
  52. </view>
  53. <scroll-view scroll-y class="popup-list">
  54. <view class="popup-item" v-for="item in popupList" :key="item.id" @click="goToDetail(item.id)">
  55. <view class="row-content">
  56. <text class="col-name-popup">{{ item.name }}</text>
  57. <text class="col-phone-popup">{{ item.phone }}</text>
  58. <text class="col-address-popup">{{ item.address }}</text>
  59. </view>
  60. <view class="row-remark" v-if="item.remark" style="font-weight:bold;">
  61. <text style="font-size: 28upx;">备注:</text>{{ item.remark }}
  62. </view>
  63. </view>
  64. </scroll-view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import DateSelect from '@/components/module/dateSelect';
  71. import NotLogin from '@/components/not-login';
  72. import AppWrapperEmpty from '@/components/app-wrapper-empty';
  73. import { getOrderListByDist } from '@/api/order';
  74. export default {
  75. name: 'orderListByDist',
  76. components: {
  77. DateSelect,
  78. NotLogin,
  79. AppWrapperEmpty
  80. },
  81. data() {
  82. return {
  83. searchTime: '今天',
  84. startTime: '',
  85. endTime: '',
  86. distList: [],
  87. myCustomDateOption: [
  88. { name: '昨天', value: 'yesterday' },
  89. { name: '今天', value: 'today' },
  90. { name: '本周', value: 'thisWeek' }
  91. ],
  92. showPopup: false,
  93. popupList: []
  94. };
  95. },
  96. onLoad() {
  97. this.getListData();
  98. },
  99. onPullDownRefresh() {
  100. this.getListData().finally(() => {
  101. uni.stopPullDownRefresh();
  102. });
  103. },
  104. methods: {
  105. init() {},
  106. selectDateFn(val) {
  107. this.searchTime = val.searchTime || '';
  108. this.startTime = val.startTime || '';
  109. this.endTime = val.endTime || '';
  110. this.getListData();
  111. },
  112. getListData() {
  113. return getOrderListByDist({
  114. searchTime: this.searchTime,
  115. startTime: this.startTime,
  116. endTime: this.endTime
  117. })
  118. .then((res) => {
  119. this.distList = this.normalizeDistList(res.data);
  120. })
  121. .catch(() => {
  122. this.distList = [];
  123. });
  124. },
  125. normalizeDistList(data) {
  126. if (this.$util.isEmpty(data)) {
  127. return [];
  128. }
  129. let result = [];
  130. // 接口标准返回:{ totalNum, list, shop, shopExt }
  131. if (data && Array.isArray(data.list)) {
  132. result = data.list.map((item, index) => this.normalizeDistItem(item, index)).filter(item => !this.$util.isEmpty(item.orderList));
  133. }
  134. const unpartitionedIndex = result.findIndex(item => item.distName === '未分区');
  135. if (unpartitionedIndex > -1) {
  136. const unpartitionedItem = result.splice(unpartitionedIndex, 1)[0];
  137. result.push(unpartitionedItem);
  138. }
  139. return result;
  140. },
  141. normalizeDistItem(item, index) {
  142. const orderListRaw = item.list || {};
  143. const orderList = [];
  144. if (typeof orderListRaw === 'object' && !Array.isArray(orderListRaw)) {
  145. Object.keys(orderListRaw).forEach(key => {
  146. const items = orderListRaw[key] || [];
  147. if (Array.isArray(items) && items.length > 0) {
  148. orderList.push(items.map(order => this.normalizeCustomItem(order)));
  149. }
  150. });
  151. } else if (Array.isArray(orderListRaw)) {
  152. orderListRaw.forEach(order => {
  153. orderList.push([this.normalizeCustomItem(order)]);
  154. });
  155. }
  156. return {
  157. distKey:item.distId || 999999 + index,
  158. distName: item.distName || '未分区',
  159. orderList
  160. };
  161. },
  162. normalizeCustomItem(item) {
  163. return {
  164. id: item.id || item.customId || '',
  165. name: item.name || '--',
  166. phone: item.mobile || '--',
  167. address: item.fullAddress || '--',
  168. remark: item.remark || ''
  169. };
  170. },
  171. getRemarks(customItems) {
  172. if (!customItems || !customItems.length) return [];
  173. const remarks = customItems.map(item => item.remark).filter(remark => !!remark);
  174. if (remarks.length === 0) {
  175. return [];
  176. }
  177. if (remarks.length === 1) {
  178. return [{ label: '备注', text: remarks[0] }];
  179. }
  180. return remarks.map((remark, index) => ({
  181. label: `备注${index + 1}`,
  182. text: remark
  183. }));
  184. },
  185. handleRowClick(customItems) {
  186. if (customItems.length === 1) {
  187. this.goToDetail(customItems[0].id);
  188. } else if (customItems.length > 1) {
  189. this.popupList = customItems;
  190. this.showPopup = true;
  191. }
  192. },
  193. closePopup() {
  194. this.showPopup = false;
  195. this.popupList = [];
  196. },
  197. goToDetail(id) {
  198. if (id) {
  199. this.$util.pageTo({ url: `/pagesOrder/detail?id=${id}`})
  200. }
  201. }
  202. }
  203. };
  204. </script>
  205. <style lang="scss" scoped>
  206. .app-content {
  207. min-height: 100vh;
  208. background-color: #f7f7f7;
  209. }
  210. .input-wrap_box {
  211. position: fixed;
  212. top: 0;
  213. z-index: 10;
  214. width: 100%;
  215. height: 100upx;
  216. background-color: #fff;
  217. display: flex;
  218. align-items: center;
  219. padding: 0 20upx;
  220. box-sizing: border-box;
  221. .select-dn_bx {
  222. width: 100%;
  223. }
  224. }
  225. .list-wrap {
  226. padding: 100upx 10upx 20upx;
  227. box-sizing: border-box;
  228. }
  229. .table-header {
  230. display: flex;
  231. align-items: center;
  232. min-height: 70upx;
  233. padding: 0 10upx;
  234. color: #8d96b0;
  235. font-size: 30upx;
  236. background-color: #eceef3;
  237. }
  238. .dist-block {
  239. background-color: #fff;
  240. }
  241. .dist-title {
  242. text-align: center;
  243. padding:18upx 0 18upx 0;
  244. font-size: 35upx;
  245. color: #3385FF;
  246. font-weight:bold;
  247. }
  248. .custom-row {
  249. display: flex;
  250. flex-direction: column;
  251. justify-content: center;
  252. min-height: 88upx;
  253. padding: 20upx;
  254. font-size: 28upx;
  255. color: #333;
  256. border-top: 1upx solid #e8e8e8;
  257. box-sizing: border-box;
  258. }
  259. .row-content {
  260. display: flex;
  261. align-items: center;
  262. width: 100%;
  263. }
  264. .row-remark {
  265. font-size: 26upx;
  266. color: hsl(0, 95%, 44%);
  267. margin-top: 10upx;
  268. width: 100%;
  269. }
  270. .col-index-header {
  271. width: 14%;
  272. margin-right: 1%;
  273. }
  274. .col-index {
  275. width: 4%;
  276. margin-right: 2%;
  277. text-align: left;
  278. }
  279. .col-name {
  280. width: 24%;
  281. margin-right: 1%;
  282. }
  283. .col-phone {
  284. width: 29%;
  285. text-align: center;
  286. }
  287. .col-address {
  288. width: 42%;
  289. text-align: center;
  290. }
  291. .col-name-popup {
  292. width: 24%;
  293. margin-right: 1%;
  294. }
  295. .col-phone-popup {
  296. width: 30%;
  297. text-align: center;
  298. }
  299. .col-address-popup {
  300. width: 46%;
  301. text-align: center;
  302. }
  303. .popup-mask {
  304. position: fixed;
  305. top: 0;
  306. left: 0;
  307. right: 0;
  308. bottom: 0;
  309. z-index: 999;
  310. background-color: rgba(0, 0, 0, 0.5);
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. }
  315. .popup-content {
  316. width: 96%;
  317. background-color: #fff;
  318. border-radius: 16upx;
  319. overflow: hidden;
  320. display: flex;
  321. flex-direction: column;
  322. max-height: 80vh;
  323. }
  324. .popup-header {
  325. position: relative;
  326. display: flex;
  327. align-items: center;
  328. justify-content: center;
  329. height: 100upx;
  330. border-bottom: 1upx solid #eee;
  331. }
  332. .popup-title {
  333. font-size: 32upx;
  334. font-weight: bold;
  335. color: #333;
  336. }
  337. .popup-close {
  338. position: absolute;
  339. right: 0;
  340. top: 0;
  341. width: 100upx;
  342. height: 100upx;
  343. display: flex;
  344. align-items: center;
  345. justify-content: center;
  346. font-size: 40upx;
  347. color: #999;
  348. }
  349. .popup-list {
  350. flex: 1;
  351. padding: 0 20upx;
  352. box-sizing: border-box;
  353. }
  354. .popup-item {
  355. display: flex;
  356. flex-direction: column;
  357. justify-content: center;
  358. min-height: 88upx;
  359. padding: 20upx 0;
  360. font-size: 28upx;
  361. color: #333;
  362. border-bottom: 1upx solid #eee;
  363. box-sizing: border-box;
  364. }
  365. .popup-item:last-child {
  366. border-bottom: none;
  367. }
  368. </style>