cardType.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view>
  3. <mescroll-body :up="upOption" 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. upOption:{
  44. page:{
  45. num : 0 ,
  46. size : 10 ,
  47. time : null
  48. }
  49. }
  50. };
  51. },
  52. onLoad() {
  53. // this.getList()
  54. },
  55. onShow() {
  56. this.userInfo = uni.getStorageSync("userInfo")
  57. this.cardTypeData.commonId=uni.getStorageSync("userInfo").id
  58. },
  59. methods: {
  60. mescrollInit(){
  61. },
  62. downCallback(){
  63. var that = this
  64. this.$nextTick(() => {
  65. // mescroll.endSuccess(data.result);
  66. that.mescroll.resetUpScroll()
  67. });
  68. },
  69. upCallback(page){
  70. var that = this
  71. uni.showLoading({
  72. title: '数据加载中'
  73. })
  74. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'list',{
  75. page:page.num,
  76. limit:page.size,
  77. commonId:uni.getStorageSync("userInfo").id
  78. }, failres => {
  79. console.log('res+++++', failres.errmsg)
  80. this.$refs.uToast.show({
  81. type: 'error',
  82. message: failres.errmsg,
  83. })
  84. uni.hideLoading()
  85. }).then(res => {
  86. console.log(res)
  87. if(page.num == 1) this.cardTypeList = [];
  88. let curPageLen = res.data.items.length;
  89. let totalPage = res.data.total;
  90. if(res.data.items.length>0){
  91. for(var i=0;i<res.data.items.length;i++){
  92. res.data.items[i].name=res.data.items[i].circleName[0]
  93. }
  94. var itemIndex=res.data.items.findIndex((item)=>{return item.topMarking==1})
  95. // console.log(itemIndex)
  96. if(itemIndex!=-1){
  97. var data=res.data.items.splice(itemIndex,1)
  98. if(page.num==1){
  99. data.push({circleName:'默认分类',name:'默'})
  100. }
  101. // console.log(data.concat(res.data.items))
  102. res.data.items=data.concat(res.data.items)
  103. }else{
  104. if(page.num==1){
  105. res.data.items=[{circleName:'默认分类',name:'默'}].concat(res.data.items)
  106. }
  107. }
  108. this.cardTypeList=this.cardTypeList.concat(res.data.items)
  109. }else{
  110. if(page.num==1){
  111. this.cardTypeList=[{circleName:'默认分类',name:'默'}]
  112. }
  113. }
  114. this.$nextTick(() => {
  115. console.log(that)
  116. // mescroll.endSuccess(data.result);
  117. that.mescroll.endBySize(curPageLen, totalPage)
  118. });
  119. // if (res.errno == 200) {
  120. uni.hideLoading()
  121. // }
  122. })
  123. },
  124. del(item){
  125. uni.showLoading({
  126. title: '加载中',
  127. mask:true
  128. })
  129. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'delete',{
  130. commonId:uni.getStorageSync("userInfo").id,
  131. id:item.id
  132. }, failres => {
  133. console.log('res+++++', failres.errmsg)
  134. uni.showToast({
  135. title: failres.errmsg,
  136. icon: 'none',
  137. duration: 2000
  138. })
  139. uni.hideLoading()
  140. }).then(res => {
  141. uni.showToast({
  142. title: '删除成功',
  143. icon: 'none',
  144. duration: 2000
  145. })
  146. uni.hideLoading()
  147. this.mescroll.resetUpScroll( )
  148. })
  149. },
  150. stick(item){
  151. uni.showLoading({
  152. title: '加载中',
  153. mask:true
  154. })
  155. var type='',type1='',data={}
  156. if(item.id){
  157. type='admin.unimall.cardClassifyInfo'
  158. type1='top'
  159. data={
  160. cardClassifyInfo:JSON.stringify({id:item.id})
  161. }
  162. }else{
  163. type='admin.unimall.cardClassifyInfo'
  164. type1='topDefault'
  165. data={
  166. cardClassifyInfo:JSON.stringify({commonId:this.cardTypeData.commonId})
  167. }
  168. }
  169. this.$request.baseRequest(type, type1,data, failres => {
  170. console.log('res+++++', failres.errmsg)
  171. uni.showToast({
  172. title: failres.errmsg,
  173. icon: 'none',
  174. duration: 2000
  175. })
  176. uni.hideLoading()
  177. }).then(res => {
  178. uni.showToast({
  179. title: '置顶成功',
  180. icon: 'none',
  181. duration: 2000
  182. })
  183. uni.hideLoading()
  184. this.mescroll.resetUpScroll( )
  185. })
  186. },
  187. add(){
  188. // if(){
  189. // }
  190. this.show=true
  191. },
  192. confirm(){
  193. if(!this.cardTypeData.circleName){
  194. uni.showToast({
  195. title: '分类名称不能为空!',
  196. icon: 'none',
  197. duration: 2000
  198. })
  199. return
  200. }
  201. if(this.cardTypeData.circleName<2||this.cardTypeData.circleName>8){
  202. uni.showToast({
  203. title: '类别名称2-8个字!',
  204. icon: 'none',
  205. duration: 2000
  206. })
  207. return
  208. }
  209. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'add',{
  210. cardClassifyInfo:JSON.stringify(this.cardTypeData)
  211. }, failres => {
  212. console.log('res+++++', failres.errmsg)
  213. uni.showToast({
  214. title: failres.errmsg,
  215. icon: 'none',
  216. duration: 2000
  217. })
  218. uni.hideLoading()
  219. }).then(res => {
  220. console.log(res)
  221. // if (res.errno == 200) {
  222. uni.hideLoading()
  223. this.show=false
  224. this.cardTypeData={
  225. commonId:uni.getStorageSync("userInfo").id,
  226. }
  227. this.mescroll.resetUpScroll( )
  228. // }
  229. })
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. </style>