song-data-pickerview.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <view class="uni-data-pickerview">
  3. <scroll-view v-if="!isCloudDataList" class="selected-area" scroll-x="true">
  4. <view class="selected-list">
  5. <view class="selected-item" v-for="(item,index) in selected" :key="index" :class="{
  6. 'selected-item-active':index == selectedIndex
  7. }" @click="handleSelect(index)">
  8. <text>{{item.text || ''}}</text>
  9. </view>
  10. </view>
  11. </scroll-view>
  12. <view class="tab-c">
  13. <scroll-view class="list" :scroll-y="true">
  14. <view class="item" :class="{'is-disabled': !!item.disable}" v-for="(item, j) in dataList[selectedIndex]"
  15. :key="j" @click="handleNodeClick(item, selectedIndex, j)">
  16. <text class="item-text"
  17. :class="selected.length > selectedIndex && item[map.value] == selected[selectedIndex].value ? 'checkColor' : ''">
  18. {{item[map.text]}}</text>
  19. <view class="check"
  20. v-if="selected.length > selectedIndex && item[map.value] == selected[selectedIndex].value">
  21. </view>
  22. </view>
  23. </scroll-view>
  24. <view class="loading-cover" v-if="loading">
  25. <uni-load-more class="load-more" :contentText="loadMore" status="loading"></uni-load-more>
  26. </view>
  27. <view class="error-message" v-if="errorMessage">
  28. <text class="error-text">{{errorMessage}}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import dataPicker from "./song-data-picker.js"
  35. /**
  36. * DataPickerview
  37. * @description uni-data-pickerview
  38. * @tutorial https://ext.dcloud.net.cn/plugin?id=3796
  39. * @property {Array} localdata 本地数据,参考
  40. * @property {Boolean} step-searh = [true|false] 是否分布查询
  41. * @value true 启用分布查询,仅查询当前选中节点
  42. * @value false 关闭分布查询,一次查询出所有数据
  43. * @property {String|DBFieldString} self-field 分布查询当前字段名称
  44. * @property {String|DBFieldString} parent-field 分布查询父字段名称
  45. * @property {String|DBCollectionString} collection 表名
  46. * @property {String|DBFieldString} field 查询字段,多个字段用 `,` 分割
  47. * @property {String} orderby 排序字段及正序倒叙设置
  48. * @property {String|JQLString} where 查询条件
  49. */
  50. export default {
  51. name: 'UniDataPickerView',
  52. emits: ['nodeclick', 'change', 'datachange', 'update:modelValue'],
  53. mixins: [dataPicker],
  54. props: {
  55. managedMode: {
  56. type: Boolean,
  57. default: false
  58. },
  59. ellipsis: {
  60. type: Boolean,
  61. default: true
  62. }
  63. },
  64. created() {
  65. if (!this.managedMode) {
  66. this.$nextTick(() => {
  67. this.loadData();
  68. })
  69. }
  70. },
  71. methods: {
  72. onPropsChange() {
  73. this._treeData = [];
  74. this.selectedIndex = 0;
  75. this.$nextTick(() => {
  76. this.loadData();
  77. })
  78. },
  79. handleSelect(index) {
  80. this.selectedIndex = index;
  81. },
  82. handleNodeClick(item, i, j) {
  83. if (item.disable) {
  84. return;
  85. }
  86. const node = this.dataList[i][j];
  87. const text = node[this.map.text];
  88. const value = node[this.map.value];
  89. if (i < this.selected.length - 1) {
  90. this.selected.splice(i, this.selected.length - i)
  91. this.selected.push({
  92. text,
  93. value
  94. })
  95. } else if (i === this.selected.length - 1) {
  96. this.selected.splice(i, 1, {
  97. text,
  98. value
  99. })
  100. }
  101. if (node.isleaf) {
  102. this.onSelectedChange(node, node.isleaf)
  103. return
  104. }
  105. const {
  106. isleaf,
  107. hasNodes
  108. } = this._updateBindData()
  109. // 本地数据
  110. if (this.isLocalData) {
  111. this.onSelectedChange(node, (!hasNodes || isleaf))
  112. } else if (this.isCloudDataList) { // Cloud 数据 (单列)
  113. this.onSelectedChange(node, true)
  114. } else if (this.isCloudDataTree) { // Cloud 数据 (树形)
  115. if (isleaf) {
  116. this.onSelectedChange(node, node.isleaf)
  117. } else if (!hasNodes) { // 请求一次服务器以确定是否为叶子节点
  118. this.loadCloudDataNode((data) => {
  119. if (!data.length) {
  120. node.isleaf = true
  121. } else {
  122. this._treeData.push(...data)
  123. this._updateBindData(node)
  124. }
  125. this.onSelectedChange(node, node.isleaf)
  126. })
  127. }
  128. }
  129. },
  130. updateData(data) {
  131. this._treeData = data.treeData
  132. this.selected = data.selected
  133. if (!this._treeData.length) {
  134. this.loadData()
  135. } else {
  136. //this.selected = data.selected
  137. this._updateBindData()
  138. }
  139. },
  140. onDataChange() {
  141. this.$emit('datachange');
  142. },
  143. onSelectedChange(node, isleaf) {
  144. if (isleaf) {
  145. this._dispatchEvent()
  146. }
  147. if (node) {
  148. this.$emit('nodeclick', node)
  149. }
  150. },
  151. _dispatchEvent() {
  152. this.$emit('change', this.selected.slice(0))
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss">
  158. .checkColor {
  159. color: #FD910C !important;
  160. }
  161. ::v-deep .selected-item-active {
  162. border-bottom: 2px solid #FD910C !important;
  163. }
  164. ::v-deep .check {
  165. color: #FD910C !important;
  166. border: none !important;
  167. display: inline-block !important;
  168. width: 10px !important;
  169. height: 3px !important;
  170. background: #FD910C !important;
  171. line-height: 0 !important;
  172. font-size: 0 !important;
  173. vertical-align: middle !important;
  174. -webkit-transform: rotate(45deg) !important;
  175. margin-top: 24rpx;
  176. }
  177. ::v-deep.check:after {
  178. content: '/';
  179. display: block;
  180. width: 20px;
  181. height: 3px;
  182. background: #FD910C;
  183. // margin-top: 24rpx;
  184. -webkit-transform: rotate(-90deg) translateY(-50%) translateX(50%);
  185. }
  186. $uni-primary: #007aff !default;
  187. .uni-data-pickerview {
  188. flex: 1;
  189. /* #ifndef APP-NVUE */
  190. display: flex;
  191. /* #endif */
  192. flex-direction: column;
  193. overflow: hidden;
  194. height: 100%;
  195. }
  196. .error-text {
  197. color: #DD524D;
  198. }
  199. .loading-cover {
  200. position: absolute;
  201. left: 0;
  202. top: 0;
  203. right: 0;
  204. bottom: 0;
  205. background-color: rgba(255, 255, 255, .5);
  206. /* #ifndef APP-NVUE */
  207. display: flex;
  208. /* #endif */
  209. flex-direction: column;
  210. align-items: center;
  211. z-index: 1001;
  212. }
  213. .load-more {
  214. /* #ifndef APP-NVUE */
  215. margin: auto;
  216. /* #endif */
  217. }
  218. .error-message {
  219. background-color: #fff;
  220. position: absolute;
  221. left: 0;
  222. top: 0;
  223. right: 0;
  224. bottom: 0;
  225. padding: 15px;
  226. opacity: .9;
  227. z-index: 102;
  228. }
  229. /* #ifdef APP-NVUE */
  230. .selected-area {
  231. width: 750rpx;
  232. }
  233. /* #endif */
  234. .selected-list {
  235. /* #ifndef APP-NVUE */
  236. display: flex;
  237. flex-wrap: nowrap;
  238. /* #endif */
  239. flex-direction: row;
  240. padding: 0 5px;
  241. border-bottom: 1px solid #f8f8f8;
  242. }
  243. .selected-item {
  244. margin-left: 10px;
  245. margin-right: 10px;
  246. padding: 12px 0;
  247. text-align: center;
  248. /* #ifndef APP-NVUE */
  249. white-space: nowrap;
  250. /* #endif */
  251. }
  252. .selected-item-text-overflow {
  253. width: 168px;
  254. /* fix nvue */
  255. overflow: hidden;
  256. /* #ifndef APP-NVUE */
  257. width: 6em;
  258. white-space: nowrap;
  259. text-overflow: ellipsis;
  260. -o-text-overflow: ellipsis;
  261. /* #endif */
  262. }
  263. .selected-item-active {
  264. border-bottom: 2px solid $uni-primary;
  265. }
  266. .selected-item-text {
  267. color: $uni-primary;
  268. }
  269. .tab-c {
  270. position: relative;
  271. flex: 1;
  272. /* #ifndef APP-NVUE */
  273. display: flex;
  274. /* #endif */
  275. flex-direction: row;
  276. overflow: hidden;
  277. }
  278. .list {
  279. flex: 1;
  280. }
  281. .item {
  282. padding: 12px 15px;
  283. /* border-bottom: 1px solid #f0f0f0; */
  284. /* #ifndef APP-NVUE */
  285. display: flex;
  286. /* #endif */
  287. flex-direction: row;
  288. justify-content: space-between;
  289. }
  290. .is-disabled {
  291. opacity: .5;
  292. }
  293. .item-text {
  294. /* flex: 1; */
  295. color: #333333;
  296. }
  297. .item-text-overflow {
  298. width: 280px;
  299. /* fix nvue */
  300. overflow: hidden;
  301. /* #ifndef APP-NVUE */
  302. width: 20em;
  303. white-space: nowrap;
  304. text-overflow: ellipsis;
  305. -o-text-overflow: ellipsis;
  306. /* #endif */
  307. }
  308. .check {
  309. margin-right: 5px;
  310. border: 2px solid $uni-primary;
  311. border-left: 0;
  312. border-top: 0;
  313. height: 12px;
  314. width: 6px;
  315. transform-origin: center;
  316. /* #ifndef APP-NVUE */
  317. transition: all 0.3s;
  318. /* #endif */
  319. transform: rotate(45deg);
  320. }
  321. </style>