musicSheetOwnerDialog.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import {NButton, NDataTable, NFormItem, NInput, NSelect, NSpace, useMessage} from 'naive-ui'
  2. import {defineComponent, onMounted, PropType, reactive, ref} from 'vue'
  3. import {musicSheetApplicationOwnerList} from '../../api'
  4. import SaveForm from "@components/save-form";
  5. import Pagination from "@components/pagination";
  6. import deepClone from "@/utils/deep.clone";
  7. export default defineComponent({
  8. name: 'musicSheetOwnerDialog',
  9. props: {
  10. musicSheetExtend: {
  11. type: Object as PropType<any>,
  12. default: () => {
  13. }
  14. },
  15. sourceType: {
  16. type: String,
  17. required: true
  18. },
  19. appData: {
  20. type: Array,
  21. required: true,
  22. default: []
  23. }
  24. },
  25. emits: ['close', 'getList', "choseMusicSheetOwnerData"],
  26. setup(props, {slots, attrs, emit}) {
  27. const state = reactive({
  28. loading: false,
  29. pagination: {
  30. page: 1,
  31. rows: 10,
  32. pageTotal: 0
  33. },
  34. searchForm: {
  35. applicationId: null,
  36. orgName: null,
  37. name: null,
  38. sourceType: null as any,
  39. },
  40. dataList: [],
  41. appData: [] as any, // 适用项目行数据
  42. })
  43. const message = useMessage()
  44. const saveForm = ref()
  45. const onSubmit = () => {
  46. state.pagination.page = 1
  47. getList()
  48. }
  49. const onSearch = () => {
  50. saveForm.value?.submit()
  51. }
  52. const getList = async () => {
  53. try {
  54. const applicationId = state.searchForm.applicationId;
  55. if (!applicationId) {
  56. message.warning("获取应用列表失败");
  57. }
  58. state.loading = true
  59. state.searchForm.sourceType = props.sourceType
  60. const {data} = await musicSheetApplicationOwnerList({...state.pagination, ...state.searchForm})
  61. state.pagination.pageTotal = Number(data.total)
  62. state.dataList = data.rows || []
  63. } catch {
  64. }
  65. state.loading = false
  66. }
  67. onMounted(async () => {
  68. // 初始化应用
  69. {
  70. // const appKeys = Object.keys(appKey);
  71. //
  72. // const {data} = await sysApplicationPage({page: 1, rows: 999, parentId: 0})
  73. // const tempList = data.rows || []
  74. // const filter = tempList.filter((next: any) => {
  75. // return appKeys.includes(next.appKey)
  76. // });
  77. // filter.forEach((item: any) => {
  78. // item.label = item.appName
  79. // item.value = item.id
  80. // })
  81. state.appData = deepClone(props.appData)
  82. if (state.appData.length == 0) {
  83. message.warning("获取应用列表失败")
  84. return
  85. }
  86. if (props.musicSheetExtend && props.musicSheetExtend.applicationId) {
  87. state.searchForm.applicationId = props.musicSheetExtend.applicationId
  88. } else {
  89. state.searchForm.applicationId = state.appData[0].value
  90. }
  91. }
  92. getList()
  93. })
  94. const columns = (): any => {
  95. if (state.searchForm.sourceType === 'ORG') {
  96. return [
  97. {
  98. title: '机构名称',
  99. key: 'orgName'
  100. },
  101. {
  102. title: '操作',
  103. key: 'operation',
  104. fixed: 'right',
  105. render(row: any) {
  106. return (
  107. <NSpace>
  108. <NButton
  109. type="primary"
  110. size="small"
  111. text
  112. onClick={() => {
  113. const choseMusicSheetOwnerData = {
  114. ...row,
  115. applicationId: state.searchForm.applicationId
  116. }
  117. emit("choseMusicSheetOwnerData", choseMusicSheetOwnerData)
  118. emit('close')
  119. }}
  120. >
  121. 选择
  122. </NButton>
  123. </NSpace>
  124. )
  125. }
  126. }
  127. ]
  128. } else {
  129. return [
  130. {
  131. title: '人员名称',
  132. key: 'userName'
  133. },
  134. {
  135. title: '手机号',
  136. key: 'phone'
  137. },
  138. {
  139. title: '操作',
  140. key: 'operation',
  141. fixed: 'right',
  142. render(row: any) {
  143. return (
  144. <NSpace>
  145. <NButton
  146. type="primary"
  147. size="small"
  148. text
  149. onClick={() => {
  150. const choseMusicSheetOwnerData = {
  151. ...row,
  152. applicationId: state.searchForm.applicationId
  153. }
  154. emit("choseMusicSheetOwnerData", choseMusicSheetOwnerData)
  155. emit('close')
  156. }}
  157. >
  158. 选择
  159. </NButton>
  160. </NSpace>
  161. )
  162. }
  163. }
  164. ]
  165. }
  166. }
  167. const orgColumns = (): any => {
  168. return [
  169. {
  170. title: '机构名称',
  171. key: 'organizationRole'
  172. },
  173. {
  174. title: '操作',
  175. key: 'operation',
  176. fixed: 'right',
  177. render(row: any) {
  178. return (
  179. <NSpace>
  180. <NButton
  181. type="primary"
  182. size="small"
  183. text
  184. onClick={() => {
  185. const choseMusicSheetOwnerData = {
  186. ...row,
  187. applicationId: state.searchForm.applicationId
  188. }
  189. emit("choseMusicSheetOwnerData", choseMusicSheetOwnerData)
  190. emit('close')
  191. }}
  192. >
  193. 选择
  194. </NButton>
  195. </NSpace>
  196. )
  197. }
  198. }
  199. ]
  200. }
  201. return () => (
  202. <div class="system-menu-container">
  203. <SaveForm
  204. ref={saveForm}
  205. model={state.searchForm}
  206. onSubmit={onSubmit}
  207. // saveKey="musicSheetOwnerDialog"
  208. onSetModel={(val: any) => (state.searchForm = val)}
  209. >
  210. <NFormItem label="应用" path="applicationId" size="small" style={'width:250px'}>
  211. <NSelect
  212. placeholder="请选择适用项目"
  213. v-model:value={state.searchForm.applicationId}
  214. options={state.appData}
  215. />
  216. </NFormItem>
  217. {state.searchForm.sourceType === 'PERSON' &&
  218. (<>
  219. <NFormItem label="所属人" path="name" size="small" style={'width:250px'}>
  220. <NInput
  221. placeholder="请输入所属人/手机号"
  222. v-model:value={state.searchForm.name}
  223. clearable
  224. />
  225. </NFormItem>
  226. </>)}
  227. {state.searchForm.sourceType === 'ORG' &&
  228. (<>
  229. <NFormItem label="机构名称" path="orgName" size="small" style={'width:250px'}>
  230. <NInput
  231. placeholder="请输入机构名称"
  232. v-model:value={state.searchForm.orgName}
  233. clearable
  234. />
  235. </NFormItem>
  236. </>)}
  237. <NFormItem size="small">
  238. <NSpace>
  239. <NButton type="primary" onClick={onSearch}>
  240. 搜索
  241. </NButton>
  242. </NSpace>
  243. </NFormItem>
  244. </SaveForm>
  245. <div class={['section-container']}>
  246. {props.sourceType === 'PERSON' &&
  247. (<NDataTable
  248. loading={state.loading}
  249. columns={columns()}
  250. data={state.dataList}
  251. ></NDataTable>)}
  252. {props.sourceType === 'ORG' &&
  253. (<NDataTable
  254. loading={state.loading}
  255. columns={orgColumns()}
  256. data={state.dataList}
  257. ></NDataTable>)}
  258. <Pagination
  259. v-model:page={state.pagination.page}
  260. v-model:pageSize={state.pagination.rows}
  261. v-model:pageTotal={state.pagination.pageTotal}
  262. onList={getList}
  263. sync
  264. // saveKey="musicSheetOwnerDialog"
  265. pageSlot={5}
  266. ></Pagination>
  267. </div>
  268. </div>
  269. )
  270. }
  271. })