index.vue 5.9 KB

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