index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const getTime = require("../../utils/getTime"),
  2. deleteMark = require("../../utils/Check");
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. fromList: {
  9. type: Array,
  10. value: []
  11. },
  12. CompletedOrNot: {
  13. type: Function
  14. }, //完成与否回调
  15. },
  16. options: {
  17. multipleSlots: true
  18. },
  19. /**
  20. * 组件的初始数据
  21. */
  22. data: {
  23. endTime: "", //结束时间
  24. selectTime: "", //选择时间
  25. sexActions: [{
  26. name: '男'
  27. }, {
  28. name: '女'
  29. }],
  30. seleteSexShow: false
  31. },
  32. lifetimes: {
  33. attached: function () {
  34. this.setData({
  35. endTime: getTime.formatTime(new Date(), '-').split(' ')[0]
  36. })
  37. }
  38. },
  39. /**
  40. * 组件的方法列表
  41. */
  42. methods: {
  43. /* 性别选择器 */
  44. seleteSex(e) {
  45. this.setData({
  46. seleteSexShow: true
  47. })
  48. },
  49. handleSex(e) {
  50. let index = this.data.fromList.findIndex(v => v.type == 'sex');
  51. if (index) this.setData({
  52. ['fromList[' + index + '].value']: e.detail.name,
  53. seleteSexShow: false
  54. })
  55. console.log(this.data.fromList[index])
  56. },
  57. cancel() {
  58. this.setData({
  59. seleteSexShow: false
  60. })
  61. },
  62. /* 输入 */
  63. inputChange(e) {
  64. let {
  65. index,
  66. item
  67. } = e.currentTarget.dataset;
  68. item.value = deleteMark.queryStr(e.detail);
  69. item.error = item.required && item.value == '' ? true : false;
  70. let fromList = this.data.fromList;
  71. fromList[index] = item;
  72. if (item.callback) item.callback(item);
  73. this.setData({
  74. fromList
  75. })
  76. this.statistics();
  77. },
  78. /* 日期选择器 */
  79. bindDateChange(e) {
  80. const {
  81. index
  82. } = e.currentTarget.dataset;
  83. let fromList = this.data.fromList;
  84. fromList[index].value = e.detail.value;
  85. fromList[index].error = false;
  86. this.setData({
  87. fromList
  88. })
  89. this.statistics();
  90. },
  91. /* 清空输入框 */
  92. inputClear(e) {
  93. console.log("清空", e.target.dataset.item.label)
  94. this.statistics();
  95. },
  96. /* 统计是否完成全部必填项 */
  97. statistics() {
  98. let list = this.data.fromList,
  99. sumCount = 0,
  100. count = 0;
  101. for (let i = 0; i < list.length; i++) {
  102. if (list[i].required) {
  103. sumCount++;
  104. if (list[i].value != "") count++;
  105. }
  106. }
  107. // console.log("必填总数", sumCount, '已填', count)
  108. this.triggerEvent("CompletedOrNot", sumCount == count)
  109. },
  110. /* 提交 */
  111. getData() {
  112. let list = this.data.fromList,
  113. returnData = {},
  114. isReturn = true;
  115. for (let i = 0; i < list.length; i++) {
  116. if (list[i].required && list[i].value == "") {
  117. list[i].error = true;
  118. isReturn = false;
  119. } else {
  120. returnData[list[i].valueName] = list[i].value;
  121. }
  122. }
  123. this.setData({
  124. fromList: list
  125. })
  126. return {
  127. returnData,
  128. isReturn
  129. }
  130. }
  131. }
  132. })