index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="one_1">
  5. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索商品">
  6. </view>
  7. <view class="one_2">
  8. <button size="mini" class="button" type="primary" @click="toAdd">添加</button>
  9. </view>
  10. </view>
  11. <view class="two">
  12. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  13. <view class="list-scroll-view">
  14. <view class="list" v-for="(item, index) in list" :key="index">
  15. <view class="list_1">
  16. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="">
  17. </image>
  18. <view class="other">
  19. <view class="name textOver">{{item.name||'暂无名称'}}</view>
  20. <view class="type">类型:{{item.zhType||'暂无类型'}}</view>
  21. <view class="type">销量:{{item.sell_num||'暂无销量'}}</view>
  22. <view class="type">是否使用:{{item.zhUser||'暂无'}}</view>
  23. </view>
  24. </view>
  25. <view class="btn">
  26. <button size="mini" class="button" type="primary" @click="toEdit(item)">修改</button>
  27. <button size="mini" class="button" type="primary" @click="toSpec(item)">新增规格</button>
  28. </view>
  29. </view>
  30. <view class="is_bottom" v-if="is_bottom">
  31. <text>已经到底了!</text>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. searchInfo: {},
  43. user: {},
  44. list: [],
  45. total: 0,
  46. skip: 0,
  47. limit: 6,
  48. page: 0,
  49. // 数据是否触底
  50. is_bottom: false,
  51. scrollTop: 0,
  52. // 字典表
  53. typeList: [],
  54. is_useList: [],
  55. }
  56. },
  57. onLoad: async function() {
  58. const that = this;
  59. that.searchToken();
  60. },
  61. onShow: async function() {
  62. const that = this;
  63. that.clearPage();
  64. await that.searchOther();
  65. await that.search();
  66. },
  67. onPullDownRefresh: async function() {
  68. const that = this;
  69. that.clearPage();
  70. await that.search();
  71. uni.stopPullDownRefresh();
  72. },
  73. methods: {
  74. searchToken() {
  75. const that = this;
  76. try {
  77. const res = uni.getStorageSync('token');
  78. if (res) that.$set(that, `user`, res);
  79. } catch (e) {
  80. uni.showToast({
  81. title: err.errmsg,
  82. icon: 'error',
  83. duration: 2000
  84. });
  85. }
  86. },
  87. async search() {
  88. const that = this;
  89. let user = that.user;
  90. let info = {
  91. skip: that.skip,
  92. limit: that.limit,
  93. supplier_id: user._id
  94. }
  95. const res = await that.$api(`/Good`, 'GET', {
  96. ...info
  97. })
  98. if (res.errcode == '0') {
  99. let list = [...that.list, ...res.data];
  100. for (let val of list) {
  101. let type = that.typeList.find(i => i.value == val.type)
  102. if (type) val.zhType = type.label;
  103. let is_use = that.is_useList.find(i => i.value == val.is_use)
  104. if (is_use) val.zhUser = is_use.label;
  105. }
  106. that.$set(that, `list`, list)
  107. that.$set(that, `total`, res.total)
  108. } else {
  109. uni.showToast({
  110. title: res.errmsg,
  111. });
  112. }
  113. },
  114. // 查看详情
  115. async toView(item) {
  116. console.log(item);
  117. },
  118. // 输入框
  119. toInput(e) {
  120. const that = this;
  121. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  122. else that.$set(that, `searchInfo`, {})
  123. that.clearPage();
  124. that.search();
  125. },
  126. // 新增
  127. toAdd() {
  128. uni.navigateTo({
  129. url: `/pagesMy/goods/add`
  130. })
  131. },
  132. // 修改
  133. toEdit(e) {
  134. uni.navigateTo({
  135. url: `/pagesMy/goods/add?id=${e._id}`
  136. })
  137. },
  138. // 新增规格
  139. toSpec(e) {
  140. uni.navigateTo({
  141. url: `/pagesMy/spec/index?id=${e._id}`
  142. })
  143. },
  144. async searchOther() {
  145. const that = this;
  146. let res;
  147. //类型
  148. res = await that.$api('/DictData', 'GET', {
  149. type: 'goods_type',
  150. is_use: '0'
  151. })
  152. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  153. //是否使用
  154. res = await that.$api('/DictData', 'GET', {
  155. type: 'is_use',
  156. is_use: '0'
  157. })
  158. if (res.errcode == '0') that.$set(that, `is_useList`, res.data);
  159. },
  160. // 分页
  161. toPage(e) {
  162. const that = this;
  163. let list = that.list;
  164. let limit = that.limit;
  165. if (that.total > list.length) {
  166. uni.showLoading({
  167. title: '加载中',
  168. mask: true
  169. })
  170. let page = that.page + 1;
  171. that.$set(that, `page`, page)
  172. let skip = page * limit;
  173. that.$set(that, `skip`, skip)
  174. that.search();
  175. uni.hideLoading();
  176. } else that.$set(that, `is_bottom`, true)
  177. },
  178. toScroll(e) {
  179. const that = this;
  180. let up = that.scrollTop;
  181. that.$set(that, `scrollTop`, e.detail.scrollTop);
  182. let num = Math.sign(up - e.detail.scrollTop);
  183. if (num == 1) that.$set(that, `is_bottom`, false);
  184. },
  185. // 清空列表
  186. clearPage() {
  187. const that = this;
  188. that.$set(that, `list`, [])
  189. that.$set(that, `skip`, 0)
  190. that.$set(that, `limit`, 6)
  191. that.$set(that, `page`, 0)
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. .content {
  198. display: flex;
  199. flex-direction: column;
  200. width: 100vw;
  201. height: 100vh;
  202. .one {
  203. display: flex;
  204. justify-content: center;
  205. align-items: center;
  206. padding: 2vw;
  207. .one_1 {
  208. padding: 0 2vw;
  209. width: 75vw;
  210. input {
  211. padding: 2vw;
  212. background-color: var(--f1Color);
  213. font-size: var(--font14Size);
  214. border-radius: 5px;
  215. }
  216. }
  217. .button {
  218. background-color: var(--f3CColor);
  219. color: var(--mainColor);
  220. }
  221. }
  222. .two {
  223. position: relative;
  224. flex-grow: 1;
  225. background-color: var(--f9Color);
  226. margin: 2vw 0 0 0;
  227. .list {
  228. background-color: var(--mainColor);
  229. border: 1px solid var(--f5Color);
  230. padding: 2vw;
  231. margin: 2vw 2vw 0 2vw;
  232. border-radius: 5px;
  233. .list_1 {
  234. display: flex;
  235. .image {
  236. width: 20vw;
  237. height: 20vw;
  238. }
  239. .other {
  240. margin: 0 0 0 2vw;
  241. .name {
  242. font-size: var(--font16Size);
  243. margin: 0 0 1vw 0;
  244. }
  245. .type {
  246. color: var(--f85Color);
  247. font-size: var(--font14Size);
  248. }
  249. }
  250. }
  251. .btn {
  252. text-align: center;
  253. margin: 1vw 0 0 0;
  254. .button {
  255. background-color: var(--f3CColor);
  256. color: var(--mainColor);
  257. margin: 0 1vw 0 0;
  258. }
  259. }
  260. }
  261. }
  262. }
  263. .scroll-view {
  264. position: absolute;
  265. top: 0;
  266. left: 0;
  267. right: 0;
  268. bottom: 0;
  269. .list-scroll-view {
  270. display: flex;
  271. flex-direction: column;
  272. }
  273. }
  274. .is_bottom {
  275. text-align: center;
  276. text {
  277. padding: 2vw 0;
  278. display: inline-block;
  279. color: var(--f85Color);
  280. font-size: var(--font14Size);
  281. }
  282. }
  283. </style>