organization.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view class="organization-wrap">
  3. <!-- 组织结构根节点 -->
  4. <view class="organization-root-tit">
  5. <view class="structure-con" v-for="(item,index) in nowStructure" :key="index">
  6. <text :class="item.disabled ? '' : 'structure-name'" @click="item.disabled ? null : checkedStructure(index)">{{item.name}}</text>
  7. <u-icon class="structure-icon" name="arrow-right" color="#999" size="28"></u-icon>
  8. </view>
  9. </view>
  10. <!-- 组织结构子节点 -->
  11. <view class="organization-node-con" v-if="organizationNowList && organizationNowList.length > 0">
  12. <view class="organization-node-item" v-for="(item, index) in organizationNowList" :key="index" @click="clickOrganization(item, index)">
  13. <text class="organization-node-item-name">{{item.name}}</text>
  14. <u-icon class="organization-node-item-icon" name="arrow-right" color="#999" size="28"></u-icon>
  15. </view>
  16. </view>
  17. <!-- 门店列表 -->
  18. <view class="list-con" :style="{'padding-top': organizationNowList && organizationNowList.length > 0 ? '0upx' : '88upx' }">
  19. <view class="list-tit">门店列表</view>
  20. <!-- 列表数据 -->
  21. <view class="listData-con">
  22. <view class="listData-item" v-for="(item, index) in list" :key="index" @click="goPage(item)">
  23. <view class="listData-item-l">
  24. <u-icon class="listData-item-l-icon" name="mendian" custom-prefix="xd-icon" size="40" color="#888"></u-icon>
  25. <text class="listData-item-l-name">{{item.name}}</text>
  26. </view>
  27. <view class="listData-item-r">
  28. <u-icon class="listData-item-r-icon" name="icon-xian-11" custom-prefix="xd-icon" size="24" color="#2b85e4"></u-icon>
  29. </view>
  30. </view>
  31. <u-empty :text="noDataText" img-width="120" v-if="list.length == 0 && status != 'loading'" style="padding: 150px 0 180px;background: #fff;" mode="list"></u-empty>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { clzConfirm } from '@/libs/tools.js'
  38. import { findStoreList,findStoreVsDevice } from '@/api/store.js'
  39. import { queryCurrentTaskUsing } from '@/api/task.js'
  40. import { findUserInfo } from '@/api/atorg.js'
  41. export default{
  42. data(){
  43. return{
  44. organizationNowList: [], // 组织机构 当前显示 列表数据
  45. organizationList: [], // 组织机构 总列表数据
  46. nowStructure: [], // 面包屑
  47. nowInd: [], // 下标数组
  48. status: 'loading', // 加载中状态
  49. noDataText: '暂无数据', // 数据异常提示
  50. list: [], // 门店数据列表
  51. readonlyLen: 0, // 只读的组织机构个数
  52. }
  53. },
  54. onLoad() {
  55. // 权限下的组织机构数据
  56. this.getOrgList()
  57. },
  58. methods: {
  59. // 权限下所有门店数据
  60. getStoreList(orgCode){
  61. this.status = 'loading'
  62. // 获取门店列表
  63. findStoreList({ orgCode: orgCode ? orgCode : '' }).then(res => {
  64. if(res.status == 200){
  65. this.list = res.data
  66. this.noDataText = '暂无数据' // 有列表数据时不显示,因此只用默认设置为无数据时所需显示的'暂无数据'即可
  67. }else{
  68. this.list = []
  69. this.noDataText = res.message
  70. }
  71. this.status = 'loadmore'
  72. })
  73. },
  74. // 组织机构数据
  75. getOrgList(){
  76. findUserInfo().then(res => {
  77. if(res.status == 200){
  78. this.nowStructure = []
  79. let parentNamePathsArr = res.data[0].parentNamePaths ? res.data[0].parentNamePaths.split(',') : []
  80. parentNamePathsArr = parentNamePathsArr.length > 0 ? parentNamePathsArr.splice(0,parentNamePathsArr.length-1) : []
  81. parentNamePathsArr.map((item,ind) => {
  82. this.nowStructure.push({ name: item, disabled: true })
  83. })
  84. this.readonlyLen = parentNamePathsArr.length
  85. this.nowStructure.push({ name: res.data[0].name, disabled: false })
  86. this.organizationList = res.data
  87. this.organizationNowList = res.data[0].children ? res.data[0].children : []
  88. this.getStoreList(res.data[0].code)
  89. }else{
  90. this.readonlyLen = 0
  91. this.organizationList = []
  92. this.organizationNowList = []
  93. this.nowStructure = []
  94. }
  95. })
  96. },
  97. // 组织机构 click
  98. clickOrganization(item, ind){
  99. this.nowInd.push(ind)
  100. if(item.children){
  101. this.organizationNowList = item.children
  102. }else{
  103. this.organizationNowList = []
  104. }
  105. this.nowStructure.push({ name: item.name, disabled: false })
  106. this.getStoreList(item.code)
  107. },
  108. // 切换至当前所选的组织结构
  109. checkedStructure(index){
  110. let ind = index - this.readonlyLen
  111. let subInd = JSON.parse(JSON.stringify(this.nowInd)).splice(0, ind)
  112. this.nowInd = subInd
  113. let code = '' // 组织机构编码
  114. if(ind == 0){
  115. this.nowInd = []
  116. this.organizationNowList = this.organizationList[0].children
  117. code = this.organizationList[0].code
  118. }else{
  119. for(let i=0; i<subInd.length; i++){
  120. if(i==0){
  121. this.organizationNowList = this.organizationList[0].children[subInd[i]].children
  122. code = this.organizationList[0].children[subInd[i]].code
  123. }else{
  124. this.organizationNowList = this.organizationNowList[subInd[i]].children
  125. code = this.organizationNowList[subInd[i]].code
  126. }
  127. }
  128. }
  129. this.nowStructure = JSON.parse(JSON.stringify(this.nowStructure)).splice(0, index+1)
  130. this.getStoreList(code)
  131. },
  132. // 开始巡店
  133. goPage(item){
  134. // 判断当前门店是否已绑定设备
  135. findStoreVsDevice({storeCode:item.code}).then(res=>{
  136. if(res.data.length){
  137. // 门店下的设备
  138. this.$u.vuex('vuex_storeVideoList',res.data)
  139. // 校验是否有历史巡店记录
  140. this.queryHasTaskUsing(item)
  141. }else{
  142. uni.showToast({
  143. icon: 'none',
  144. title: '当前门店没有绑定设备,暂时不能视频巡店'
  145. })
  146. }
  147. })
  148. },
  149. // 判断当前门店是否已绑定设备
  150. // type VIDEO_INSPECTION:视频巡店、SPOT_INSPECTION:现场巡店、POINT_INSPECTION:点检任务
  151. queryHasTaskUsing(item){
  152. queryCurrentTaskUsing({ storeId: item.id, type: 'VIDEO_INSPECTION' }).then(res => {
  153. if(res.status == 200){
  154. if(res.data){ // 为true有历史巡店记录
  155. clzConfirm({
  156. title: '提示',
  157. content: '有进行中的巡店任务,是否继续?',
  158. confirmText: '继续巡店',
  159. cancelText: '重新开始',
  160. buttons: ['继续巡店','重新开始'],
  161. success: function (result) {
  162. if (result.confirm || result.index==0) { // 继续巡店
  163. uni.navigateTo({
  164. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&taskId='+ res.data + '&restart=0&types=video'
  165. })
  166. }else if(result.cancel || result.index==1){ // 重新开始
  167. uni.navigateTo({
  168. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&taskId='+ res.data + '&restart=1&types=video'
  169. })
  170. }
  171. }
  172. })
  173. }else{
  174. uni.navigateTo({
  175. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&types=video'
  176. })
  177. }
  178. }else{
  179. uni.showToast({icon: 'none', title: res.message})
  180. }
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. page {
  188. background-color: #f8f8f8;
  189. height: 100vh;
  190. }
  191. .organization-wrap{
  192. position: relative;
  193. .organization-root-tit{
  194. position: fixed;
  195. left: 0;
  196. // top: 0;
  197. width: 100%;
  198. padding: 20upx 30upx;
  199. line-height: 45upx;
  200. background-color: #fff;
  201. border-bottom: 6upx solid #f8f8f8;
  202. z-index: 1;
  203. .structure-con{
  204. display: inline-block;
  205. .structure-name{
  206. color: #2979ff;
  207. }
  208. .structure-icon{
  209. padding: 0 10upx;
  210. }
  211. }
  212. }
  213. .organization-node-con{
  214. padding: 88upx 30upx 0;
  215. background-color: #fff;
  216. .organization-node-item{
  217. display: flex;
  218. padding: 25upx 10upx 25upx 20upx;
  219. border-bottom: 1px solid #f8f8f8;
  220. &:active{
  221. opacity: 0.5;
  222. }
  223. &-name{
  224. flex-grow: 1;
  225. }
  226. &-icon{
  227. flex-shrink: 0;
  228. }
  229. }
  230. }
  231. // 门店列表
  232. .list-con{
  233. padding: 0 20upx;
  234. .list-tit{
  235. padding: 20upx 6upx;
  236. border-bottom: 1upx solid #f8f8f8;
  237. }
  238. .listData-con{
  239. box-sizing: border-box;
  240. .listData-item{
  241. display: flex;
  242. justify-content: space-between;
  243. align-items: center;
  244. padding: 25upx;
  245. border-bottom: 1px solid #f8f8f8;
  246. background-color: #fff;
  247. &:active{
  248. opacity: 0.5;
  249. }
  250. &-l{
  251. flex-grow: 1;
  252. padding-right: 10upx;
  253. position: relative;
  254. padding-left: 50upx;
  255. &-icon{
  256. vertical-align: sub;
  257. padding-right: 8upx;
  258. position: absolute;
  259. left: 0;
  260. top: -4upx;
  261. }
  262. }
  263. &-r{
  264. flex-shrink: 0;
  265. }
  266. }
  267. }
  268. }
  269. }
  270. </style>