musicSheetOwnerDialog.tsx 8.5 KB

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