index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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" style="padding-left: 1%;">
  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. <view @click="goPutSupply()">
  36. <view class="menu">
  37. <view>
  38. <image src="/static/supply/putSupply.png" />
  39. </view>
  40. <view class="menu_title">发布供需</view>
  41. </view>
  42. </view>
  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. goPutSupply(){
  75. if(!getApp().globalData.user_phone){
  76. uni.showToast({
  77. title: "您还没有登录授权",
  78. duration: 2500,
  79. icon: "none",
  80. });
  81. uni.navigateTo({
  82. url:'/pages/auth/index'
  83. })
  84. }else {
  85. uni.navigateTo({
  86. url:'/pages/supply/putSupply'
  87. })
  88. }
  89. },
  90. toDetail(index) {
  91. uni.navigateTo({
  92. url: "/pages/supply/supply_detail?id=" + index,
  93. });
  94. },
  95. getMyList() {
  96. let md5Sign = md5(
  97. "method=" +
  98. "need" +
  99. "&timestamp=" +
  100. getApp().globalData.globalTimestamp +
  101. "&secret=" +
  102. getApp().globalData.secret
  103. );
  104. let url =
  105. getApp().globalData.shareUrl +
  106. "api/api.php" +
  107. "?method=need&source=need&action=list&timestamp=" +
  108. getApp().globalData.globalTimestamp +
  109. "&sign=" +
  110. md5Sign;
  111. let postData = {
  112. s_type: this.index == 2 ? 1 : 2,
  113. };
  114. uni.request({
  115. url: url,
  116. method: "POST",
  117. header: {
  118. "content-type": "application/x-www-form-urlencoded",
  119. },
  120. data: this.index == -1 || this.index == 0 ? {} : postData,
  121. success: (res) => {
  122. if (res.data.code === 200) {
  123. let list = res.data.data.list;
  124. /*
  125. supplyList: new Array(5).fill({
  126. image: "/static/supply/u1779.png",
  127. title: "移动式空气消毒机",
  128. time: "2021-08-30 14:50:00",
  129. state: 1,
  130. }),
  131. */
  132. console.log(list);
  133. this.supplyList = list.map((item) => {
  134. let ob = {
  135. image: "",
  136. title: "",
  137. time: "",
  138. state: "",
  139. id: "",
  140. };
  141. ob.id = item.id;
  142. ob.title = item.title;
  143. let time = this.$options.filters["globalTime"](item.addtime);
  144. let timeSecond = this.$options.filters["globalTimeSecond"](
  145. item.addtime
  146. );
  147. ob.time = time + " " + timeSecond;
  148. ob.state = item.type;
  149. // ob.image = "/static/nodata.svg";
  150. ob.image = item.attach_list[0]
  151. ? getApp().globalData.shareUrl + item.attach_list[0]
  152. : "/static/nodata.svg";
  153. return ob;
  154. });
  155. // console.log(res.data.data.list);
  156. }
  157. },
  158. fail: () => {
  159. console.log("连接失败");
  160. },
  161. });
  162. },
  163. },
  164. };
  165. </script>
  166. <style lang="scss" scope>
  167. .active {
  168. color: $uni-color-primary;
  169. }
  170. .content {
  171. font-size: 32rpx;
  172. margin: 0 5%;
  173. .picker {
  174. display: flex;
  175. justify-content: flex-start;
  176. position: relative;
  177. width: 100%;
  178. margin: 20rpx 0;
  179. .picker_self {
  180. width: 100%;
  181. }
  182. .picker_title {
  183. z-index: 99;
  184. // width: 100%;
  185. height: 100%;
  186. display: flex;
  187. justify-content: flex-start;
  188. }
  189. }
  190. .picker::after {
  191. content: "";
  192. position: absolute;
  193. left: 11%;
  194. top: 20%;
  195. width: 0;
  196. height: 0;
  197. border-top: 15rpx solid rgb(173, 173, 173);
  198. border-left: 15rpx solid transparent;
  199. border-right: 15rpx solid transparent;
  200. }
  201. .supplyList {
  202. .supplyCard {
  203. display: flex;
  204. width: 92%;
  205. margin: 3% 0;
  206. padding: 2% 4%;
  207. height: 5%;
  208. border-radius: 30rpx;
  209. box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 0rpx;
  210. .image_content {
  211. margin-right: 5%;
  212. display: flex;
  213. align-items: center;
  214. image {
  215. width: 100rpx;
  216. height: 100rpx;
  217. border-radius: 20rpx;
  218. background-color: rgb(228, 228, 228);
  219. }
  220. }
  221. .info {
  222. display: flex;
  223. flex-flow: column;
  224. justify-content: space-around;
  225. .title {
  226. width: 100%;
  227. text-overflow: -o-ellipsis-lastline;
  228. overflow: hidden;
  229. text-overflow: ellipsis;
  230. display: -webkit-box;
  231. -webkit-line-clamp: 2;
  232. line-clamp: 2;
  233. -webkit-box-orient: vertical;
  234. font-size: 32rpx;
  235. }
  236. .time {
  237. font-weight: 100;
  238. font-size: 26rpx;
  239. }
  240. }
  241. }
  242. }
  243. .menus {
  244. z-index: 999;
  245. display: flex;
  246. justify-content: space-around;
  247. width: 80%;
  248. // height: 6%;
  249. position: fixed;
  250. top: 85%;
  251. left: 50%;
  252. padding: 4%;
  253. border-radius: 40rpx;
  254. box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 0rpx;
  255. transform: translateX(-50%);
  256. background-color: #fff;
  257. image {
  258. width: 50rpx;
  259. height: 50rpx;
  260. border-radius: 10rpx;
  261. }
  262. .menu {
  263. display: flex;
  264. flex-flow: column;
  265. align-items: center;
  266. .menu_title {
  267. text-align: center;
  268. font-size: 28rpx;
  269. }
  270. }
  271. }
  272. }
  273. </style>