list.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view class="app-content" @click="globalClick">
  3. <view class="list-wrap">
  4. <block v-if="!$util.isEmpty(list.data)">
  5. <view class="list" v-for="(item, index) in list.data" :key="index">
  6. <view class="list-index">
  7. <image :src="item.smallCover" style="width:80upx;height:80upx;" mode="widthFix"></image>
  8. </view>
  9. <view class="list-det" @click="editItem(item)">
  10. <view class="app-size-28 app-color-0" style="font-size:28upx;font-weight:bold;color:#333333;">
  11. {{ item.name || '' }}
  12. </view>
  13. <view class="list-operate">
  14. <view class="operate-det" style="color:#333333;">
  15. <span>序号 {{ item.inTurn }}</span>
  16. </view>
  17. <view class="operate-icon">
  18. <i class="iconfont iconbianji" style="font-size:38upx;"></i>
  19. </view>
  20. <view class="operate-icon" @click.stop="delClass(item)">
  21. <i class="iconfont iconshanchu1" style="font-size:38upx;"></i>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </block>
  27. <block v-else>
  28. <app-wrapper-empty title="暂无数据" :is-empty="$util.isEmpty(list.data)" />
  29. </block>
  30. </view>
  31. <view class="app-footer">
  32. <button class="admin-button-com middle blue" @click="addCategoryFn">添加分类</button>
  33. </view>
  34. <modal-module :show="modifyModal" :maskClosable="false" @cancel="modalCancel" @click="replaceModalClick" :title="modifyTitle" padding="30rpx 30rpx">
  35. <template v-slot:content>
  36. <view class="app-modal-input-wrap modify-modal">
  37. <view class="inp-list-line">
  38. <view class="line-label">名称</view>
  39. <view class="line-input">
  40. <input type="text" v-model="replaceForm.name" :adjust-position="false" @focus="replaceForm.name=''" class="inp-input" placeholder="请填写" />
  41. </view>
  42. </view>
  43. <view class="inp-list-line">
  44. <view class="line-label">顺序</view>
  45. <view class="line-input">
  46. <input type="number" v-model="replaceForm.inTurn" @focus="replaceForm.inTurn=''" :adjust-position="false" class="inp-input" placeholder="越大越靠前" />
  47. </view>
  48. </view>
  49. <view class="inp-list-line">
  50. <view class="line-label">打印显示</view>
  51. <view class="line-input">
  52. <switch style="transform:scale(0.7,0.7)" :checked="replaceForm.print == 0 ? false : true" @change="printChange" /> {{replaceForm.print==0 ? '否' : '是'}}
  53. </view>
  54. </view>
  55. <view class="inp-list-line cover-upload-line">
  56. <view class="line-label">封面</view>
  57. <view class="line-input cover-upload-wrap">
  58. <htz-image-upload :max="1" :compress="true" v-model="coverImgData" :headers="headers"
  59. @uploadSuccess="coverUploadSuccess" @imgDelete="coverImgDelete" :action="loginInfo.imgUploadApi">
  60. </htz-image-upload>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. </modal-module>
  66. <modal-module :show="delModal" :maskClosable="false" @cancel="modalCancel" @click="delModalClick" content="确定删除?" color="#333" :size="32" padding="30upx 30upx"></modal-module>
  67. </view>
  68. </template>
  69. <script>
  70. import ModalModule from '@/components/plugin/modal'
  71. import AppUploader from '@/components/app-uploader'
  72. import OperateModule from '@/admin/home/components/module/operate'
  73. import AppWrapperEmpty from '@/components/app-wrapper-empty'
  74. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
  75. import { list } from '@/mixins'
  76. import { getList,addClass,updateClass,delClass} from '@/api/item-class'
  77. import { mapGetters } from 'vuex'
  78. export default {
  79. name: 'item-class-list',
  80. components: {
  81. ModalModule,
  82. AppUploader,
  83. OperateModule,
  84. AppWrapperEmpty,
  85. htzImageUpload
  86. },
  87. mixins: [list],
  88. data() {
  89. return {
  90. modifyModal: false,
  91. modifyTitle: '添加',
  92. replaceForm: {
  93. name: '',
  94. id:0,
  95. inTurn: 100,
  96. print:1,
  97. cover: ''
  98. },
  99. coverImgData: [],
  100. headers: {token:''},
  101. delModal: false,
  102. operateShow: false,
  103. operateData: {},
  104. operateIndex: null,
  105. operateTop: 0
  106. }
  107. },
  108. computed: {
  109. btnData() {
  110. return [
  111. {
  112. text: '编辑',
  113. icon: 'iconbianji',
  114. click: () => {
  115. this.modifyModal = true
  116. this.modifyTitle = '编辑'
  117. this.modifyForm = {
  118. name: this.operateData.name,
  119. id: this.operateData.id,
  120. inTurn: this.operateData.inTurn,
  121. print:this.operateData.print,
  122. cover: this.operateData.shortCover
  123. }
  124. }
  125. },
  126. {
  127. text: '删除',
  128. icon: 'iconshanchu1',
  129. click: () => {
  130. this.delModal = true
  131. }
  132. }
  133. ]
  134. }
  135. },
  136. onPullDownRefresh() {
  137. this.resetList()
  138. this.getClassList().then(res => {
  139. uni.stopPullDownRefresh()
  140. })
  141. },
  142. onReachBottom() {
  143. if (!this.list.finished) {
  144. this.getClassList().then(res => {
  145. uni.stopPullDownRefresh()
  146. })
  147. } else {
  148. uni.stopPullDownRefresh()
  149. }
  150. },
  151. onLoad() {
  152. const token = uni.getStorageSync('token')
  153. this.headers.token = token
  154. },
  155. methods: {
  156. coverUploadSuccess(res) {
  157. var _res = JSON.parse(res.data)
  158. if(_res.code == 1){
  159. this.replaceForm.cover = _res.data.shortUrl
  160. this.coverImgData.push(_res.data.bigUrl)
  161. this.$msg('上传成功')
  162. }
  163. },
  164. coverImgDelete(res){
  165. this.replaceForm.cover = ''
  166. },
  167. printChange(e){
  168. this.replaceForm.print = e.target.value ? 1 : 0
  169. },
  170. delClass(item){
  171. let that = this
  172. that.$util.confirmModal({content:'确认删除?此分类的花材将移到默认分类'},() => {
  173. delClass({id:item.id}).then(res=>{
  174. if(res.code == 1){
  175. that.$msg('删除成功')
  176. that.getClassList()
  177. }
  178. })
  179. })
  180. },
  181. editItem(item){
  182. this.modifyModal = true
  183. this.modifyTitle = '编辑'
  184. this.replaceForm = {
  185. id:item.id,
  186. name: item.name,
  187. inTurn: item.inTurn,
  188. print:item.print,
  189. cover: item.shortCover
  190. }
  191. this.coverImgData = item.bigCover ? [item.bigCover] : []
  192. },
  193. async init() {
  194. this.getClassList()
  195. },
  196. getClassList() {
  197. return getList({page: this.list.page}).then(res => {
  198. this.completes(res)
  199. })
  200. },
  201. replaceClass() {
  202. if (!this.replaceForm.name) {
  203. this.$msg('请填写分类名称')
  204. return false
  205. }
  206. let host = this.replaceForm.id == 0 ? addClass : updateClass;
  207. let form = JSON.parse(JSON.stringify(this.replaceForm))
  208. host({ ...form }).then(res => {
  209. this.$msg('操作成功')
  210. this.modalCancel()
  211. this.operateCancle()
  212. setTimeout(() => {
  213. this.resetList()
  214. this.getClassList()
  215. }, 1000)
  216. })
  217. },
  218. addCategoryFn() {
  219. this.resetForm()
  220. this.modifyModal = true
  221. this.modifyTitle = '新增'
  222. },
  223. resetForm() {
  224. this.replaceForm = {
  225. name: '',
  226. inTurn: 0,
  227. id:0,
  228. cover: ''
  229. }
  230. this.coverImgData = []
  231. },
  232. replaceModalClick(e) {
  233. if (e.index === 0) {
  234. this.modalCancel()
  235. } else {
  236. this.replaceClass()
  237. }
  238. },
  239. modalCancel() {
  240. this.delModal = false
  241. this.modifyModal = false
  242. },
  243. switchChangeFn(e) {
  244. this.replaceForm.status = e.detail.value ? 1 : 0
  245. },
  246. delModalClick(e) {
  247. if (e.index === 0) {
  248. this.modalCancel()
  249. } else {
  250. uni.showToast({
  251. title: '开发中',
  252. duration: 2000,
  253. icon:'none',
  254. });
  255. }
  256. },
  257. operateFn(item, index, event) {
  258. this.operateData = item
  259. this.operateIndex = index
  260. this.operateShow = true
  261. this.operateTop = event.currentTarget.offsetTop
  262. },
  263. operateCancle() {
  264. this.operateData = {}
  265. this.operateIndex = null
  266. this.operateShow = false
  267. },
  268. globalClick(){
  269. this.operateCancle()
  270. }
  271. }
  272. }
  273. </script>
  274. <style lang="scss" scoped>
  275. .app-content {
  276. min-height: calc(100vh - 100upx);
  277. padding-bottom: 100upx;
  278. }
  279. .list-wrap {
  280. position: relative;
  281. background-color: #fff;
  282. .list {
  283. height: 130upx;
  284. @include disFlex(center, flex-start);
  285. margin: 0 30upx 0 30upx;
  286. color: $fontColor3;
  287. border-bottom: 1upx solid $borderColor;
  288. .list-index {
  289. width: 80upx;
  290. }
  291. .list-img {
  292. img {
  293. height: 100%;
  294. }
  295. }
  296. .list-det {
  297. width: calc(100% - 50upx);
  298. margin-left: 10upx;
  299. & > div {
  300. margin-top: 14upx;
  301. &:first-child {
  302. margin-top: 0;
  303. }
  304. }
  305. .list-operate {
  306. @include disFlex(center, space-between);
  307. .operate-det {
  308. & > span {
  309. margin-left: 60upx;
  310. &:first-child {
  311. margin-left: 0;
  312. }
  313. }
  314. }
  315. .add-price{
  316. text-decoration:underline;
  317. font-size:30upx;
  318. margin-left:10upx;
  319. }
  320. .operate-icon{
  321. margin-left:5upx;
  322. }
  323. }
  324. }
  325. }
  326. }
  327. .app-footer {
  328. justify-content: flex-end;
  329. .admin-button-com {
  330. width: 200upx;
  331. margin-right: 30upx;
  332. }
  333. }
  334. .modify-modal {
  335. .prompt-text {
  336. color: red;
  337. position: relative;
  338. right: 52upx;
  339. bottom: 24upx;
  340. }
  341. .line-label {
  342. width: 140upx;
  343. flex-shrink: 0;
  344. }
  345. .switch-wrap {
  346. margin-top: 30upx;
  347. }
  348. .cover-upload-line {
  349. flex-direction: column;
  350. align-items: flex-start;
  351. }
  352. .cover-upload-wrap {
  353. width: 100%;
  354. margin-top: 15upx;
  355. }
  356. }
  357. </style>