人民医院前端

uni-data-pickerview.vue 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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', '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. nodeList:[],
  75. }
  76. },
  77. created() {
  78. // console.log(this.showSearch)
  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. console.log(this.candidates.indexOf(e));
  93. console.log(node);
  94. this._dispatchEvent()
  95. this.$emit('nodeclick', node)
  96. }
  97. //console.log(this.loadData());
  98. },
  99. //点击选择组别
  100. handleClick(item){
  101. let text = item.text;
  102. for(let i in this.nodeList){
  103. if(this.nodeList[i].parent_value == text){
  104. this.$emit('nodeclick', this.nodeList[i])
  105. }
  106. }
  107. this._dispatchEvent()
  108. },
  109. onPropsChange() {
  110. this._treeData = []
  111. this.selectedIndex = 0
  112. this.load()
  113. },
  114. load() {
  115. if (this.isLocaldata) {
  116. this.loadData()
  117. } else if (this.dataValue.length) {
  118. this.getTreePath((res) => {
  119. this.loadData()
  120. })
  121. }
  122. },
  123. handleSelect(index) {
  124. this.selectedIndex = index
  125. },
  126. handleNodeClick(item, i, j) {
  127. if (item.disable) {
  128. return
  129. }
  130. const node = this.dataList[i][j]
  131. const text = node[this.map.text]
  132. const value = node[this.map.value]
  133. if (i < this.selected.length - 1) {
  134. this.selected.splice(i, this.selected.length - i)
  135. this.selected.push({
  136. text,
  137. value
  138. })
  139. // console.log(this.selected);
  140. } else if (i === this.selected.length - 1) {
  141. this.selected.splice(i, 1, {
  142. text,
  143. value
  144. })
  145. // console.log(this.selected);
  146. }
  147. if (node.isleaf) {
  148. this.onSelectedChange(node, node.isleaf)
  149. return
  150. }
  151. const {
  152. isleaf,
  153. hasNodes
  154. } = this._updateBindData()
  155. if (!this._isTreeView() && !hasNodes) {
  156. this.onSelectedChange(node, true)
  157. return
  158. }
  159. if (this.isLocaldata && (!hasNodes || isleaf)) {
  160. this.onSelectedChange(node, true)
  161. return
  162. }
  163. if (!isleaf && !hasNodes) {
  164. this._loadNodeData((data) => {
  165. if (!data.length) {
  166. node.isleaf = true
  167. } else {
  168. this._treeData.push(...data)
  169. this._updateBindData(node)
  170. }
  171. this.onSelectedChange(node, node.isleaf)
  172. }, this._nodeWhere())
  173. return
  174. }
  175. this.onSelectedChange(node, false)
  176. },
  177. updateData(data) {
  178. //新增筛选用户功能ld
  179. let curTreeData=data.treeData;
  180. this.candidates = [];
  181. this.nodeList =[];
  182. for(let i in curTreeData){
  183. if(curTreeData[i].parent_value){
  184. this.candidates.push(curTreeData[i].text);
  185. this.nodeList.push(curTreeData[i])
  186. }
  187. }
  188. this._treeData = data.treeData
  189. this.selected = data.selected
  190. if (!this._treeData.length) {
  191. this.loadData()
  192. } else {
  193. //this.selected = data.selected
  194. this._updateBindData()
  195. }
  196. },
  197. onDataChange() {
  198. this.$emit('datachange')
  199. },
  200. onSelectedChange(node, isleaf) {
  201. if (isleaf) {
  202. this._dispatchEvent()
  203. }
  204. if (node) {
  205. this.$emit('nodeclick', node)
  206. }
  207. },
  208. _dispatchEvent() {
  209. this.$emit('change', this.selected.slice(0))
  210. }
  211. }
  212. }
  213. </script>
  214. <style >
  215. .uni-data-pickerview {
  216. flex: 1;
  217. /* #ifndef APP-NVUE */
  218. display: flex;
  219. /* #endif */
  220. flex-direction: column;
  221. overflow: hidden;
  222. height: 100%;
  223. }
  224. .error-text {
  225. color: #DD524D;
  226. }
  227. .loading-cover {
  228. position: absolute;
  229. left: 0;
  230. top: 0;
  231. right: 0;
  232. bottom: 0;
  233. background-color: rgba(255, 255, 255, .5);
  234. /* #ifndef APP-NVUE */
  235. display: flex;
  236. /* #endif */
  237. flex-direction: column;
  238. align-items: center;
  239. z-index: 1001;
  240. }
  241. .load-more {
  242. /* #ifndef APP-NVUE */
  243. margin: auto;
  244. /* #endif */
  245. }
  246. .error-message {
  247. background-color: #fff;
  248. position: absolute;
  249. left: 0;
  250. top: 0;
  251. right: 0;
  252. bottom: 0;
  253. padding: 15px;
  254. opacity: .9;
  255. z-index: 102;
  256. }
  257. /* #ifdef APP-NVUE */
  258. .selected-area {
  259. width: 750rpx;
  260. }
  261. /* #endif */
  262. .selected-list {
  263. /* #ifndef APP-NVUE */
  264. display: flex;
  265. /* #endif */
  266. flex-direction: row;
  267. flex-wrap: nowrap;
  268. padding: 0 5px;
  269. border-bottom: 1px solid #f8f8f8;
  270. }
  271. .selected-item {
  272. margin-left: 10px;
  273. margin-right: 10px;
  274. padding: 12px 0;
  275. text-align: center;
  276. /* #ifndef APP-NVUE */
  277. white-space: nowrap;
  278. /* #endif */
  279. }
  280. .selected-item-text-overflow {
  281. width: 168px;
  282. /* fix nvue */
  283. overflow: hidden;
  284. /* #ifndef APP-NVUE */
  285. width: 6em;
  286. white-space: nowrap;
  287. text-overflow: ellipsis;
  288. -o-text-overflow: ellipsis;
  289. /* #endif */
  290. }
  291. .selected-item-active {
  292. border-bottom: 2px solid #007aff;
  293. }
  294. .selected-item-text {
  295. color: #007aff;
  296. }
  297. .tab-c {
  298. position: relative;
  299. flex: 1;
  300. /* #ifndef APP-NVUE */
  301. display: flex;
  302. /* #endif */
  303. flex-direction: row;
  304. overflow: hidden;
  305. }
  306. .list {
  307. flex: 1;
  308. }
  309. .item {
  310. padding: 12px 15px;
  311. /* border-bottom: 1px solid #f0f0f0; */
  312. /* #ifndef APP-NVUE */
  313. display: flex;
  314. /* #endif */
  315. flex-direction: row;
  316. justify-content: space-between;
  317. }
  318. .is-disabled {
  319. opacity: .5;
  320. }
  321. .item-text {
  322. /* flex: 1; */
  323. color: #333333;
  324. }
  325. .item-text-overflow {
  326. width: 280px;
  327. /* fix nvue */
  328. overflow: hidden;
  329. /* #ifndef APP-NVUE */
  330. width: 20em;
  331. white-space: nowrap;
  332. text-overflow: ellipsis;
  333. -o-text-overflow: ellipsis;
  334. /* #endif */
  335. }
  336. .check {
  337. margin-right: 5px;
  338. border: 2px solid #007aff;
  339. border-left: 0;
  340. border-top: 0;
  341. height: 12px;
  342. width: 6px;
  343. transform-origin: center;
  344. /* #ifndef APP-NVUE */
  345. transition: all 0.3s;
  346. /* #endif */
  347. transform: rotate(45deg);
  348. }
  349. </style>