index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view class="work-container">
  3. <view class="header">
  4. <u-search placeholder="请输入客户名称" :clearabled="true" @clear="searchDept" @custom="searchDept"
  5. v-model="search.deptName" @search="searchDept"></u-search>
  6. </view>
  7. <scroll-view
  8. scroll-y
  9. style="height: 100vh"
  10. @scrolltolower="loadMore">
  11. <uni-card v-if="item.parentId !==0" v-for="item in displayList" :title="item.deptName"
  12. :extra="item.createTime">
  13. <view style="position: relative">
  14. <view>联系人:{{item.leader}}</view>
  15. <view>联系电话:{{item.phone}}</view>
  16. <view style="width: 50px;position: absolute;right:-10px;bottom:0px"><u-button @click="toUser(item)"
  17. type="primary" :plain="true" size="mini" text="查看人员"></u-button>
  18. </view>
  19. <view style="width: 50px;position: absolute;right:90rpx;bottom:0rpx"><u-button type="success"
  20. @click="toDeviceList(item)" :plain="true" size="mini" text="查看设备"></u-button>
  21. </view>
  22. <view style="width: 50px;position: absolute;right:200rpx;bottom:0rpx"><u-button type="warning "
  23. @click="toDel(item)" :plain="true" size="mini" text="删除客户"></u-button>
  24. </view>
  25. </view>
  26. </uni-card>
  27. <view v-if="loading" class="loading">加载中...</view>
  28. <view v-if="allLoaded" class="no-more">没有更多了</view>
  29. </scroll-view>
  30. <view style="position: fixed;bottom: 0px;text-align: center;width: 100%">
  31. <u-button type="primary" text="新增客户" @click="newUser"></u-button>
  32. </view>
  33. <u-modal :show="showAdd " title="客户信息" @cancel="closeDlg" :showCancelButton="true" @confirm="doAddUser">
  34. <view class="slot-content">
  35. <u--form labelPosition="left" :model="model1" ref="s">
  36. <u-form-item label="客户名称:" prop="chooseUser.deptName" borderBottom ref="item1" labelWidth="auto">
  37. <u--input v-model="chooseUser.deptName" border="none"></u--input>
  38. </u-form-item>
  39. <u-form-item label="联系人:" prop="chooseUser.nickName" borderBottom ref="item1" labelWidth="auto">
  40. <u--input v-model="chooseUser.nickName" border="none"></u--input>
  41. </u-form-item>
  42. <u-form-item label="手机号:" prop="chooseUser.phonenumber" borderBottom ref="item1" labelWidth="auto">
  43. <u--input v-model="chooseUser.phonenumber" border="none"></u--input>
  44. </u-form-item>
  45. <u-form-item label="密码:" prop="chooseUser.password" borderBottom ref="item1" labelWidth="auto">
  46. <u--input v-if="showAdd" v-model="chooseUser.password" border="none"></u--input>
  47. </u-form-item>
  48. <u-form-item label="登录账号:" borderBottom ref="item1" labelWidth="auto">
  49. <u--input v-model="chooseUser.phonenumber" border="none" disabled></u--input>
  50. </u-form-item>
  51. <u-form-item label="状态:" prop="chooseUser.password" borderBottom ref="item1" labelWidth="auto">
  52. <u-radio-group v-model="statusValue" placement="row">
  53. <u-radio v-for="(item, index) in statusList" :key="index" :label="item.name"
  54. :name="item.name" @change="statusChange">
  55. </u-radio>
  56. </u-radio-group>
  57. </u-form-item>
  58. <u-form-item label="显示排序:" prop="chooseUser.orderNum" borderBottom ref="item1" labelWidth="auto">
  59. <uni-number-box v-model="chooseUser.orderNum" />
  60. </u-form-item>
  61. </u--form>
  62. </view>
  63. </u-modal>
  64. </view>
  65. </template>
  66. <script>
  67. import authObj from '@/plugins/auth.js';
  68. import {
  69. getDeptList,
  70. getUserListByDept
  71. } from '@/api/user/user';
  72. import {
  73. addDeptAndUser,
  74. delDept
  75. } from '@/api/dept/dept'
  76. import {
  77. unbind
  78. } from '@/api/device/device.js'
  79. import UText from "../../uni_modules/uview-ui/components/u-text/u-text";
  80. import {
  81. checkStr
  82. } from "@/utils/validate.js"
  83. export default {
  84. components: {
  85. UText
  86. },
  87. data() {
  88. return {
  89. deptList: [],
  90. displayList:[],
  91. loading:false,
  92. allLoaded :false,
  93. pageSize:50,
  94. currentPage:1,
  95. search: {
  96. deptName: ""
  97. },
  98. statusList: [{
  99. name: '启用',
  100. disabled: false
  101. },
  102. {
  103. name: '禁用',
  104. disabled: false
  105. }
  106. ],
  107. statusValue: '启用',
  108. //showEdit: false,
  109. showAdd: false,
  110. chooseUser: {},
  111. }
  112. },
  113. onLoad() {
  114. this.getDeptList();
  115. },
  116. methods: {
  117. newUser() {
  118. this.showAdd = true;
  119. this.chooseUser.orderNum = 1
  120. },
  121. closeDlg() {
  122. console.log('closeDlg>>>>>>>')
  123. this.showAdd = false;
  124. this.chooseUser = {};
  125. },
  126. statusChange(e) {
  127. console.log(e);
  128. },
  129. searchDept() {
  130. this.getDeptList();
  131. },
  132. toUser(item) {
  133. uni.navigateTo({
  134. url: '/pages/user/list?deptId=' + item.deptId
  135. });
  136. },
  137. toDeviceList(item) {
  138. uni.navigateTo({
  139. url: '/subpkg/device/index?deptId=' + item.deptId
  140. });
  141. },
  142. //删除客户,并删除客户下的用户信息和解绑设备
  143. toDel(item){
  144. let self=this
  145. uni.showModal({
  146. title: '提示',
  147. content: "删除客户信息并解绑设备?",
  148. confirmText:'取消',
  149. confirmColor:'#2979ff',
  150. cancelText:'确定',
  151. cancelColor:'#ed1c24',
  152. success: function (res) {
  153. if (res.confirm) {
  154. console.log('取消'+JSON.stringify(item));
  155. } else if (res.cancel) {
  156. console.log('用户点击确定'+JSON.stringify(item));
  157. unbind(item.deptId).then(res=>{
  158. uni.showToast({
  159. title: '操作成功',
  160. icon: 'none',
  161. duration: 1500
  162. })
  163. location.reload()
  164. })
  165. }
  166. }
  167. });
  168. },
  169. loadMore() {
  170. if (this.loading || this.allLoaded) return
  171. this.loading = true
  172. setTimeout(() => {
  173. const start = this.currentPage * this.pageSize
  174. const end = start + this.pageSize
  175. const nextPageData = this.deptList.slice(start, end)
  176. if (nextPageData.length === 0) {
  177. this.allLoaded = true
  178. } else {
  179. this.displayList = this.displayList.concat(nextPageData)
  180. this.currentPage++
  181. }
  182. this.loading = false
  183. }, 300) // 模拟加载时间,实际可以去掉
  184. },
  185. getDeptList() {
  186. getDeptList(this.search.deptName).then(res => {
  187. this.deptList = res.data;
  188. this.displayList = this.deptList.slice(0, 50)
  189. });
  190. },
  191. doAddUser() {
  192. let self = this;
  193. this.chooseUser.postIds = [];
  194. if (this.statusValue == '启用') {
  195. this.chooseUser.status = 0;
  196. } else {
  197. this.chooseUser.status = 1;
  198. }
  199. if (!checkStr(this.chooseUser.phonenumber, 'mobile')) {
  200. uni.showToast({
  201. title: '手机号码格式有误',
  202. icon: 'none',
  203. duration: 1000
  204. })
  205. } else {
  206. this.chooseUser.userName = this.chooseUser.phonenumber
  207. if (this.showAdd) {
  208. addDeptAndUser(this.chooseUser).then(res => {
  209. uni.showToast({
  210. title: '操作成功',
  211. icon: 'none',
  212. duration: 1500
  213. })
  214. self.closeDlg();
  215. location.reload()
  216. }).catch(res => {
  217. console.log('close>>>>>>erro')
  218. })
  219. }
  220. }
  221. },
  222. }
  223. }
  224. </script>
  225. <style lang="scss">
  226. /* #ifndef APP-NVUE */
  227. .u-collapse-content {
  228. display: flex;
  229. flex-direction: column;
  230. }
  231. page {
  232. display: flex;
  233. flex-direction: column;
  234. box-sizing: border-box;
  235. background-color: #fff;
  236. min-height: 100%;
  237. height: auto;
  238. }
  239. view {
  240. font-size: 14px;
  241. line-height: inherit;
  242. }
  243. /* #endif */
  244. .text {
  245. text-align: center;
  246. font-size: 26rpx;
  247. margin-top: 10rpx;
  248. }
  249. .grid-item-box {
  250. flex: 1;
  251. /* #ifndef APP-NVUE */
  252. display: flex;
  253. /* #endif */
  254. flex-direction: column;
  255. align-items: center;
  256. justify-content: center;
  257. padding: 15px 0;
  258. }
  259. .uni-margin-wrap {
  260. width: 690rpx;
  261. width: 100%;
  262. ;
  263. }
  264. .swiper {
  265. height: 300rpx;
  266. }
  267. .swiper-box {
  268. height: 150px;
  269. }
  270. .swiper-item {
  271. /* #ifndef APP-NVUE */
  272. display: flex;
  273. /* #endif */
  274. flex-direction: column;
  275. justify-content: center;
  276. align-items: center;
  277. color: #fff;
  278. height: 300rpx;
  279. line-height: 300rpx;
  280. }
  281. @media screen and (min-width: 500px) {
  282. .uni-swiper-dot-box {
  283. width: 400px;
  284. /* #ifndef APP-NVUE */
  285. margin: 0 auto;
  286. /* #endif */
  287. margin-top: 8px;
  288. }
  289. .image {
  290. width: 100%;
  291. }
  292. }
  293. </style>