zjf
2023-03-08 51468f93275c2bcfcc7ad25bf05f3d6a079ff764
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<template>
  <div class="task-sub">
    <div
      v-clickoutside="subtasksSubmit"
      class="subtasks-content">
      <div class="checkbox-box subtasks-box">
        <el-checkbox
          v-model="checkboxData"
          disabled/>
      </div>
      <div class="subtasks-content-box">
        <el-input
          :maxlength="50"
          v-model="subtasksTextarea"
          type="textarea"
          autosize
          placeholder="请输入内容"
          @keyup.enter.native="subtasksSubmit"/>
      </div>
      <flexbox class="subtasks-content-png">
        <div class="time">
          <el-date-picker
            ref="subtasksDate"
            v-model="subtasksDate"
            :style="{'width': subtasksDataText ? '54px': '28px'}"
            type="date"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            @change="subtasksDateClick(subtasksDate)"/>
          <span
            v-if="subtasksDataText && subtasksDataText !== 0"
            class="bg-color">{{ subtasksDataText | moment("MM-DD") }}</span>
          <i
            v-else
            class="wukong wukong-time-task"
            @click="subtasksDateFun"/>
        </div>
        <!-- 选择负责人 -->
        <el-popover
          placement="bottom-end"
          width="280"
          trigger="click">
          <xh-user
            ref="xhuser"
            :selected-data="xhUserData"
            radio
            @changeCheckout="xhUserCheckout"/>
          <div
            slot="reference"
            class="select-box">
            <template v-if="subtaskChange">
              <span
                v-for="(item, index) in xhUserData"
                :key="index">
                <el-tooltip
                  placement="bottom"
                  effect="light"
                  popper-class="tooltip-change-border">
                  <div slot="content">
                    <span>{{ item.realname }}</span>
                  </div>
                  <div
                    v-photo="item"
                    v-lazy:background-image="$options.filters.filterUserLazyImg(item.img)"
                    class="div-photo"/>
                </el-tooltip>
              </span>
            </template>
            <i
              v-else
              class="wukong wukong-user"/>
          </div>
        </el-popover>
      </flexbox>
    </div>
  </div>
</template>
 
<script>
// import { addTask, editTask } from '@/api/oamanagement/task'
import XhUser from '@/components/CreateCom/XhUser'
 
