uni-data-pickerview.vue 8.0 KB

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