cardType.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view>
  3. <mescroll-body ref="mescrollRef" @init="mescrollInit" @up="upCallback" @down="downCallback">
  4. <u-list @scrolltolower="scrolltolower">
  5. <u-list-item v-for='item in cardTypeList'>
  6. <view class='flex'>
  7. {{item.name}}
  8. {{item.circleName}}
  9. <u-icon v-if='item.circleName!="默认分类"' @click="del(item)" name="trash-fill" color="#2979ff" size="28"></u-icon>
  10. <u-icon @click="stick(item)" name="pushpin" color="#2979ff" size="28"></u-icon>
  11. </view>
  12. </u-list-item>
  13. </u-list>
  14. </mescroll-body>
  15. <u-modal showCancelButton='true'
  16. @confirm='$u.debounce(confirm, 500)'
  17. @cancel='show=false' :show="show" title="新增分类" >
  18. <view class="slot-content">
  19. <u--input
  20. v-model="cardTypeData.circleName"
  21. placeholder="输入分类名称,2-8个字符"
  22. border="none"
  23. ></u--input>
  24. </view>
  25. </u-modal>
  26. <view class="footer">
  27. <view @click='add' class='button'>新增</view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  33. export default {
  34. mixins: [MescrollMixin],
  35. data() {
  36. return {
  37. show:false,
  38. page:1,
  39. limit:20,
  40. cardTypeList:[],
  41. cardTypeData:{},
  42. userInfo:{},
  43. canReset:false,
  44. };
  45. },
  46. onLoad() {
  47. // this.getList()
  48. },
  49. onShow() {
  50. this.userInfo = uni.getStorageSync("userInfo")
  51. this.cardTypeData.commonId=uni.getStorageSync("userInfo").id
  52. this.$nextTick(function() {
  53. this.canReset && this.mescroll.resetUpScroll() // 重置列表数据为第一页
  54. this.canReset && this.mescroll.scrollTo(0, 0) // 重置列表数据为第一页时,建议把滚动条也重置到顶部,避免无法再次翻页的问题
  55. this.canReset = true // 过滤第一次的onShow事件,避免初始化界面时重复触发upCallback, 无需配置auto:false
  56. });
  57. },
  58. methods: {
  59. mescrollInit(){
  60. },
  61. downCallback(){
  62. var that = this
  63. this.$nextTick(() => {
  64. // mescroll.endSuccess(data.result);
  65. that.mescroll.resetUpScroll()
  66. });
  67. },
  68. upCallback(page){
  69. var that = this
  70. uni.showLoading({
  71. title: '数据加载中'
  72. })
  73. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'list',{
  74. page:page.num,
  75. limit:page.size,
  76. commonId:uni.getStorageSync("userInfo").id
  77. }, failres => {
  78. console.log('res+++++', failres.errmsg)
  79. this.$refs.uToast.show({
  80. type: 'error',
  81. message: failres.errmsg,
  82. })
  83. uni.hideLoading()
  84. }).then(res => {
  85. console.log(res)
  86. if(page.num == 1) this.cardTypeList = [];
  87. let curPageLen = res.data.items.length;
  88. let totalPage = res.data.total;
  89. if(res.data.items.length>0){
  90. for(var i=0;i<res.data.items.length;i++){
  91. res.data.items[i].name=res.data.items[i].circleName[0]
  92. }
  93. var itemIndex=res.data.items.findIndex((item)=>{return item.topMarking==1})
  94. // console.log(itemIndex)
  95. if(itemIndex!=-1){
  96. var data=res.data.items.splice(itemIndex,1)
  97. if(page.num==1){
  98. data.push({circleName:'默认分类',name:'默'})
  99. }
  100. // console.log(data.concat(res.data.items))
  101. res.data.items=data.concat(res.data.items)
  102. }else{
  103. if(page.num==1){
  104. res.data.items=[{circleName:'默认分类',name:'默'}].concat(res.data.items)
  105. }
  106. }
  107. this.cardTypeList=this.cardTypeList.concat(res.data.items)
  108. }else{
  109. if(page.num==1){
  110. this.cardTypeList=[{circleName:'默认分类',name:'默'}]
  111. }
  112. }
  113. this.$nextTick(() => {
  114. console.log(that)
  115. // mescroll.endSuccess(data.result);
  116. that.mescroll.endBySize(curPageLen, totalPage)
  117. });
  118. // if (res.errno == 200) {
  119. uni.hideLoading()
  120. // }
  121. })
  122. },
  123. del(item){
  124. uni.showLoading({
  125. title: '加载中',
  126. mask:true
  127. })
  128. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'delete',{
  129. commonId:uni.getStorageSync("userInfo").id,
  130. id:item.id
  131. }, failres => {
  132. console.log('res+++++', failres.errmsg)
  133. uni.showToast({
  134. title: failres.errmsg,
  135. icon: 'none',
  136. duration: 2000
  137. })
  138. uni.hideLoading()
  139. }).then(res => {
  140. uni.showToast({
  141. title: '删除成功',
  142. icon: 'none',
  143. duration: 2000
  144. })
  145. uni.hideLoading()
  146. this.mescroll.resetUpScroll( )
  147. })
  148. },
  149. stick(item){
  150. uni.showLoading({
  151. title: '加载中',
  152. mask:true
  153. })
  154. var type='',type1='',data={}
  155. if(item.id){
  156. type='admin.unimall.cardClassifyInfo'
  157. type1='top'
  158. data={
  159. cardClassifyInfo:JSON.stringify({id:item.id})
  160. }
  161. }else{
  162. type='admin.unimall.cardClassifyInfo'
  163. type1='topDefault'
  164. data={
  165. cardClassifyInfo:JSON.stringify({commonId:this.cardTypeData.commonId})
  166. }
  167. }
  168. this.$request.baseRequest(type, type1,data, failres => {
  169. console.log('res+++++', failres.errmsg)
  170. uni.showToast({
  171. title: failres.errmsg,
  172. icon: 'none',
  173. duration: 2000
  174. })
  175. uni.hideLoading()
  176. }).then(res => {
  177. uni.showToast({
  178. title: '置顶成功',
  179. icon: 'none',
  180. duration: 2000
  181. })
  182. uni.hideLoading()
  183. this.mescroll.resetUpScroll( )
  184. })
  185. },
  186. add(){
  187. // if(){
  188. // }
  189. this.show=true
  190. },
  191. confirm(){
  192. if(!this.cardTypeData.circleName){
  193. uni.showToast({
  194. title: '分类名称不能为空!',
  195. icon: 'none',
  196. duration: 2000
  197. })
  198. return
  199. }
  200. if(this.cardTypeData.circleName<2||this.cardTypeData.circleName>8){
  201. uni.showToast({
  202. title: '类别名称2-8个字!',
  203. icon: 'none',
  204. duration: 2000
  205. })
  206. return
  207. }
  208. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'add',{
  209. cardClassifyInfo:JSON.stringify(this.cardTypeData)
  210. }, failres => {
  211. console.log('res+++++', failres.errmsg)
  212. uni.showToast({
  213. title: failres.errmsg,
  214. icon: 'none',
  215. duration: 2000
  216. })
  217. uni.hideLoading()
  218. }).then(res => {
  219. console.log(res)
  220. // if (res.errno == 200) {
  221. uni.hideLoading()
  222. this.show=false
  223. this.cardTypeData={
  224. commonId:uni.getStorageSync("userInfo").id,
  225. }
  226. this.mescroll.resetUpScroll( )
  227. // }
  228. })
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="scss" scoped>
  234. </style>