add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. .enter-module-icon {
  108. display: inline-block;
  109. width: 16px;
  110. height: 16px;
  111. margin-right: 5px;
  112. border-radius: 4px;
  113. vertical-align: middle;
  114. cursor: pointer;
  115. &.p1 {
  116. background-color: #ff0000;
  117. }
  118. &.p2 {
  119. background-color: #BB9F35;
  120. }
  121. &.p3 {
  122. background-color: #449EDD;
  123. }
  124. &.p4 {
  125. background-color: #84A83B;
  126. }
  127. &.user {
  128. width: 24px;
  129. height: 24px;
  130. margin-left: 10px;
  131. margin-right: 10px;
  132. .avatar {
  133. width: 24px;
  134. height: 24px;
  135. font-size: 14px;
  136. line-height: 24px;
  137. border-radius: 12px;
  138. }
  139. i {
  140. line-height: 24px;
  141. font-size: 16px;
  142. }
  143. }
  144. i {
  145. width: 100%;
  146. height: 100%;
  147. color: #ffffff;
  148. line-height: 16px;
  149. font-size: 14px;
  150. transform: scale(0.85);
  151. vertical-align: 0;
  152. }
  153. }
  154. .enter-module-flex {
  155. flex: 1;
  156. }
  157. .enter-module-btn {
  158. button {
  159. font-size: 12px;
  160. }
  161. .enter-module-btn-1 {
  162. border-top-right-radius: 0;
  163. border-bottom-right-radius: 0;
  164. }
  165. .enter-module-btn-2 {
  166. padding: 0 2px;
  167. border-top-left-radius: 0;
  168. border-bottom-left-radius: 0;
  169. }
  170. .enter-module-btn-drop {
  171. margin-left: -4px;
  172. border-left: 1px solid #c0daff;
  173. }
  174. }
  175. }
  176. }
  177. .load-box {
  178. position: absolute;
  179. top: 0;
  180. left: 0;
  181. right: 0;
  182. bottom: 0;
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. z-index: 9;
  187. .load-box-main {
  188. width: 24px;
  189. height: 24px;
  190. }
  191. }
  192. }
  193. </style>
  194. <script>
  195. export default {
  196. name: 'ProjectAddTask',
  197. props: {
  198. placeholder: {
  199. type: String,
  200. default: ''
  201. },
  202. projectid: {
  203. type: Number,
  204. default: 0
  205. },
  206. labelid: {
  207. type: Number,
  208. default: 0
  209. },
  210. },
  211. data() {
  212. return {
  213. loadIng: 0,
  214. addText: '',
  215. addLevel: 2,
  216. addUserInfo: {},
  217. addFocus: false,
  218. nameTipDisabled: false,
  219. userInfo: {},
  220. }
  221. },
  222. mounted() {
  223. this.userInfo = $A.getUserInfo((res, isLogin) => {
  224. this.userInfo = res;
  225. }, false);
  226. this.addUserInfo = $A.cloneData(this.userInfo);
  227. },
  228. methods: {
  229. changeUser(user) {
  230. if (typeof user.username === "undefined") {
  231. this.addUserInfo = $A.cloneData(this.userInfo);
  232. } else {
  233. this.addUserInfo = user;
  234. }
  235. },
  236. dropAdd(name) {
  237. if (name == 'insertbottom') {
  238. this.clickAdd(true);
  239. }
  240. },
  241. clickAdd(insertbottom = false) {
  242. let addText = this.addText.trim();
  243. if ($A.count(addText) == 0 || this.loadIng > 0) {
  244. return;
  245. }
  246. this.loadIng++;
  247. $A.apiAjax({
  248. url: 'project/task/add',
  249. data: {
  250. projectid: this.projectid,
  251. labelid: this.labelid,
  252. title: addText,
  253. level: this.addLevel,
  254. username: this.addUserInfo.username,
  255. insertbottom: insertbottom ? 1 : 0,
  256. },
  257. complete: () => {
  258. this.loadIng--;
  259. },
  260. error: () => {
  261. alert(this.$L('网络繁忙,请稍后再试!'));
  262. },
  263. success: (res) => {
  264. if (res.ret === 1) {
  265. this.addText = '';
  266. this.addFocus = false;
  267. this.$Message.success(res.msg);
  268. res.data.insertbottom = insertbottom;
  269. this.$emit('on-add-success', res.data);
  270. $A.triggerTaskInfoListener('create', res.data);
  271. $A.triggerTaskInfoChange(res.data.id);
  272. } else {
  273. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  274. }
  275. }
  276. });
  277. },
  278. addKeydown(e) {
  279. if (e.keyCode == 13) {
  280. if (e.shiftKey) {
  281. return;
  282. }
  283. this.clickAdd(false);
  284. e.preventDefault();
  285. }
  286. },
  287. setFocus() {
  288. this.$refs.addInput.focus();
  289. },
  290. onFocus(focus) {
  291. this.addFocus = focus;
  292. this.$emit('on-focus', focus);
  293. }
  294. }
  295. }
  296. </script>