1da168ac13944b4371581125737c6cd50ff9a13e.svn-base 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="1200"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @ok="handleOk"
  8. @cancel="handleCancel"
  9. cancelText="关闭">
  10. <a-spin :spinning="confirmLoading">
  11. <a-form :form="form">
  12. <a-card class="card" :bordered="false">
  13. <a-row class="form-row" :gutter="16">
  14. <a-col :lg="8">
  15. <a-form-item label="任务名">
  16. <a-input placeholder="请输入任务名称" v-decorator="[ 'task.name', {rules: [{ required: true, message: '请输入任务名称', whitespace: true}]} ]"/>
  17. </a-form-item>
  18. </a-col>
  19. <a-col :lg="8">
  20. <a-form-item label="任务描述">
  21. <a-input placeholder="请输入任务描述" v-decorator="['task.description', {rules: [{ required: true, message: '请输入任务描述', whitespace: true}]} ]"/>
  22. </a-form-item>
  23. </a-col>
  24. <a-col :lg="8">
  25. <a-form-item label="执行人">
  26. <a-select placeholder="请选择执行人" v-decorator="['task.executor',{rules: [{ required: true, message: '请选择执行人'}]} ]">
  27. <a-select-option value="黄丽丽">黄丽丽</a-select-option>
  28. <a-select-option value="李大刀">李大刀</a-select-option>
  29. </a-select>
  30. </a-form-item>
  31. </a-col>
  32. </a-row>
  33. <a-row class="form-row" :gutter="16">
  34. <a-col :lg="8">
  35. <a-form-item label="责任人">
  36. <a-select placeholder="请选择责任人" v-decorator="['task.manager', {rules: [{ required: true, message: '请选择责任人'}]} ]">
  37. <a-select-option value="王伟">王伟</a-select-option>
  38. <a-select-option value="李红军">李红军</a-select-option>
  39. </a-select>
  40. </a-form-item>
  41. </a-col>
  42. <a-col :lg="8">
  43. <a-form-item label="提醒时间">
  44. <a-time-picker style="width: 100%" v-decorator="['task.time', {rules: [{ required: true, message: '请选择提醒时间'}]} ]"/>
  45. </a-form-item>
  46. </a-col>
  47. <a-col :lg="8">
  48. <a-form-item
  49. label="任务类型">
  50. <a-select placeholder="请选择任务类型" v-decorator="['task.type', {rules: [{ required: true, message: '请选择任务类型'}]} ]">
  51. <a-select-option value="定时执行">定时执行</a-select-option>
  52. <a-select-option value="周期执行">周期执行</a-select-option>
  53. </a-select>
  54. </a-form-item>
  55. </a-col>
  56. </a-row>
  57. </a-card>
  58. <a-tabs defaultActiveKey="1" >
  59. <a-tab-pane tab="Tab 1" key="1">
  60. <a-table :columns="columns" :dataSource="data" :pagination="false" size="middle">
  61. <template v-for="(col, i) in ['name', 'workId', 'department']" :slot="col" slot-scope="text, record, index">
  62. <a-tooltip title="必填项" :defaultVisible="false" :overlayStyle="{ color: 'red' }">
  63. <a-input :key="col" v-if="record.editable" style="margin: -5px 0" :value="text" :placeholder="columns[i].title" @change="e => handlerRowChange(e.target.value, record.key, col)"/>
  64. <template v-else>{{ text }}</template>
  65. </a-tooltip>
  66. </template>
  67. <template slot="operation" slot-scope="text, record, index">
  68. <template v-if="record.editable">
  69. <span v-if="record.isNew">
  70. <a @click="saveRow(record.key)">添加</a>
  71. <a-divider type="vertical"/>
  72. <a-popconfirm title="是否要删除此行?" @confirm="removeRow(record.key)"><a>删除</a></a-popconfirm>
  73. </span>
  74. <span v-else>
  75. <a @click="saveRow(record.key)">保存</a>
  76. <a-divider type="vertical"/>
  77. <a @click="cancelEditRow(record.key)">取消</a>
  78. </span>
  79. </template>
  80. <span v-else>
  81. <a @click="editRow(record.key)">编辑</a>
  82. <a-divider type="vertical"/>
  83. <a-popconfirm title="是否要删除此行?" @confirm="removeRow(record.key)"><a>删除</a></a-popconfirm>
  84. </span>
  85. </template>
  86. </a-table>
  87. <a-button style="width: 100%; margin-top: 16px; margin-bottom: 8px" type="dashed" icon="plus" @click="newRow">新增成员</a-button>
  88. </a-tab-pane>
  89. <a-tab-pane tab="Tab 2" key="2" forceRender>
  90. Content of Tab Pane 2
  91. </a-tab-pane>
  92. <a-tab-pane tab="Tab 3" key="3">Content of Tab Pane 3</a-tab-pane>
  93. </a-tabs>
  94. </a-form>
  95. </a-spin>
  96. </a-modal>
  97. </template>
  98. <script>
  99. import {httpAction} from '@/api/manage'
  100. import pick from 'lodash.pick'
  101. import moment from "moment"
  102. export default {
  103. name: "JeecgDemoTabsModal",
  104. data() {
  105. return {
  106. title: "操作",
  107. visible: false,
  108. model: {},
  109. // table
  110. columns: [
  111. {
  112. title: '成员姓名',
  113. dataIndex: 'name',
  114. key: 'name',
  115. width: '20%',
  116. scopedSlots: {customRender: 'name'}
  117. },
  118. // {
  119. // title: '工号',
  120. // dataIndex: 'workId',
  121. // key: 'workId',
  122. // width: '20%',
  123. // scopedSlots: {customRender: 'workId'}
  124. // },
  125. {
  126. title: '所属部门',
  127. dataIndex: 'department',
  128. key: 'department',
  129. width: '40%',
  130. scopedSlots: {customRender: 'department'}
  131. },
  132. {
  133. title: '操作',
  134. key: 'action',
  135. scopedSlots: {customRender: 'operation'}
  136. }
  137. ],
  138. data: [
  139. {
  140. key: '1',
  141. name: '小明',
  142. workId: '001',
  143. editable: false,
  144. department: '行政部'
  145. },
  146. {
  147. key: '2',
  148. name: '李莉',
  149. workId: '002',
  150. editable: false,
  151. department: 'IT部'
  152. },
  153. {
  154. key: '3',
  155. name: '王小帅',
  156. workId: '003',
  157. editable: false,
  158. department: '财务部'
  159. }
  160. ],
  161. confirmLoading: false,
  162. form: this.$form.createForm(this),
  163. validatorRules: {},
  164. url: {
  165. add: "/test/jeecgDemo/add",
  166. edit: "/test/jeecgDemo/edit",
  167. },
  168. }
  169. },
  170. created() {
  171. },
  172. methods: {
  173. add() {
  174. this.edit({});
  175. },
  176. edit(record) {
  177. this.form.resetFields();
  178. this.model = Object.assign({}, record);
  179. this.visible = true;
  180. this.$nextTick(() => {
  181. this.form.setFieldsValue(pick(this.model, 'name', 'keyWord', 'sex', 'age', 'email', 'content'))
  182. //时间格式化
  183. this.form.setFieldsValue({punchTime: this.model.punchTime ? moment(this.model.punchTime, 'YYYY-MM-DD HH:mm:ss') : null})
  184. this.form.setFieldsValue({birthday: this.model.birthday ? moment(this.model.birthday) : null})
  185. });
  186. },
  187. close() {
  188. this.$emit('close');
  189. this.visible = false;
  190. },
  191. handleOk() {
  192. const that = this;
  193. // 触发表单验证
  194. this.form.validateFields((err, values) => {
  195. if (!err) {
  196. that.confirmLoading = true;
  197. let httpurl = '';
  198. let method = '';
  199. if (!this.model.id) {
  200. httpurl += this.url.add;
  201. method = 'post';
  202. } else {
  203. httpurl += this.url.edit;
  204. //method = 'put';
  205. method = 'post';
  206. }
  207. let formData = Object.assign(this.model, values);
  208. //时间格式化
  209. formData.punchTime = formData.punchTime ? formData.punchTime.format('YYYY-MM-DD HH:mm:ss') : null;
  210. formData.birthday = formData.birthday ? formData.birthday.format() : null;
  211. console.log(formData)
  212. httpAction(httpurl, formData, method).then((res) => {
  213. if (res.success) {
  214. that.$message.success(res.message);
  215. that.$emit('ok');
  216. } else {
  217. that.$message.warning(res.message);
  218. }
  219. }).finally(() => {
  220. that.confirmLoading = false;
  221. that.close();
  222. })
  223. }
  224. })
  225. },
  226. handleCancel() {
  227. this.close()
  228. },
  229. newRow () {
  230. // 通过时间戳生成 UUID
  231. let uuid = Math.round(new Date().getTime()).toString();
  232. console.log('uuid: '+ uuid)
  233. this.data.push({
  234. key: uuid,
  235. name: '',
  236. workId: '',
  237. department: '',
  238. editable: true,
  239. isNew: true
  240. })
  241. },
  242. removeRow (key) {
  243. const newData = this.data.filter(item => item.key !== key)
  244. this.data = newData
  245. },
  246. saveRow (key) {
  247. let target = this.data.filter(item => item.key === key)[0]
  248. target.editable = false
  249. target.isNew = false
  250. },
  251. handlerRowChange (value, key, column) {
  252. const newData = [...this.data]
  253. const target = newData.filter(item => key === item.key)[0]
  254. if (target) {
  255. target[column] = value
  256. this.data = newData
  257. }
  258. },
  259. editRow (key) {
  260. let target = this.data.filter(item => item.key === key)[0]
  261. target.editable = !target.editable
  262. },
  263. cancelEditRow (key) {
  264. let target = this.data.filter(item => item.key === key)[0]
  265. target.editable = false
  266. },
  267. }
  268. }
  269. </script>
  270. <style scoped>
  271. .ant-modal-body {
  272. padding: 8px!important;
  273. }
  274. </style>