cardType.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. if (res.data.items.length > 0) {
  69. for (var i = 0; i < res.data.items.length; i++) {
  70. res.data.items[i].name = res.data.items[i].circleName[0]
  71. }
  72. var itemIndex = res.data.items.findIndex((item) => {
  73. return item.topMarking == 1
  74. })
  75. if (itemIndex != -1) {
  76. var data = res.data.items.splice(itemIndex, 1)
  77. res.data.items.unshift({
  78. circleName: '默认分类',
  79. name: '默'
  80. })
  81. res.data.items = data.concat(res.data.items)
  82. } else {
  83. res.data.items = [{
  84. circleName: '默认分类',
  85. name: '默'
  86. }].concat(res.data.items)
  87. }
  88. this.cardTypeList = res.data.items
  89. } else {
  90. this.cardTypeList = [{
  91. circleName: '默认分类',
  92. name: '默'
  93. }]
  94. }
  95. })
  96. },
  97. del(item) {
  98. uni.showLoading({
  99. title: '加载中',
  100. mask: true
  101. })
  102. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'delete', {
  103. commonId: uni.getStorageSync("userInfo").id,
  104. id: item.id
  105. }, failres => {
  106. console.log('res+++++', failres.errmsg)
  107. uni.showToast({
  108. title: failres.errmsg,
  109. icon: 'none',
  110. duration: 2000
  111. })
  112. uni.hideLoading()
  113. }).then(res => {
  114. uni.hideLoading()
  115. this.$refs.uToast.show({
  116. type: 'success',
  117. message: '删除成功!',
  118. complete() {
  119. that.getList()
  120. }
  121. })
  122. })
  123. },
  124. stick(item) {
  125. uni.showLoading({
  126. title: '加载中',
  127. mask: true
  128. })
  129. var type = '',
  130. type1 = '',
  131. data = {}
  132. if (item.id) {
  133. type = 'admin.unimall.cardClassifyInfo'
  134. type1 = 'top'
  135. data = {
  136. cardClassifyInfo: JSON.stringify({
  137. id: item.id
  138. })
  139. }
  140. } else {
  141. type = 'admin.unimall.cardClassifyInfo'
  142. type1 = 'topDefault'
  143. data = {
  144. cardClassifyInfo: JSON.stringify({
  145. commonId: this.cardTypeData.commonId
  146. })
  147. }
  148. }
  149. this.$request.baseRequest(type, type1, data, failres => {
  150. console.log('res+++++', failres.errmsg)
  151. uni.showToast({
  152. title: failres.errmsg,
  153. icon: 'none',
  154. duration: 2000
  155. })
  156. uni.hideLoading()
  157. }).then(res => {
  158. uni.hideLoading()
  159. this.$refs.uToast.show({
  160. type: 'success',
  161. message: '置顶成功!',
  162. complete() {
  163. that.getList()
  164. }
  165. })
  166. })
  167. },
  168. add() {
  169. this.show = true
  170. },
  171. confirm() {
  172. if (!this.cardTypeData.circleName) {
  173. uni.showToast({
  174. title: '分类名称不能为空!',
  175. icon: 'none',
  176. duration: 2000
  177. })
  178. return
  179. }
  180. if (this.cardTypeData.circleName < 2 || this.cardTypeData.circleName > 8) {
  181. uni.showToast({
  182. title: '类别名称2-8个字!',
  183. icon: 'none',
  184. duration: 2000
  185. })
  186. return
  187. }
  188. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'add', {
  189. cardClassifyInfo: JSON.stringify(this.cardTypeData)
  190. }, failres => {
  191. console.log('res+++++', failres.errmsg)
  192. this.$refs.uToast.show({
  193. type: 'error',
  194. message: failres.errmsg,
  195. })
  196. uni.hideLoading()
  197. }).then(res => {
  198. uni.hideLoading()
  199. this.show = false
  200. this.cardTypeData = {
  201. commonId: uni.getStorageSync("userInfo").id,
  202. }
  203. this.$refs.uToast.show({
  204. type: 'success',
  205. message: '操作成功',
  206. complete() {
  207. that.getList()
  208. }
  209. })
  210. })
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .content1 {
  217. .row {
  218. margin: 20rpx 20rpx 0 20rpx;
  219. background-color: #fff;
  220. padding: 20rpx;
  221. border-radius: 20rpx;
  222. .f-text {
  223. width: 58rpx;
  224. height: 58rpx;
  225. background-color: #112253;
  226. border-radius: 50%;
  227. color: #fff;
  228. margin-right: 20rpx;
  229. font-size: 32rpx;
  230. }
  231. .img {
  232. width: 48rpx;
  233. margin-left: 20rpx;
  234. }
  235. }
  236. }
  237. .button {
  238. position: fixed;
  239. bottom: 108rpx;
  240. width: calc(100% - 40rpx);
  241. padding: 24rpx 0;
  242. color: #fff;
  243. background-color: #112253;
  244. text-align: center;
  245. margin: 0 20rpx;
  246. border-radius: 20rpx;
  247. }
  248. </style>