SetEvaModal.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <div>
  3. <a-modal
  4. class="modalBox"
  5. :footer="null"
  6. title="选择考评项"
  7. v-model="isshow"
  8. @cancle="cancel"
  9. :width="'80%'">
  10. <a-row :gutter="24">
  11. <a-col class="title" :span="20">
  12. <!-- 考评方案名称 -->
  13. <span>考评方案名称: {{ itemName }}</span>
  14. </a-col>
  15. </a-row>
  16. <a-row :gutter="24">
  17. <a-form :form="form" ref="form" @submit="handleSubmit">
  18. <a-card class="card-content">
  19. <a-col :span="15">
  20. <p>已选考评项目:</p>
  21. <!-- 已选考评项列表 -->
  22. <a-table
  23. ref="table"
  24. size="default"
  25. :pagination="false"
  26. :rowKey="(record) => record.id"
  27. :columns="columns"
  28. :dataSource="checkedList"
  29. bordered>
  30. <!-- 操作 -->
  31. <template slot="action" slot-scope="text, record, index">
  32. <a-button
  33. id="setEvaModal-moveUp"
  34. type="primary"
  35. ghost
  36. size="small"
  37. class="actionBtn"
  38. @click="moveUp(index)"
  39. v-if="index>0"
  40. icon="arrow-up">上移</a-button>
  41. <a-button
  42. id="setEvaModal-moveDown"
  43. type="primary"
  44. ghost
  45. size="small"
  46. class="actionBtn"
  47. @click="moveDown(index)"
  48. v-if="index < checkedList.length-1"
  49. icon="arrow-down">下移</a-button>
  50. <a-button
  51. id="setEvaModal-moveTop"
  52. type="danger"
  53. ghost
  54. size="small"
  55. class="actionBtn"
  56. @click="moveTop(index)"
  57. v-if="index>0"
  58. icon="up">置顶</a-button>
  59. <a-button
  60. id="setEvaModal-moveBottom"
  61. type="danger"
  62. ghost
  63. size="small"
  64. class="actionBtn"
  65. @click="moveBottom(index)"
  66. v-if="index < checkedList.length-1"
  67. icon="down">置底</a-button>
  68. </template>
  69. </a-table>
  70. </a-col>
  71. <a-col span="1" class="divider">
  72. </a-col>
  73. <a-col span="8">
  74. <a-row>
  75. <p>请选择需要的考评项目:</p>
  76. </a-row>
  77. <s-table
  78. ref="tableItem"
  79. size="default"
  80. :showPagination="false"
  81. :row-selection="rowSelection"
  82. :rowKey="(record) => record.id"
  83. :columns="itemColumns"
  84. :data="loadItemData"
  85. bordered>
  86. <!-- 启用禁用 -->
  87. <template slot="enable" slot-scope="text, row">
  88. <span :class="[text==1 ? 'green' : 'grey']">{{ text==1 ? '启用' : '禁用' }}</span>
  89. </template>
  90. </s-table>
  91. </a-col>
  92. </a-card>
  93. <a-form-item class="footer" :wrapper-col="{ span: 24, offset: 12 }">
  94. <a-button :loading="loading" id="setEvaModal-submit" type="primary" @click="handleSubmit()">
  95. 保存
  96. </a-button>
  97. <a-button id="setEvaModal-cancel" :style="{ marginLeft: '8px' }" @click="handleCancel()">
  98. 取消
  99. </a-button>
  100. </a-form-item>
  101. </a-form>
  102. </a-row>
  103. </a-modal>
  104. </div>
  105. </template>
  106. <script>
  107. import {
  108. STable,
  109. VSelect
  110. } from '@/components'
  111. import {
  112. planItemQuery,
  113. planItemSave
  114. } from '@/api/evaluationPlan.js'
  115. import { getItemList } from '@/api/evaluationItem.js'
  116. export default {
  117. name: 'AddEvaModal',
  118. components: {
  119. STable,
  120. VSelect
  121. },
  122. props: {
  123. visible: {
  124. type: Boolean,
  125. default: false
  126. },
  127. // 要编辑的方案id
  128. itemId: {
  129. type: [String, Number],
  130. default: ''
  131. },
  132. // 要编辑的方案名字
  133. itemName: {
  134. type: String,
  135. default: ''
  136. }
  137. },
  138. watch: {
  139. visible (newValue, oldValue) {
  140. this.isshow = newValue
  141. },
  142. isshow (newValue, oldValue) {
  143. if (newValue) {
  144. // 获取已选列表数据
  145. this.getCheckedList()
  146. } else {
  147. this.cancel()
  148. }
  149. }
  150. },
  151. data () {
  152. return {
  153. isshow: this.visible, // 弹框显示隐藏
  154. form: this.$form.createForm(this, {
  155. name: 'SetEvaModal'
  156. }),
  157. loading: false, // 确定按钮loading
  158. // 已选考评项数据
  159. checkedList: [], // 已选考评项列表
  160. // 表头
  161. columns: [{
  162. title: '序号',
  163. dataIndex: 'no',
  164. width: '40',
  165. align: 'center'
  166. },
  167. {
  168. title: '考评项目名称',
  169. dataIndex: 'assessItemName',
  170. align: 'center'
  171. },
  172. {
  173. title: '操作',
  174. width: '200',
  175. align: 'center',
  176. scopedSlots: {
  177. customRender: 'action'
  178. }
  179. }
  180. ],
  181. // 考评项列表数据
  182. itemColumns: [{
  183. title: '考评项目名称',
  184. dataIndex: 'name',
  185. align: 'center'
  186. },
  187. {
  188. title: '状态',
  189. width: '200',
  190. dataIndex: 'status',
  191. align: 'center',
  192. scopedSlots: {
  193. customRender: 'enable'
  194. }
  195. }
  196. ],
  197. // 加载数据方法 必须为 Promise 对象
  198. loadItemData: parameter => {
  199. return getItemList().then(res => {
  200. if (res.status == 200) {
  201. return res.data
  202. }
  203. })
  204. }
  205. }
  206. },
  207. computed: {
  208. // 已选择的复选框
  209. selectedRowKeys () {
  210. const arr = []
  211. this.checkedList.map(item => {
  212. arr.push(item.assessItemId)
  213. })
  214. return arr
  215. },
  216. // 列表项是否可选择的配置
  217. rowSelection () {
  218. return {
  219. columnTitle: '选择', // 选择框标题
  220. columnWidth: 80, // 选择框宽度
  221. selectedRowKeys: this.selectedRowKeys, // 指定选中项的 key 数组
  222. // 选中项发生变化时的回调 selectedRowKeys:指定选中项的 key 数组 selectedRows:已选中的数组数据
  223. onChange: (selectedRowKeys, selectedRows) => {
  224. const arr = []
  225. let index = 0
  226. // 根据选择项的顺序展示已选列表
  227. selectedRowKeys.map(item => {
  228. index++
  229. const p = selectedRows.find(row => row.id == item)
  230. const row = {}
  231. if (p) {
  232. row.no = index
  233. row.assessItemId = p.id
  234. row.assessItemName = p.name
  235. row.assessSchemeId = this.itemId
  236. arr.push(row)
  237. }
  238. })
  239. this.checkedList = arr
  240. // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
  241. },
  242. getCheckboxProps: record => ({
  243. props: {
  244. disabled: record.status == '0' // 禁用状态不可选
  245. }
  246. })
  247. }
  248. }
  249. },
  250. methods: {
  251. // 获取已选列表数据
  252. getCheckedList () {
  253. planItemQuery({ assessSchemeId: this.itemId }).then(res => {
  254. if (res.status == 200) {
  255. this.checkedList = res.data
  256. this.checkedList.map((item, index) => {
  257. item.no = index + 1
  258. })
  259. } else {
  260. this.checkedList = []
  261. this.$message.warning(res.message)
  262. }
  263. })
  264. },
  265. // 点击弹框x号触发事件
  266. cancel (e) {
  267. this.clear()
  268. this.$emit('close')
  269. },
  270. // 上移
  271. moveUp (index) {
  272. this.moveArr(index, index - 1)
  273. },
  274. // 下移
  275. moveDown (index) {
  276. this.moveArr(index, index + 1)
  277. },
  278. // 置顶
  279. moveTop (index) {
  280. this.goToArr(index, 1)
  281. },
  282. // 置底
  283. moveBottom (index) {
  284. this.goToArr(index, 0)
  285. },
  286. // 置顶和置底
  287. goToArr (index, type) {
  288. const arr = this.checkedList
  289. const row = arr[index]
  290. arr.splice(index, 1)
  291. if (type) {
  292. arr.unshift(row)
  293. } else {
  294. arr.push(row)
  295. }
  296. arr.map((item, index) => {
  297. item.no = index + 1
  298. })
  299. },
  300. // 移动
  301. moveArr (index1, index2) {
  302. const arr = this.checkedList
  303. arr[index1] = arr.splice(index2, 1, arr[index1])[0]
  304. arr.map((item, index) => {
  305. item.no = index + 1
  306. })
  307. this.checkedList = arr
  308. },
  309. // 保存提交
  310. handleSubmit () {
  311. const _this = this
  312. this.form.validateFields((err, values) => {
  313. if (!err) {
  314. if (!this.checkedList.length) {
  315. return this.$message.warning('请先选择考评项目')
  316. }
  317. this.loading = true
  318. planItemSave(this.checkedList).then(res => {
  319. console.log(res, 'res--save')
  320. if (res.status + '' === '200') {
  321. this.$message.success(res.message ? res.message : '保存成功')
  322. this.$emit('refresh')
  323. setTimeout(function () {
  324. _this.cancel()
  325. }, 300)
  326. } else {
  327. // this.$message.warning(res.message)
  328. }
  329. this.loading = false
  330. })
  331. }
  332. })
  333. },
  334. // 取消
  335. handleCancel () {
  336. const _this = this
  337. this.$confirm({
  338. title: '提示',
  339. content: '确定取消吗?',
  340. okText: '确定',
  341. cancelText: '取消',
  342. onOk () {
  343. _this.clear()
  344. _this.cancel()
  345. }
  346. })
  347. },
  348. clear () {
  349. this.form.resetFields()
  350. }
  351. },
  352. beforeCreate () {
  353. this.form = this.$form.createForm(this, {
  354. name: 'SetEvaModal'
  355. })
  356. }
  357. }
  358. </script>
  359. <style scoped>
  360. .title {
  361. font-size: 16px;
  362. color: black;
  363. padding-bottom: 30px;
  364. }
  365. .card-content {
  366. max-height: 650px;
  367. overflow-y: scroll;
  368. }
  369. .actionBtn {
  370. font-size: 12px;
  371. margin: 0 5px;
  372. }
  373. .green {
  374. color: #16b50e;
  375. }
  376. .grey {
  377. color: rgb(153, 153, 153);
  378. }
  379. .footer {
  380. margin-top: 20px;
  381. }
  382. </style>