index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="content">
  3. <view class="picker">
  4. <picker
  5. @change="bindPickerChange"
  6. :value="index"
  7. :range="array"
  8. range-key="name"
  9. >
  10. <view class="picker_title">
  11. <view class="pickername">
  12. <view v-if="index != -1">
  13. {{ array[index].name }}
  14. </view>
  15. <view v-else>类型</view>
  16. </view>
  17. <view class="triangle-down"></view>
  18. </view>
  19. </picker>
  20. </view>
  21. <view class="supplyList">
  22. <view
  23. class="supplyCard"
  24. v-for="(supply, i) in supplyList"
  25. :key="i"
  26. @tap="toDetail(supply.id)"
  27. >
  28. <view class="image_content">
  29. <image :src="supply.image" />
  30. </view>
  31. <view class="info">
  32. <view class="title">
  33. {{ supply.title }}
  34. </view>
  35. <view class="time">发布时间:{{ supply.time }}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="menus">
  40. <navigator url="/pages/supply/putSupply">
  41. <view class="menu">
  42. <view>
  43. <image src="/static/supply/putSupply.png" />
  44. </view>
  45. <view class="menu_title">发布供需</view>
  46. </view>
  47. </navigator>
  48. <navigator url="/pages/supply/mySupply">
  49. <view class="menu">
  50. <view>
  51. <image src="/static/supply/mySupply.png" />
  52. </view>
  53. <view class="menu_title">我的供需</view>
  54. </view>
  55. </navigator>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import md5 from "@/common/md5.js";
  61. export default {
  62. data() {
  63. return {
  64. supplyList: [],
  65. array: [{ name: "全部" }, { name: "供需" }, { name: "需求" }],
  66. index: -1,
  67. };
  68. },
  69. onLoad() {
  70. this.getMyList();
  71. },
  72. methods: {
  73. bindPickerChange(e) {
  74. this.index = e.detail.value;
  75. this.getMyList();
  76. },
  77. toDetail(index) {
  78. uni.navigateTo({
  79. url: "/pages/supply/supply_detail?id=" + index,
  80. });
  81. },
  82. getMyList() {
  83. let md5Sign = md5(
  84. "method=" +
  85. "need" +
  86. "&timestamp=" +
  87. getApp().globalData.globalTimestamp +
  88. "&secret=" +
  89. getApp().globalData.secret
  90. );
  91. let url =
  92. getApp().globalData.shareUrl +
  93. "api/api.php" +
  94. "?method=need&source=need&action=list&timestamp=" +
  95. getApp().globalData.globalTimestamp +
  96. "&sign=" +
  97. md5Sign;
  98. let postData = {
  99. s_type:this.index==2?1:2
  100. }
  101. uni.request({
  102. url: url,
  103. method: "POST",
  104. header: {
  105. "content-type": "application/x-www-form-urlencoded",
  106. },
  107. data: this.index==-1||this.index==0?{}:postData,
  108. success: (res) => {
  109. if (res.data.code === 200) {
  110. let list = res.data.data.list;
  111. /*
  112. supplyList: new Array(5).fill({
  113. image: "/static/supply/u1779.png",
  114. title: "移动式空气消毒机",
  115. time: "2021-08-30 14:50:00",
  116. state: 1,
  117. }),
  118. */
  119. console.log(list);
  120. this.supplyList = list.map((item) => {
  121. let ob = {
  122. image: "",
  123. title: "",
  124. time: "",
  125. state: "",
  126. id: "",
  127. };
  128. ob.id = item.id;
  129. ob.title = item.title;
  130. let time = this.$options.filters["globalTime"](item.addtime);
  131. let timeSecond = this.$options.filters["globalTimeSecond"](
  132. item.addtime
  133. );
  134. ob.time = time + " " + timeSecond;
  135. ob.state = item.type;
  136. ob.image = item.url;
  137. return ob;
  138. });
  139. // console.log(res.data.data.list);
  140. }
  141. },
  142. fail: () => {
  143. console.log("连接失败");
  144. },
  145. });
  146. },
  147. },
  148. };
  149. </script>
  150. <style lang="scss" scope>
  151. .content {
  152. font-size: 30rpx;
  153. margin: 0 5%;
  154. .picker {
  155. position: fixed;
  156. top: 3%;
  157. left: 5%;
  158. .picker_title {
  159. width: 100rpx;
  160. display: flex;
  161. align-items: center;
  162. justify-content: space-between;
  163. .triangle-down {
  164. width: 0;
  165. height: 0;
  166. border-top: 15rpx solid rgb(173, 173, 173);
  167. border-left: 15rpx solid transparent;
  168. border-right: 15rpx solid transparent;
  169. }
  170. .pickername {
  171. font-weight: 100;
  172. }
  173. }
  174. }
  175. .supplyList {
  176. margin-top: 12%;
  177. .supplyCard {
  178. display: flex;
  179. width: 92%;
  180. margin: 2% 0;
  181. padding: 2% 4%;
  182. height: 5%;
  183. border-radius: 30rpx;
  184. box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 0rpx;
  185. .image_content {
  186. margin-right: 5%;
  187. image {
  188. width: 100rpx;
  189. height: 100rpx;
  190. border-radius: 20rpx;
  191. background-color: rgb(228, 228, 228);
  192. }
  193. }
  194. .info {
  195. display: flex;
  196. flex-flow: column;
  197. justify-content: space-around;
  198. .time {
  199. font-weight: 100;
  200. font-size: 25rpx;
  201. }
  202. }
  203. }
  204. }
  205. .menus {
  206. z-index: 999;
  207. display: flex;
  208. justify-content: space-around;
  209. width: 80%;
  210. // height: 6%;
  211. position: fixed;
  212. top: 85%;
  213. left: 50%;
  214. padding: 4%;
  215. border-radius: 40rpx;
  216. box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 0rpx;
  217. transform: translateX(-50%);
  218. background-color: #fff;
  219. image {
  220. width: 50rpx;
  221. height: 50rpx;
  222. border-radius: 10rpx;
  223. }
  224. .menu {
  225. display: flex;
  226. flex-flow: column;
  227. align-items: center;
  228. .menu_title {
  229. text-align: center;
  230. font-size: 25rpx;
  231. }
  232. }
  233. }
  234. }
  235. </style>