add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div class="task-input-box">
  3. <div v-if="!addText" class="input-placeholder">
  4. <Icon type="md-create" size="18"/>&nbsp;{{addFocus?`${$L('输入任务,回车即可保存')}`:placeholder}}
  5. </div>
  6. <div class="input-enter">
  7. <Input
  8. v-model="addText"
  9. ref="addInput"
  10. type="textarea"
  11. class="input-enter-textarea"
  12. :class="{bright:addFocus===true,highlight:!!addText}"
  13. element-id="project-panel-enter-textarea"
  14. @on-focus="onFocus(true)"
  15. @on-blur="onFocus(false)"
  16. :autosize="{ minRows: 1, maxRows: 6 }"
  17. :maxlength="255"
  18. @on-keydown="addKeydown"/>
  19. <div v-if="!!addText" class="input-enter-module">
  20. <Tooltip :content="$L('重要且紧急')" placement="bottom" transfer><div @click="addLevel=1" class="enter-module-icon p1"><Icon v-if="addLevel=='1'" type="md-checkmark" /></div></Tooltip>
  21. <Tooltip :content="$L('重要不紧急')" placement="bottom" transfer><div @click="addLevel=2" class="enter-module-icon p2"><Icon v-if="addLevel=='2'" type="md-checkmark" /></div></Tooltip>
  22. <Tooltip :content="$L('紧急不重要')" placement="bottom" transfer><div @click="addLevel=3" class="enter-module-icon p3"><Icon v-if="addLevel=='3'" type="md-checkmark" /></div></Tooltip>
  23. <Tooltip :content="$L('不重要不紧急')" placement="bottom" transfer><div @click="addLevel=4" class="enter-module-icon p4"><Icon v-if="addLevel=='4'" type="md-checkmark" /></div></Tooltip>
  24. <div class="enter-module-flex"></div>
  25. <Poptip placement="bottom" @on-popper-show="nameTipDisabled=true" @on-popper-hide="nameTipDisabled=false" transfer>
  26. <Tooltip placement="bottom" :disabled="nameTipDisabled">
  27. <div class="enter-module-icon user">
  28. <UserImg :info="addUserInfo" class="avatar"/>
  29. </div>
  30. <div slot="content">
  31. {{$L('负责人')}}: <UserView :username="addUserInfo.username"/>
  32. </div>
  33. </Tooltip>
  34. <div slot="content">
  35. <div style="width:240px">
  36. {{$L('选择负责人')}}
  37. <UserInput v-model="addUserInfo.username" :projectid="projectid" @change="changeUser" :placeholder="$L('留空默认: 自己')" style="margin:5px 0 3px"></UserInput>
  38. </div>
  39. </div>
  40. </Poptip>
  41. <div class="enter-module-btn">
  42. <Button class="enter-module-btn-1" type="info" size="small" @click="clickAdd(false)">{{$L('添加任务')}}</Button>
  43. <Dropdown class="enter-module-btn-drop" @on-click="dropAdd" placement="bottom-end" transfer>
  44. <Button class="enter-module-btn-2" type="info" size="small"><Icon type="ios-arrow-down"></Icon></Button>
  45. <DropdownMenu slot="list" class="enter-module-btn-drop-list">
  46. <DropdownItem name="insertbottom">{{$L('添加至列表结尾')}}</DropdownItem>
  47. </DropdownMenu>
  48. </Dropdown>
  49. </div>
  50. </div>
  51. </div>
  52. <div v-if="loadIng > 0" class="load-box" @click.stop="">
  53. <div class="load-box-main"><w-loading></w-loading></div>
  54. </div>
  55. </div>
  56. </template>
  57. <style lang="scss">
  58. .enter-module-btn-drop-list {
  59. .ivu-dropdown-item {
  60. padding: 5px 16px;
  61. font-size: 12px !important;
  62. }
  63. }
  64. </style>
  65. <style lang="scss" scoped>
  66. .task-input-box {
  67. position: relative;
  68. margin-top: 5px;
  69. margin-bottom: 20px;
  70. min-height: 70px;
  71. .input-placeholder,
  72. .input-enter {
  73. position: absolute;
  74. top: 0;
  75. left: 0;
  76. right: 0;
  77. width: 100%;
  78. }
  79. .input-placeholder {
  80. z-index: 1;
  81. height: 40px;
  82. line-height: 40px;
  83. color: rgba(0, 0, 0, .36);
  84. padding-left: 12px;
  85. padding-right: 12px;
  86. }
  87. .input-enter {
  88. z-index: 2;
  89. position: relative;
  90. background-color: transparent;
  91. .input-enter-textarea {
  92. border-radius: 4px;
  93. padding-left: 12px;
  94. padding-right: 12px;
  95. color: rgba(0, 0, 0, 0.85);
  96. &.bright {
  97. background-color: rgba(46, 73, 136, .08);
  98. }
  99. &.highlight {
  100. background-color: #ffffff;
  101. }
  102. }
  103. .input-enter-module {
  104. display: flex;
  105. width: 100%;
  106. margin-top: 8px;
  107. align-items: center;
  108. .enter-module-icon {
  109. display: inline-block;
  110. width: 16px;
  111. height: 16px;
  112. margin-right: 5px;
  113. border-radius: 4px;
  114. vertical-align: middle;
  115. cursor: pointer;
  116. &.p1 {
  117. background-color: #ff0000;
  118. }
  119. &.p2 {
  120. background-color: #BB9F35;
  121. }
  122. &.p3 {
  123. background-color: #449EDD;
  124. }
  125. &.p4 {
  126. background-color: #84A83B;
  127. }
  128. &.user {
  129. width: 24px;
  130. height: 24px;
  131. margin-left: 10px;
  132. margin-right: 10px;
  133. .avatar {
  134. width: 24px;
  135. height: 24px;
  136. font-size: 14px;
  137. line-height: 24px;
  138. border-radius: 12px;
  139. }
  140. i {
  141. line-height: 24px;
  142. font-size: 16px;
  143. }
  144. }
  145. i {
  146. width: 100%;
  147. height: 100%;
  148. color: #ffffff;
  149. line-height: 16px;
  150. font-size: 14px;
  151. transform: scale(0.85);
  152. vertical-align: 0;
  153. }
  154. }
  155. .enter-module-flex {
  156. flex: 1;
  157. }
  158. .enter-module-btn {
  159. button {
  160. font-size: 12px;
  161. }
  162. .enter-module-btn-1 {
  163. border-top-right-radius: 0;
  164. border-bottom-right-radius: 0;
  165. }
  166. .enter-module-btn-2 {
  167. padding: 0 2px;
  168. border-top-left-radius: 0;
  169. border-bottom-left-radius: 0;
  170. }
  171. .enter-module-btn-drop {
  172. margin-left: -4px;
  173. border-left: 1px solid #c0daff;
  174. }
  175. }
  176. }
  177. }
  178. .load-box {
  179. position: absolute;
  180. top: 0;
  181. left: 0;
  182. right: 0;
  183. bottom: 0;
  184. display: flex;
  185. align-items: center;
  186. justify-content: center;
  187. z-index: 9;
  188. .load-box-main {
  189. width: 24px;
  190. height: 24px;
  191. }
  192. }
  193. }
  194. </style>
  195. <script>
  196. export default {
  197. name: 'ProjectAddTask',
  198. props: {
  199. placeholder: {
  200. type: String,
  201. default: ''
  202. },
  203. projectid: {
  204. type: Number,
  205. default: 0
  206. },
  207. labelid: {
  208. type: Number,
  209. default: 0
  210. },
  211. },
  212. data() {
  213. return {
  214. loadIng: 0,
  215. addText: '',
  216. addLevel: 2,
  217. addUserInfo: {},
  218. addFocus: false,
  219. nameTipDisabled: false,
  220. }
  221. },
  222. mounted() {
  223. this.addUserInfo = $A.cloneData(this.usrInfo);
  224. },
  225. methods: {
  226. changeUser(user) {
  227. if (typeof user.username === "undefined") {
  228. this.addUserInfo = $A.cloneData(this.usrInfo);
  229. } else {
  230. this.addUserInfo = user;
  231. }
  232. },
  233. dropAdd(name) {
  234. if (name == 'insertbottom') {
  235. this.clickAdd(true);
  236. }
  237. },
  238. clickAdd(insertbottom = false) {
  239. let addText = this.addText.trim();
  240. if ($A.count(addText) == 0 || this.loadIng > 0) {
  241. return;
  242. }
  243. this.loadIng++;
  244. $A.apiAjax({
  245. url: 'project/task/add',
  246. data: {
  247. projectid: this.projectid,
  248. labelid: this.labelid,
  249. title: addText,
  250. level: this.addLevel,
  251. username: this.addUserInfo.username,
  252. insertbottom: insertbottom ? 1 : 0,
  253. },
  254. complete: () => {
  255. this.loadIng--;
  256. },
  257. error: () => {
  258. alert(this.$L('网络繁忙,请稍后再试!'));
  259. },
  260. success: (res) => {
  261. if (res.ret === 1) {
  262. this.addText = '';
  263. this.addFocus = false;
  264. this.$Message.success(res.msg);
  265. res.data.insertbottom = insertbottom;
  266. this.$emit('on-add-success', res.data);
  267. $A.triggerTaskInfoListener('create', res.data);
  268. $A.triggerTaskInfoChange(res.data.id);
  269. } else {
  270. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  271. }
  272. }
  273. });
  274. },
  275. addKeydown(e) {
  276. if (e.keyCode == 13) {
  277. if (e.shiftKey) {
  278. return;
  279. }
  280. this.clickAdd(false);
  281. e.preventDefault();
  282. }
  283. },
  284. setFocus() {
  285. this.$refs.addInput.focus();
  286. },
  287. onFocus(focus) {
  288. this.addFocus = focus;
  289. this.$emit('on-focus', focus);
  290. }
  291. }
  292. }
  293. </script>