index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 = ''
  137. // ob.image = item.attach_list[0]
  138. // ? getApp().globalData.shareUrl + item.attach_list[0].url
  139. // : "";
  140. return ob;
  141. });
  142. // console.log(res.data.data.list);
  143. }
  144. },
  145. fail: () => {
  146. console.log("连接失败");
  147. },
  148. });
  149. },
  150. },
  151. };
  152. </script>
  153. <style lang="scss" scope>
  154. .content {
  155. font-size: 30rpx;
  156. margin: 0 5%;
  157. .picker {
  158. position: fixed;
  159. top: 3%;
  160. left: 10%;
  161. color: #007aff;
  162. .picker_title {
  163. width: 120rpx;
  164. display: flex;
  165. align-items: center;
  166. justify-content: space-between;
  167. .triangle-down {
  168. width: 0;
  169. height: 0;
  170. border-top: 20rpx solid rgb(173, 173, 173);
  171. border-left: 20rpx solid transparent;
  172. border-right: 20rpx solid transparent;
  173. }
  174. .pickername {
  175. font-size: 35rpx;
  176. font-weight: 100;
  177. }
  178. }
  179. }
  180. .supplyList {
  181. margin-top: 15%;
  182. .supplyCard {
  183. display: flex;
  184. width: 92%;
  185. margin: 2% 0;
  186. padding: 2% 4%;
  187. height: 5%;
  188. border-radius: 30rpx;
  189. box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 0rpx;
  190. .image_content {
  191. margin-right: 5%;
  192. image {
  193. width: 100rpx;
  194. height: 100rpx;
  195. border-radius: 20rpx;
  196. background-color: rgb(228, 228, 228);
  197. }
  198. }
  199. .info {
  200. display: flex;
  201. flex-flow: column;
  202. justify-content: space-around;
  203. .time {
  204. font-weight: 100;
  205. font-size: 25rpx;
  206. }
  207. }
  208. }
  209. }
  210. .menus {
  211. z-index: 999;
  212. display: flex;
  213. justify-content: space-around;
  214. width: 80%;
  215. // height: 6%;
  216. position: fixed;
  217. top: 85%;
  218. left: 50%;
  219. padding: 4%;
  220. border-radius: 40rpx;
  221. box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 0rpx;
  222. transform: translateX(-50%);
  223. background-color: #fff;
  224. image {
  225. width: 50rpx;
  226. height: 50rpx;
  227. border-radius: 10rpx;
  228. }
  229. .menu {
  230. display: flex;
  231. flex-flow: column;
  232. align-items: center;
  233. .menu_title {
  234. text-align: center;
  235. font-size: 25rpx;
  236. }
  237. }
  238. }
  239. }
  240. </style>