workshop-add-or-update.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div>
  3. <div class="my-title">{{ !id ? "新增" : "修改" }}</div>
  4. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="180px">
  5. <el-row>
  6. <el-col :span="12">
  7. <el-form-item label="名称" prop="name">
  8. <el-input v-model="dataForm.name" placeholder="请输入" />
  9. </el-form-item>
  10. </el-col>
  11. <el-col :span="12">
  12. <el-form-item label="主管" prop="workshopManager">
  13. <UserComponent v-model="dataForm.workshopManager" :user-id="dataForm.workshopManager" :displayStar="true" />
  14. </el-form-item>
  15. </el-col>
  16. </el-row>
  17. <el-row>
  18. <el-col :span="24">
  19. <el-form-item label="描述" prop="description">
  20. <el-input v-model="dataForm.description" placeholder="请输入" />
  21. </el-form-item>
  22. </el-col>
  23. </el-row>
  24. <el-row>
  25. <el-col :span="24">
  26. <el-form-item label="备注说明" prop="remark">
  27. <el-input v-model="dataForm.remark" placeholder="请输入" type="textarea"></el-input>
  28. </el-form-item>
  29. </el-col>
  30. </el-row>
  31. <el-row v-if="id">
  32. <el-col :span="24">
  33. <el-form-item label="工种列表">
  34. <el-table :data="dataForm.proWorkTypeList" border style="width: 100%;margin-top: 10px">
  35. <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
  36. <el-table-column prop="name" label="工种名称" wimin-widthdth="150"></el-table-column>
  37. <el-table-column prop="levelValue" label="工种级别" min-width="120"></el-table-column>
  38. <el-table-column prop="requirement" label="工种要求" min-width="120"></el-table-column>
  39. <el-table-column prop="quotedPrice" label="工时单价" min-width="100"></el-table-column>
  40. <el-table-column prop="masterNames" label="掌握人" min-width="120"
  41. :show-tooltip-when-overflow="true"></el-table-column>
  42. <el-table-column prop="workshopManagerName" label="负责人" min-width="120"
  43. :show-tooltip-when-overflow="true"></el-table-column>
  44. <el-table-column prop="createTime" label="创建时间" min-width="160"></el-table-column>
  45. <el-table-column prop="notes" label="备注" min-width="160"
  46. :show-tooltip-when-overflow="true"></el-table-column>
  47. <el-table-column fixed="right" label="操作" width="50">
  48. <template slot-scope="{ row, $index }">
  49. <el-button style="color: red" type="text" size="small"
  50. @click="removeWorkType(row.typeId, $index)">删除</el-button>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. </el-form-item>
  55. </el-col>
  56. </el-row>
  57. </el-form>
  58. <span slot="footer" class="dialog-footer">
  59. <el-button @click="onChose">取消</el-button>
  60. <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  61. </span>
  62. </div>
  63. </template>
  64. <script>
  65. import { getDetail } from '@/api/workshop'
  66. import { removeWorkType } from '@/api/worktype'
  67. import UserComponent from '../common/user-component.vue'
  68. export default {
  69. name: 'workshop-add-or-update',
  70. components: {
  71. UserComponent
  72. },
  73. data() {
  74. return {
  75. id: 0,
  76. dataForm: {
  77. proWorkTypeList: [],
  78. },
  79. materialList: [],
  80. dataRule: {
  81. name: [
  82. { required: true, message: '请输入名称', trigger: 'blur' },
  83. { min: 1, max: 50, message: '长度在 1 到 50 个字符之间', trigger: 'blur' }
  84. ],
  85. workshopManager: [
  86. { required: true, message: '请选择主管', trigger: 'change' }
  87. ]
  88. }
  89. }
  90. },
  91. created() {
  92. },
  93. methods: {
  94. init(id) {
  95. this.id = id || 0
  96. if (!id) return
  97. this.getDetail()
  98. },
  99. onChose() {
  100. this.$emit('onChose')
  101. },
  102. getDetail() {
  103. getDetail(this.id).then(({ data }) => {
  104. if (data && data.code === '200') {
  105. this.dataForm = data.data || {}
  106. } else {
  107. this.$message.error(data.msg)
  108. }
  109. })
  110. },
  111. dataFormSubmit() {
  112. this.$refs['dataForm'].validate((valid) => {
  113. if (valid) {
  114. this.$http({
  115. url: !this.id
  116. ? this.$http.adornUrl(`/biz-service/pro-workshop/save`)
  117. : this.$http.adornUrl(`/biz-service/pro-workshop/update`),
  118. method: 'post',
  119. data: this.$http.adornData({ ...this.dataForm, orgId: this.orgId })
  120. }).then(({ data }) => {
  121. if (data && data.code === '200') {
  122. this.$message({
  123. message: '操作成功',
  124. type: 'success',
  125. duration: 1500,
  126. onClose: () => {
  127. this.onChose()
  128. this.$emit('refreshDataList')
  129. }
  130. })
  131. } else {
  132. this.$message.error(data.msg)
  133. }
  134. })
  135. }
  136. })
  137. },
  138. removeWorkType(typeId, $index) {
  139. this.$confirm('确定要删除该工种记录吗?', '提示', {
  140. confirmButtonText: '确定',
  141. cancelButtonText: '取消',
  142. type: 'warning'
  143. }).then(() => {
  144. this.dataListLoading = true
  145. let ids = []
  146. ids.push(typeId)
  147. // 调用删除接口
  148. removeWorkType(ids).then(({ data }) => {
  149. this.dataListLoading = false
  150. if (data && data.code === '200') {
  151. this.$message.success('删除成功')
  152. // 删除这一行
  153. this.dataForm.proWorkTypeList.splice($index, 1)
  154. } else {
  155. this.$message.error(data && data.msg ? data.msg : '删除失败')
  156. }
  157. }).catch(() => {
  158. this.dataListLoading = false
  159. })
  160. }).catch(() => { })
  161. }
  162. }
  163. }
  164. </script>
  165. <style></style>