offer.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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() {
  73. uni.$on('addConsumable', this.addConsumable)
  74. },
  75. methods: {
  76. // 单价输入框输入回调
  77. handleChangePrice(e, item) {
  78. // 验证输入单价格式 只能是数字,小数点最多两位
  79. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
  80. if (!reg.test(e.detail.value)) {
  81. uni.showToast({
  82. title: '请确定单价为数字,并且只能保留两位小数点',
  83. icon: 'none'
  84. })
  85. item.price = 0
  86. }
  87. },
  88. // 确认提交按钮回调
  89. handleSub() {
  90. if (!this.goodList.length) {
  91. uni.showToast({
  92. title: '请添加耗材',
  93. icon: 'none'
  94. })
  95. return
  96. }
  97. if (this.countMoney <= 0) {
  98. uni.showToast({
  99. title: '合计费用不能小于0元',
  100. icon: 'none'
  101. })
  102. return
  103. }
  104. uni.showToast({
  105. title: '报价成功',
  106. icon: 'success'
  107. })
  108. setTimeout(() => {
  109. uni.reLaunch({
  110. url: '/pagesRepairs/box/box'
  111. })
  112. }, 1500)
  113. console.log(this.goodList)
  114. console.log(this.countMoney)
  115. console.log(this.worker)
  116. console.log(this.phone)
  117. },
  118. // 全局自定义事件
  119. addConsumable(e) {
  120. // console.log(e)
  121. // 判断是否存在相同的耗材
  122. let flag = this.goodList.some((ele) => {
  123. return ele.name === e.data
  124. })
  125. if (!flag) {
  126. this.goodList.push({
  127. name: e.data,
  128. num: 1,
  129. price: 0
  130. })
  131. }
  132. },
  133. // 耗材数量计数器改变回调
  134. bindChange(e, index) {
  135. // console.log(e)
  136. // console.log(index)
  137. if (e === 0) {
  138. this.goodList.splice(index, 1)
  139. }
  140. },
  141. // 添加耗材按钮回调
  142. handleAdd() {
  143. uni.navigateTo({
  144. url: '/pagesRepairs/addGoods/addGoods'
  145. })
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .container {
  152. box-sizing: border-box;
  153. padding: 0 30rpx;
  154. width: 100vw;
  155. height: 100vh;
  156. overflow-y: auto;
  157. .title {
  158. height: 109rpx;
  159. line-height: 109rpx;
  160. font-size: 36rpx;
  161. font-weight: bold;
  162. }
  163. .detail_box {
  164. box-sizing: border-box;
  165. margin-bottom: 46rpx;
  166. padding: 5rpx 30rpx 0;
  167. width: 690rpx;
  168. height: 284rpx;
  169. border-radius: 9rpx;
  170. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
  171. .detail_box_item {
  172. display: flex;
  173. justify-content: space-between;
  174. align-items: center;
  175. height: 92rpx;
  176. font-size: 32rpx;
  177. border-bottom: 1rpx solid #e5e5e5;
  178. .item_key {
  179. width: 150rpx;
  180. color: #808080;
  181. }
  182. .item_value {
  183. font-weight: bold;
  184. input {
  185. text-align: right;
  186. }
  187. }
  188. }
  189. }
  190. .add {
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. width: 690rpx;
  195. height: 90rpx;
  196. color: #6fb6b8;
  197. font-size: 32rpx;
  198. border-radius: 9rpx;
  199. background-color: #ebf2f2;
  200. text {
  201. margin-right: 10rpx;
  202. font-size: 48rpx;
  203. }
  204. }
  205. .total {
  206. display: flex;
  207. justify-content: space-between;
  208. align-items: center;
  209. margin: auto;
  210. width: 622rpx;
  211. height: 100rpx;
  212. font-size: 32rpx;
  213. font-weight: bold;
  214. border-bottom: 1rpx solid #e5e5e5;
  215. }
  216. .box {
  217. display: flex;
  218. align-items: center;
  219. height: 94rpx;
  220. font-size: 32rpx;
  221. border-radius: 10rpx;
  222. border: 1rpx solid #cccccc;
  223. img {
  224. margin: 0 14rpx 0 30rpx;
  225. width: 40rpx;
  226. height: 40rpx;
  227. }
  228. }
  229. .title2 {
  230. height: 126rpx;
  231. line-height: 126rpx;
  232. font-size: 36rpx;
  233. font-weight: bold;
  234. }
  235. .btn {
  236. display: flex;
  237. justify-content: center;
  238. align-items: center;
  239. margin: 194rpx 0 60rpx;
  240. height: 100rpx;
  241. color: #fff;
  242. font-size: 32rpx;
  243. border-radius: 12rpx;
  244. background-color: #6fb6b8;
  245. }
  246. }
  247. </style>