index.vue 6.2 KB

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