commonText.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="common_v">
  3. <mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption"
  4. :bottombar="false" top="120">
  5. <SwipeItem :list="commonWordsList" :buttons="actionData" @action="bindClick" ref="swipeItem" :marginB="20">
  6. <template v-slot="{ item }">
  7. <view class="action-item">
  8. {{item.commonWordsText}}
  9. </view>
  10. </template>
  11. </SwipeItem>
  12. </mescroll-uni>
  13. <view class="flowBefore-actions">
  14. <u-button class="buttom-btn" type="primary" @click='editCommonWord'>添加常用语</u-button>
  15. </view>
  16. </view>
  17. <uni-popup ref="inputDialog" type="dialog">
  18. <uni-popup-dialog ref="inputClose" @confirm="confirm" mode="input" class="popup-dialog"
  19. borderRadius="20px 20px 20px 20px" beforeClose @close="close" title="审批常用语">
  20. <!-- #ifndef MP-WEIXIN -->
  21. <u-input v-model="commonWordsText" type="textarea" placeholder="请输入内容" :auto-height="false"
  22. maxlength="99999" height="150" />
  23. <!-- #endif -->
  24. <!-- #ifdef MP-WEIXIN -->
  25. <textarea v-model="commonWordsText" :maxlength="99999" placeholder="请输入内容"
  26. style="padding: 20rpx 0; "></textarea>
  27. <!-- #endif -->
  28. </uni-popup-dialog>
  29. </uni-popup>
  30. </template>
  31. <script>
  32. import {
  33. commonWords,
  34. Create,
  35. Update,
  36. Delete
  37. } from "@/api/commonWords.js";
  38. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  39. import resources from '@/libs/resources.js'
  40. import SwipeItem from "@/components/SwipeItem/index"
  41. export default {
  42. mixins: [MescrollMixin],
  43. components: {
  44. SwipeItem
  45. },
  46. props: {
  47. showCommonWords: {
  48. type: Boolean,
  49. default: false
  50. }
  51. },
  52. data() {
  53. return {
  54. downOption: {
  55. use: true,
  56. auto: true
  57. },
  58. upOption: {
  59. page: {
  60. num: 0,
  61. size: 30,
  62. time: null
  63. },
  64. empty: {
  65. use: true,
  66. icon: resources.message.nodata,
  67. tip: this.$t('common.noData'),
  68. fixed: true,
  69. top: "360rpx"
  70. },
  71. textNoMore: this.$t('app.apply.noMoreData')
  72. },
  73. actionData: [{
  74. style: {
  75. backgroundColor: '#1890ff'
  76. },
  77. value: 'edit',
  78. text: '编辑'
  79. },
  80. {
  81. style: {
  82. backgroundColor: '#F56C6C'
  83. },
  84. value: 'delete',
  85. text: '删除'
  86. }
  87. ],
  88. commonWordsText: '',
  89. commonWordsData: {},
  90. commonWordsList: [],
  91. showAdd: false
  92. }
  93. },
  94. methods: {
  95. upCallback(page) {
  96. const query = {
  97. currentPage: page.num,
  98. pageSize: page.size,
  99. commonWordsType: 1
  100. }
  101. commonWords(query).then(res => {
  102. const curPageData = res.data.list || [] // 当前页数据
  103. if (page.num == 1) this.commonWordsList = []; // 第一页需手动制空列表
  104. this.mescroll.endSuccess(res.data.list.length);
  105. this.commonWordsList = this.commonWordsList.concat(curPageData); //追加新数据
  106. }).catch(() => {
  107. this.mescroll.endErr();
  108. })
  109. },
  110. bindClick(item) {
  111. if (item.btn.value == 'edit') this.editCommonWord(item.item)
  112. if (item.btn.value == 'delete') this.delCommonWord(item.item)
  113. },
  114. editCommonWord(item) {
  115. this.$refs.inputDialog.open()
  116. let data = {
  117. commonWordsText: "",
  118. enabledMark: 1,
  119. id: 0,
  120. sortCode: 0,
  121. systemIds: [],
  122. systemNames: [],
  123. };
  124. if (item.id) {
  125. this.commonWordsText = item.commonWordsText;
  126. this.commonWordsData = {
  127. ...item,
  128. systemIds: [],
  129. systemNames: []
  130. };
  131. } else {
  132. this.commonWordsText = "";
  133. this.commonWordsData = data;
  134. }
  135. },
  136. delCommonWord(item) {
  137. Delete(item.id).then(res => {
  138. this.$u.toast(res.msg)
  139. this.mescroll.resetUpScroll()
  140. })
  141. },
  142. close() {
  143. this.$refs.inputDialog.close()
  144. },
  145. confirm() {
  146. this.commonWordsData.commonWordsText = this.commonWordsText;
  147. this.commonWordsData.commonWordsType = 1
  148. if (!this.commonWordsText) return this.$u.toast(`审批常用语不能为空`);
  149. let funs = this.commonWordsData.id === 0 ? Create : Update;
  150. funs(this.commonWordsData).then((res) => {
  151. this.close()
  152. this.commonWordsText = "";
  153. uni.showToast({
  154. title: res.msg,
  155. icon: "none",
  156. complete: () => {
  157. this.mescroll.resetUpScroll()
  158. },
  159. });
  160. }).catch(() => {
  161. this.close()
  162. this.mescroll.resetUpScroll()
  163. });
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss">
  169. .action-item {
  170. width: 100%;
  171. min-height: 3.6rem;
  172. background-color: #fff;
  173. display: flex;
  174. align-items: center;
  175. border-bottom: 1rpx solid #eee;
  176. padding: 10rpx 20rpx;
  177. word-break: break-all;
  178. }
  179. </style>