index.vue 7.1 KB

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