commonText.vue 4.5 KB

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