index.vue 6.6 KB

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