offer.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="container">
  3. <view class="title">关联耗材</view>
  4. <!-- 每一个耗材盒子区域 -->
  5. <view class="detail_box" v-for="(item, index) in goodList" :key="index">
  6. <view class="detail_box_item">
  7. <view class="item_key">耗材名称</view>
  8. <view class="item_value">{{ item.name }}</view>
  9. </view>
  10. <view class="detail_box_item">
  11. <view class="item_key">耗材数量</view>
  12. <view class="item_value">
  13. <uni-number-box v-model="item.num" :min="0" @change="bindChange($event, index)"></uni-number-box>
  14. </view>
  15. </view>
  16. <view class="detail_box_item">
  17. <view class="item_key">耗材单价</view>
  18. <view class="item_value">
  19. <input type="number" placeholder="请输入耗材单价" v-model="item.price" @blur="handleChangePrice($event, item)" />
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 添加耗材区域 -->
  24. <view class="add" @click="handleAdd">
  25. <text>+</text>
  26. 添加耗材
  27. </view>
  28. <!-- 合计费用区域 -->
  29. <view class="total">
  30. <view>合计费用</view>
  31. <view>{{ countMoney }}元</view>
  32. </view>
  33. <view class="title">维修师傅</view>
  34. <view class="box">
  35. <img src="../../static/images/repairsImg/people.png" />
  36. {{ worker }}
  37. </view>
  38. <view class="title2">手机</view>
  39. <view class="box">
  40. <img src="../../static/images/repairsImg/phone2.png" />
  41. {{ phone }}
  42. </view>
  43. <view class="btn" @click="handleSub">确认提交</view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. // 维修师傅
  51. worker: '张三',
  52. // 手机号码
  53. phone: '13659854589',
  54. // 耗材列表
  55. goodList: []
  56. }
  57. },
  58. computed: {
  59. // 合计费用
  60. countMoney() {
  61. let countMoney = 0
  62. this.goodList.forEach((ele) => {
  63. countMoney += Number(ele.num) * Number(ele.price)
  64. })
  65. if (countMoney) {
  66. return countMoney
  67. } else {
  68. return 0
  69. }
  70. }
  71. },
  72. onLoad(options) {
  73. console.log(options)
  74. if (options.type) {
  75. console.log('改价')
  76. }
  77. uni.$on('addConsumable', this.addConsumable)
  78. },
  79. methods: {
  80. // 单价输入框输入回调
  81. handleChangePrice(e, item) {
  82. // 验证输入单价格式 只能是数字,小数点最多两位
  83. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
  84. if (!reg.test(e.detail.value)) {
  85. uni.showToast({
  86. title: '请确定单价为数字,并且只能保留两位小数点',
  87. icon: 'none'
  88. })
  89. item.price = 0
  90. }
  91. },
  92. // 确认提交按钮回调
  93. handleSub() {
  94. if (!this.goodList.length) {
  95. uni.showToast({
  96. title: '请添加耗材',
  97. icon: 'none'
  98. })
  99. return
  100. }
  101. if (this.countMoney <= 0) {
  102. uni.showToast({
  103. title: '合计费用不能小于0元',
  104. icon: 'none'
  105. })
  106. return
  107. }
  108. uni.showModal({
  109. title: '提示',
  110. content: '确认提交吗?',
  111. success: (res) => {
  112. if (res.confirm) {
  113. uni.showToast({
  114. title: '提交成功',
  115. icon: 'success'
  116. })
  117. setTimeout(() => {
  118. uni.reLaunch({
  119. url: '/pagesRepairs/box/box'
  120. })
  121. }, 1500)
  122. console.log(this.goodList)
  123. console.log(this.countMoney)
  124. console.log(this.worker)
  125. console.log(this.phone)
  126. }
  127. }
  128. })
  129. },
  130. // 全局自定义事件
  131. addConsumable(e) {
  132. // console.log(e)
  133. // 判断是否存在相同的耗材
  134. let flag = this.goodList.some((ele) => {
  135. return ele.name === e.data
  136. })
  137. if (!flag) {
  138. this.goodList.push({
  139. name: e.data,
  140. num: 1,
  141. price: ''
  142. })
  143. }
  144. },
  145. // 耗材数量计数器改变回调
  146. bindChange(e, index) {
  147. // console.log(e)
  148. // console.log(index)
  149. if (e === 0) {
  150. this.goodList.splice(index, 1)
  151. }
  152. },
  153. // 添加耗材按钮回调
  154. handleAdd() {
  155. uni.navigateTo({
  156. url: '/pagesRepairs/addGoods/addGoods'
  157. })
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .container {
  164. box-sizing: border-box;
  165. padding: 0 30rpx;
  166. width: 100vw;
  167. height: 100vh;
  168. overflow-y: auto;
  169. .title {
  170. height: 109rpx;
  171. line-height: 109rpx;
  172. font-size: 36rpx;
  173. font-weight: bold;
  174. }
  175. .detail_box {
  176. box-sizing: border-box;
  177. margin-bottom: 46rpx;
  178. padding: 5rpx 30rpx 0;
  179. width: 690rpx;
  180. height: 284rpx;
  181. border-radius: 9rpx;
  182. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
  183. .detail_box_item {
  184. display: flex;
  185. justify-content: space-between;
  186. align-items: center;
  187. height: 92rpx;
  188. font-size: 32rpx;
  189. border-bottom: 1rpx solid #e5e5e5;
  190. .item_key {
  191. width: 150rpx;
  192. color: #808080;
  193. }
  194. .item_value {
  195. font-weight: bold;
  196. input {
  197. text-align: right;
  198. }
  199. }
  200. }
  201. }
  202. .add {
  203. display: flex;
  204. justify-content: center;
  205. align-items: center;
  206. width: 690rpx;
  207. height: 90rpx;
  208. color: #6fb6b8;
  209. font-size: 32rpx;
  210. border-radius: 9rpx;
  211. background-color: #ebf2f2;
  212. text {
  213. margin-right: 10rpx;
  214. font-size: 48rpx;
  215. }
  216. }
  217. .total {
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. margin: auto;
  222. width: 622rpx;
  223. height: 100rpx;
  224. font-size: 32rpx;
  225. font-weight: bold;
  226. border-bottom: 1rpx solid #e5e5e5;
  227. }
  228. .box {
  229. display: flex;
  230. align-items: center;
  231. height: 94rpx;
  232. font-size: 32rpx;
  233. border-radius: 10rpx;
  234. border: 1rpx solid #cccccc;
  235. img {
  236. margin: 0 14rpx 0 30rpx;
  237. width: 40rpx;
  238. height: 40rpx;
  239. }
  240. }
  241. .title2 {
  242. height: 126rpx;
  243. line-height: 126rpx;
  244. font-size: 36rpx;
  245. font-weight: bold;
  246. }
  247. .btn {
  248. display: flex;
  249. justify-content: center;
  250. align-items: center;
  251. margin: 194rpx 0 60rpx;
  252. height: 100rpx;
  253. color: #fff;
  254. font-size: 32rpx;
  255. border-radius: 12rpx;
  256. background-color: #6fb6b8;
  257. }
  258. }
  259. </style>