index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. uni.showModal({
  159. title: '提示',
  160. content: '确定取消该商品吗?',
  161. success: async function(res) {
  162. if (res.confirm) {
  163. const res = await that.$api(`/Good/${e._id}`, 'DELETE', {})
  164. if (res.errcode == 0) {
  165. that.clearPage();
  166. that.search();
  167. } else {
  168. uni.showToast({
  169. title: res.errmsg,
  170. icon: 'none'
  171. })
  172. }
  173. }
  174. }
  175. });
  176. },
  177. // 新增规格
  178. toSpec(e) {
  179. uni.navigateTo({
  180. url: `/pagesMy/spec/index?id=${e._id}`
  181. })
  182. },
  183. async searchOther() {
  184. const that = this;
  185. let res;
  186. //类型
  187. res = await that.$api('/DictData', 'GET', {
  188. type: 'goods_type',
  189. is_use: '0'
  190. })
  191. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  192. //是否使用
  193. res = await that.$api('/DictData', 'GET', {
  194. type: 'is_use',
  195. is_use: '0'
  196. })
  197. if (res.errcode == '0') that.$set(that, `is_useList`, res.data);
  198. },
  199. // 分页
  200. toPage(e) {
  201. const that = this;
  202. let list = that.list;
  203. let limit = that.limit;
  204. if (that.total > list.length) {
  205. uni.showLoading({
  206. title: '加载中',
  207. mask: true
  208. })
  209. let page = that.page + 1;
  210. that.$set(that, `page`, page)
  211. let skip = page * limit;
  212. that.$set(that, `skip`, skip)
  213. that.search();
  214. uni.hideLoading();
  215. } else that.$set(that, `is_bottom`, true)
  216. },
  217. toScroll(e) {
  218. const that = this;
  219. let up = that.scrollTop;
  220. that.$set(that, `scrollTop`, e.detail.scrollTop);
  221. let num = Math.sign(up - e.detail.scrollTop);
  222. if (num == 1) that.$set(that, `is_bottom`, false);
  223. },
  224. // 清空列表
  225. clearPage() {
  226. const that = this;
  227. that.$set(that, `list`, [])
  228. that.$set(that, `skip`, 0)
  229. that.$set(that, `limit`, 6)
  230. that.$set(that, `page`, 0)
  231. }
  232. }
  233. }
  234. </script>
  235. <style lang="scss">
  236. .content {
  237. display: flex;
  238. flex-direction: column;
  239. width: 100vw;
  240. height: 100vh;
  241. .one {
  242. display: flex;
  243. justify-content: center;
  244. align-items: center;
  245. padding: 2vw;
  246. .one_1 {
  247. padding: 0 2vw;
  248. width: 75vw;
  249. input {
  250. padding: 2vw;
  251. background-color: var(--f1Color);
  252. font-size: var(--font14Size);
  253. border-radius: 5px;
  254. }
  255. }
  256. .button {
  257. background-color: var(--f3CColor);
  258. color: var(--mainColor);
  259. }
  260. }
  261. .two {
  262. position: relative;
  263. flex-grow: 1;
  264. background-color: var(--f9Color);
  265. margin: 2vw 0 0 0;
  266. .list {
  267. background-color: var(--mainColor);
  268. border: 1px solid var(--f5Color);
  269. padding: 2vw;
  270. margin: 2vw 2vw 0 2vw;
  271. border-radius: 5px;
  272. .list_1 {
  273. display: flex;
  274. .image {
  275. width: 20vw;
  276. height: 20vw;
  277. }
  278. .other {
  279. width: 69vw;
  280. margin: 0 0 0 2vw;
  281. .name {
  282. font-size: var(--font16Size);
  283. margin: 0 0 1vw 0;
  284. }
  285. .type {
  286. color: var(--f85Color);
  287. font-size: var(--font14Size);
  288. }
  289. }
  290. }
  291. .btn {
  292. text-align: center;
  293. margin: 1vw 0 0 0;
  294. .button {
  295. background-color: var(--f3CColor);
  296. color: var(--mainColor);
  297. margin: 0 1vw 0 0;
  298. }
  299. .button1 {
  300. margin: 0 1vw 0 0;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. .scroll-view {
  307. position: absolute;
  308. top: 0;
  309. left: 0;
  310. right: 0;
  311. bottom: 0;
  312. .list-scroll-view {
  313. display: flex;
  314. flex-direction: column;
  315. }
  316. }
  317. .is_bottom {
  318. width: 100%;
  319. text-align: center;
  320. text {
  321. padding: 2vw 0;
  322. display: inline-block;
  323. color: var(--f85Color);
  324. font-size: var(--font14Size);
  325. }
  326. }
  327. </style>