SetEvaModal.vue 9.9 KB

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