form.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <zj-page-layout hasFooter>
  4. <view class="all-container">
  5. <view class="top-container card">
  6. <view class="main">
  7. <image :src="cimg" mode="aspectFill" v-if="cimg"></image>
  8. <view class="name">{{cname}}</view>
  9. </view>
  10. <view class="tips">温馨提示:机器状况将影响预估回收价,请准确填写</view>
  11. </view>
  12. <view class="item-container card" v-for="(item, index) in attrList.filter((it, idx) => idx <= attrIndex || it.goodsCategoryItems.some(o => o.active))" :key="index">
  13. <view class="main">
  14. <view class="label">{{item.name}}</view>
  15. <view class="right" v-if="item.typeOption == 'MANY' && item.open">
  16. <view class="btn" @tap="confirmOption(index)">确认</view>
  17. </view>
  18. <view class="right" @tap="clickAction(index)" v-else>
  19. <view class="value" v-if="!item.open || item.goodsCategoryItems.some(o => o.active)">
  20. {{item.typeOption == 'SIGIN' ? (item.goodsCategoryItems.find(o => o.active) ? item.goodsCategoryItems.find(o => o.active).dictName : '') : item.goodsCategoryItems.filter(o => o.active).map(o => o.dictName).join('、')}}
  21. </view>
  22. <u-icon name="arrow-down-fill" size="12" color="#999999"></u-icon>
  23. </view>
  24. </view>
  25. <view class="options" v-show="item.open">
  26. <view class="it" :class="it.active || it.activeWait ? 'active' : ''" v-for="(it, idx) in item.goodsCategoryItems" :key="idx" @tap="clickOption(index, idx)">{{it.dictName}}<u-icon name="checkmark-circle-fill" size="20" color="#3D8FFD" v-if="it.active || it.activeWait"></u-icon></view>
  27. </view>
  28. </view>
  29. </view>
  30. <template slot="footer">
  31. <view class="footer-btn-group">
  32. <u-button type="primary" shape="circle" text="立即换新" :disabled="!attrList.every(item => item.goodsCategoryItems.some(o => o.active))" @click="submitData"></u-button>
  33. </view>
  34. </template>
  35. </zj-page-layout>
  36. <!-- #endif -->
  37. <!-- #ifndef H5 -->
  38. <web-view :src="webViewHref(`/packageGoods/pages/tradein/form`, pam, crossPagePam)" @message="crossPage.$listener"></web-view>
  39. <!-- #endif -->
  40. </template>
  41. <script>
  42. // #ifdef H5
  43. export default {
  44. data() {
  45. return {
  46. pid: '',
  47. cid: '',
  48. cname: '',
  49. cimg: '',
  50. attrList: [],
  51. attrIndex: 0,
  52. }
  53. },
  54. onLoad({pid, cid, cname, cimg}) {
  55. this.pid = pid;
  56. this.cid = cid;
  57. this.cname = cname;
  58. this.cimg = cimg;
  59. this.getAttrList();
  60. },
  61. methods: {
  62. // 获取属性
  63. getAttrList() {
  64. this.$api.get('/trade/listCategoryItem', {
  65. mainId: this.cid,
  66. }).then(res => {
  67. res.data.forEach(item => {
  68. item.open = false;
  69. item.goodsCategoryItems.forEach(it => {
  70. it.active = false;
  71. it.activeWait = false;
  72. })
  73. })
  74. res.data[0].open = true;
  75. this.attrList = res.data;
  76. })
  77. },
  78. // 点击属性值
  79. clickAction(index) {
  80. for(let i=0; i < this.attrList.length; i++) {
  81. if(this.attrList[i].typeOption == 'MANY' && this.attrList[i].goodsCategoryItems.every(o => !o.active) && this.attrList[i].open) {
  82. return this.$toast('请确认');
  83. }
  84. }
  85. this.attrList.forEach(item => {
  86. item.open = false;
  87. })
  88. this.attrList[index].open = true;
  89. const type = this.attrList[index].typeOption;
  90. // 多选
  91. if(type == 'MANY') {
  92. this.attrList[index].goodsCategoryItems.forEach(item => {
  93. item.active = false;
  94. })
  95. }
  96. },
  97. // 点击选项
  98. clickOption(index, idx) {
  99. const type = this.attrList[index].typeOption;
  100. // 单选
  101. if(type == 'SIGIN') {
  102. this.attrList[index].open = false;
  103. if(this.attrList[index + 1] && this.attrList[index + 1].goodsCategoryItems.every(o => !o.active)) {
  104. this.attrList[index + 1].open = true;
  105. }
  106. this.attrList[index].goodsCategoryItems.forEach(item => {
  107. item.active = false;
  108. })
  109. this.attrList[index].goodsCategoryItems[idx].active = true;
  110. this.attrIndex = index + 1;
  111. }
  112. // 多选
  113. else {
  114. this.attrList[index].goodsCategoryItems[idx].activeWait = !this.attrList[index].goodsCategoryItems[idx].activeWait;
  115. }
  116. },
  117. // 多选确认
  118. confirmOption(index, idx) {
  119. if(this.attrList[index].goodsCategoryItems.every(o => !o.activeWait)) {
  120. return this.$toast('请选择');
  121. }
  122. this.attrList[index].goodsCategoryItems.forEach(item => {
  123. if(item.activeWait) {
  124. item.active = true;
  125. }
  126. })
  127. this.attrList[index].open = false;
  128. if(this.attrList[index + 1] && this.attrList[index + 1].goodsCategoryItems.every(o => !o.active)) {
  129. this.attrList[index + 1].open = true;
  130. }
  131. this.attrIndex = index + 1;
  132. },
  133. // 提交
  134. submitData() {
  135. let activeList = [];
  136. this.attrList.forEach(item => {
  137. if(item.typeOption == 'SIGIN') {
  138. activeList.push(item.goodsCategoryItems.find(o => o.active)).id
  139. }else {
  140. activeList.push(...item.goodsCategoryItems.filter(o => o.active))
  141. }
  142. })
  143. let ids = activeList.map(o => o.id).join(',');
  144. this.$navToPage({
  145. url: `/packageGoods/pages/order?tradeIds=${ids}`
  146. }, 'redirectTo')
  147. }
  148. }
  149. }
  150. // #endif
  151. // #ifndef H5
  152. export default {
  153. data() {
  154. return {
  155. pam: {},
  156. }
  157. },
  158. onLoad(pam) {
  159. this.pam = pam;
  160. }
  161. }
  162. // #endif
  163. </script>
  164. <style lang="scss" scoped>
  165. .all-container {
  166. padding: 20rpx;
  167. }
  168. .card {
  169. @include zj-card;
  170. }
  171. .top-container {
  172. .main {
  173. display: flex;
  174. align-items: center;
  175. padding: 30rpx;
  176. image {
  177. width: 80rpx;
  178. height: 80rpx;
  179. }
  180. .name {
  181. margin-left: 20rpx;
  182. font-size: 32rpx;
  183. font-weight: 600;
  184. }
  185. }
  186. .tips {
  187. background: #f5f5f5;
  188. font-size: 24rpx;
  189. padding: 30rpx;
  190. color: $sec-font;
  191. }
  192. }
  193. .item-container {
  194. padding: 40rpx 30rpx;
  195. margin-top: 20rpx;
  196. .main {
  197. display: flex;
  198. align-items: center;
  199. justify-content: space-between;
  200. .label {
  201. font-size: 32rpx;
  202. font-weight: 600;
  203. }
  204. .right {
  205. display: flex;
  206. align-items: center;
  207. .btn {
  208. color: $theme-color;
  209. font-size: 32rpx;
  210. font-weight: 500;
  211. }
  212. .value {
  213. font-size: 28rpx;
  214. margin-right: 10rpx;
  215. }
  216. }
  217. }
  218. .options {
  219. padding-top: 10rpx;
  220. .it {
  221. font-size: 28rpx;
  222. background: #f5f5f5;
  223. height: 88rpx;
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. margin-top: 20rpx;
  228. position: relative;
  229. font-weight: 600;
  230. border-radius: 10rpx;
  231. &.active {
  232. background: rgba($color: $theme-color, $alpha: .15);
  233. }
  234. ::v-deep .u-icon {
  235. position: absolute;
  236. right: 26rpx;
  237. top: 26rpx;
  238. }
  239. }
  240. }
  241. }
  242. </style>