人民医院前端

uni-data-pickerview.vue 8.9KB

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