index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 == '') {
  115. that.$set(that, `searchInfo`, {})
  116. } else {
  117. that.$set(that.searchInfo, `goods`, e.detail.value);
  118. }
  119. that.clearPage();
  120. that.search();
  121. },
  122. // 查询列表
  123. async search() {
  124. const that = this;
  125. let user = that.user;
  126. if (user._id) {
  127. let info = {
  128. skip: that.skip,
  129. limit: that.limit,
  130. customer: user._id,
  131. }
  132. let res = await that.$api(`/zrOrder`, 'GET', {
  133. ...info,
  134. ...that.searchInfo
  135. }, `integral`)
  136. if (res.errcode == '0') {
  137. let list = [...that.list, ...res.data];
  138. for (let val of list) {
  139. let status = that.statusList.find(i => i.value == val.status)
  140. if (status) val.zhStatus = status.label;
  141. }
  142. that.$set(that, `list`, list);
  143. that.$set(that, `total`, res.total)
  144. }
  145. }
  146. },
  147. // 查询其他信息
  148. async searchOther() {
  149. const that = this;
  150. let res;
  151. res = await that.$api(`/dictData`, 'GET', {
  152. code: "order_process"
  153. });
  154. if (res.errcode == '0') {
  155. that.$set(that, `statusList`, res.data)
  156. }
  157. },
  158. // 分页
  159. toPage(e) {
  160. const that = this;
  161. let list = that.list;
  162. let limit = that.limit;
  163. if (that.total > list.length) {
  164. uni.showLoading({
  165. title: '加载中',
  166. mask: true
  167. })
  168. let page = that.page + 1;
  169. that.$set(that, `page`, page)
  170. let skip = page * limit;
  171. that.$set(that, `skip`, skip)
  172. that.search();
  173. uni.hideLoading();
  174. } else that.$set(that, `is_bottom`, true)
  175. },
  176. toScroll(e) {
  177. const that = this;
  178. let up = that.scrollTop;
  179. that.$set(that, `scrollTop`, e.detail.scrollTop);
  180. let num = Math.sign(up - e.detail.scrollTop);
  181. if (num == 1) that.$set(that, `is_bottom`, false);
  182. },
  183. // 清空列表
  184. clearPage() {
  185. const that = this;
  186. that.$set(that, `list`, [])
  187. that.$set(that, `skip`, 0)
  188. that.$set(that, `limit`, 6)
  189. that.$set(that, `page`, 0)
  190. }
  191. },
  192. onPullDownRefresh: async function() {
  193. const that = this;
  194. that.$set(that, `list`, [])
  195. that.$set(that, `skip`, 0)
  196. that.$set(that, `limit`, 6)
  197. that.$set(that, `page`, 0)
  198. await that.search();
  199. uni.stopPullDownRefresh();
  200. }
  201. }
  202. </script>
  203. <style lang="scss">
  204. .main {
  205. display: flex;
  206. flex-direction: column;
  207. width: 100vw;
  208. height: 100vh;
  209. .one {
  210. border-bottom: 1px solid var(--f85Color);
  211. padding: 2vw;
  212. input {
  213. padding: 2vw;
  214. background-color: var(--f1Color);
  215. font-size: var(--font14Size);
  216. border-radius: 5px;
  217. }
  218. }
  219. .two {
  220. position: relative;
  221. flex-grow: 1;
  222. padding: 2vw 0 0 0;
  223. .list {
  224. margin: 0 0 1vw 0;
  225. padding: 2vw;
  226. border-bottom: 1px solid #f5f5f5;
  227. .list_1 {
  228. margin: 0 0 2vw 0;
  229. .shopname {
  230. text:last-child {
  231. padding: 0 0 0 2vw;
  232. }
  233. }
  234. }
  235. .list_2 {
  236. margin: 0 0 1vw 0;
  237. .market {
  238. display: flex;
  239. .url {
  240. width: 20vw;
  241. .image {
  242. width: 100%;
  243. height: 20vw;
  244. border-radius: 5px;
  245. }
  246. }
  247. .name {
  248. display: flex;
  249. flex-direction: column;
  250. width: 60vw;
  251. padding: 0 2vw;
  252. .specs {
  253. margin: 1vw 0 0 0;
  254. color: var(--f85Color);
  255. font-size: var(--font12Size);
  256. }
  257. }
  258. .other {
  259. width: 15vw;
  260. text-align: right;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. .scroll-view {
  268. position: absolute;
  269. top: 0;
  270. left: 0;
  271. right: 0;
  272. bottom: 0;
  273. .list-scroll-view {
  274. display: flex;
  275. flex-direction: column;
  276. }
  277. }
  278. .is_bottom {
  279. text-align: center;
  280. text {
  281. padding: 2vw 0;
  282. display: inline-block;
  283. color: #858585;
  284. font-size: 14px;
  285. }
  286. }
  287. </style>