index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. uni.showModal({
  158. title: '提示',
  159. content: '确定取消该规格吗?',
  160. success: async function(res) {
  161. if (res.confirm) {
  162. const res = await that.$api(`/Specs/${e._id}`, 'DELETE', {})
  163. if (res.errcode == 0) {
  164. that.clearPage();
  165. that.search();
  166. } else {
  167. uni.showToast({
  168. title: res.errmsg,
  169. icon: 'none'
  170. })
  171. }
  172. }
  173. }
  174. });
  175. },
  176. async searchOther() {
  177. const that = this;
  178. let res;
  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. }
  287. }
  288. }
  289. }
  290. .scroll-view {
  291. position: absolute;
  292. top: 0;
  293. left: 0;
  294. right: 0;
  295. bottom: 0;
  296. .list-scroll-view {
  297. display: flex;
  298. flex-direction: column;
  299. }
  300. }
  301. .is_bottom {
  302. width: 100%;
  303. text-align: center;
  304. text {
  305. padding: 2vw 0;
  306. display: inline-block;
  307. color: var(--f85Color);
  308. font-size: var(--font14Size);
  309. }
  310. }
  311. </style>