edit.vue 13 KB

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