index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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.money||'暂无'}}元</view>
  21. <view class="type">库存:{{item.num||'0'}}</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. </view>
  28. </view>
  29. <view class="is_bottom" v-if="is_bottom">
  30. <text>已经到底了!</text>
  31. </view>
  32. </view>
  33. </scroll-view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. id: '',
  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. is_useList: [],
  54. }
  55. },
  56. onLoad: async function(e) {
  57. const that = this;
  58. that.$set(that, `id`, e && e.id || '');
  59. that.searchToken();
  60. await that.searchOther();
  61. },
  62. onShow: async function() {
  63. const that = this;
  64. that.clearPage();
  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 id = that.id;
  90. let info = {
  91. skip: that.skip,
  92. limit: that.limit,
  93. goods: id
  94. }
  95. const res = await that.$api(`/Specs`, 'GET', {
  96. ...info
  97. })
  98. if (res.errcode == '0') {
  99. let list = [...that.list, ...res.data];
  100. for (let val of list) {
  101. let is_use = that.is_useList.find(i => i.value == val.is_use)
  102. if (is_use) val.zhUser = is_use.label;
  103. }
  104. that.$set(that, `list`, list)
  105. that.$set(that, `total`, res.total)
  106. } else {
  107. uni.showToast({
  108. title: res.errmsg,
  109. });
  110. }
  111. },
  112. // 查看详情
  113. async toView(item) {
  114. console.log(item);
  115. },
  116. // 输入框
  117. toInput(e) {
  118. const that = this;
  119. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  120. else that.$set(that, `searchInfo`, {})
  121. that.clearPage();
  122. that.search();
  123. },
  124. // 新增
  125. toAdd() {
  126. const that = this;
  127. uni.navigateTo({
  128. url: `/pagesMy/spec/add?goods=${that.id}`
  129. })
  130. },
  131. // 修改
  132. toEdit(e) {
  133. uni.navigateTo({
  134. url: `/pagesMy/spec/add?id=${e._id}&goods=${e.goods}`
  135. })
  136. },
  137. async searchOther() {
  138. const that = this;
  139. let res;
  140. //是否使用
  141. res = await that.$api('/DictData', 'GET', {
  142. type: 'is_use',
  143. is_use: '0'
  144. })
  145. if (res.errcode == '0') that.$set(that, `is_useList`, res.data);
  146. },
  147. // 分页
  148. toPage(e) {
  149. const that = this;
  150. let list = that.list;
  151. let limit = that.limit;
  152. if (that.total > list.length) {
  153. uni.showLoading({
  154. title: '加载中',
  155. mask: true
  156. })
  157. let page = that.page + 1;
  158. that.$set(that, `page`, page)
  159. let skip = page * limit;
  160. that.$set(that, `skip`, skip)
  161. that.search();
  162. uni.hideLoading();
  163. } else that.$set(that, `is_bottom`, true)
  164. },
  165. toScroll(e) {
  166. const that = this;
  167. let up = that.scrollTop;
  168. that.$set(that, `scrollTop`, e.detail.scrollTop);
  169. let num = Math.sign(up - e.detail.scrollTop);
  170. if (num == 1) that.$set(that, `is_bottom`, false);
  171. },
  172. // 清空列表
  173. clearPage() {
  174. const that = this;
  175. that.$set(that, `list`, [])
  176. that.$set(that, `skip`, 0)
  177. that.$set(that, `limit`, 6)
  178. that.$set(that, `page`, 0)
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. .content {
  185. display: flex;
  186. flex-direction: column;
  187. width: 100vw;
  188. height: 100vh;
  189. .one {
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. padding: 2vw;
  194. .one_1 {
  195. padding: 0 2vw;
  196. width: 75vw;
  197. input {
  198. padding: 2vw;
  199. background-color: var(--f1Color);
  200. font-size: var(--font14Size);
  201. border-radius: 5px;
  202. }
  203. }
  204. .button {
  205. background-color: var(--f3CColor);
  206. color: var(--mainColor);
  207. }
  208. }
  209. .two {
  210. position: relative;
  211. flex-grow: 1;
  212. background-color: var(--f9Color);
  213. margin: 2vw 0 0 0;
  214. .list {
  215. background-color: var(--mainColor);
  216. border: 1px solid var(--f5Color);
  217. padding: 2vw;
  218. margin: 2vw 2vw 0 2vw;
  219. border-radius: 5px;
  220. .list_1 {
  221. display: flex;
  222. .image {
  223. width: 20vw;
  224. height: 20vw;
  225. }
  226. .other {
  227. margin: 0 0 0 2vw;
  228. .name {
  229. font-size: var(--font16Size);
  230. margin: 0 0 1vw 0;
  231. }
  232. .type {
  233. color: var(--f85Color);
  234. font-size: var(--font14Size);
  235. }
  236. }
  237. }
  238. .btn {
  239. text-align: center;
  240. margin: 1vw 0 0 0;
  241. .button {
  242. background-color: var(--f3CColor);
  243. color: var(--mainColor);
  244. margin: 0 1vw 0 0;
  245. }
  246. }
  247. }
  248. }
  249. }
  250. .scroll-view {
  251. position: absolute;
  252. top: 0;
  253. left: 0;
  254. right: 0;
  255. bottom: 0;
  256. .list-scroll-view {
  257. display: flex;
  258. flex-direction: column;
  259. }
  260. }
  261. .is_bottom {
  262. text-align: center;
  263. text {
  264. padding: 2vw 0;
  265. display: inline-block;
  266. color: var(--f85Color);
  267. font-size: var(--font14Size);
  268. }
  269. }
  270. </style>