add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div>
  3. <el-button size="small" type="primary" @click="(drawer = true)">新 建</el-button>
  4. <el-drawer
  5. title="新建项目工作任务"
  6. :visible.sync="drawer"
  7. direction="rtl"
  8. append-to-body
  9. :show-close="false"
  10. size="80%">
  11. <div class="drawer__panel">
  12. <el-row :gutter="20">
  13. <el-form :model="form" ref="form" :rules="rules" class="demo-form-inline" size="small" label-position="rigth" label-width="90px">
  14. <el-col :span="20">
  15. <el-form-item style="width:100%" label="工作任务" prop="taskname">
  16. <el-input style="width:100%" v-model="form.taskname" placeholder="输入工作任务"></el-input>
  17. </el-form-item>
  18. </el-col>
  19. <el-col :span="4">
  20. <el-form-item label="排序">
  21. <el-input v-model="form.sequence"></el-input>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="24">
  25. <el-form-item label="关键任务">
  26. <el-radio-group class="inline-16" v-model="form.important">
  27. <el-radio :label="1">是</el-radio>
  28. <el-radio :label="0">否</el-radio>
  29. </el-radio-group>
  30. <div class="inline-16">
  31. <el-checkbox v-model="form.onparties" :true-label="1" :false-label="0" @change="onPartiesChange">关联客户对象</el-checkbox>
  32. <AssociateCustomerObject ref="onparties" :data="form" class="inline-16" style="margin-left: 10px" @selectObject="selectFormObject"></AssociateCustomerObject>
  33. </div>
  34. <div class="inline-16">
  35. <el-checkbox v-model="form.onstage" :true-label="1" :false-label="0" style="font-size: 14px" @change="onOnstageChange">关联项目阶段</el-checkbox>
  36. <AssociatedProjectPhases ref="onstage" :data="form" class="inline-16" style="margin-left: 10px" @selectStage="selectFormStage"></AssociatedProjectPhases>
  37. </div>
  38. </el-form-item>
  39. </el-col>
  40. </el-form>
  41. </el-row>
  42. <div class="normal-margin">
  43. <div class="normal-margin flex-align-center flex-between">
  44. <p class="normal-title">评估项</p>
  45. <el-button type="primary" size="small" @click="addOptions">添加任务</el-button>
  46. </div>
  47. <el-table
  48. :data="form.projtaskmag_options"
  49. style="width: 100%"
  50. @row-click="rowClick"
  51. highlight-current-row
  52. border>
  53. <el-table-column
  54. type="index"
  55. width="50">
  56. </el-table-column>
  57. <el-table-column
  58. prop="optionname"
  59. label="任务内容"
  60. width="360">
  61. <template slot-scope="scope">
  62. <el-input v-model="scope.row.optionname" placeholder=""></el-input>
  63. </template>
  64. </el-table-column>
  65. <el-table-column
  66. prop="remarks"
  67. label="描述"
  68. width="0">
  69. <template slot-scope="scope">
  70. <el-input v-model="scope.row.remarks" placeholder=""></el-input>
  71. </template>
  72. </el-table-column>
  73. <el-table-column
  74. prop="score"
  75. width="160"
  76. label="独立项分值">
  77. <template slot-scope="scope">
  78. <el-input v-model="scope.row.score" placeholder=""></el-input>
  79. </template>
  80. </el-table-column>
  81. <el-table-column
  82. prop="operation"
  83. width="100"
  84. label="操作">
  85. <template slot-scope="scope">
  86. <el-button type="text" size="mini" :disabled="form.projtaskmag_options.length === 1" @click="deleteOptions(scope.$index)">删除</el-button>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. </div>
  91. <div>
  92. <p class="normal-title normal-margin">关联设置({{act_projtask?act_projtask.optionname:""}})</p>
  93. <el-table
  94. :data="optionscore"
  95. border
  96. style="width: 100%">
  97. <el-table-column
  98. v-if="form.onparties"
  99. prop="partiestype"
  100. label="客户对象"
  101. >
  102. </el-table-column>
  103. <el-table-column
  104. v-if="form.onstage"
  105. prop="stagename"
  106. label="项目阶段"
  107. >
  108. </el-table-column>
  109. <el-table-column
  110. prop="score"
  111. label="分值">
  112. <template slot-scope="scope">
  113. <el-input v-model="scope.row.score" placeholder=""></el-input>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. </div>
  118. </div>
  119. <div class="fixed__btn__panel">
  120. <el-button size="small" @click="onClose" class="normal-btn-width">取 消</el-button>
  121. <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
  122. </div>
  123. </el-drawer>
  124. </div>
  125. </template>
  126. <script>
  127. import AssociateCustomerObject from '@/HDrpManagement/projectTask/modules/AssociateCustomerObject.vue'
  128. import AssociatedProjectPhases from '@/HDrpManagement/projectTask/modules/AssociatedProjectStage.vue'
  129. export default {
  130. components:{
  131. AssociateCustomerObject,
  132. AssociatedProjectPhases
  133. },
  134. data () {
  135. return {
  136. drawer:false,
  137. show:true,
  138. form:{
  139. "sa_projtaskmagid": 0,
  140. "taskname": "",
  141. "sequence": 0,
  142. "important": 0,
  143. "onparties": 0,
  144. "onstage": 0,
  145. "projtaskmag_options": [
  146. ]
  147. },
  148. optionscore:[],
  149. partiesType:[],
  150. projectStage:[],
  151. act_projtask:null,
  152. objects: new Map(),
  153. stages: new Map(),
  154. relateForm: [],
  155. rules:{
  156. taskname: [
  157. { required: true, message: '任务名称不能为空', trigger: 'blur' },
  158. ],
  159. },
  160. }
  161. },
  162. methods:{
  163. selectFormObject(val) {
  164. this.partiesType = val
  165. this.selectObject(val);
  166. },
  167. selectFormStage(val) {
  168. this.projectStage = val
  169. this.selectStage(val);
  170. },
  171. // 选择客户对象
  172. selectObject (val) {
  173. this.objects = new Map()
  174. val.forEach(v => this.objects.set(v.partiestype, v))
  175. console.log('try calculate')
  176. this.optionscore = this.calculate(this.optionscore)
  177. this.act_projtask?this.act_projtask.projtaskmag_optionscore = this.optionscore:''
  178. this.form.projtaskmag_options
  179. .filter(task => task != this.act_projtask)
  180. .map(task => {
  181. console.log(`88888 re-build optionscore for task ${task.optionname}`)
  182. return task
  183. })
  184. .forEach(task => task.projtaskmag_optionscore = this.calculate(task.projtaskmag_optionscore))
  185. },
  186. // 选择项目阶段
  187. selectStage (val) {
  188. // (e == 0 && val.length === 0) ? this.form.onparties = 0 : ""
  189. this.stages = new Map()
  190. val.forEach(v => this.stages.set(v.stagename, v))
  191. this.optionscore = this.calculate(this.optionscore)
  192. this.act_projtask?this.act_projtask.projtaskmag_optionscore = this.optionscore:''
  193. this.form.projtaskmag_options
  194. .filter(task => task != this.act_projtask)
  195. .map(task => {
  196. console.log(`88888 re-build optionscore for task ${task.optionname}`)
  197. return task
  198. })
  199. .forEach(task => task.projtaskmag_optionscore = this.calculate(task.projtaskmag_optionscore))
  200. },
  201. calculate(optionscore) {
  202. var list = [];
  203. if (this.stages == null || this.stages.size == 0){
  204. this.objects.forEach((item, key) => {
  205. list.push({
  206. sa_projtaskmag_optionscoreid: 0,
  207. partiestype: item.partiestype,
  208. stagename : '',
  209. score: optionscore ? this.getScore(optionscore, item.partiestype, '') : 0
  210. })
  211. })
  212. } else if (this.objects == null || this.objects.size == 0) {
  213. this.stages.forEach((item, key) => {
  214. list.push({
  215. sa_projtaskmag_optionscoreid: 0,
  216. partiestype: '',
  217. stagename: item.stagename,
  218. sa_projstagemagid: item.sa_projstagemagid,
  219. score: optionscore ? this.getScore(optionscore, '', item.stagename) : 0
  220. })
  221. })
  222. } else {
  223. this.objects.forEach((objItem, objKey) => {
  224. this.stages.forEach((stageItem, stageKey) => {
  225. list.push({
  226. sa_projtaskmag_optionscoreid: 0,
  227. partiestype: objItem.partiestype,
  228. stagename: stageItem.stagename,
  229. sa_projstagemagid: stageItem.sa_projstagemagid,
  230. score: optionscore ? this.getScore(optionscore, objItem.partiestype, stageItem.stagename) : 0
  231. })
  232. })
  233. })
  234. }
  235. return list;
  236. },
  237. getScore(optionscore, partiestype, stagename) {
  238. let result = optionscore.filter(item => item.partiestype == partiestype && item.stagename == stagename)
  239. return result.length > 0 ? result[0].score : 0
  240. },
  241. // 勾选对象状态
  242. onPartiesChange(val) {
  243. val?this.$refs['onparties'].drawer = true:''
  244. this.selectObject(val ? this.partiesType : [])
  245. },
  246. // 勾选阶段状态
  247. onOnstageChange(val) {
  248. val?this.$refs['onstage'].drawer = true:''
  249. this.selectStage(val ? this.projectStage : [])
  250. },
  251. // 新建任务
  252. addOptions(){
  253. let row = {
  254. "sa_projtaskmag_optionsid": 0,
  255. "optionname": "",
  256. "remarks": "",
  257. "score": 0,
  258. "projtaskmag_optionscore": this.calculate(null)
  259. }
  260. this.form.projtaskmag_options.push(row)
  261. if (!this.act_projtask) {
  262. this.rowClick(row)
  263. }
  264. },
  265. // 删除任务
  266. deleteOptions(index) {
  267. console.log(index)
  268. this.form.projtaskmag_options = this.form.projtaskmag_options.filter((e,idx)=>{
  269. if (idx !== index) {
  270. return e
  271. }
  272. })
  273. },
  274. // 点击任务行
  275. rowClick (row) {
  276. // 记录当前选中行的行
  277. this.act_projtask = row
  278. this.optionscore = row.projtaskmag_optionscore
  279. },
  280. onSubmit () {
  281. this.$refs.form.validate(async (valid)=>{
  282. if (!valid) return false
  283. const res = await this.$api.requested({
  284. "id": "20221128144204",
  285. "content":this.form
  286. })
  287. this.tool.showMessage(res,()=>{
  288. this.$emit('onSuccess')
  289. this.form = {
  290. "sa_projtaskmagid": 0,
  291. "taskname": "",
  292. "sequence": 0,
  293. "important": 0,
  294. "onparties": 0,
  295. "onstage": 0,
  296. "projtaskmag_options": []
  297. }
  298. this.optionscore=[]
  299. this.partiesType=[]
  300. this.projectStage=[]
  301. this.drawer = false
  302. this.$refs.onparties.$refs.projectType.$refs.tables.clearSelection()
  303. this.$refs.onstage.$refs.projectType.$refs.tables.clearSelection()
  304. })
  305. })
  306. },
  307. onClose(){
  308. this.drawer = false
  309. this.form = {
  310. "sa_projtaskmagid": 0,
  311. "taskname": "",
  312. "sequence": 0,
  313. "important": 0,
  314. "onparties": 0,
  315. "onstage": 0,
  316. "projtaskmag_options": []
  317. }
  318. this.optionscore=[]
  319. this.partiesType=[]
  320. this.projectStage=[]
  321. this.$refs.onparties.$refs.projectType.$refs.tables.clearSelection()
  322. this.$refs.onstage.$refs.projectType.$refs.tables.clearSelection()
  323. }
  324. }
  325. }
  326. </script>