orderListByDist.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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">
  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.showPopup = false;
  200. uni.navigateTo({
  201. url: `/pagesOrder/detail?id=${id}`
  202. });
  203. }
  204. }
  205. }
  206. };
  207. </script>
  208. <style lang="scss" scoped>
  209. .app-content {
  210. min-height: 100vh;
  211. background-color: #f7f7f7;
  212. }
  213. .input-wrap_box {
  214. position: fixed;
  215. top: 0;
  216. z-index: 10;
  217. width: 100%;
  218. height: 100upx;
  219. background-color: #fff;
  220. display: flex;
  221. align-items: center;
  222. padding: 0 20upx;
  223. box-sizing: border-box;
  224. .select-dn_bx {
  225. width: 100%;
  226. }
  227. }
  228. .list-wrap {
  229. padding: 100upx 10upx 20upx;
  230. box-sizing: border-box;
  231. }
  232. .table-header {
  233. display: flex;
  234. align-items: center;
  235. min-height: 70upx;
  236. padding: 0 10upx;
  237. color: #8d96b0;
  238. font-size: 30upx;
  239. background-color: #eceef3;
  240. }
  241. .dist-block {
  242. background-color: #fff;
  243. }
  244. .dist-title {
  245. text-align: center;
  246. padding:18upx 0 18upx 0;
  247. font-size: 35upx;
  248. color: #3385FF;
  249. font-weight:bold;
  250. }
  251. .custom-row {
  252. display: flex;
  253. flex-direction: column;
  254. justify-content: center;
  255. min-height: 88upx;
  256. padding: 20upx;
  257. font-size: 28upx;
  258. color: #333;
  259. border-top: 1upx solid #e8e8e8;
  260. box-sizing: border-box;
  261. }
  262. .row-content {
  263. display: flex;
  264. align-items: center;
  265. width: 100%;
  266. }
  267. .row-remark {
  268. font-size: 26upx;
  269. color: hsl(0, 95%, 44%);
  270. margin-top: 10upx;
  271. width: 100%;
  272. }
  273. .col-index-header {
  274. width: 14%;
  275. margin-right: 1%;
  276. }
  277. .col-index {
  278. width: 4%;
  279. margin-right: 2%;
  280. text-align: left;
  281. }
  282. .col-name {
  283. width: 24%;
  284. margin-right: 1%;
  285. }
  286. .col-phone {
  287. width: 29%;
  288. text-align: center;
  289. }
  290. .col-address {
  291. width: 42%;
  292. text-align: center;
  293. }
  294. .col-name-popup {
  295. width: 24%;
  296. margin-right: 1%;
  297. }
  298. .col-phone-popup {
  299. width: 30%;
  300. text-align: center;
  301. }
  302. .col-address-popup {
  303. width: 46%;
  304. text-align: center;
  305. }
  306. .popup-mask {
  307. position: fixed;
  308. top: 0;
  309. left: 0;
  310. right: 0;
  311. bottom: 0;
  312. z-index: 999;
  313. background-color: rgba(0, 0, 0, 0.5);
  314. display: flex;
  315. align-items: center;
  316. justify-content: center;
  317. }
  318. .popup-content {
  319. width: 96%;
  320. background-color: #fff;
  321. border-radius: 16upx;
  322. overflow: hidden;
  323. display: flex;
  324. flex-direction: column;
  325. max-height: 80vh;
  326. }
  327. .popup-header {
  328. position: relative;
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. height: 100upx;
  333. border-bottom: 1upx solid #eee;
  334. }
  335. .popup-title {
  336. font-size: 32upx;
  337. font-weight: bold;
  338. color: #333;
  339. }
  340. .popup-close {
  341. position: absolute;
  342. right: 0;
  343. top: 0;
  344. width: 100upx;
  345. height: 100upx;
  346. display: flex;
  347. align-items: center;
  348. justify-content: center;
  349. font-size: 40upx;
  350. color: #999;
  351. }
  352. .popup-list {
  353. flex: 1;
  354. padding: 0 20upx;
  355. box-sizing: border-box;
  356. }
  357. .popup-item {
  358. display: flex;
  359. flex-direction: column;
  360. justify-content: center;
  361. min-height: 88upx;
  362. padding: 20upx 0;
  363. font-size: 28upx;
  364. color: #333;
  365. border-bottom: 1upx solid #eee;
  366. box-sizing: border-box;
  367. }
  368. .popup-item:last-child {
  369. border-bottom: none;
  370. }
  371. </style>