seiminModel.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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" :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. computed: {
  108. ...mapState('other', ["nurseDeptSwitchTip"]),
  109. ...mapState("login", ["loginInfo"]),
  110. },
  111. methods: {
  112. // 显示弹窗
  113. show(args = {}) {
  114. // 默认配置项
  115. let defaultOptions = {
  116. skin: "default", //弹窗风格(default|toast|qrcode|)
  117. isVisible: false, //是否显示弹窗
  118. title: "提示", //标题
  119. icon: "success", //图标(success|error|warn|)
  120. content: "", //内容
  121. btns: [{
  122. name: "取消",
  123. textColor: "#666",
  124. flex: 1,
  125. click: this.close,
  126. },
  127. {
  128. name: "确认",
  129. textColor: "#49B856",
  130. flex: 1,
  131. click: this.close,
  132. },
  133. ], //弹窗按钮
  134. };
  135. // 根据弹窗风格修改默认配置项
  136. switch (args.skin) {
  137. case "toast":
  138. defaultOptions.btns = [{
  139. name: "知道了",
  140. textColor: "#49b856",
  141. flex: 1,
  142. click: this.close,
  143. }, ];
  144. break;
  145. }
  146. // 按钮合并参数
  147. if (Array.isArray(args.btns)) {
  148. let btns = [];
  149. args.btns.forEach((v, i) => {
  150. btns.push(Object.assign({}, defaultOptions.btns[i], v));
  151. });
  152. args.btns = btns;
  153. }
  154. // 合并配置
  155. this.opts = Object.assign({}, defaultOptions, args, {
  156. isVisible: true,
  157. });
  158. if (this.opts.skin === "qrcode") {
  159. // 如果是动态二维码,则需要发起请求
  160. this.showNurseCode();
  161. } else if (this.opts.skin === 'evaluate') {
  162. // 如果是评价弹窗,则默认选中五个笑脸
  163. this.stars = ['pda-haoping', 'pda-haoping', 'pda-haoping', 'pda-haoping', 'pda-haoping'];
  164. }
  165. },
  166. // 关闭弹窗
  167. close() {
  168. this.opts.isVisible = false;
  169. if (this.opts.skin === "qrcode") {
  170. clearInterval(this.timer);
  171. this.timer = null;
  172. }
  173. },
  174. // 科室动态二维码方法
  175. showNurseCode() {
  176. let deptId = this.loginInfo.user && this.loginInfo.user.dept.id;
  177. reqDeptCodes([deptId]).then((res) => {
  178. if (res.status == 200) {
  179. res["data"] = res["data"] || [];
  180. res["data"][0] = res["data"][0] || {};
  181. this.nurseCodeImg = res["data"][0].base64 || "";
  182. this.refreshQRCodeTime = res["data"][0].refreshQRCodeTime || 30;
  183. clearInterval(this.timer);
  184. this.timer = setInterval(() => {
  185. this.refreshQRCodeTime = Math.max(--this.refreshQRCodeTime, 0);
  186. if (this.refreshQRCodeTime === 0) {
  187. clearInterval(this.timer);
  188. this.showNurseCode();
  189. }
  190. }, 1000);
  191. } else {
  192. clearInterval(this.timer);
  193. uni.showToast({
  194. icon: "none",
  195. title: "获取数据失败",
  196. });
  197. }
  198. });
  199. },
  200. // 切换科室弹窗
  201. showChangeDept(options = {}) {
  202. this.show(options);
  203. // (1) 当用户设置为正数时,用户必须查看此窗体指定秒数。
  204. // (2) 当用户设置为负数时,用户可点击知道了也可倒计时自动关闭。
  205. // (3) 如果用户填写0则为无自动关闭和强制查看时间。
  206. if (this.nurseDeptSwitchTip === 0) {
  207. return;
  208. }
  209. this.closeTime = Math.abs(this.nurseDeptSwitchTip);
  210. clearInterval(this.timerCloseTime);
  211. this.timerCloseTime = setInterval(() => {
  212. this.closeTime = Math.max(--this.closeTime, 0);
  213. if (this.closeTime === 0) {
  214. if (this.nurseDeptSwitchTip < 0) {
  215. this.close();
  216. }
  217. clearInterval(this.timerCloseTime);
  218. }
  219. }, 1000);
  220. },
  221. // 选择星级
  222. clickStar(index) {
  223. for (let i = 0; i < this.stars.length; i++) {
  224. this.$set(this.stars, i, i > index ? 'pda-haoping1' : 'pda-haoping');
  225. }
  226. },
  227. },
  228. };
  229. </script>
  230. <style lang="scss" scoped>
  231. .seiminModel {
  232. font-size: 36rpx;
  233. color: #000;
  234. line-height: 50rpx;
  235. text-align: center;
  236. &.seiminModel_mask {
  237. background-color: rgba(0, 0, 0, 0.5);
  238. position: fixed;
  239. top: 0;
  240. right: 0;
  241. bottom: 0;
  242. left: 0;
  243. margin: auto;
  244. z-index: 999;
  245. @include flex(center, center);
  246. .seiminModel_container {
  247. width: 560rpx;
  248. border-radius: 8rpx;
  249. background-color: #fff;
  250. display: flex;
  251. flex-direction: column;
  252. align-content: center;
  253. .seiminModel_status {
  254. margin-bottom: 35rpx;
  255. .pda {
  256. font-size: 138rpx;
  257. }
  258. }
  259. .seiminModel_header {
  260. height: 100rpx;
  261. position: relative;
  262. @include flex(center, center);
  263. &.noTitle {
  264. height: 40rpx;
  265. }
  266. .seiminModel_countDown {
  267. position: absolute;
  268. right: 26rpx;
  269. font-size: 28rpx;
  270. color: $defaultColor;
  271. }
  272. }
  273. .seiminModel_content {
  274. flex: 1;
  275. background-color: #f9fafb;
  276. margin: 0 36rpx 25rpx;
  277. border: 1px solid #e5e9ed;
  278. color: #333;
  279. padding: 76rpx 24rpx;
  280. @include numbersAndLettersNoWrap;
  281. // 动态二维码
  282. &.qrcode {
  283. padding: 24rpx;
  284. font-size: 32rpx;
  285. color: #999;
  286. .qrcode_operate {
  287. @include flex(space-between, center);
  288. .refreshQRCode {
  289. color: $defaultColor;
  290. }
  291. }
  292. }
  293. // 加急
  294. &.urgent {
  295. padding: 0;
  296. .urgent_txt {
  297. font-size: 28rpx;
  298. color: #666;
  299. line-height: 40rpx;
  300. border-bottom: 2rpx solid #E5E9ED;
  301. padding: 24rpx;
  302. }
  303. .urgent_textarea {
  304. width: 440rpx;
  305. margin: 24rpx;
  306. min-height: 212rpx;
  307. background: #FFFFFF;
  308. border-radius: 2rpx;
  309. border: 2rpx solid #E5E9ED;
  310. text-align: left;
  311. ::v-deep .uni-textarea-textarea {
  312. padding: 18rpx;
  313. }
  314. }
  315. }
  316. // 评价
  317. &.evaluate {
  318. padding: 0;
  319. .evaluate_txt {
  320. font-size: 28rpx;
  321. color: #666;
  322. line-height: 40rpx;
  323. border-bottom: 2rpx solid #E5E9ED;
  324. padding: 24rpx 0;
  325. }
  326. .evaluate_list {
  327. padding: 20rpx 34rpx;
  328. .evaluate_item {
  329. font-size: 34rpx;
  330. color: #666;
  331. margin-top: 10rpx;
  332. @include flex;
  333. .evaluate_label {}
  334. .evaluate_icons {
  335. flex: 1;
  336. @include flex;
  337. .pda {
  338. font-size: 40rpx;
  339. margin-right: 10rpx;
  340. &.pda-haoping {
  341. color: $defaultColor;
  342. }
  343. }
  344. }
  345. .evaluate_textarea {
  346. flex: 1;
  347. min-height: 212rpx;
  348. background: #FFFFFF;
  349. border-radius: 2rpx;
  350. border: 2rpx solid #E5E9ED;
  351. text-align: left;
  352. ::v-deep .uni-textarea-textarea {
  353. padding: 18rpx;
  354. }
  355. }
  356. }
  357. }
  358. }
  359. }
  360. .seiminModel_footer {
  361. border-top: 1px solid #e5e5e5;
  362. height: 100rpx;
  363. color: #666;
  364. @include flex(center, center);
  365. .seiminModel_footer__btn {
  366. height: 100%;
  367. @include flex(center, center);
  368. position: relative;
  369. &::after {
  370. content: "";
  371. height: 86rpx;
  372. position: absolute;
  373. width: 1px;
  374. bottom: 0;
  375. right: 0;
  376. background-color: #dde1e5;
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. </style>