add-or-update-dialog.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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"> </el-row>
  107. <el-row class="my-row">
  108. <el-col :span="8">
  109. <el-form-item label="工单附件" prop="attachList">
  110. <upload-component
  111. :display="display"
  112. :displayStar="true"
  113. :title="'工单附件'"
  114. :accept="'*'"
  115. v-model="dataForm.attachList"
  116. @uploadSuccess="uploadSuccess"
  117. />
  118. </el-form-item>
  119. </el-col>
  120. </el-row>
  121. </el-form>
  122. <span slot="footer">
  123. <el-button @click="onChose">取消</el-button>
  124. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  125. </span>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import uploadComponent from '../common/upload-component-v2'
  131. import { getUserList } from '@/api/user'
  132. import { taskTypeOption, rankTypeOption } from '@/utils/enums'
  133. export default {
  134. name: 'worder-add-or-update',
  135. components: { uploadComponent },
  136. data () {
  137. return {
  138. id: 0,
  139. type: '',
  140. visible: false,
  141. isModify: false,
  142. display: false,
  143. bizType: 1,
  144. dataForm: {},
  145. attachList: [],
  146. userList: [],
  147. taskTypeOption: taskTypeOption,
  148. rankTypeOption: rankTypeOption,
  149. dataRule: {
  150. taskCode: [
  151. { required: true, message: '请输入工单编码', trigger: 'blur' }
  152. ],
  153. taskType: [
  154. { required: true, message: '请选择工单类型', trigger: 'change' }
  155. ],
  156. ranks: [
  157. { required: true, message: '请选择工单级别', trigger: 'change' }
  158. ],
  159. taskName: [
  160. { required: true, message: '请输入工单名称', trigger: 'blur' }
  161. ],
  162. content: [
  163. { required: true, message: '请输入工单内容', trigger: 'blur' }
  164. ],
  165. planCompletionTime: [
  166. { required: true, message: '请选择要求完成时间', trigger: 'blur' }
  167. ],
  168. receiver: [
  169. { required: true, message: '请输入工单任务接收人', trigger: 'blur' }
  170. ],
  171. attachList: [
  172. { required: true, message: '请上传附件', trigger: 'blur' }
  173. ]
  174. }
  175. }
  176. },
  177. methods: {
  178. onChose () {
  179. this.$emit('onChose')
  180. this.visible = false
  181. },
  182. // 初始化。type:{addItem:仅回调方法返回数据,update:调用接口更新}
  183. async init (id, item, type) {
  184. this.id = id || 0
  185. this.type = type
  186. if (item) {
  187. this.isModify = true
  188. if (item.attachList) {
  189. item.attachList.map(t => {
  190. if (t.fileName) { t.name = t.fileName }
  191. })
  192. }
  193. this.dataForm = item
  194. } else {
  195. this.isModify = false
  196. this.dataForm = {
  197. recordId: Math.round(Math.random() * 1000000)
  198. }
  199. }
  200. this.userList = []
  201. this.attachList = []
  202. this.visible = true
  203. await getUserList().then(({ data }) => {
  204. if (data && data.code === '200') {
  205. this.userList = data.data.records
  206. }
  207. })
  208. },
  209. // 表单提交
  210. dataFormSubmit () {
  211. this.$refs['dataForm'].validate((valid) => {
  212. if (valid) {
  213. this.visible = false
  214. this.dataForm.receiverName = this.userList.find(
  215. (t) => t.userId === this.dataForm.receiver
  216. ).name
  217. if (this.type === 'addItem') {
  218. this.$emit('submit', this.dataForm)
  219. } else if (this.type === 'update') {
  220. }
  221. }
  222. })
  223. },
  224. prodSelected (item) {
  225. this.dataForm.productId = item.value
  226. this.dataForm.relatedProduct = item.label
  227. },
  228. uploadSuccess (fileList) {
  229. this.attachList = fileList
  230. }
  231. }
  232. }
  233. </script>
  234. <style scoped></style>