homePage.vue 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  1. <template>
  2. <view class="HomeItem">
  3. <view v-if="!online && online !== undefined && workSchemeType == 1">
  4. <view class="goWork" @click="GoWork()">
  5. <view class="goWork_btn_E">
  6. <view class="goWork_btn_W"> 上班 </view>
  7. </view>
  8. </view>
  9. <view class="goWork_text">
  10. <view class="goWork_text-p">上班提醒</view>
  11. <view>请点击" 上班 "开始接单!</view>
  12. </view>
  13. </view>
  14. <view v-if="!online && online !== undefined && workSchemeType == 2" class="goWorkAll">
  15. <view class="goWorkSelect combination">
  16. <view class="goWorkSelect-head">上班选择工作组合</view>
  17. <scroll-view class="goWorkSelect-list scroll" scroll-y :refresher-enabled="scroll_refresher_enabled"
  18. :refresher-triggered="triggered" @refresherrefresh="refresherrefresh" @refresherrestore="refresherrestore"
  19. @scrolltolower="scrolltolower" :scroll-top="scroll_top" @refresherabort="refresherabort" @scroll="scroll">
  20. <radio-group @change="radioChange1">
  21. <label class="goWorkSelect-item" v-for="item in zxzData" :key="item.str">
  22. <radio :value="item.str" :checked="item.checked" />
  23. <view>{{ item.configName }}</view>
  24. </label>
  25. </radio-group>
  26. </scroll-view>
  27. </view>
  28. <view class="goWorkSelect history">
  29. <view class="goWorkSelect-head"> 历史上班记录 </view>
  30. <view class="goWorkSelect-list">
  31. <radio-group @change="radioChange2">
  32. <label class="goWorkSelect-item" v-for="(item, index) in historys" :key="index">
  33. <radio :value="item.str" :checked="item.checked" />
  34. <view>{{ item.useTime }}上班记录快捷上班</view>
  35. <button @click="lock(item)">
  36. {{ item.locking == 1 ? "解锁" : "锁定" }}
  37. </button>
  38. </label>
  39. </radio-group>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- APP或H5账号密码登录页面 start -->
  44. <view class="login" v-if="!workSchemeType && (isApp||isH5AndPwd)">
  45. <view class="title"> 医疗服务中心转运系统 </view>
  46. <input class="login_input" v-model="username" placeholder="请输入用户名" />
  47. <input class="login_input" password v-model="password" placeholder="请输入密码" />
  48. <input class="login_input" v-show="!isH5AndPwd" v-model="ip" placeholder="请输入域名或IP地址,如:http(s)://192.168.3.108" />
  49. <view class="savePassword">
  50. <checkbox-group @change="checkboxChange">
  51. <label>
  52. <checkbox v-for="(item,index) in savePassword" :key="item.value" color="#42b983" :value="item.value"
  53. :checked="item.checked" />记住密码
  54. </label>
  55. </checkbox-group>
  56. </view>
  57. <view class="page_item_btn" @click="login()"> 登录 </view>
  58. <view class="tips" v-show="isH5AndPwd">
  59. (此系统为服务中心及药房人员使用,其他科室人员请勿进行操作)
  60. </view>
  61. </view>
  62. <!-- APP或H5账号密码登录页面 end -->
  63. <view class="botImg" v-if="online || (!online && online !== undefined && workSchemeType == 1)">
  64. <view class="img"></view>
  65. </view>
  66. <!-- 弹窗 -->
  67. <showModel :title="models.title" :icon="models.icon" :disjunctor="models.disjunctor" :content="models.content"
  68. @ok="ok" @cancel="cancel" :operate="models.operate" :phone="models.phone" @know="know"></showModel>
  69. <!-- 锁定-弹窗 -->
  70. <showModel :title="modelsLock.title" :icon="modelsLock.icon" :disjunctor="modelsLock.disjunctor"
  71. :content="modelsLock.content" @ok="okLock" @cancel="cancelLock" :operate="modelsLock.operate" @know="knowLock">
  72. </showModel>
  73. </view>
  74. </template>
  75. <script>
  76. import {
  77. get,
  78. post,
  79. changeIP,
  80. webHandle
  81. } from "../../http/http.js";
  82. import showModel from "../../components/showModel/showModel.vue";
  83. import {
  84. AES,
  85. mode,
  86. pad,
  87. enc
  88. } from "crypto-js";
  89. export default {
  90. data() {
  91. return {
  92. //#ifdef H5
  93. type: "",
  94. //#endif
  95. //记住密码
  96. savePassword: [{
  97. value: 'savePassword',
  98. name: '记住密码',
  99. checked: true
  100. }],
  101. // 是否上班了
  102. online: undefined,
  103. // 是否是app
  104. isApp: false,
  105. // 是否是H5,账号密码登录
  106. isH5AndPwd: false,
  107. // 用户名
  108. username: "",
  109. // 密码
  110. password: "",
  111. //ip地址或域名
  112. ip: "hsms.dashitech.com",
  113. scroll_refresher_enabled: true, //是否开启自定义下拉刷新
  114. triggered: false, //下拉刷新状态
  115. freshing: false, //上拉加载开关
  116. scroll_top: 0, //距离顶部的距离
  117. //分页页码
  118. idx: 0,
  119. // 列表项总数
  120. totalNum: -1,
  121. // 上班选择工作组合列表
  122. zxzData: [],
  123. workSchemeId: "", //启动中工作分配方案id
  124. workSchemeType: "", //启动中工作分配方案类型
  125. ruleType: "", //工作分配方案规则、、例如自由抢单等
  126. // 上班历史记录列表
  127. historys: [],
  128. // 弹窗model
  129. models: {
  130. disjunctor: false,
  131. },
  132. //锁定的选项
  133. itemLock: {},
  134. // 弹窗model--锁定
  135. modelsLock: {
  136. disjunctor: false,
  137. },
  138. };
  139. },
  140. methods: {
  141. //aes加密
  142. encryptByEnAES(data) {
  143. let Key = "dsadmin";
  144. let tmpAES = AES.encrypt(data, Key, {
  145. mode: mode.CBC,
  146. padding: pad.Pkcs7,
  147. });
  148. return tmpAES.toString();
  149. },
  150. //aes解密
  151. encryptByDeAES(data) {
  152. let Key = "dsadmin";
  153. let tmpDeAES = AES.decrypt(data, Key, {
  154. mode: mode.CBC,
  155. padding: pad.Pkcs7,
  156. });
  157. return tmpDeAES.toString(enc.Utf8);
  158. },
  159. //记住密码
  160. checkboxChange(e) {
  161. console.log(e.detail.value);
  162. let arr = e.detail.value;
  163. if (arr.length) {
  164. this.savePassword.forEach(v => {
  165. v.checked = true;
  166. })
  167. } else {
  168. this.savePassword.forEach(v => {
  169. v.checked = false;
  170. })
  171. }
  172. console.log(this.savePassword)
  173. },
  174. // 锁定
  175. lock(data) {
  176. console.log(data);
  177. this.itemLock = data;
  178. this.modelsLock = {
  179. disjunctor: true,
  180. title: "提示",
  181. content: `是否${
  182. this.itemLock.locking == 1 ? "解锁" : "锁定"
  183. }该上班记录`,
  184. icon: "warn",
  185. operate: {
  186. ok: "确定",
  187. cancel: "取消",
  188. },
  189. };
  190. },
  191. //知道了
  192. knowLock() {
  193. this.modelsLock.disjunctor = false;
  194. let userId = uni.getStorageSync("userData").user.id;
  195. this.getHistorys(userId); //获取上班历史记录
  196. },
  197. //确定
  198. okLock() {
  199. this.modelsLock.disjunctor = false;
  200. let postData = {
  201. workConfigHistory: {
  202. id: this.itemLock.id,
  203. locking: this.itemLock.locking == 1 ? 0 : 1,
  204. },
  205. };
  206. uni.showLoading({
  207. title: "加载中",
  208. mask: true,
  209. });
  210. post("/configuration/updData/workConfigHistory", postData).then(
  211. (result) => {
  212. uni.hideLoading();
  213. if (result.status == 200) {
  214. this.modelsLock = {
  215. disjunctor: true,
  216. title: "提示",
  217. content: `${this.itemLock.locking == 0 ? "锁定" : "解锁"}成功`,
  218. icon: "success",
  219. operate: {
  220. know: "知道了",
  221. },
  222. };
  223. } else {
  224. uni.showToast({
  225. icon: "none",
  226. title: "请求失败",
  227. });
  228. }
  229. }
  230. );
  231. },
  232. //取消
  233. cancelLock() {
  234. this.modelsLock.disjunctor = false;
  235. },
  236. // 选择历史上班记录
  237. radioChange2(value) {
  238. this.objHistory = JSON.parse(value.target.value);
  239. let depts = this.objHistory.deptList.map((item) => item.dept).join();
  240. this.models = {
  241. disjunctor: true,
  242. title: "提示",
  243. content: `组合名称是【${this.objHistory.workAllocationQuick.configName}】;选择的科室是【${depts}】`,
  244. icon: "warn",
  245. operate: {
  246. ok: "快捷上班",
  247. cancel: "取消",
  248. },
  249. };
  250. },
  251. //知道了
  252. know() {
  253. this.models.disjunctor = false;
  254. },
  255. //确定
  256. ok() {
  257. this.models.disjunctor = false;
  258. this.ruleType = 3;
  259. uni.setStorageSync("setDepts", this.objHistory.deptList); //存科室列表
  260. uni.setStorageSync("setDeptConfg", {
  261. //存设置科室的配置信息
  262. configName: this.objHistory.workAllocationQuick.configName, //组合名称
  263. workSchemeType: 2, //方案类型
  264. ruleType: 3, //方案规则,科室绑定人员
  265. id: this.objHistory.workAllocationQuick.id, //组合id
  266. classesId: this.objHistory.classId,
  267. });
  268. this.GoWork();
  269. },
  270. //取消
  271. cancel() {
  272. this.models.disjunctor = false;
  273. let userId = uni.getStorageSync("userData").user.id;
  274. this.historys = [];
  275. this.getHistorys(userId); //获取上班历史记录
  276. },
  277. // 获取上班历史记录
  278. getHistorys(id) {
  279. let postData = {
  280. idx: 0,
  281. sum: 3,
  282. workConfigHistory: {
  283. hosId: uni.getStorageSync("userData").user.currentHospital.id,
  284. user: {
  285. id: id,
  286. },
  287. },
  288. };
  289. post("/configuration/fetchDataList/workConfigHistory", postData).then(
  290. (res) => {
  291. if (res.status == 200) {
  292. this.historys = res.list;
  293. this.historys.forEach((item) => {
  294. let d = new Date(item.useTime);
  295. let month = (d.getMonth() + 1 + "").padStart(2, "0");
  296. let day = (d.getDate() + "").padStart(2, "0");
  297. item.useTime = `${month}月${day}日`;
  298. let o = JSON.parse(JSON.stringify(item));
  299. item.str = JSON.stringify(o);
  300. item.checked = false;
  301. });
  302. } else {
  303. uni.showToast({
  304. icon: "none",
  305. title: "请求失败",
  306. });
  307. }
  308. }
  309. );
  310. },
  311. // 选择上班快捷组合
  312. radioChange1(value) {
  313. let obj = JSON.parse(value.target.value);
  314. console.log(obj);
  315. this.ruleType = obj.ruleType;
  316. if (obj.ruleType == 1) {
  317. //自由抢单,直接上班
  318. if (uni.getStorageSync("setDeptConfg")) {
  319. uni.removeStorageSync("setDeptConfg"); //清空选择的科室配置,初始化
  320. }
  321. this.GoWork();
  322. } else if (obj.ruleType == 3) {
  323. //科室绑定人员,进入设置科室界面
  324. uni.setStorageSync("setDeptConfg", {
  325. //存设置科室的配置信息
  326. configName: obj.configName,
  327. workSchemeType: this.workSchemeType,
  328. ruleType: obj.ruleType,
  329. id: obj.id,
  330. classesId: obj.classes.id,
  331. });
  332. uni.navigateTo({
  333. url: `../setDept/setDept?configName=${obj.configName}&id=${obj.id}`,
  334. });
  335. }
  336. },
  337. // 连接上下班的websocket baba type如果是wx则是微信,app则是app;有app必有ip
  338. offWork(type, ip) {
  339. let ipp, wws;
  340. if (type == "wx") {
  341. wws = document.location.protocol === "http:" ? "ws" : "wss"; //ws协议
  342. ipp = document.domain;
  343. } else if (type == "app") {
  344. wws = ip.split(":")[0] === "http" ? "ws" : "wss"; //ws协议
  345. ipp = ip.split(":")[1];
  346. }
  347. console.log(ipp, wws);
  348. uni.connectSocket({
  349. url: `${wws}://${ipp}:8080/webSocket/message/onlineStatus`,
  350. // url: `${wws}://192.168.3.74:8080/webSocket/message/onlineStatus`,
  351. });
  352. uni.onSocketOpen(function(res) {
  353. console.log("WebSocket连接已打开!");
  354. let userid = uni.getStorageSync("userData").user.id;
  355. uni.sendSocketMessage({
  356. data: JSON.stringify({
  357. userid,
  358. }),
  359. success: function(res) {
  360. console.log(res, "传参");
  361. },
  362. fail: function(err) {
  363. console.log(err, "传参错误");
  364. },
  365. });
  366. });
  367. uni.onSocketError(function(res) {
  368. console.log("WebSocket连接打开失败,请检查!");
  369. });
  370. uni.onSocketMessage((res) => {
  371. console.log("收到服务器内容:" + res.data);
  372. if (res.data == "ok") {
  373. this.goOffWork();
  374. }
  375. });
  376. },
  377. // 下班
  378. goOffWork() {
  379. let setDeptConfg = uni.getStorageSync("setDeptConfg");
  380. if (setDeptConfg.workSchemeType == 2 && setDeptConfg.ruleType == 3) {
  381. post("/auth/onOrOffLine", {
  382. type: "off",
  383. customWorking: "off",
  384. classId: uni.getStorageSync("setDeptConfg").classesId
  385. }).then((res) => {
  386. if (res.status == 200) {
  387. if (uni.getStorageSync("setDeptConfg")) {
  388. uni.removeStorageSync("setDeptConfg"); //清空选择的科室配置,初始化
  389. }
  390. uni.showToast({
  391. icon: "none",
  392. title: "您已被强制下班!",
  393. mask: true,
  394. duration: 5000,
  395. });
  396. setTimeout(() => {
  397. uni.redirectTo({
  398. url: "../mypage/mypage",
  399. });
  400. }, 5000);
  401. } else {
  402. uni.showToast({
  403. icon: "none",
  404. title: "请求失败",
  405. });
  406. }
  407. });
  408. } else {
  409. post("/auth/onOrOffLine", {
  410. type: "off",
  411. classId: uni.getStorageSync("setDeptConfg").classesId
  412. }).then((res) => {
  413. if (res.status == 200) {
  414. if (uni.getStorageSync("setDeptConfg")) {
  415. uni.removeStorageSync("setDeptConfg"); //清空选择的科室配置,初始化
  416. }
  417. uni.showToast({
  418. icon: "none",
  419. title: "您已被强制下班!",
  420. mask: true,
  421. duration: 5000,
  422. });
  423. setTimeout(() => {
  424. uni.redirectTo({
  425. url: "../mypage/mypage",
  426. });
  427. }, 5000);
  428. } else {
  429. uni.showToast({
  430. icon: "none",
  431. title: "请求失败",
  432. });
  433. }
  434. });
  435. }
  436. },
  437. // 上班
  438. GoWork() {
  439. uni.showLoading({
  440. title: "加载中",
  441. mask: true,
  442. });
  443. if (this.workSchemeType == 2 && this.ruleType == 3) {
  444. let obj = uni.getStorageSync("setDeptConfg");
  445. let depts = this.objHistory.deptList.map((item) => item.id).join();
  446. let userId = uni.getStorageSync("userData").user.id;
  447. post("/auth/onOrOffLine", {
  448. type: "on",
  449. customWorking: "on",
  450. quickId: obj.id,
  451. deptIds: depts,
  452. userId: userId,
  453. classId: uni.getStorageSync("setDeptConfg").classesId
  454. }).then((result) => {
  455. uni.hideLoading();
  456. if (result.status == 200) {
  457. let obj = uni.getStorageSync("userData");
  458. obj.user.online = true;
  459. uni.setStorageSync("userData", obj);
  460. uni.redirectTo({
  461. url: "../receiptpage/receiptpage",
  462. });
  463. } else if (result.status == 504) {
  464. let dept = result.department.dept;
  465. let user = result.user.name;
  466. let phone = result.user.phone;
  467. this.models = {
  468. disjunctor: true,
  469. title: "提示",
  470. content: `您选择的科室已经被使用,请换个科室,或者联系:科室[${dept}]人员[${user}]号码[${phone}] 切换科室解决`,
  471. icon: "warn",
  472. phone,
  473. operate: {
  474. know: "知道了",
  475. },
  476. };
  477. } else {
  478. uni.showToast({
  479. icon: "none",
  480. title: "请求失败",
  481. });
  482. }
  483. });
  484. } else {
  485. post("/auth/onOrOffLine", {
  486. type: "on",
  487. classId: uni.getStorageSync("setDeptConfg").classesId
  488. }).then((res) => {
  489. uni.hideLoading();
  490. if (res.status == 200) {
  491. let obj = uni.getStorageSync("userData");
  492. obj.user.online = true;
  493. uni.setStorageSync("userData", obj);
  494. uni.redirectTo({
  495. url: "../receiptpage/receiptpage",
  496. });
  497. } else {
  498. uni.showToast({
  499. icon: "none",
  500. title: "请求失败",
  501. });
  502. }
  503. });
  504. }
  505. },
  506. // 登录
  507. login() {
  508. // 用户名,密码,域名(ip)不能为空
  509. if (
  510. this.username.trim() === "" ||
  511. this.password.trim() === "" ||
  512. this.ip.trim() === ""
  513. ) {
  514. uni.showToast({
  515. icon: "none",
  516. title: "请输入用户名,密码,域名或IP",
  517. });
  518. return;
  519. }
  520. // 域名ip正则验证
  521. let regUrl =
  522. /^https?:\/\/([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)| (io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp))(\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))?$/;
  523. let regIp =
  524. /^https?:\/\/((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d)(\.((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d)){3}(\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))?$/;
  525. if (!regUrl.test(this.ip.trim()) && !regIp.test(this.ip.trim())) {
  526. uni.showToast({
  527. icon: "none",
  528. title: "请输入正确的域名或IP",
  529. });
  530. return;
  531. }
  532. if (this.savePassword[0].checked) {
  533. //记住密码
  534. uni.setStorageSync("ip", this.ip);
  535. } else {
  536. // 不记住密码
  537. uni.removeStorageSync('ip');
  538. }
  539. changeIP(this.ip);
  540. uni.showLoading({
  541. title: "登录中",
  542. mask: true,
  543. });
  544. let data = {
  545. username: this.username.trim(),
  546. password: this.password.trim(),
  547. type: 'APP'
  548. };
  549. post("/auth/login", data).then((res) => {
  550. uni.hideLoading();
  551. if (res.status == 200) {
  552. //获取角色信息
  553. let role = res.user.user.role;
  554. // 配药师和支助人员才能登录
  555. let workerFlag = role.some((item) => item.rolecode === "worker");
  556. let pharmacistFlag = role.some((item) => item.rolecode === "pharmacist");
  557. if (!workerFlag && !pharmacistFlag) {
  558. uni.showToast({
  559. icon: "none",
  560. title: "暂无权限登录!",
  561. });
  562. return;
  563. }
  564. if (this.savePassword[0].checked) {
  565. //记住密码
  566. uni.setStorageSync("username", this.encryptByEnAES(this.username)); //存储用户名
  567. uni.setStorageSync("password", this.encryptByEnAES(this.password)); //存储密码
  568. uni.setStorageSync("savePasswordTime", Date.now()); //存储当前时间戳
  569. } else {
  570. uni.removeStorageSync('username');
  571. uni.removeStorageSync('password');
  572. uni.removeStorageSync('savePasswordTime');
  573. }
  574. uni.setStorageSync("userData", res.user);
  575. this.getWorkScheme(false, res.user.user.currentHospital.id); //获取当前启动中的工作分配方案
  576. this.getHistorys(res.user.user.id); //获取上班历史记录
  577. this.offWork("app", this.ip);
  578. if (workerFlag) { //有配药师角色
  579. if (!res.user.user.online) {
  580. this.online = false;
  581. } else {
  582. this.online = true;
  583. // 建立websocket连接
  584. webHandle("receiptpage", "app", this.ip);
  585. }
  586. } else {
  587. webHandle("pharmacy", "app", this.ip);
  588. }
  589. } else if (!res.status && !res.remarks) {
  590. //如果乱填写域名或ip
  591. uni.showToast({
  592. icon: "none",
  593. title: "服务器连接失败!请检查输入的域名(IP)及端口号",
  594. });
  595. } else {
  596. uni.showToast({
  597. icon: "none",
  598. title: res.remarks ? res.remarks : "请求失败",
  599. });
  600. }
  601. });
  602. },
  603. // 微信登录公用方法
  604. // user:当前登录用户对象
  605. // type:有值的话则是从菜单访问的
  606. // workerFlag:是否有支助人员角色
  607. // pharmacistFlag:是否有配药师角色
  608. submCommon(user, type, workerFlag, pharmacistFlag) {
  609. //从药房菜单过来的
  610. if (type === "pharmacy") {
  611. //药房来
  612. // 药房才能登录
  613. if (!pharmacistFlag) {
  614. uni.showToast({
  615. icon: "none",
  616. title: "暂无权限登录!",
  617. });
  618. return;
  619. }
  620. } else if (type === "mypage") { //从我的菜单过来的
  621. if (!workerFlag) {
  622. uni.showToast({
  623. icon: "none",
  624. title: "暂无权限登录!",
  625. });
  626. return;
  627. }
  628. } else {
  629. //正常进入
  630. if (!workerFlag && !pharmacistFlag) {
  631. uni.showToast({
  632. icon: "none",
  633. title: "暂无权限登录!",
  634. });
  635. return;
  636. }
  637. }
  638. uni.setStorageSync("userData", user);
  639. this.getWorkScheme(false, user.user.currentHospital.id); //获取当前启动中的工作分配方案
  640. this.getHistorys(user.user.id); //获取上班历史记录
  641. this.offWork("wx");
  642. // uni.setStorageSync('type', '')
  643. if (type === "pharmacy") {
  644. // 建立websocket连接
  645. webHandle("pharmacy", "wx");
  646. } else if (type === "mypage") {
  647. // 建立websocket连接
  648. webHandle("mypage", "wx");
  649. } else {
  650. if (workerFlag) { //有支助人员的角色
  651. if (!user.user.online) {
  652. this.online = false;
  653. } else {
  654. this.online = true;
  655. // 建立websocket连接
  656. webHandle("receiptpage", "wx");
  657. }
  658. } else { //只有药房橘色
  659. webHandle("pharmacy", "wx");
  660. }
  661. }
  662. },
  663. //微信
  664. subm() {
  665. uni.showLoading({
  666. title: "登录中",
  667. mask: true,
  668. });
  669. var href = location.href; //获取链接地址
  670. console.log(href, "href");
  671. var href_wenhao = href.indexOf("?code="); //判断有没有问号,没有是-1
  672. var wenhaohoumian = location.href.split("?code="); //截取问号地址数组
  673. this.arr_last = wenhaohoumian[1]; //地址数组赋值
  674. if (href_wenhao == -1) {
  675. post("/auth/wxlogin").then((res) => {
  676. this.url = res.url;
  677. this.state = res.status;
  678. uni.setStorageSync("type", this.type); //存储来源type
  679. uni.hideLoading();
  680. if (this.state == "200") {
  681. //获取角色信息
  682. let role = res.user.user.role;
  683. let workerFlag = role.some((item) => item.rolecode === "worker");
  684. let pharmacistFlag = role.some((item) => item.rolecode === "pharmacist");
  685. this.submCommon(res.user, this.type, workerFlag, pharmacistFlag);
  686. } else if (this.state == "501") {
  687. uni.showModal({
  688. title: '提示',
  689. content: res.remarks,
  690. showCancel: false,
  691. confirmColor: '#49b856',
  692. success: function(res) {
  693. if (res.confirm) {
  694. console.log('用户点击确定');
  695. } else if (res.cancel) {
  696. console.log('用户点击取消');
  697. }
  698. }
  699. });
  700. } else if (this.state == "555") {
  701. // 如果需要绑定账号 并且 没有微信号
  702. if (this.type) {
  703. uni.redirectTo({
  704. url: `../bindUser/bindUser?type=${this.type}`
  705. })
  706. } else {
  707. uni.redirectTo({
  708. url: `../bindUser/bindUser`
  709. })
  710. }
  711. } else {
  712. console.log(this.url, "url");
  713. // https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww2506abad3086cfab&redirect_uri=http://weixintest2.ngser.dashitech.com/app&response_type=code&scope=snsapi_base&agentid=1000013&state=STATE&connect_redirect=1#wechat_redirect
  714. location.assign(this.url);
  715. }
  716. });
  717. } else if (href_wenhao != -1) {
  718. this.arr_last = this.arr_last.split("&");
  719. this.arr_last = this.arr_last[0];
  720. post("/auth/wxlogina", {
  721. code: this.arr_last,
  722. }).then((res) => {
  723. this.state = res.status;
  724. uni.hideLoading();
  725. if (this.state == "200") {
  726. this.type = uni.getStorageSync("type"); //刷新页面后获取type
  727. console.log(this.type);
  728. //获取角色信息
  729. let role = res.user.user.role;
  730. let workerFlag = role.some((item) => item.rolecode === "worker");
  731. let pharmacistFlag = role.some((item) => item.rolecode === "pharmacist");
  732. this.submCommon(res.user, this.type, workerFlag, pharmacistFlag);
  733. } else if (this.state == "501") {
  734. uni.showModal({
  735. title: '提示',
  736. content: res.remarks,
  737. showCancel: false,
  738. confirmColor: '#49b856',
  739. success: function(res) {
  740. if (res.confirm) {
  741. console.log('用户点击确定');
  742. } else if (res.cancel) {
  743. console.log('用户点击取消');
  744. }
  745. }
  746. });
  747. } else if (this.state == "555") {
  748. this.type = uni.getStorageSync("type"); //刷新页面后获取type
  749. // 如果需要绑定账号 并且 没有微信号
  750. if (this.type) {
  751. uni.redirectTo({
  752. url: `../bindUser/bindUser?type=${this.type}`
  753. })
  754. } else {
  755. uni.redirectTo({
  756. url: `../bindUser/bindUser`
  757. })
  758. }
  759. } else {
  760. uni.showToast({
  761. icon: "none",
  762. title: "请求失败",
  763. });
  764. }
  765. });
  766. }
  767. },
  768. // 获取工作组合列表
  769. getCombinationById(idx, type) {
  770. console.log(this.type);
  771. if (this.zxzData.length == this.totalNum && !type) {
  772. uni.showToast({
  773. icon: "none",
  774. title: "没有更多数据了!",
  775. });
  776. this.freshing = true;
  777. return;
  778. }
  779. let data = {
  780. workAllocationQuickConfig: {
  781. workSchemeId: this.workSchemeId,
  782. },
  783. idx: idx,
  784. sum: 20,
  785. };
  786. uni.showLoading({
  787. title: "加载中",
  788. mask: true,
  789. });
  790. // 请求列表数据
  791. post("/configuration/fetchDataList/workAllocationQuickConfig", data).then(
  792. (res) => {
  793. uni.hideLoading();
  794. if (res.status == 200) {
  795. this.triggered = false;
  796. this.freshing = true;
  797. this.totalNum = res.totalNum;
  798. if (idx === 0) {
  799. res.list.forEach((item) => {
  800. let o = JSON.parse(JSON.stringify(item));
  801. item.str = JSON.stringify(o);
  802. item.checked = false;
  803. });
  804. this.zxzData = res.list;
  805. } else {
  806. res.list.forEach((item) => {
  807. let o = JSON.parse(JSON.stringify(item));
  808. item.str = JSON.stringify(o);
  809. item.checked = false;
  810. });
  811. this.zxzData.push(...res.list);
  812. }
  813. } else {
  814. uni.showToast({
  815. icon: "none",
  816. title: "请求失败!",
  817. });
  818. }
  819. }
  820. );
  821. },
  822. //刷新
  823. refresherrefresh() {
  824. if (this.triggered) {
  825. return;
  826. }
  827. console.log("下拉刷新");
  828. this.triggered = true;
  829. this.idx = 0;
  830. this.totalNum = -1;
  831. this.getCombinationById(0);
  832. },
  833. // 下拉刷新复位
  834. refresherrestore() {
  835. this.triggered = false;
  836. console.log("下拉刷新复位");
  837. },
  838. //下拉刷新中止
  839. refresherabort() {
  840. this.triggered = false;
  841. console.log("下拉刷新中止");
  842. },
  843. //分页,上拉加载
  844. scrolltolower() {
  845. if (this.freshing) {
  846. console.log("上拉加载");
  847. this.freshing = false;
  848. this.getCombinationById(++this.idx);
  849. }
  850. },
  851. // 滚动
  852. scroll(e) {
  853. if (e.detail.scrollTop < 20) {
  854. this.scroll_refresher_enabled = true;
  855. } else {
  856. this.scroll_refresher_enabled = false;
  857. }
  858. },
  859. // 获取启动中的工作分配方案
  860. getWorkScheme(type, hosId) {
  861. let postData = {
  862. idx: 0,
  863. workScheme: {
  864. status: 1,
  865. hosId
  866. },
  867. sum: 1,
  868. };
  869. post("/simple/data/fetchDataList/workScheme", postData).then((res) => {
  870. if (res.status == 200) {
  871. this.workSchemeId = res.list[0].id;
  872. this.workSchemeType = res.list[0].workType;
  873. if (type) {
  874. if (this.workSchemeType == 2) {
  875. this.getCombinationById(0, "no");
  876. } else if (this.workSchemeType == 1) {
  877. if (uni.getStorageSync("setDeptConfg")) {
  878. uni.removeStorageSync("setDeptConfg"); //清空选择的科室配置,初始化
  879. }
  880. }
  881. } else {
  882. this.getCombinationById(0);
  883. }
  884. } else {
  885. uni.showToast({
  886. icon: "none",
  887. title: "请求失败!",
  888. });
  889. }
  890. });
  891. },
  892. // 阻止浏览器滑动
  893. stop(e) {
  894. e.preventDefault();
  895. },
  896. //获取查询参数
  897. GetQueryString(name) {
  898. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  899. var r = location.search.substr(1).match(reg);
  900. if (r != null) {
  901. return unescape(r[2]);
  902. }
  903. return null;
  904. }
  905. },
  906. onHide() {
  907. this.zxzData = [];
  908. this.historys = [];
  909. // #ifdef H5
  910. document.body.removeEventListener("touchmove", this.stop, {
  911. passive: false,
  912. });
  913. // #endif
  914. },
  915. onShow() {
  916. console.log('onShow');
  917. // let flag = true;
  918. if (uni.getStorageSync("userData")) {
  919. this.online = uni.getStorageSync("userData").user.online;
  920. }
  921. if (!this.workSchemeType) {
  922. return;
  923. }
  924. // if (this.workSchemeType == 2 && !this.online) {
  925. // let userId = uni.getStorageSync('userData').user.id;
  926. // this.getCombinationById(this.idx, 'no');
  927. // this.getHistorys(userId); //获取上班历史记录
  928. // }
  929. let userId = uni.getStorageSync("userData").user.id;
  930. this.getWorkScheme(true, uni.getStorageSync("userData").user.currentHospital.id);
  931. this.getHistorys(userId); //获取上班历史记录
  932. // #ifdef APP-PLUS
  933. uni.closeSocket();
  934. // #endif
  935. // #ifdef H5
  936. document.body.addEventListener("touchmove", this.stop, {
  937. passive: false,
  938. });
  939. // #endif
  940. },
  941. onLoad(options) {
  942. if (uni.getStorageSync("setDepts")) {
  943. uni.removeStorageSync("setDepts"); //清空选择的科室,初始化
  944. }
  945. console.log(options);
  946. console.log(typeof uni.getStorageSync("savePasswordTime"));
  947. if (Date.now() - uni.getStorageSync("savePasswordTime") < 10 * 24 * 60 * 60 * 1000) {
  948. //记住密码,10天内有效
  949. this.ip = uni.getStorageSync("ip") || this.ip;
  950. if (uni.getStorageSync("username")) {
  951. this.username = this.encryptByDeAES(uni.getStorageSync("username"));
  952. }
  953. if (uni.getStorageSync("password")) {
  954. this.password = this.encryptByDeAES(uni.getStorageSync("password"));
  955. }
  956. }
  957. //#ifdef H5
  958. this.isApp = false;
  959. this.type = options.type || "";
  960. console.log(this.type);
  961. if (this.GetQueryString('login') === '1') {
  962. //H5页面账号密码登录
  963. this.isH5AndPwd = true;
  964. this.ip = location.origin;
  965. } else {
  966. this.isH5AndPwd = false;
  967. this.subm();
  968. }
  969. //#endif
  970. // #ifdef APP-PLUS
  971. this.isApp = true;
  972. // 通知权限 start
  973. // var main = plus.android.runtimeMainActivity();
  974. // var pkName = main.getPackageName();
  975. // var NotificationManagerCompat = plus.android.importClass(
  976. // "android.support.v4.app.NotificationManagerCompat"
  977. // );
  978. // var packageNames = NotificationManagerCompat.from(main);
  979. // console.log(JSON.stringify(packageNames));
  980. // if (packageNames.areNotificationsEnabled()) {
  981. // console.log("已开启通知权限");
  982. // } else {
  983. // uni.showModal({
  984. // title: "提示",
  985. // content: "请先打开APP通知权限",
  986. // showCancel: true,
  987. // success: function(res) {
  988. // if (res.confirm) {
  989. // var Intent = plus.android.importClass("android.content.Intent");
  990. // var intent = new Intent(
  991. // "android.settings.APP_NOTIFICATION_SETTINGS"
  992. // ); //可设置表中所有Action字段
  993. // intent.putExtra("android.provider.extra.APP_PACKAGE", pkName);
  994. // main.startActivity(intent);
  995. // }
  996. // },
  997. // });
  998. // }
  999. // 通知权限 end
  1000. // #endif
  1001. },
  1002. };
  1003. </script>
  1004. <style lang="less" scoped>
  1005. .HomeItem {
  1006. height: 100vh;
  1007. .login {
  1008. height: 420rpx;
  1009. padding: 0 32rpx;
  1010. padding-top: 164rpx;
  1011. position: relative;
  1012. z-index: 999;
  1013. .savePassword {
  1014. margin-top: 32rpx;
  1015. }
  1016. /deep/ uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
  1017. border-color: #42b983 !important;
  1018. }
  1019. .login_input {
  1020. margin-top: 32rpx;
  1021. background-color: #ffffff;
  1022. height: 72rpx;
  1023. box-sizing: border-box;
  1024. padding: 16rpx;
  1025. }
  1026. .title {
  1027. font-size: 36rpx;
  1028. color: #42b983;
  1029. text-align: center;
  1030. }
  1031. .tips {
  1032. font-size: 28rpx;
  1033. color: red;
  1034. margin-top: 16rpx;
  1035. }
  1036. .page_item_btn {
  1037. height: 88rpx;
  1038. background-image: linear-gradient(to right, #72c172, #3bb197);
  1039. border-radius: 8rpx;
  1040. line-height: 88rpx;
  1041. color: #fff;
  1042. font-size: 36rpx;
  1043. font-weight: 700;
  1044. margin-top: 64rpx;
  1045. text-align: center;
  1046. }
  1047. }
  1048. //上班页面
  1049. .goWorkAll {
  1050. height: 100%;
  1051. display: flex;
  1052. flex-direction: column;
  1053. justify-content: space-between;
  1054. /deep/ .uni-radio-input-checked {
  1055. background-color: #42b983 !important;
  1056. border-color: #42b983 !important;
  1057. }
  1058. .goWorkSelect {
  1059. &.history {
  1060. height: 356rpx;
  1061. padding-bottom: 16rpx;
  1062. }
  1063. &.combination {
  1064. .goWorkSelect-head {
  1065. position: fixed;
  1066. top: 0;
  1067. left: 0;
  1068. width: 100%;
  1069. }
  1070. .goWorkSelect-list {
  1071. margin-top: 82rpx;
  1072. }
  1073. }
  1074. .goWorkSelect-head {
  1075. font-size: 36rpx;
  1076. padding: 16rpx 0;
  1077. color: #42b983;
  1078. border-bottom: 2rpx solid #42b983;
  1079. text-align: center;
  1080. }
  1081. .goWorkSelect-list {
  1082. &.scroll {
  1083. height: calc(100vh - 356rpx - 82rpx);
  1084. }
  1085. .goWorkSelect-item {
  1086. height: 52rpx;
  1087. display: flex;
  1088. align-items: center;
  1089. border-bottom: 2rpx solid #e5e9ed;
  1090. padding: 16rpx;
  1091. button {
  1092. font-size: 32rpx;
  1093. height: 52rpx;
  1094. line-height: 52rpx;
  1095. margin: 0;
  1096. margin-left: 16rpx;
  1097. color: rgb(7, 134, 60);
  1098. font-weight: 700;
  1099. }
  1100. }
  1101. }
  1102. }
  1103. }
  1104. .goWork {
  1105. margin: 0 auto 48rpx;
  1106. width: 240rpx;
  1107. height: 240rpx;
  1108. .goWork_btn_E {
  1109. width: 100%;
  1110. height: 100%;
  1111. background: #bee1a7;
  1112. border-radius: 30%;
  1113. .goWork_btn_W {
  1114. width: 75%;
  1115. height: 75%;
  1116. background-image: linear-gradient(to right, #72c172, #3bb197);
  1117. border-radius: 30%;
  1118. margin: 0 auto;
  1119. position: relative;
  1120. top: 12.5%;
  1121. line-height: 180rpx;
  1122. color: #fff;
  1123. font-size: 36rpx;
  1124. text-align: center;
  1125. }
  1126. }
  1127. }
  1128. .goWork_text {
  1129. width: 100%;
  1130. view {
  1131. text-align: center;
  1132. }
  1133. .goWork_text-p {
  1134. font-size: 36rpx;
  1135. margin-bottom: 48rpx;
  1136. }
  1137. }
  1138. .botImg {
  1139. height: 600rpx;
  1140. width: 100%;
  1141. position: fixed;
  1142. bottom: 0;
  1143. .img {
  1144. height: 100%;
  1145. background: url("../../static/img/BG.png") no-repeat center center;
  1146. background-size: 100% 100%;
  1147. }
  1148. }
  1149. }
  1150. </style>