add-or-update-dialog.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <!-- 工单新增或编辑 -->
  2. <template>
  3. <div>
  4. <el-dialog
  5. :title="!isModify ? '新增工单' : '修改工单'"
  6. width="70%"
  7. :close-on-click-modal="false"
  8. :visible.sync="visible"
  9. >
  10. <el-form
  11. :model="dataForm"
  12. :rules="dataRule"
  13. ref="dataForm"
  14. label-width="120px"
  15. >
  16. <el-row class="my-row">
  17. <el-col :span="8">
  18. <el-form-item label="工单类型" prop="taskType">
  19. <el-select
  20. v-model="dataForm.taskType"
  21. placeholder="请选择"
  22. style="width: 100%"
  23. >
  24. <el-option
  25. v-for="item in taskTypeOption"
  26. :key="item.value"
  27. :label="item.label"
  28. :value="item.value"
  29. ></el-option>
  30. </el-select>
  31. </el-form-item>
  32. </el-col>
  33. <el-col :span="8">
  34. <el-form-item label="工单级别" prop="ranks">
  35. <el-select
  36. v-model="dataForm.ranks"
  37. placeholder="请选择"
  38. style="width: 100%"
  39. >
  40. <el-option
  41. v-for="item in rankTypeOption"
  42. :key="item.value"
  43. :label="item.label"
  44. :value="item.value"
  45. ></el-option>
  46. </el-select>
  47. </el-form-item>
  48. </el-col>
  49. </el-row>
  50. <el-row class="my-row">
  51. <el-col :span="8">
  52. <el-form-item label="工单名称" prop="taskName">
  53. <el-input
  54. v-model="dataForm.taskName"
  55. placeholder="请输入"
  56. ></el-input>
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="8">
  60. <el-form-item label="工单内容" prop="content">
  61. <el-input
  62. v-model="dataForm.content"
  63. placeholder="请输入"
  64. ></el-input>
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="8">
  68. <el-form-item label="要求完成时间" prop="planCompletionTime">
  69. <el-date-picker
  70. v-model="dataForm.planCompletionTime"
  71. value-format="yyyy-MM-dd"
  72. type="date"
  73. style="width: 100%"
  74. >
  75. </el-date-picker>
  76. </el-form-item>
  77. </el-col>
  78. </el-row>
  79. <el-row class="my-row">
  80. <el-col :span="8">
  81. <el-form-item label="任务接收人" prop="receiver">
  82. <el-select
  83. v-model="dataForm.receiver"
  84. placeholder="请选择"
  85. style="width: 100%"
  86. >
  87. <el-option
  88. v-for="item in userList"
  89. :key="item.userId"
  90. :label="item.name"
  91. :value="item.userId"
  92. ></el-option>
  93. </el-select>
  94. </el-form-item>
  95. </el-col>
  96. <el-col :span="16">
  97. <el-form-item label="备注" prop="notes">
  98. <el-input
  99. type="textarea"
  100. v-model="dataForm.notes"
  101. placeholder="备注"
  102. ></el-input>
  103. </el-form-item>
  104. </el-col>
  105. </el-row>
  106. <el-row class="my-row">
  107. <el-col :span="8">
  108. <el-form-item label="工单附件" prop="attachList">
  109. <upload-component
  110. :display="display"
  111. :title="'工单附件'"
  112. :accept="'*'"
  113. v-model="dataForm.attachList"
  114. @uploadSuccess="uploadSuccess"
  115. />
  116. </el-form-item>
  117. </el-col>
  118. </el-row>
  119. </el-form>
  120. <span slot="footer">
  121. <el-button @click="onChose">取消</el-button>
  122. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  123. </span>
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <script>
  128. import uploadComponent from '../common/upload-component-v2'
  129. import { getUserList } from '@/api/user'
  130. import { taskTypeOption, rankTypeOption } from '@/utils/enums'
  131. export default {
  132. name: 'worder-add-or-update',
  133. components: { uploadComponent },
  134. data () {
  135. return {
  136. id: 0,
  137. type: '',
  138. visible: false,
  139. isModify: false,
  140. display: false,
  141. bizType: 1,
  142. dataForm: {},
  143. attachList: [],
  144. userList: [],
  145. taskTypeOption: taskTypeOption,
  146. rankTypeOption: rankTypeOption,
  147. dataRule: {
  148. taskCode: [
  149. { required: true, message: '请输入工单编码', trigger: 'blur' }
  150. ],
  151. taskType: [
  152. { required: true, message: '请选择工单类型', trigger: 'change' }
  153. ],
  154. ranks: [
  155. { required: true, message: '请选择工单级别', trigger: 'change' }
  156. ],
  157. taskName: [
  158. { required: true, message: '请输入工单名称', trigger: 'blur' }
  159. ],
  160. content: [
  161. { required: true, message: '请输入工单内容', trigger: 'blur' }
  162. ],
  163. planCompletionTime: [
  164. { required: true, message: '请选择要求完成时间', trigger: 'blur' }
  165. ],
  166. receiver: [
  167. { required: true, message: '请输入工单任务接收人', trigger: 'blur' }
  168. ]
  169. }
  170. }
  171. },
  172. methods: {
  173. onChose () {
  174. this.$emit('onChose')
  175. this.visible = false
  176. },
  177. // 初始化。type:{addItem:仅回调方法返回数据,update:调用接口更新}
  178. async init (id, item, type) {
  179. this.id = id || 0
  180. this.type = type || 'addItem'
  181. if (item) {
  182. this.isModify = true
  183. if (item.attachList) {
  184. item.attachList.map(t => {
  185. if (t.fileName) { t.name = t.fileName }
  186. })
  187. }
  188. this.dataForm = item
  189. } else {
  190. this.isModify = false
  191. this.dataForm = {
  192. taskType: 'routine',
  193. recordId: Math.round(Math.random() * 1000000)
  194. }
  195. }
  196. this.userList = []
  197. this.attachList = []
  198. this.visible = true
  199. await getUserList().then(({ data }) => {
  200. if (data && data.code === '200') {
  201. this.userList = data.data.records
  202. }
  203. })
  204. },
  205. // 表单提交
  206. dataFormSubmit () {
  207. this.$refs['dataForm'].validate((valid) => {
  208. if (valid) {
  209. this.visible = false
  210. this.dataForm.receiverName = this.userList.find(
  211. (t) => t.userId === this.dataForm.receiver
  212. ).name
  213. if (this.type === 'addItem') {
  214. this.$emit('submit', this.dataForm)
  215. } else if (this.type === 'update') {
  216. }
  217. }
  218. })
  219. },
  220. prodSelected (item) {
  221. this.dataForm.productId = item.value
  222. this.dataForm.relatedProduct = item.label
  223. },
  224. uploadSuccess (fileList) {
  225. this.attachList = fileList
  226. }
  227. }
  228. }
  229. </script>
  230. <style scoped></style>