index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <input type="text" v-model="searchInfo.goods" @blur="toInput" placeholder="搜索商品">
  6. </view>
  7. <view class="two">
  8. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  9. <view class="list-scroll-view">
  10. <view class="list" v-for="(item,index) in list" :key="index">
  11. <view class="list_1">
  12. <view class="shopname">
  13. <text class="iconfont icon-shangdian"></text>
  14. <text>{{item.shop.name}}</text>
  15. </view>
  16. </view>
  17. <view class="list_2">
  18. <view class="market">
  19. <view class="url">
  20. <image class="image"
  21. :src="item.goods.file&&item.goods.file.length>0?item.goods.file[0].url:''"
  22. mode=""></image>
  23. </view>
  24. <view class="name">
  25. {{item.goods.name}}
  26. <view class="specs">
  27. {{item.zhStatus}}
  28. </view>
  29. <view class="specs">
  30. 购买时间:{{item.buy_time}}
  31. </view>
  32. <view class="specs">
  33. 备注:{{item.remarks||'暂无'}}
  34. </view>
  35. </view>
  36. <view class="other">
  37. <view class="price">
  38. ¥{{item.goods.cost}}
  39. </view>
  40. <view class="num">
  41. ×{{item.buy_num}}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="is_bottom" v-if="is_bottom">
  48. <text>{{config.bottom_title}}</text>
  49. </view>
  50. </view>
  51. </scroll-view>
  52. </view>
  53. </view>
  54. </mobile-frame>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. // 系统设置
  61. config: {},
  62. searchInfo:{},
  63. user: {},
  64. list: [],
  65. total: 0,
  66. skip: 0,
  67. limit: 6,
  68. page: 0,
  69. // 状态
  70. statusList: [],
  71. // 数据是否触底
  72. is_bottom: false,
  73. scrollTop: 0,
  74. };
  75. },
  76. onShow: async function() {
  77. const that = this;
  78. that.searchConfig();
  79. await that.searchOther();
  80. await that.watchLogin();
  81. },
  82. onHide: function() {
  83. const that = this;
  84. that.clearPage();
  85. },
  86. methods: {
  87. // 查询基本设置
  88. searchConfig() {
  89. const that = this;
  90. uni.getStorage({
  91. key: 'config',
  92. success: function(res) {
  93. if (res.data) that.$set(that, `config`, res.data)
  94. },
  95. fail: function(err) {
  96. console.log(err);
  97. }
  98. })
  99. },
  100. watchLogin() {
  101. const that = this;
  102. uni.getStorage({
  103. key: 'token',
  104. success: function(res) {
  105. let user = that.$jwt(res.data);
  106. that.$set(that, `user`, user)
  107. that.search()
  108. }
  109. })
  110. },
  111. // 输入框
  112. toInput(e) {
  113. const that = this;
  114. if (e.detail.value) that.$set(that.searchInfo, `goods`, e.detail.value);
  115. that.clearPage();
  116. that.search();
  117. },
  118. // 查询列表
  119. async search() {
  120. const that = this;
  121. let user = that.user;
  122. if (user._id) {
  123. let info = {
  124. skip: that.skip,
  125. limit: that.limit,
  126. customer: user._id,
  127. }
  128. let res = await that.$api(`/zrOrder`, 'GET', {
  129. ...info,
  130. ...that.searchInfo
  131. }, `integral`)
  132. if (res.errcode == '0') {
  133. let list = [...that.list, ...res.data];
  134. for (let val of list) {
  135. let status = that.statusList.find(i => i.value == val.status)
  136. if (status) val.zhStatus = status.label;
  137. }
  138. that.$set(that, `list`, list);
  139. that.$set(that, `total`, res.total)
  140. }
  141. }
  142. },
  143. // 查询其他信息
  144. async searchOther() {
  145. const that = this;
  146. let res;
  147. res = await that.$api(`/dictData`, 'GET', {
  148. code: "order_process"
  149. });
  150. if (res.errcode == '0') {
  151. that.$set(that, `statusList`, res.data)
  152. }
  153. },
  154. // 分页
  155. toPage(e) {
  156. const that = this;
  157. let list = that.list;
  158. let limit = that.limit;
  159. if (that.total > list.length) {
  160. uni.showLoading({
  161. title: '加载中',
  162. mask: true
  163. })
  164. let page = that.page + 1;
  165. that.$set(that, `page`, page)
  166. let skip = page * limit;
  167. that.$set(that, `skip`, skip)
  168. that.search();
  169. uni.hideLoading();
  170. } else that.$set(that, `is_bottom`, true)
  171. },
  172. toScroll(e) {
  173. const that = this;
  174. let up = that.scrollTop;
  175. that.$set(that, `scrollTop`, e.detail.scrollTop);
  176. let num = Math.sign(up - e.detail.scrollTop);
  177. if (num == 1) that.$set(that, `is_bottom`, false);
  178. },
  179. // 清空列表
  180. clearPage() {
  181. const that = this;
  182. that.$set(that, `list`, [])
  183. that.$set(that, `skip`, 0)
  184. that.$set(that, `limit`, 6)
  185. that.$set(that, `page`, 0)
  186. }
  187. },
  188. onPullDownRefresh: async function() {
  189. const that = this;
  190. that.$set(that, `list`, [])
  191. that.$set(that, `skip`, 0)
  192. that.$set(that, `limit`, 6)
  193. that.$set(that, `page`, 0)
  194. await that.search();
  195. uni.stopPullDownRefresh();
  196. }
  197. }
  198. </script>
  199. <style lang="scss">
  200. .main {
  201. display: flex;
  202. flex-direction: column;
  203. width: 100vw;
  204. height: 100vh;
  205. .one {
  206. border-bottom: 1px solid var(--f85Color);
  207. padding: 2vw;
  208. input {
  209. padding: 2vw;
  210. background-color: var(--f1Color);
  211. font-size: var(--font14Size);
  212. border-radius: 5px;
  213. }
  214. }
  215. .two {
  216. position: relative;
  217. flex-grow: 1;
  218. padding: 2vw 0 0 0;
  219. .list {
  220. margin: 0 0 1vw 0;
  221. padding: 2vw;
  222. border-bottom: 1px solid #f5f5f5;
  223. .list_1 {
  224. margin: 0 0 2vw 0;
  225. .shopname {
  226. text:last-child {
  227. padding: 0 0 0 2vw;
  228. }
  229. }
  230. }
  231. .list_2 {
  232. margin: 0 0 1vw 0;
  233. .market {
  234. display: flex;
  235. .url {
  236. width: 20vw;
  237. .image {
  238. width: 100%;
  239. height: 20vw;
  240. border-radius: 5px;
  241. }
  242. }
  243. .name {
  244. display: flex;
  245. flex-direction: column;
  246. width: 60vw;
  247. padding: 0 2vw;
  248. .specs {
  249. margin: 1vw 0 0 0;
  250. color: var(--f85Color);
  251. font-size: var(--font12Size);
  252. }
  253. }
  254. .other {
  255. width: 15vw;
  256. text-align: right;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. }
  263. .scroll-view {
  264. position: absolute;
  265. top: 0;
  266. left: 0;
  267. right: 0;
  268. bottom: 0;
  269. .list-scroll-view {
  270. display: flex;
  271. flex-direction: column;
  272. }
  273. }
  274. .is_bottom {
  275. text-align: center;
  276. text {
  277. padding: 2vw 0;
  278. display: inline-block;
  279. color: #858585;
  280. font-size: 14px;
  281. }
  282. }
  283. </style>