Month.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <style lang="scss" scoped>
  2. .day-cell{
  3. height: 100%;
  4. }
  5. .dialog-style{
  6. div{
  7. text-align: center;
  8. margin: 5px 0;
  9. label,/deep/ .el-input,/deep/ .el-textarea{
  10. display: inline-block;
  11. vertical-align: middle;
  12. }
  13. /deep/ .el-input{
  14. width: 200px;
  15. }
  16. /deep/ .el-textarea{
  17. width: 460px;
  18. }
  19. .el-select /deep/ .el-input{
  20. width: 70px;
  21. }
  22. }
  23. .add-bt{
  24. cursor: pointer;
  25. font-size: 18px;
  26. float: right;
  27. }
  28. .del-bt{
  29. cursor: pointer;
  30. font-size: 18px;
  31. }
  32. }
  33. .hide{
  34. opacity: 0;
  35. }
  36. </style>
  37. <template>
  38. <div>
  39. <el-calendar v-model="searchMonth">
  40. <template
  41. slot="dateCell"
  42. slot-scope="{date, data}">
  43. <div class="day-cell" @click="chooseDay(data)">
  44. <p>{{getDayNum(data.day)}}</p>
  45. <div v-if="new Date(data.day).getMonth() == searchMonth.getMonth()">
  46. <p v-for="item in planList[getDayNum(data.day)]" :key="item.id" :style="{'color':colorSet[item.status]}">
  47. {{item.name}}
  48. </p>
  49. </div>
  50. </div>
  51. </template>
  52. </el-calendar>
  53. <el-dialog
  54. class="dialog-style"
  55. title="编辑计划"
  56. :visible.sync="visibleChange"
  57. width="1000px">
  58. <div v-for="(item, index) in dayPlan" :key="index">
  59. <label>计划:</label>
  60. <el-input placeholder="" v-model="item.name" :disabled="!ableEdit"></el-input>
  61. &nbsp;
  62. <label>内容:</label>
  63. <el-input type="textarea" autosize placeholder="" v-model="item.content" :disabled="!ableEdit"></el-input>
  64. &nbsp;
  65. <label :class="{'hide':!item.id}">状态:</label>
  66. <el-select v-model="item.status" placeholder="请选择" size="mini" :class="{'hide':!item.id}" :disabled="item.id == null || !ableEdit">
  67. <el-option :label="'准备'" :value="0"></el-option>
  68. <el-option :label="'执行'" :value="1"></el-option>
  69. <el-option :label="'暂搁'" :value="2"></el-option>
  70. <el-option :label="'完成'" :value="3"></el-option>
  71. <el-option :label="'中止'" :value="4"></el-option>
  72. </el-select>
  73. &nbsp;
  74. <el-button @click="judgePlan(item)" type="text" :class="{'hide':!item.id}" :disabled="item.id == null">评价</el-button>
  75. &nbsp;
  76. <i class="el-icon-remove-outline del-bt" @click="visibleDelete = true;plan = item;deleteIndex = index" v-if="ableEdit"></i>
  77. </div>
  78. <i class="el-icon-circle-plus-outline add-bt" @click="addDayPlan()" v-if="ableEdit"></i>
  79. <span slot="footer" class="dialog-footer" v-if="ableEdit">
  80. <el-button @click="visibleChange = false">取 消</el-button>
  81. <el-button type="primary" @click="editTask">确 定</el-button>
  82. </span>
  83. </el-dialog>
  84. <el-dialog
  85. :title="plan.name + ' 任务评价'"
  86. :visible.sync="visibleJudge"
  87. width="800px">
  88. <div v-html="plan.evaluation" v-show="noEdit"></div>
  89. <Judge :planJudge="plan.evaluation" :changeSignal="changeSignal" @setEvaluation="setEvaluation" v-show="!noEdit"></Judge>
  90. <span slot="footer" class="dialog-footer">
  91. <el-button type="primary" @click="noEdit = false;" v-if="noEdit">编辑</el-button>
  92. <el-button type="primary" @click="visibleJudge = false;plan={}" v-if="!noEdit">取消</el-button>
  93. <el-button type="primary" @click="editTask" v-if="!noEdit">确 定</el-button>
  94. </span>
  95. </el-dialog>
  96. <el-dialog
  97. title="提示"
  98. :visible.sync="visibleDelete"
  99. width="200px">
  100. <p class="center-text">确认删除?</p>
  101. <span slot="footer" class="dialog-footer">
  102. <el-button @click="visibleDelete = false;plan={}">取 消</el-button>
  103. <el-button type="primary" @click="deletePlan">确 定</el-button>
  104. </span>
  105. </el-dialog>
  106. </div>
  107. </template>
  108. <script>
  109. import { getMonthPlan,addPlan,updatePlan,deletePlan } from '@/api/month';
  110. import Judge from "@/components/MainPage/Judge/Judge";
  111. export default {
  112. name: 'Month',
  113. components: {
  114. Judge
  115. },
  116. data () {
  117. return {
  118. colorSet:{
  119. 0:'gray',
  120. 1:'blue',
  121. 2:'red',
  122. 3:'green',
  123. 4:'yellow',
  124. },
  125. searchMonth: new Date(),
  126. params:{
  127. startTime: '',
  128. userId: this.$store.state.checkUser.id
  129. },
  130. visibleChange: false,
  131. planList: {},
  132. dayPlan: [],
  133. visibleDelete: false,
  134. plan:{},
  135. deleteIndex: '',
  136. noEdit: false,
  137. visibleJudge: false,
  138. changeSignal: false
  139. }
  140. },
  141. created() {
  142. this.getMonthPlan();
  143. },
  144. watch: {
  145. searchMonth(val,old) {
  146. if(val.getMonth() != old.getMonth()){
  147. this.params.startTime = val.getTime();
  148. this.getMonthPlan();
  149. }
  150. },
  151. '$store.state.checkUser.id'(val){
  152. this.params.userId = val;
  153. this.getMonthPlan();
  154. }
  155. },
  156. computed: {
  157. ableEdit() {
  158. return this.$store.state.loginUser.id == this.$store.state.checkUser.id;
  159. },
  160. },
  161. methods: {
  162. getMonthPlan(){
  163. getMonthPlan(this.params).then((data) => {
  164. this.planList = {};
  165. for(let key in data.data){
  166. this.$set(this.planList,key,data.data[key]);
  167. }
  168. })
  169. },
  170. editTask(){
  171. this.visibleChange = false;
  172. this.dayPlan.forEach(item => {
  173. if(item.id){
  174. let temp = {
  175. "id": item.id,
  176. "name": item.name,
  177. "content": item.content,
  178. "status": item.status,
  179. "startTime": this.searchMonth.getTime(),
  180. }
  181. updatePlan(temp).then((data) => {
  182. if(!data.result){
  183. this.$message(data.message);
  184. }
  185. this.getMonthPlan();
  186. })
  187. }
  188. else{
  189. addPlan(item).then((data) => {
  190. if(!data.result){
  191. this.$message(data.message);
  192. }
  193. this.getMonthPlan();
  194. })
  195. }
  196. })
  197. },
  198. chooseDay(data){
  199. if(new Date(data.day).getMonth() != this.searchMonth.getMonth()){
  200. return;
  201. }
  202. this.visibleChange = true;
  203. let day = this.getDayNum(data.day);
  204. this.dayPlan = JSON.parse(JSON.stringify(this.planList[day]));
  205. },
  206. addDayPlan(){
  207. this.dayPlan.push({
  208. "name": "",
  209. "content": "",
  210. "year": this.searchMonth.getFullYear(),
  211. "userId": "",
  212. "startTime": this.searchMonth.getTime(),
  213. })
  214. },
  215. deletePlan(){
  216. if(this.plan.id){
  217. let temp = {
  218. id: this.plan.id
  219. }
  220. deletePlan(temp).then((data) => {
  221. if(!data.result){
  222. this.$message(data.message);
  223. }
  224. else{
  225. this.dayPlan.splice(this.deleteIndex,1);
  226. }
  227. })
  228. }
  229. else{
  230. this.dayPlan.splice(this.deleteIndex,1);
  231. }
  232. this.visibleDelete = false;
  233. this.plan={};
  234. },
  235. getDayNum(day){
  236. return ~~day.split('-')[2];
  237. },
  238. setEvaluation(val){
  239. this.plan.evaluation = val;
  240. },
  241. judgePlan(item){
  242. this.visibleJudge = true;
  243. this.noEdit = true;
  244. this.plan = JSON.parse(JSON.stringify( item ));
  245. this.changeSignal = !this.changeSignal;
  246. }
  247. }
  248. }
  249. </script>