cardType.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="content">
  3. <view class="content1">
  4. <view v-for='item in cardTypeList'>
  5. <view class='flex row flex-between'>
  6. <view class="left flex">
  7. <view class="f-text flex flex-all-center">{{item.circleName[0]}}</view>
  8. <view class="text">{{item.circleName}}</view>
  9. </view>
  10. <view class="right">
  11. <image src="../../static/imgs/mySet/del.png" class="img" mode="widthFix"
  12. v-if='item.circleName!="默认分类"' @click="del(item)"></image>
  13. <image src="../../static/imgs/mySet/zd.png" class="img" mode="widthFix" @click="stick(item)">
  14. </image>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <u-modal showCancelButton='true' @confirm='$u.debounce(confirm, 500)' @cancel='show=false' :show="show"
  20. title="新增分类" confirmColor="#112253">
  21. <view class="slot-content">
  22. <u--input v-model="cardTypeData.circleName" placeholder="输入分类名称,2-8个字符" border="none"></u--input>
  23. </view>
  24. </u-modal>
  25. <view @click='add' class='button'>新增</view>
  26. <u-toast ref="uToast"></u-toast>
  27. </view>
  28. </template>
  29. <script>
  30. var that;
  31. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  32. export default {
  33. mixins: [MescrollMixin],
  34. data() {
  35. return {
  36. show: false,
  37. cardTypeList: [],
  38. cardTypeData: {},
  39. userInfo: {},
  40. canReset: false,
  41. };
  42. },
  43. onLoad() {
  44. that = this
  45. },
  46. onShow() {
  47. this.userInfo = uni.getStorageSync("userInfo")
  48. this.cardTypeData.commonId = uni.getStorageSync("userInfo").id
  49. this.getList()
  50. },
  51. methods: {
  52. getList() {
  53. uni.showLoading({
  54. title: '数据加载中'
  55. })
  56. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'list', {
  57. commonId: uni.getStorageSync("userInfo").id
  58. }, failres => {
  59. console.log('res+++++', failres.errmsg)
  60. this.$refs.uToast.show({
  61. type: 'error',
  62. message: failres.errmsg,
  63. })
  64. uni.hideLoading()
  65. }).then(res => {
  66. // this.cardTypeList = res.data.items
  67. uni.hideLoading()
  68. debugger
  69. if (res.data.items.length > 0) {
  70. for (var i = 0; i < res.data.items.length; i++) {
  71. res.data.items[i].name = res.data.items[i].circleName[0]
  72. }
  73. var itemIndex = res.data.items.findIndex((item) => {
  74. return item.topMarking == 1
  75. })
  76. if (itemIndex != -1) {
  77. var data = res.data.items.splice(itemIndex, 1)
  78. res.data.items.unshift({
  79. circleName: '默认分类',
  80. name: '默'
  81. })
  82. res.data.items = data.concat(res.data.items)
  83. } else {
  84. res.data.items = [{
  85. circleName: '默认分类',
  86. name: '默'
  87. }].concat(res.data.items)
  88. }
  89. this.cardTypeList = res.data.items
  90. } else {
  91. this.cardTypeList = [{
  92. circleName: '默认分类',
  93. name: '默'
  94. }]
  95. }
  96. })
  97. },
  98. del(item) {
  99. uni.showLoading({
  100. title: '加载中',
  101. mask: true
  102. })
  103. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'delete', {
  104. commonId: uni.getStorageSync("userInfo").id,
  105. id: item.id
  106. }, failres => {
  107. console.log('res+++++', failres.errmsg)
  108. uni.showToast({
  109. title: failres.errmsg,
  110. icon: 'none',
  111. duration: 2000
  112. })
  113. uni.hideLoading()
  114. }).then(res => {
  115. uni.hideLoading()
  116. this.$refs.uToast.show({
  117. type: 'success',
  118. message: '删除成功!',
  119. complete() {
  120. that.getList()
  121. }
  122. })
  123. })
  124. },
  125. stick(item) {
  126. uni.showLoading({
  127. title: '加载中',
  128. mask: true
  129. })
  130. var type = '',
  131. type1 = '',
  132. data = {}
  133. if (item.id) {
  134. type = 'admin.unimall.cardClassifyInfo'
  135. type1 = 'top'
  136. data = {
  137. cardClassifyInfo: JSON.stringify({
  138. id: item.id
  139. })
  140. }
  141. } else {
  142. type = 'admin.unimall.cardClassifyInfo'
  143. type1 = 'topDefault'
  144. data = {
  145. cardClassifyInfo: JSON.stringify({
  146. commonId: this.cardTypeData.commonId
  147. })
  148. }
  149. }
  150. this.$request.baseRequest(type, type1, data, failres => {
  151. console.log('res+++++', failres.errmsg)
  152. uni.showToast({
  153. title: failres.errmsg,
  154. icon: 'none',
  155. duration: 2000
  156. })
  157. uni.hideLoading()
  158. }).then(res => {
  159. uni.hideLoading()
  160. this.$refs.uToast.show({
  161. type: 'success',
  162. message: '置顶成功!',
  163. complete() {
  164. that.getList()
  165. }
  166. })
  167. })
  168. },
  169. add() {
  170. this.show = true
  171. },
  172. confirm() {
  173. if (!this.cardTypeData.circleName) {
  174. uni.showToast({
  175. title: '分类名称不能为空!',
  176. icon: 'none',
  177. duration: 2000
  178. })
  179. return
  180. }
  181. if (this.cardTypeData.circleName < 2 || this.cardTypeData.circleName > 8) {
  182. uni.showToast({
  183. title: '类别名称2-8个字!',
  184. icon: 'none',
  185. duration: 2000
  186. })
  187. return
  188. }
  189. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'add', {
  190. cardClassifyInfo: JSON.stringify(this.cardTypeData)
  191. }, failres => {
  192. console.log('res+++++', failres.errmsg)
  193. this.$refs.uToast.show({
  194. type: 'error',
  195. message: failres.errmsg,
  196. })
  197. uni.hideLoading()
  198. }).then(res => {
  199. uni.hideLoading()
  200. this.show = false
  201. this.cardTypeData = {
  202. commonId: uni.getStorageSync("userInfo").id,
  203. }
  204. this.$refs.uToast.show({
  205. type: 'success',
  206. message: '操作成功',
  207. complete() {
  208. that.getList()
  209. }
  210. })
  211. })
  212. }
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .content1 {
  218. .row {
  219. margin: 20rpx 20rpx 0 20rpx;
  220. background-color: #fff;
  221. padding: 20rpx;
  222. border-radius: 20rpx;
  223. .f-text {
  224. width: 58rpx;
  225. height: 58rpx;
  226. background-color: #112253;
  227. border-radius: 50%;
  228. color: #fff;
  229. margin-right: 20rpx;
  230. font-size: 32rpx;
  231. }
  232. .img {
  233. width: 48rpx;
  234. margin-left: 20rpx;
  235. }
  236. }
  237. }
  238. .button {
  239. position: fixed;
  240. bottom: 108rpx;
  241. width: calc(100% - 40rpx);
  242. padding: 24rpx 0;
  243. color: #fff;
  244. background-color: #112253;
  245. text-align: center;
  246. margin: 0 20rpx;
  247. border-radius: 20rpx;
  248. }
  249. </style>