v1.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace zin;
  3. class productRoadmapBox extends wg
  4. {
  5. /**
  6. * Define widget properties.
  7. *
  8. * @var array
  9. * @access protected
  10. */
  11. protected static $defineProps = array(
  12. 'preProducts?: array', // 预设产品列表。
  13. 'products?: array', // 产品下拉列表。
  14. 'branchGroups?: array', // 产品分支分组列表。
  15. 'roadmapPlanGroups?: array', // 产品路标分组列表。
  16. 'storyGrades?: array' // 需求层级列表
  17. );
  18. public static function getPageCSS()
  19. {
  20. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  21. }
  22. public static function getPageJS()
  23. {
  24. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  25. }
  26. protected function build()
  27. {
  28. $productsBox = $this->initProductsBox();
  29. return div
  30. (
  31. setClass('productsBox'),
  32. on::click('.productsBox .addLine', 'window.addNewLine'),
  33. on::click('.productsBox .removeLine', 'window.removeLine'),
  34. on::change('.linkProduct .pick-value', 'window.refreshPicker(e.target)'),
  35. on::change('[name^=branch]', 'window.loadBranch'),
  36. on::change('[name^=storyGrade]', 'window.loadRoadmapPlans'),
  37. $productsBox
  38. );
  39. }
  40. protected function initProductsBox()
  41. {
  42. global $lang;
  43. list($preProducts, $products, $branchGroups, $roadmapPlanGroups, $storyGrades) = $this->prop(array('preProducts', 'products', 'branchGroups', 'roadmapPlanGroups', 'storyGrades'));
  44. $productsBox = array();
  45. foreach(array_values($preProducts) as $index => $productID)
  46. {
  47. $hasBranch = !empty($branchGroups[$productID]);
  48. $branches = isset($branchGroups[$productID]) ? $branchGroups[$productID] : array();
  49. $defaultBranch = !empty($branches) ? key($branches) : 0;
  50. $roadmapPlans = !empty($roadmapPlanGroups[$productID][$defaultBranch]) ? $roadmapPlanGroups[$productID][$defaultBranch] : array();
  51. /* Add label for options. */
  52. $roadmapPlanItems = array();
  53. foreach($roadmapPlans as $value => $text)
  54. {
  55. $type = strpos($value, '-') !== false ? substr($value, 0, strpos($value, '-')) : 'roadmap';
  56. $labelName = $type == 'roadmap' ? $lang->roadmap->common : $lang->productplan->shortCommon;
  57. $roadmapPlanItems[] = array('value' => $value, 'text' => $text, 'leading' => array('html' => "<span class='label gray-pale rounded-xl clip'>{$labelName}</span> "));
  58. }
  59. $productsBox[] = div
  60. (
  61. set::className('productBox flex'),
  62. formGroup
  63. (
  64. set::width('1/3'),
  65. setClass('distributeProduct text-clip'),
  66. set::required(true),
  67. set::label($lang->demand->distributeProduct),
  68. $index != 0 ? set::labelClass('hidden') : null,
  69. count($products) ? null : set::checkbox(array('text' => $lang->demand->addProduct, 'name' => 'addProduct', 'checked' => false)),
  70. on::change('[name=addProduct]', 'addProduct'),
  71. inputGroup
  72. (
  73. div
  74. (
  75. setClass('grow linkProduct w-1/2'),
  76. picker(set::name("product[$index]"), set::value($productID), set::items($products), set::last($productID), $hasBranch ? set::lastBranch($branches ? 0 : implode(',', $branches)) : null),
  77. input
  78. (
  79. setClass('hidden'),
  80. set::disabled(true),
  81. set::name("productName")
  82. )
  83. ),
  84. div
  85. (
  86. setClass('ml-px linkBranch'),
  87. $hasBranch ? null : setClass('hidden'),
  88. picker
  89. (
  90. set::name("branch[$index]"),
  91. set::items($branches),
  92. set::value($defaultBranch),
  93. set::emptyValue('')
  94. )
  95. )
  96. )
  97. ),
  98. formGroup
  99. (
  100. set::className('storyGradeBox'),
  101. set::width('1/5'),
  102. set::label($lang->demand->storyGrade),
  103. $index != 0 ? set::labelClass('hidden') : null,
  104. picker
  105. (
  106. set::className('storyGrade'),
  107. set::name("storyGrade[$index]"),
  108. set::required(true),
  109. set::items(isset($storyGrades[$productID]) ? $storyGrades[$productID] : array())
  110. )
  111. ),
  112. formGroup
  113. (
  114. set::width('1/2'),
  115. set::label($lang->demand->roadmapOrPlan),
  116. $index != 0 ? set::labelClass('hidden') : null,
  117. set::className('roadmapBox text-clip'),
  118. inputGroup
  119. (
  120. div
  121. (
  122. setClass('grow linkRoadmap w-1/2'),
  123. picker
  124. (
  125. set::name("roadmap[$index]"),
  126. set::items($roadmapPlanItems)
  127. )
  128. )
  129. )
  130. ),
  131. count($products) ? formGroup
  132. (
  133. set::label(''),
  134. set::labelClass('hidden'),
  135. set::className('actionsBox'),
  136. div
  137. (
  138. setClass('pl-2 flex self-center line-btn c-actions', $index == 0 ? 'first-action' : ''),
  139. btn
  140. (
  141. setClass('btn btn-link text-gray addLine'),
  142. icon('plus')
  143. ),
  144. btn
  145. (
  146. setClass('btn btn-link text-gray removeLine'),
  147. setClass($index == 0 && count(array_filter($preProducts)) <= 1 ? 'hidden' : ''),
  148. icon('trash')
  149. )
  150. )
  151. ) : null
  152. );
  153. }
  154. return $productsBox;
  155. }
  156. }