changeseed.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view :class="[AppTheme]" class="contrin">
  3. <!-- 头部切换 -->
  4. <view class="head_case bg-primary">
  5. <view class="head_case_item" @click="caseheaditem(index)" v-for="(item, index) in typeset" :key="index"
  6. :class="[senumber === index ? 'head_case_item_back' : '']">
  7. <u-icon :name="item.iconname" :color="setbackcolor(index)" size="45"></u-icon>
  8. <view class="head_case_title">
  9. {{ item.casetitle }}
  10. <text v-if="index === 0">{{ landareanum }}㎡</text>
  11. </view>
  12. </view>
  13. </view>
  14. <!-- 种子列表 -->
  15. <view class="seedlist" v-if="senumber === 0">
  16. <view class="seed_item" v-for="(item, index) in orderseedlist" :key="index">
  17. <image class="seeditem_thumbnail" :src="item.seeditem.ripe_pic" mode="aspectFill"></image>
  18. <view class="seeditem_deti">
  19. <view class="seeditem_deti_title">{{ item.seeditem.seed_name }}</view>
  20. <view class="seeditem_deti_subtitle">
  21. 最低种植:{{ item.seeditem.min_plant_area }}㎡;产量:{{ item.seeditem.seed_yield }}kg/㎡</view>
  22. <view class="priceanum">
  23. <view class="sedprice text-neutral">¥{{ item.seeditem.price }}</view>
  24. <view class="unumber_box">
  25. <!-- <u-number-box v-model="item.seednum" @plus="plus(item,index)" @minus="mixin(item,index)" :max="num"></u-number-box> -->
  26. <u-icon size="35" color="#222" name="minus" @click="changeseednum('minus', index)"></u-icon>
  27. <view class="unumnum">{{ item.seednum }}</view>
  28. <u-icon size="35" color="#222" name="plus" @click="changeseednum('plus', index)"></u-icon>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class=""></view>
  35. <!-- 待播种 -->
  36. <view v-if="senumber === 1" class="seedlist">待播种</view>
  37. <!-- 种植中 -->
  38. <view v-if="senumber === 2" class="seedlist">种植中</view>
  39. <!-- 已成熟 -->
  40. <view v-if="senumber === 3" class="seedlist">已成熟</view>
  41. <view class="vacantplot">
  42. <view class="title_price">
  43. <view class="footer_case_title">空闲地块</view>
  44. <view class="footer_case_price">已选:{{ seedarea() }}/{{ landareanum }}㎡,总计:{{ seedtariff() }}元</view>
  45. </view>
  46. <u-button class=" button bg-linear-gradient" type="success" shape="square" size="medium"
  47. @click="configseed()">确认</u-button>
  48. </view>
  49. <!-- 通知 -->
  50. <view class="load_window">
  51. <u-toast ref="uToast" />
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import Landapi from '@/api/land/index.js';
  57. export default {
  58. data() {
  59. return {
  60. primary: this.$theme.primary,
  61. settingFile: getApp().globalData.siteinfo,
  62. // 订单信息
  63. ordermess: {},
  64. // 空闲土地面积
  65. landareanum: 0,
  66. //当前选中类型下标
  67. senumber: 0,
  68. typeset: [{
  69. casetitle: '空闲土地',
  70. iconname: 'hourglass-half-fill'
  71. }],
  72. //种子列表
  73. seeddatalist: [],
  74. //选中种子
  75. orderseedlist: [],
  76. // 选择完毕种子后订单信息
  77. seedordermy: {},
  78. //追加种子订单
  79. addseedparams: null,
  80. orderseed: {}
  81. };
  82. },
  83. onLoad(options) {
  84. let params = JSON.parse(options.params);
  85. this.orderseed = params.seeds;
  86. this.landareanum = parseInt(params.selelanditemtext.area);
  87. this.vueinit();
  88. this.getList();
  89. },
  90. methods: {
  91. //初始化页面所需数据
  92. vueinit() {
  93. var that = this;
  94. // that.ordermess = that.$store.state.landleaseorder;
  95. },
  96. //进入页面获取种子数据
  97. getList() {
  98. var that = this;
  99. Landapi.seed_list({
  100. type: that.senumber + 1,
  101. p: 1
  102. }).then(res => {
  103. if (res.status == 1) {
  104. that.orderseedlist = [];
  105. that.seeddatalist = res.data;
  106. that.seeddatalist.forEach((item, index) => {
  107. that.orderseedlist.push({
  108. //种子详情
  109. seeditem: item,
  110. //种植面积
  111. seednum: 0
  112. });
  113. });
  114. that.orderseed.forEach((item, index) => {
  115. that.orderseedlist.forEach((item2, index2) => {
  116. if (item.seeditem.id === item2.seeditem.id) {
  117. that.orderseedlist[index2].seednum = that.orderseed[index]
  118. .seednum + that.orderseedlist[index2].seednum;
  119. }
  120. });
  121. });
  122. } else {
  123. that.$api.msg('获取种子数据失败!');
  124. }
  125. });
  126. },
  127. //设置图标颜色
  128. setbackcolor(senumber) {
  129. if (senumber === this.senumber) {
  130. return '#FFFFFF';
  131. } else {
  132. return '#56AB2F';
  133. }
  134. },
  135. //切换选中模块
  136. caseheaditem(senumber) {
  137. this.senumber = senumber;
  138. this.getList();
  139. },
  140. //更改步进器值
  141. changeseednum(changtype, index) {
  142. var that = this;
  143. if (that.orderseedlist.length > 0) {
  144. if (changtype === 'minus') {
  145. if (that.orderseedlist[index].seednum > that.orderseedlist[index].seeditem.min_plant_area) {
  146. that.orderseedlist[index].seednum = that.orderseedlist[index].seednum - 1;
  147. } else {
  148. if (that.orderseedlist[index].seednum - that.orderseedlist[index].seeditem.min_plant_area >=
  149. 0) {
  150. that.orderseedlist[index].seednum = that.orderseedlist[index].seednum - that.orderseedlist[
  151. index].seeditem.min_plant_area;
  152. }
  153. }
  154. } else if (changtype === 'plus') {
  155. let ocedlandarea = 0;
  156. that.orderseedlist.forEach((item, index) => {
  157. ocedlandarea = ocedlandarea + item.seednum;
  158. });
  159. //判断当前可用面积是否有剩余
  160. if (ocedlandarea < that.landareanum) {
  161. //判断是否满足最低种植面积,满足则每次+1,否则补充为最低种植面积
  162. if (that.orderseedlist[index].seednum >= that.orderseedlist[index].seeditem.min_plant_area) {
  163. //判断土地是否满足增加种植量
  164. if (that.landareanum - ocedlandarea >= 1) {
  165. that.orderseedlist[index].seednum = that.orderseedlist[index].seednum + 1;
  166. } else {
  167. that.$refs.uToast.show({
  168. title: '该地块可用面积不足了~',
  169. type: 'error'
  170. });
  171. }
  172. } else {
  173. //判断土地是否满足增加最低种植量
  174. if (that.landareanum - ocedlandarea >= that.orderseedlist[index].seeditem.min_plant_area) {
  175. that.orderseedlist[index].seednum = that.orderseedlist[index].seednum + that
  176. .orderseedlist[index].seeditem.min_plant_area;
  177. } else {
  178. that.$refs.uToast.show({
  179. title: '该地块可用面积不足了~',
  180. type: 'error'
  181. });
  182. }
  183. }
  184. } else {
  185. that.$refs.uToast.show({
  186. title: '该地块选择的种子已经够了,可以下单了~',
  187. type: 'success'
  188. });
  189. }
  190. }
  191. }
  192. },
  193. //反馈信息
  194. showToast(type, promptstatement) {
  195. var that = this;
  196. that.$refs.uToast.show({
  197. type: type,
  198. title: promptstatement
  199. });
  200. },
  201. // 实时计算已选种子占用土地面积
  202. seedarea() {
  203. var comattribute = 0;
  204. this.orderseedlist.forEach(item => {
  205. comattribute = comattribute + item.seednum;
  206. });
  207. return comattribute;
  208. },
  209. // 实时计算已选种子总金额
  210. seedtariff() {
  211. var comattribute = 0;
  212. this.orderseedlist.forEach(item => {
  213. comattribute += item.seednum * parseInt(item.seeditem.price);
  214. });
  215. return comattribute;
  216. },
  217. //确定选择完毕种子
  218. configseed() {
  219. var that = this;
  220. let orderlist = that.orderseedlist;
  221. that.orderseedlist = [];
  222. orderlist.forEach((item, index) => {
  223. if (item.seednum !== 0) {
  224. that.orderseedlist.push(item);
  225. }
  226. });
  227. that.seedordermy = {
  228. seedtariff: that.seedtariff(),
  229. seedarea: that.seedarea(),
  230. allarea: that.landareanum,
  231. orderseedlist: that.orderseedlist
  232. };
  233. that.ordermess.seedordermy = that.seedordermy;
  234. let params = {
  235. setupseed: true,
  236. ordermess: that.ordermess
  237. };
  238. let pages = getCurrentPages();
  239. let prevPage = pages[pages.length - 2]; //上一页页面实例
  240. if (prevPage.$vm) {
  241. prevPage.$vm.ordermess.seedordermy = that.ordermess.seedordermy; //修改上一页data里面的sercode参数值
  242. prevPage.$vm.calprice();
  243. }
  244. uni.navigateBack({
  245. //uni.navigateTo跳转的返回,默认1为返回上一级
  246. delta: 1
  247. });
  248. }
  249. }
  250. };
  251. </script>
  252. <style lang="scss">
  253. .contrin {
  254. background-color: #fafafa;
  255. min-height: 100vh;
  256. }
  257. .head_case {
  258. display: flex;
  259. justify-content: center;
  260. margin-top: 20rpx;
  261. }
  262. .head_case_item {
  263. width: 100%;
  264. text-align: center;
  265. padding: 25rpx 0;
  266. }
  267. .head_case_title {
  268. font-size: 24rpx;
  269. margin-top: 15rpx;
  270. }
  271. .head_case_item_back {
  272. // background-color: #56ab2f;
  273. color: #ffffff;
  274. }
  275. .seedlist {
  276. margin: 0 2.5%;
  277. width: 95%;
  278. }
  279. .seed_item {
  280. display: flex;
  281. justify-content: flex-start;
  282. align-items: center;
  283. margin: 25rpx 0;
  284. background-color: #ffffff;
  285. border-radius: 15rpx;
  286. box-shadow: 2px 4px 12px rgba(0, 0, 0, 0.08);
  287. }
  288. .seeditem_thumbnail {
  289. width: 220rpx;
  290. height: 220rpx;
  291. border-radius: 10rpx;
  292. }
  293. .seeditem_deti {
  294. margin-left: 35rpx;
  295. }
  296. .seeditem_deti_title {
  297. color: #000000;
  298. font-size: 30rpx;
  299. }
  300. .seeditem_deti_subtitle {
  301. font-size: 26rpx;
  302. color: #999999;
  303. margin: 25rpx 0 50rpx 0;
  304. }
  305. .priceanum {
  306. display: flex;
  307. justify-content: space-between;
  308. align-items: center;
  309. }
  310. .sedprice {
  311. // color: red;
  312. font-size: 32rpx;
  313. font-weight: 800;
  314. }
  315. .load_window {
  316. position: fixed;
  317. top: 50%;
  318. left: 50%;
  319. width: 100%;
  320. transform: translate(-50%, -50%);
  321. }
  322. .unumber_box {
  323. display: flex;
  324. justify-content: flex-start;
  325. align-items: center;
  326. }
  327. .unumnum {
  328. font-size: 28rpx;
  329. color: rgb(50, 50, 51);
  330. margin: 0 25rpx;
  331. }
  332. .vacantplot {
  333. position: fixed;
  334. width: 100%;
  335. padding: 10rpx 20rpx;
  336. bottom: env(safe-area-inset-bottom);
  337. background-color: #FFFFFF;
  338. // background: transparent;
  339. display: flex;
  340. justify-content: space-between;
  341. .button {
  342. color: #fff;
  343. }
  344. }
  345. .title_price {}
  346. .footer_case_title {
  347. font-size: 30rpx;
  348. color: #000000;
  349. }
  350. .footer_case_price {
  351. font-size: 24rpx;
  352. color: #666;
  353. margin-top: 10rpx;
  354. }
  355. </style>