seiminModel.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <!--
  2. * @Author: 廖明明
  3. * @Date: 2022-04-01 17:11:19
  4. * @LastEditors: 廖明明
  5. * @LastEditTime: 2022-04-21 13:16:48
  6. * @Description: 自定义弹窗组件
  7. -->
  8. <template>
  9. <view class="seiminModel seiminModel_mask" v-if="opts.isVisible">
  10. <view class="seiminModel_container animate__animated animate__fadeIn animate__faster">
  11. <!-- 标题 -->
  12. <view class="seiminModel_header" :class="{noTitle:!opts.title}">
  13. <text>{{ opts.title }}</text>
  14. <text class="seiminModel_countDown" v-if="
  15. nurseDeptSwitchTip < 0 || (nurseDeptSwitchTip > 0 && closeTime > 0)
  16. ">
  17. <text v-if="nurseDeptSwitchTip < 0">关闭</text>倒计时<text>{{ closeTime }}s</text>
  18. </text>
  19. </view>
  20. <!-- 动态二维码 -->
  21. <view class="seiminModel_content qrcode" v-if="opts.skin === 'qrcode'">
  22. <image class="w100 qrcode_img" :src="nurseCodeImg" mode="widthFix"></image>
  23. <view class="qrcode_operate">
  24. <view class="refreshQRCode" @click="showNurseCode"> 刷新 </view>
  25. <view>{{ refreshQRCodeTime }}s</view>
  26. </view>
  27. </view>
  28. <!-- 加急 -->
  29. <view class="seiminModel_content urgent" v-else-if="opts.skin === 'urgent'">
  30. <view class="urgent_txt" v-html="opts.content"></view>
  31. <textarea :focus="true" class="urgent_textarea" auto-height :maxlength="100"
  32. :placeholder-style="placeholderStyle" placeholder="请填写加急原因" v-model="urgentTextArea" />
  33. </view>
  34. <!-- 评价 -->
  35. <view class="seiminModel_content evaluate" v-else-if="opts.skin === 'evaluate'">
  36. <view class="evaluate_txt" v-html="opts.content"></view>
  37. <view class="evaluate_list">
  38. <view class="evaluate_item">
  39. <text class="evaluate_label">星级:</text>
  40. <view class="evaluate_icons">
  41. <text class="pda" :class="star" v-for="(star,i) in stars" :key="i" @click="clickStar(i)"></text>
  42. </view>
  43. </view>
  44. <view class="evaluate_item">
  45. <text class="evaluate_label">评级:</text>
  46. <textarea :focus="true" class="evaluate_textarea" auto-height :maxlength="100"
  47. :placeholder-style="placeholderStyle" placeholder="请输入..." v-model="evaluateTextArea" />
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 正常弹窗 -->
  52. <view class="seiminModel_content" v-else>
  53. <!-- 图标 -->
  54. <view class="seiminModel_status">
  55. <text class="pda pda-shibai red" v-if="opts.icon === 'error'"></text>
  56. <text class="pda pda-wenhao yellow" v-if="opts.icon === 'warn'"></text>
  57. <text class="pda pda-duigou green" v-if="opts.icon === 'success'"></text>
  58. </view>
  59. <!-- 内容 -->
  60. <view class="seiminModel_txt" v-html="opts.content"></view>
  61. </view>
  62. <!-- 底部 -->
  63. <view class="seiminModel_footer" v-if="
  64. nurseDeptSwitchTip <= 0 || (nurseDeptSwitchTip > 0 && closeTime === 0)
  65. ">
  66. <view class="seiminModel_footer__btn" v-for="(btn, i) in opts.btns" :style="{
  67. flex: btn.flex,
  68. color: btn.textColor,
  69. }" @click="btn.click($event)" :key="i">{{ btn.name }}</view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import {
  76. mapState
  77. } from "vuex";
  78. import {
  79. reqDeptCodes
  80. } from "../../request/api.js";
  81. export default {
  82. name: "seiminModel",
  83. data() {
  84. return {
  85. // 配置项
  86. opts: {},
  87. // 动态二维码定时器
  88. timer: null,
  89. // 动态二维码qrcode
  90. nurseCodeImg: "",
  91. // 动态二维码刷新间隔时长
  92. refreshQRCodeTime: 30,
  93. // 护士科室切换提示自动关闭设置(时长,单位秒)
  94. closeTime: 0,
  95. // 护士科室切换提示自动关闭设置(定时器,单位秒)
  96. timerCloseTime: null,
  97. // 加急原因
  98. urgentTextArea: '',
  99. // 加急原因的placeholder样式
  100. placeholderStyle: 'color:#999;padding:18rpx;',
  101. // 星级
  102. stars: [],
  103. // 评价内容
  104. evaluateTextArea: '',
  105. };
  106. },
  107. onUnload() {
  108. if (this.timerCloseTime) {
  109. clearInterval(this.timerCloseTime);
  110. this.timerCloseTime = null;
  111. }
  112. if (this.timer) {
  113. clearInterval(this.timer);
  114. this.timer = null;
  115. }
  116. },
  117. computed: {
  118. ...mapState('other', ["nurseDeptSwitchTip"]),
  119. ...mapState("login", ["loginInfo"]),
  120. },
  121. methods: {
  122. // 显示弹窗
  123. show(args = {}) {
  124. // 默认配置项
  125. let defaultOptions = {
  126. skin: "default", //弹窗风格(default|toast|qrcode|)
  127. isVisible: false, //是否显示弹窗
  128. title: "提示", //标题
  129. icon: "success", //图标(success|error|warn|)
  130. content: "", //内容
  131. btns: [{
  132. name: "取消",
  133. textColor: "#666",
  134. flex: 1,
  135. click: this.close,
  136. },
  137. {
  138. name: "确认",
  139. textColor: "#49B856",
  140. flex: 1,
  141. click: this.close,
  142. },
  143. ], //弹窗按钮
  144. };
  145. // 根据弹窗风格修改默认配置项
  146. switch (args.skin) {
  147. case "toast":
  148. defaultOptions.btns = [{
  149. name: "知道了",
  150. textColor: "#49b856",
  151. flex: 1,
  152. click: this.close,
  153. }, ];
  154. break;
  155. }
  156. // 按钮合并参数
  157. if (Array.isArray(args.btns)) {
  158. let btns = [];
  159. args.btns.forEach((v, i) => {
  160. btns.push(Object.assign({}, defaultOptions.btns[i], v));
  161. });
  162. args.btns = btns;
  163. }
  164. // 合并配置
  165. this.opts = Object.assign({}, defaultOptions, args, {
  166. isVisible: true,
  167. });
  168. if (this.opts.skin === "qrcode") {
  169. // 如果是动态二维码,则需要发起请求
  170. this.showNurseCode();
  171. } else if (this.opts.skin === 'evaluate') {
  172. // 如果是评价弹窗,则默认选中五个笑脸
  173. this.stars = ['pda-haoping', 'pda-haoping', 'pda-haoping', 'pda-haoping', 'pda-haoping'];
  174. }
  175. },
  176. // 关闭弹窗
  177. close() {
  178. this.opts.isVisible = false;
  179. if (this.opts.skin === "qrcode") {
  180. clearInterval(this.timer);
  181. this.timer = null;
  182. }
  183. },
  184. // 科室动态二维码方法
  185. showNurseCode() {
  186. let deptId = this.loginInfo.user && this.loginInfo.user.dept.id;
  187. reqDeptCodes([deptId]).then((res) => {
  188. if (res.status == 200) {
  189. res["data"] = res["data"] || [];
  190. res["data"][0] = res["data"][0] || {};
  191. this.nurseCodeImg = res["data"][0].base64 || "";
  192. this.refreshQRCodeTime = res["data"][0].refreshQRCodeTime || 30;
  193. clearInterval(this.timer);
  194. this.timer = setInterval(() => {
  195. this.refreshQRCodeTime = Math.max(--this.refreshQRCodeTime, 0);
  196. if (this.refreshQRCodeTime === 0) {
  197. clearInterval(this.timer);
  198. this.showNurseCode();
  199. }
  200. }, 1000);
  201. } else {
  202. clearInterval(this.timer);
  203. uni.showToast({
  204. icon: "none",
  205. title: "获取数据失败",
  206. });
  207. }
  208. });
  209. },
  210. // 切换科室弹窗
  211. showChangeDept(options = {}) {
  212. this.show(options);
  213. // (1) 当用户设置为正数时,用户必须查看此窗体指定秒数。
  214. // (2) 当用户设置为负数时,用户可点击知道了也可倒计时自动关闭。
  215. // (3) 如果用户填写0则为无自动关闭和强制查看时间。
  216. if (this.nurseDeptSwitchTip === 0) {
  217. return;
  218. }
  219. this.closeTime = Math.abs(this.nurseDeptSwitchTip);
  220. clearInterval(this.timerCloseTime);
  221. this.timerCloseTime = setInterval(() => {
  222. this.closeTime = Math.max(--this.closeTime, 0);
  223. if (this.closeTime === 0) {
  224. if (this.nurseDeptSwitchTip < 0) {
  225. this.close();
  226. }
  227. clearInterval(this.timerCloseTime);
  228. }
  229. }, 1000);
  230. },
  231. // 选择星级
  232. clickStar(index) {
  233. for (let i = 0; i < this.stars.length; i++) {
  234. this.$set(this.stars, i, i > index ? 'pda-haoping1' : 'pda-haoping');
  235. }
  236. },
  237. },
  238. };
  239. </script>
  240. <style lang="scss" scoped>
  241. .seiminModel {
  242. font-size: 36rpx;
  243. color: #000;
  244. line-height: 50rpx;
  245. text-align: center;
  246. &.seiminModel_mask {
  247. background-color: rgba(0, 0, 0, 0.5);
  248. position: fixed;
  249. top: 0;
  250. right: 0;
  251. bottom: 0;
  252. left: 0;
  253. margin: auto;
  254. z-index: 999;
  255. @include flex(center, center);
  256. .seiminModel_container {
  257. width: 560rpx;
  258. border-radius: 8rpx;
  259. background-color: #fff;
  260. display: flex;
  261. flex-direction: column;
  262. align-content: center;
  263. .seiminModel_status {
  264. margin-bottom: 35rpx;
  265. .pda {
  266. font-size: 138rpx;
  267. }
  268. }
  269. .seiminModel_header {
  270. height: 100rpx;
  271. position: relative;
  272. @include flex(center, center);
  273. &.noTitle {
  274. height: 40rpx;
  275. }
  276. .seiminModel_countDown {
  277. position: absolute;
  278. right: 26rpx;
  279. font-size: 28rpx;
  280. color: $defaultColor;
  281. }
  282. }
  283. .seiminModel_content {
  284. flex: 1;
  285. background-color: #f9fafb;
  286. margin: 0 36rpx 25rpx;
  287. color: #333;
  288. padding: 76rpx 24rpx;
  289. @include border;
  290. @include numbersAndLettersNoWrap;
  291. // 动态二维码
  292. &.qrcode {
  293. padding: 24rpx;
  294. font-size: 32rpx;
  295. color: #999;
  296. .qrcode_img {
  297. height: 464rpx;
  298. }
  299. .qrcode_operate {
  300. @include flex(space-between, center);
  301. .refreshQRCode {
  302. color: $defaultColor;
  303. }
  304. }
  305. }
  306. // 加急
  307. &.urgent {
  308. padding: 0;
  309. .urgent_txt {
  310. font-size: 28rpx;
  311. color: #666;
  312. line-height: 40rpx;
  313. padding: 24rpx;
  314. @include border(bottom);
  315. }
  316. .urgent_textarea {
  317. width: 440rpx;
  318. margin: 24rpx;
  319. min-height: 212rpx;
  320. background: #FFFFFF;
  321. border-radius: 2rpx;
  322. text-align: left;
  323. @include border;
  324. ::v-deep .uni-textarea-textarea {
  325. padding: 18rpx;
  326. }
  327. }
  328. }
  329. // 评价
  330. &.evaluate {
  331. padding: 0;
  332. .evaluate_txt {
  333. font-size: 28rpx;
  334. color: #666;
  335. line-height: 40rpx;
  336. padding: 24rpx 0;
  337. @include border(bottom);
  338. }
  339. .evaluate_list {
  340. padding: 20rpx 34rpx;
  341. .evaluate_item {
  342. font-size: 34rpx;
  343. color: #666;
  344. margin-top: 10rpx;
  345. @include flex;
  346. .evaluate_label {}
  347. .evaluate_icons {
  348. flex: 1;
  349. @include flex;
  350. .pda {
  351. font-size: 40rpx;
  352. margin-right: 10rpx;
  353. &.pda-haoping {
  354. color: $defaultColor;
  355. }
  356. }
  357. }
  358. .evaluate_textarea {
  359. flex: 1;
  360. min-height: 212rpx;
  361. background: #FFFFFF;
  362. border-radius: 2rpx;
  363. text-align: left;
  364. @include border;
  365. ::v-deep .uni-textarea-textarea {
  366. padding: 18rpx;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. .seiminModel_footer {
  374. height: 100rpx;
  375. color: #666;
  376. @include border(top);
  377. @include flex(center, center);
  378. .seiminModel_footer__btn {
  379. height: 100%;
  380. position: relative;
  381. @include flex(center, center);
  382. &::after {
  383. content: "";
  384. height: 86rpx;
  385. position: absolute;
  386. width: 1px;
  387. bottom: 0;
  388. right: 0;
  389. background-color: #dde1e5;
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. </style>