export default {
  components: {
    XhUser
  },
  props: {
    taskData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // 子任务输入内容
    text: String,
    time: [String, Number],
    subData: Object,
    subTaskCom: {
      type: String,
      default: ''
    },
    taskId: [Number, String],
    checkboxData: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      // 子任务选择时间
      subtasksDate: '',
      // 子任务数据
      xhUserData: [],
      subtasksDataText: null,
      // 子任务人员
      subtaskChange: false,
      num: 0,
      subtasksTextarea: '',
      isNum: 0
    }
  },
  watch: {},
  created () {
    if (this.subTaskCom === 'edit') {
      this.subtasksTextarea = this.text ? this.text : ''
      this.subtasksDataText = this.time
      if (JSON.stringify(this.subData) !== '{}') {
        if (this.subData.mainUser) {
          this.subtaskChange = true
          this.xhUserData = [this.subData.mainUser]
        }
      } else {
        this.xhUserData = []
        this.subtaskChange = false
      }
    }
  },
  methods: {
    // 子任务 -- 选中时间
    subtasksDateClick (val) {
      this.subtasksDataText = val.substring(5)
    },
    subtasksSubmit (event) {
      this.subtasksTextarea = this.subtasksTextarea.split(/[\n]/).join('')
      if (this.subtasksTextarea && this.num === 0) {
        this.num = 1
        if (this.subTaskCom === 'new') {
          this.$emit('on-handle', { type: 'add', result: 'success' })
          // addTask({
          //   pid: this.taskData.taskId,
          //   name: this.subtasksTextarea,
          //   stopTime: this.subtasksDate,
          //   mainUserId:
          //     this.xhUserData.length !== 0 ? this.xhUserData[0].userId : ''
          // })
          //   .then(res => {
          //     this.taskData.childTask.push({
          //       name: this.subtasksTextarea,
          //       stopTime: this.subtasksDate,
          //       taskId: res.data.taskId,
          //       mainUser: this.xhUserData.length > 0 ? this.xhUserData[0] : null
          //     })
          //     this.$message.success('子任务创建成功')
          //     // 创建成功 -- 清除选择
          //     this.subtasksTextarea = ''
          //     this.subtasksDataText = null
          //     this.subtaskChange = false
          //     this.num = 0
          //   })
          //   .catch(() => {
          //     this.$emit('on-handle', { type: 'add', result: 'error' })
          //     this.$message.error('子任务创建失败')
          //     this.num = 0
          //   })
        } else if (this.subTaskCom === 'edit') {
          if (
            this.isNum === 1 ||
            this.text !== this.subtasksTextarea ||
            this.subtasksDataText !== this.time
          ) {
            this.$emit('on-handle', { type: 'edit', result: 'success' })
            // editTask({
            //   taskId: this.taskId,
            //   stopTime: this.subtasksDate,
            //   mainUserId:
            //     this.xhUserData.length > 0 ? this.xhUserData[0].id : '',
            //   name: this.subtasksTextarea
            // })
            //   .then(res => {
            //     const dataList = this.taskData.childTask
            //     for (const i in dataList) {
            //       if (dataList[i].taskId === this.taskId) {
            //         const list = dataList[i]
            //         list.name = this.subtasksTextarea
            //         list.stopTime = this.subtasksDate
            //         list.mainUser =
            //           this.xhUserData.length > 0 ? this.xhUserData[0] : null
            //         dataList.splice(i, 1, list)
            //         break
            //       }
            //     }
            //     this.num = 0
            //     this.$message.success('子任务编辑成功')
            //   })
            //   .catch(() => {
            //     this.$emit('on-handle', { type: 'edit', result: 'error' })
            //     this.$message.error('子任务编辑失败')
            //     this.num = 0
            //   })
          } else {
            this.$emit('on-handle', { type: 'cancel' })
          }
        }
      } else {
        this.$emit('on-handle', { type: 'cancel' })
      }
    },
    xhUserCheckout (data) {
      if (data.data.length !== 0) {
        this.subtaskChange = true
        if (this.xhUserData.length !== 0) {
          this.$set(this.xhUserData[0], 'img', data.data[0].img)
          this.$set(this.xhUserData[0], 'realname', data.data[0].realname)
        } else {
          this.xhUserData = data.data
        }
        this.isNum = 1
      } else {
        this.isNum = 0
        this.subtaskChange = false
      }
    },
    // 子任务 -- 时间弹框
    subtasksDateFun () {
      this.$refs.subtasksDate.change()
    }
  }
}
</script>
 
<style scoped lang="scss">
.wukong {
  color: #666;
}
.subtasks-content {
  border: 1px solid #4D88FF;
  border-radius: 3px;
  display: flex;
  flex-direction: row;
  align-items: center;
  // margin-top: 10px;
  height: 40px;
  .subtasks-box {
    line-height: 40px;
  }
  .subtasks-content-box {
    flex: 1;
    .el-textarea /deep/ .el-textarea__inner {
      border-width: 0;
      resize: none;
    }
  }
  .subtasks-content-png {
    width: auto;
    img {
      margin-right: 10px;
      cursor: pointer;
      vertical-align: middle;
    }
    .time {
      display: inline-block;
      position: relative;
      vertical-align: middle;
      .el-date-editor {
        position: absolute;
        right: 0;
        width: 28px;
        opacity: 0;
        bottom: 0;
        top: 0;
      }
      .el-date-editor /deep/ .el-input__inner {
        padding: 0;
        height: 100%;
      }
      .el-date-editor /deep/ .el-input__suffix {
        display: none;
      }
      .el-date-editor /deep/ .el-input__prefix {
        left: 0;
        right: 0;
      }
      .bg-color {
        padding: 2px 10px;
      }
      .wukong-time-task {
        margin-right: 10px;
        cursor: pointer;
        vertical-align: middle;
      }
    }
    .select-box {
      display: inline-block;
      .div-photo {
        width: 24px;
        height: 24px;
        border-radius: 12px;
      }
      .wukong-user {
        margin-right: 10px;
        cursor: pointer;
        vertical-align: middle;
      }
    }
  }
  .checkbox-box {
    margin-left: 10px;
  }
  .subtask-popover-span {
    padding: 0 10px 0 5px;
  }
}
</style>