post.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="container">
  3. <view class="safe-area-inset-bottom">
  4. <rider-curd
  5. v-model="form"
  6. :option="option"
  7. :data="list"
  8. :rules="rules"
  9. :readonly.sync="readonly"
  10. @search="onSearch"
  11. @action-click="onActionClick"
  12. @submit="onSubmit"
  13. @del="onRemove"
  14. ref="crud"
  15. >
  16. <template #form>
  17. <u-form-item label="岗位类型" prop="category" :label-width="option.labelWidth || 160" required>
  18. <u-input
  19. v-model="formLabel.category"
  20. placeholder="角色名称"
  21. type="select"
  22. @click="
  23. () => {
  24. if (!readonly) categoryShow = true
  25. }
  26. "
  27. />
  28. </u-form-item>
  29. <u-form-item label="岗位编号" prop="postCode" :label-width="option.labelWidth || 160" required>
  30. <u-input v-model="form.postCode" :disabled="readonly" placeholder="岗位编号" />
  31. </u-form-item>
  32. <u-form-item label="岗位名称" prop="postName" :label-width="option.labelWidth || 160" required>
  33. <u-input v-model="form.postName" :disabled="readonly" placeholder="岗位名称" />
  34. </u-form-item>
  35. <u-form-item label="岗位排序" prop="sort" :label-width="option.labelWidth || 160" required>
  36. <u-input v-model="form.sort" :disabled="readonly" type="number" placeholder="岗位排序" />
  37. </u-form-item>
  38. <u-form-item label="岗位描述" prop="remark" :label-width="option.labelWidth || 160">
  39. <u-input
  40. v-model="form.remark"
  41. :disabled="readonly"
  42. type="textarea"
  43. :maxlength="-1"
  44. :height="35"
  45. placeholder="岗位描述"
  46. />
  47. </u-form-item>
  48. </template>
  49. <template #loadmore>
  50. <u-loadmore :status="loadStatus" @loadmore="getList()" />
  51. </template>
  52. </rider-curd>
  53. </view>
  54. <u-select
  55. v-model="categoryShow"
  56. :list="categoryList"
  57. value-name="dictKey"
  58. label-name="dictValue"
  59. @confirm="onConfirm"
  60. safe-area-inset-bottom
  61. ></u-select>
  62. </view>
  63. </template>
  64. <script>
  65. import riderCurd from '@/components/rider-crud/index'
  66. import { getList, add, update, remove } from '@/api/system/post.js'
  67. import { tenantSelect } from '@/api/system/tenant.js'
  68. import { dictionary } from '@/api/system/dict.js'
  69. import { getDicLabel } from '@/components/rider-crud/util/tool.js'
  70. export default {
  71. components: { riderCurd },
  72. data() {
  73. return {
  74. checkedSwitch: false,
  75. form: {},
  76. formLabel: {},
  77. list: [],
  78. params: {
  79. current: 1,
  80. size: 10
  81. },
  82. readonly: false, // 查看时控制表单只读
  83. loadStatus: 'loadmore', // 列表加载状态
  84. option: {
  85. navTitle: '岗位管理', //标题
  86. manageBtn: true, // 右上角管理按钮,默认不显示
  87. searchShow: true, //是否显示搜索,默认不显示
  88. labelWidth: 160, //form表单lable宽度, 默认160,单位rpx
  89. column: [
  90. {
  91. label: '岗位名称',
  92. prop: 'postName'
  93. },
  94. {
  95. label: '岗位编号',
  96. prop: 'postCode'
  97. },
  98. {
  99. label: '所属租户',
  100. prop: 'tenantName'
  101. },
  102. {
  103. label: '岗位类型',
  104. prop: 'categoryName'
  105. },
  106. {
  107. label: '岗位排序',
  108. prop: 'sort'
  109. },
  110. {
  111. label: '岗位描述',
  112. prop: 'remark'
  113. }
  114. ],
  115. actions: [
  116. {
  117. name: '编辑', // 操作名称
  118. icon: 'edit-pen', //操作图标,有图标文字不显示
  119. color: '#333', // 字体颜色
  120. fontsize: 30, //字体大小,单位rpx
  121. width: 40, // 宽度,单位px
  122. background: '#fff' // 菜单按钮背景色
  123. },
  124. {
  125. name: '删除',
  126. icon: 'trash',
  127. color: '#333',
  128. fontsize: 30,
  129. width: 40,
  130. background: '#fff'
  131. }
  132. ]
  133. },
  134. rules: {
  135. category: [{ required: true, message: '请选择岗位类型', trigger: 'change', type: 'number' }],
  136. postCode: [{ required: true, message: '请输入岗位编号', trigger: 'blur' }],
  137. postName: [{ required: true, message: '请输入岗位名称', trigger: 'blur' }],
  138. sort: [{ required: true, message: '请输入岗位排序', trigger: 'blur', type: 'number' }]
  139. },
  140. categoryShow: false,
  141. categoryList: [],
  142. category: '',
  143. tenantList: []
  144. }
  145. },
  146. onReady() {
  147. this.getTenant().then(() => {
  148. this.getList(true)
  149. })
  150. this.getCategoryList()
  151. },
  152. onPullDownRefresh() {
  153. this.getList(true)
  154. },
  155. onReachBottom() {
  156. if (this.loadStatus == 'nomore') return
  157. this.getList()
  158. },
  159. methods: {
  160. // 获取列表
  161. getList(override = false) {
  162. if (override) {
  163. this.params.current = 1
  164. }
  165. const { size } = this.params
  166. getList(this.params)
  167. .then(res => {
  168. const { records, current } = res.data
  169. if (records.length < size) this.loadStatus = 'nomore'
  170. else this.loadStatus = 'loadmore'
  171. if (override) {
  172. this.list = records
  173. } else {
  174. this.list = this.list.concat(records)
  175. }
  176. if (this.list && this.list.length > 0) {
  177. this.list.map(e => {
  178. e.tenantName = getDicLabel(e.tenantId, this.tenantList, { label: 'tenantName', value: 'tenantId' })
  179. })
  180. }
  181. this.params.current++
  182. uni.stopPullDownRefresh()
  183. })
  184. .catch(err => {
  185. uni.stopPullDownRefresh()
  186. })
  187. },
  188. // 获取类型
  189. getCategoryList() {
  190. dictionary({ code: 'post_category' }).then(res => {
  191. this.categoryList = res.data
  192. })
  193. },
  194. // 租户类型
  195. getTenant() {
  196. return new Promise(resolve => {
  197. tenantSelect().then(res => {
  198. this.tenantList = res.data
  199. resolve()
  200. })
  201. })
  202. },
  203. // 类型回调
  204. onConfirm(e) {
  205. this.$set(this.form, 'category', Number(e[0].value))
  206. this.$set(this.formLabel, 'category', e[0].label)
  207. },
  208. // 搜索 (自行配置搜索内容)
  209. onSearch(val) {
  210. this.params = {
  211. current: 1,
  212. size: 10,
  213. postName: val
  214. }
  215. this.getList(true)
  216. },
  217. // 左滑按钮点击
  218. onActionClick({ index, data, action, done }) {
  219. const { name } = action
  220. console.log(name, index)
  221. switch (name) {
  222. case '新增':
  223. done()
  224. break
  225. case '删除':
  226. this.onRemove(data.id)
  227. break
  228. case '查看':
  229. this.readonly = true
  230. case '编辑':
  231. this.formLabel.category = getDicLabel(data.category, this.categoryList)
  232. done()
  233. break
  234. }
  235. },
  236. // 删除
  237. onRemove(id) {
  238. uni.showModal({
  239. title: '确定要删除吗?',
  240. success: action => {
  241. if (action.confirm) {
  242. remove(id).then(() => {
  243. uni.showToast({
  244. title: '删除成功',
  245. icon: 'none'
  246. })
  247. setTimeout(() => {
  248. this.$refs['crud'].allCheckHide(false)
  249. }, 100)
  250. // #ifdef APP
  251. this.getList(true)
  252. // #endif
  253. // #ifndef APP
  254. uni.startPullDownRefresh({})
  255. // #endif
  256. })
  257. }
  258. }
  259. })
  260. },
  261. // 表单提交
  262. onSubmit(form, action, unloading, done) {
  263. if (action == '新增') {
  264. add(form)
  265. .then(res => {
  266. uni.showToast({
  267. title: '新增成功',
  268. icon: 'none'
  269. })
  270. this.formLabel = {}
  271. done()
  272. uni.startPullDownRefresh({})
  273. })
  274. .catch(() => {
  275. unloading()
  276. })
  277. } else if (action == '编辑') {
  278. update(form)
  279. .then(res => {
  280. uni.showToast({
  281. title: '编辑成功',
  282. icon: 'none'
  283. })
  284. this.formLabel = {}
  285. done()
  286. uni.startPullDownRefresh({})
  287. })
  288. .catch(() => {
  289. unloading()
  290. })
  291. }
  292. }
  293. }
  294. }
  295. </script>
  296. <style>
  297. page {
  298. background: #f6f6f6;
  299. }
  300. </style>
  301. <style lang="scss" scoped>
  302. .nav-right {
  303. color: #fff;
  304. font-size: 28rpx;
  305. font-weight: normal;
  306. padding-right: 24rpx;
  307. }
  308. </style>