select.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="billing_box_bg">
  3. <app-tabs
  4. :tabs="tabs"
  5. :currentTab="tabIndex"
  6. @change="change"
  7. itemWidth="50%"
  8. />
  9. <view class="input-wrap">
  10. <app-search-module
  11. v-model="py"
  12. placeholder="请输入关键词,支持拼音首字母搜索"
  13. @search="searchFn"
  14. />
  15. </view>
  16. <view class="scroll-middle_bx">
  17. <scroll-view
  18. scroll-y
  19. scroll-with-animation
  20. class="tab-view"
  21. :scroll-top="scrollTop"
  22. >
  23. <div
  24. v-for="(item, index) in filterProductInfo"
  25. :key="index"
  26. class="tab-bar-item"
  27. :class="[classIndex == index ? 'active' : '']"
  28. :data-current="index"
  29. @tap.stop="swichClass"
  30. >
  31. <text>{{ item.className || "" }}</text>
  32. <text class="tag" v-if=" getSelectClassById(item.classId).bigCount > 0 || getSelectClassById(item.classId).smallCount > 0">
  33. <text v-if="getSelectClassById(item.classId).bigCount > 0 || getSelectClassById(item.classId).smallCount > 0">
  34. {{ `${getSelectClassById(item.classId).bigCount}` }}
  35. </text>
  36. <text v-if="getSelectClassById(item.classId).smallCount > 0">/</text>
  37. <text v-if="getSelectClassById(item.classId).smallCount > 0">{{getSelectClassById(item.classId).smallCount}}</text>
  38. </text>
  39. </div>
  40. </scroll-view>
  41. <scroll-view scroll-y class="right-box" v-if="tabIndex == 0" :scroll-into-view="scrollClassId">
  42. <!--内容部分 start -->
  43. <block v-if="!$util.isEmpty(filterProductInfo)">
  44. <view
  45. class="item_list_bx"
  46. v-for="(classItem, classIndex) in filterProductInfo"
  47. :key="classIndex"
  48. :id="`class_${classItem.classId}`"
  49. >
  50. <view class="item_list_title">
  51. {{ classItem.className }}
  52. </view>
  53. <template v-for="(productItem, productIndex) in classItem.child">
  54. <view
  55. :id="`class_${classItem.classId}_${productItem.id}`"
  56. :key="productIndex"
  57. >
  58. <Commondity
  59. :info="productItem"
  60. :bigCount="
  61. getSelectItemById(productItem.id, classItem.classId).bigCount
  62. "
  63. :smallCount="
  64. getSelectItemById(productItem.id, classItem.classId).smallCount
  65. "
  66. @customNum="customNum"
  67. @add="addEvent"
  68. @del="delEvent"
  69. ></Commondity>
  70. </view>
  71. <!-- <Commondity
  72. :type="COMMODITY_TYPE.CHANGE"
  73. @customNum="customNum"
  74. ></Commondity> -->
  75. </template>
  76. </view>
  77. </block>
  78. <block v-else>
  79. <app-wrapper-empty title="暂无数据" :is-empty="$util.isEmpty(filterProductInfo)" />
  80. </block>
  81. <!--内容部分 end -->
  82. </scroll-view>
  83. <block v-else>
  84. <view style="width:100%">
  85. <AppWrapperEmpty title="敬请期待" :is-empty="true" />
  86. </view>
  87. </block>
  88. </view>
  89. <!-- :maskClosable="false" -->
  90. <modal-module :show="isModel" @cancel="modalCancel" @click="affirm" :title="customData.itemName" color="#333" :size="32" padding="30rpx 30rpx">
  91. <template slot="customContent">
  92. <view class="select-cmd_bx" v-if="customData">
  93. <view class="kc"> 库存{{ customData.stock }} </view>
  94. <view class="num_bx">
  95. <input v-model="customData.bigCount" focus type="number" >扎
  96. <!-- <input v-model="customData.bigCount" :focus="isModel" @focus="allSelect" :selection-start="startIndex" :selection-end="endIndex" type="number" >扎-->
  97. <input v-model="customData.smallCount" type="number" style="margin-left:24upx" />支
  98. </view>
  99. </view>
  100. </template>
  101. </modal-module>
  102. <modal-module :show="showSubmitModel" @cancel="cancelEvent" @click="submitEvent" :title="confirmContent" color="#333" :size="32" padding="30rpx 30rpx" >
  103. </modal-module>
  104. <FooterCart :price="allPrice" :count="allCount" @confirm="confirmSelectEvent" ></FooterCart>
  105. </view>
  106. </template>
  107. <script>
  108. import AppSearchModule from "@/components/module/app-search";
  109. import AppTabs from "@/components/plugin/tabs";
  110. import AppWrapperEmpty from "@/components/app-wrapper-empty";
  111. import Commondity from "@/components/module/app-commodity";
  112. import FooterCart from "@/components/module/app-footer-cart";
  113. import ModalModule from "@/components/plugin/modal";
  114. import { COMMODITY_TYPE } from "@/utils/declare";
  115. import { chooseOrderProductApi } from "@/api/order/index";
  116. import productMins from "@/mixins/product";
  117. export default {
  118. name: "Billing", // 开单
  119. components: {
  120. AppTabs,
  121. AppSearchModule,
  122. AppWrapperEmpty,
  123. Commondity,
  124. ModalModule,
  125. FooterCart
  126. },
  127. mixins: [productMins],
  128. data() {
  129. return {
  130. pageType: "order_change",
  131. COMMODITY_TYPE,
  132. tabIndex: 0,
  133. tabs: [
  134. {
  135. name: "花材"
  136. },
  137. {
  138. name: "商品"
  139. }
  140. // {
  141. // name: '课程'
  142. // },
  143. ],
  144. isModel: false,
  145. customData: {
  146. bigCount: 0,
  147. smallCount: 0
  148. },
  149. showSubmitModel: false
  150. };
  151. },
  152. computed: {
  153. confirmContent() {
  154. let content = "确认下一步?";
  155. if (this.hasNoStock) {
  156. content = "有花材库存不足,确认下一步?";
  157. }
  158. return content;
  159. }
  160. },
  161. onUnload() {
  162. this.resetSelectInfoByType(this.pageType);
  163. },
  164. methods: {
  165. //自定义数量
  166. customNum(info) {
  167. this.isModel = true;
  168. this.customData = info;
  169. },
  170. modalCancel() {
  171. this.isModel = false;
  172. this.customData = {};
  173. }, // 取消 确认
  174. affirm(val) {
  175. if (val.index === 0) {
  176. this.modalCancel();
  177. } else {
  178. const {
  179. bigCount,
  180. smallCount,
  181. bigNum,
  182. bigUnit,
  183. smallNum,
  184. smallUnit,
  185. ratio
  186. } = this.customData;
  187. const ratioNum = Number(ratio);
  188. //超过库存时 设置为库存最大值
  189. if (
  190. Number(bigCount) * ratioNum + Number(smallCount) >
  191. Number(bigNum) * ratioNum + Number(smallNum)
  192. ) {
  193. uni.showToast({
  194. title: `库存只有${bigNum}${bigUnit}${smallNum}${smallUnit}`,
  195. icon: "none"
  196. });
  197. this.customData.bigCount = bigNum;
  198. this.customData.smallCount = smallNum;
  199. } else {
  200. this.updateItemEvent(this.customData);
  201. this.modalCancel();
  202. }
  203. }
  204. },
  205. cancelEvent() {
  206. this.showSubmitModel = false;
  207. },
  208. submitEvent(val) {
  209. if (val.index === 0) {
  210. this.cancelEvent();
  211. } else {
  212. console.log(444, this.selectList);
  213. uni.navigateBack({
  214. delta: 1
  215. });
  216. this.cancelEvent();
  217. }
  218. },
  219. async confirmSelectEvent() {
  220. try {
  221. if (this.selectList.length > 0) {
  222. const product = this.selectList.map(ele => {
  223. return {
  224. classId:ele.classId,
  225. productId: ele.id,
  226. bigNum: ele.bigCount,
  227. smallNum: ele.smallCount
  228. };
  229. });
  230. let params = {
  231. id: this.option.id,
  232. product: JSON.stringify(product)
  233. };
  234. await chooseOrderProductApi(params);
  235. this.$msg("修改成功");
  236. uni.navigateBack({
  237. delta: 1
  238. });
  239. } else {
  240. this.$msg("请选择花材");
  241. }
  242. } catch (error) {}
  243. },
  244. change(e) {
  245. if (this.tabIndex == e.index) {
  246. return false;
  247. } else {
  248. this.tabIndex = e.index;
  249. }
  250. },
  251. scrollTop() {}
  252. }
  253. };
  254. </script>
  255. <style lang="scss" scoped>
  256. .billing_box_bg {
  257. height: 100%;
  258. display: flex;
  259. flex-direction: column;
  260. .input-wrap {
  261. padding: 22upx 20upx 22upx 30upx;
  262. }
  263. .scroll-middle_bx {
  264. flex: 1;
  265. display: flex;
  266. width: 100%;
  267. height: 100%;
  268. overflow: hidden;
  269. }
  270. .tab-view {
  271. height: 100%;
  272. width: 170upx;
  273. flex-shrink: 0;
  274. background-color: #f0f2f6;
  275. .tab-bar-item {
  276. position: relative;
  277. width: 170upx;
  278. height: 90upx;
  279. box-sizing: border-box;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. font-size: 26upx;
  284. color: #444;
  285. font-weight: 400;
  286. .tag {
  287. display: flex;
  288. padding: 0 20upx;
  289. align-items: center;
  290. position: absolute;
  291. right: 0;
  292. top: 0;
  293. height: 32upx;
  294. background: #ff2842;
  295. border-radius: 16upx;
  296. color: #fff;
  297. font-size: 20upx;
  298. }
  299. &:last-child{
  300. margin-bottom: 110upx;
  301. }
  302. }
  303. .active {
  304. position: relative;
  305. color: $mainColor;
  306. font-size: 26upx;
  307. background: #fff;
  308. }
  309. .active::before {
  310. content: "";
  311. position: absolute;
  312. border-left: 8upx solid $mainColor;
  313. height: 100%;
  314. left: 0;
  315. }
  316. }
  317. .right-box {
  318. height: 100%;
  319. flex: 1;
  320. box-sizing: border-box;
  321. }
  322. .item_list_bx {
  323. padding: 40upx 16upx;
  324. &:last-child{
  325. margin-bottom: 70upx;
  326. }
  327. }
  328. .item_list_title {
  329. margin-bottom: 20upx;
  330. font-size: 30upx;
  331. font-weight: bold;
  332. color: #067a40;
  333. }
  334. .select-cmd_bx {
  335. & .kc {
  336. color: #999999;
  337. font-size: 28upx;
  338. font-weight: 400;
  339. margin-bottom: 60upx;
  340. text-align: center;
  341. margin-top: 10upx;
  342. }
  343. & .num_bx {
  344. display: flex;
  345. align-items: center;
  346. margin-bottom: 80upx;
  347. & > input {
  348. width: 212upx;
  349. height: 80upx;
  350. border: 1px solid #dddddd;
  351. border-radius: 4upx;
  352. text-align: center;
  353. margin-right: 24upx;
  354. }
  355. }
  356. }
  357. }
  358. </style>