美文网首页
weex拖动排序模型

weex拖动排序模型

作者: huanghaodong | 来源:发表于2018-09-04 09:54 被阅读0次
Untitled.gif

注意

  • 列表长度不超过一屏适用
  • 150为列表到screenTop之间多余到距离(自定义导航栏的高度)
<!--created by allen on 2018/05/29-->

<template>
  <div class="ud-good-style">
    <navigation-bar title="商品分类" :useDefaultReturn="false" @wxcMinibarLeftButtonClicked="goBack"></navigation-bar>
    <scroller class="goods-style-page" :show-scrollbar="false">
      <div style="height: 20px"></div>
      <div v-for="(item, index) in goodsStyle" class="list" @click="goSeconfClass(item)">
        <div :ref="'item' + index"
             :style="{opacity: moveIndex == index ? 0 : 1, borderBottomWidth: index == goodsStyle.length -1 ? '0px' : '2px'}" class='listCell'>
          <div class="listCell_left">
            <text>{{item.name}}</text>
          </div>
          <div class="listCell_right" v-if="goodsStyle.length>1" @panstart="panStart($event,index)" @panmove="panMove($event,index)" @panend="panEnd($event,index)">
            <text class="iconfont right_icon">&#xe751;</text>
          </div>
            <div class="listCell_right" v-else>
                <text class="iconfont right_icon">&#xe751;</text>
            </div>
        </div>
      </div>
      <div v-if='Move' class="sub-box" :style="sub">
        <div class='listCell'>
          <div class="listCell_left">
            <text>{{chooseItem.name}}</text>
          </div>
          <div class="listCell_right">
            <text class="iconfont right_icon">&#xe751;</text>
          </div>
        </div>
      </div>
    </scroller>
  </div>

</template>

<script>
  import { getFirstClassList, categorySort } from '../services/goods'
  import { Utils } from 'weex-ui'
  export default {
    components: {
      NavigationBar: require('../common/navigationBar')
    },
    data:()=>({
      goodsStyle:[],
      Move:false,
      startIndex: '',
      sub: {
        top: 0,
        left: 0,
      },
      moveIndex: null,
      chooseItem: ''
    }),
    created() {
      this.getFirstCategoryList()
    },
    methods: {
      goBack () {
        this.$router.setBackParams({refresh: true})
        this.$router.back()
      },
      panStart (e,index) {
        this.Move = true
        this.sub = {
          top: e.changedTouches[0].screenY - 50
        }
        this.moveIndex = index
        this.startIndex = index
        this.chooseItem = this.goodsStyle[index]
      },
      panMove(e,index){
        if(this.goodsStyle.length > 1) {
          let moveIndex = Math.round((e.changedTouches[0].screenY-150)/100)
          console.log(moveIndex)
          let item = this.goodsStyle[this.moveIndex]
          if (moveIndex != this.moveIndex && moveIndex < this.goodsStyle.length && moveIndex >= 0) {
            this.goodsStyle.splice(this.moveIndex, 1)
            this.goodsStyle.splice(moveIndex, 0, item)
            this.moveIndex = moveIndex
          }
          let top = e.changedTouches[0].screenY - 50
          let h = Utils.env.getScreenHeight()
          this.sub = {
            top: top <= 0 ? 0 : top > h ? h : top
          }
        }
      },
      panEnd(e,index){
          let moveAt = 0

          if (this.moveIndex > index ) { //下移动

              moveAt = this.goodsStyle[this.moveIndex -1 ].gc_id

          } else if (this.moveIndex < index){ //上移动

              moveAt = this.goodsStyle[this.moveIndex + 1 ].gc_id

          }else{

            moveAt = this.goodsStyle[this.moveIndex].gc_id

          }

        this.Move = false
          if (moveAt === 0 ){
              return false
          }
          this.moveIndex = null
        categorySort({
          move_at: moveAt,
          category: this.chooseItem.gc_id
        }, data => {
            console.log('成功!')
        })
      },
      //获得一级分类
      getFirstCategoryList () {
        getFirstClassList({
          state: 1
        }, data => {
          if (data.data.length > 0) {
            this.goodsStyle = data.data
          }
        })
      },
      goSeconfClass (item) {
        this.$router.open({
          name: 'goodsStyleSec',
          params: {
            category: item
          }
        })
      }
    }
  }
</script>

<style src="../common.css"></style>
<style>
  .goods-style-page{
    padding-bottom: 20px;
  }
  .list{
    background-color: rgba(255,45,75,0.3);
    /*padding-left: 26px;*/
    /*padding-right: 26px;*/
  }
  .listCell{
    width:750px;
    padding-left: 26px;
    padding-right: 26px;
    justify-content: space-between;
    flex-direction: row;
    border-bottom-width: 2px;
    border-bottom-color: #eeeeee;
    background-color: #ffffff;
  }
  .listCell_left{
    flex: 1;
    height: 100px;
    justify-content: center;
  }
  .listCell_right{
    height: 100px;
    width: 40px;
    justify-content: center;
    align-items: center;
  }
  .right_icon{
    color:#D6D9DA;
    text-align: center;
  }
  .iconfont{
    font-family: iconfont;
  }
  .sub-box{
    position: fixed;
    width: 750px;
  }
</style>

相关文章

  • weex拖动排序模型

    注意 列表长度不超过一屏适用 150为列表到screenTop之间多余到距离(自定义导航栏的高度)

  • RecyclerView如何禁用某个item的拖动事件

    类似网易新闻的栏目拖动排序,头条需要显示出来,但是不能被排序和拖动,排序和拖动做好以后发现RecyclerV...

  • Weex——公共样式

    所有 weex 标签都有以下基本样式规则。 weex 盒模型基于 CSS 盒模型,每个 weex 元素都可视作一个...

  • flex 总结

    布局相关 所有 Weex 组件都支持以下通用样式规则。 盒模型 Weex 盒模型基于 [CSS 盒模型],每个 W...

  • 图标的拖动排序

    最近遇到一个新的需求,要求弹窗展示一个图标列表,然后每个图标都可以拖动排序......what?拖动排序?然后满脑...

  • 关于PHP+jQuery-ui拖动浮动层排序并保存到数据库实例

    PHP+jQuery-ui实现的拖动浮动层排序布局并将拖动后的浮动层位置排序结果保存到数据库实例。 首先引入jQu...

  • UICollectionView 拖动排序

    创建UICollectionView---- iOS9 添加的API - (BOOL)beginInteracti...

  • JS拖动排序

    1. 最终效果 2. 插件的下载以及代码 下载 引入js文件即可使用 注意看一下jquery链接有没有失效 jqu...

  • UITableViewCell拖动排序

    UITableViewCell拖动排序功能系统本身就有的,不过系统的只能长按一个按钮才能拖动,如何实现整行可以长按...

  • VueDraggable 拖动排序

    记录下

网友评论

      本文标题:weex拖动排序模型

      本文链接:https://www.haomeiwen.com/subject/flzwwftx.html