productModal.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <u-mask class="productModal" :show="isShow" :mask-click-able="false">
  3. <view class="product-con">
  4. <view class="product-main">
  5. <view class="list-item-tit">
  6. <view class="item-tit ellipsis-one" :style="{borderColor: $config('primaryColor')}">{{infoData && infoData.productName}}</view>
  7. </view>
  8. <view class="list-item-con flex align_center justify_between">
  9. <view class="pimgs">
  10. <u-image :src="infoData && infoData.productMainPic && infoData.productMainPic.imageUrl?infoData.productMainPic.imageUrl:`../../static/${theme}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  11. </view>
  12. <view class="flex_1">
  13. <view>产品编码:{{infoData && infoData.productCode || '--'}}</view>
  14. <view class="padding_3">原厂编码:{{infoData && infoData.productOrigCode || '--'}}</view>
  15. <view v-if="infoData && (infoData.warehouseName || infoData.warehouseLocationName)">仓库仓位:{{infoData && infoData.warehouseName}} > {{infoData && infoData.warehouseLocationName}}</view>
  16. </view>
  17. </view>
  18. <u-form class="form-content" :model="form" :error-type="['toast']" ref="uForm" label-width="180">
  19. <u-form-item label="销售单价" required prop="price">
  20. <u-input class="form-item" v-model="form.price" @input="numberToFixed('price',2,999999)" placeholder="请输入销售单价" :clearable="false" type="digit" input-align="right" style="margin-right: 8upx;" />元
  21. </u-form-item>
  22. <u-form-item label="销售数量" required prop="qty">
  23. <view style="text-align: right;width: 100%;">
  24. <u-number-box class="form-item" input-height="60" v-model="form.qty" :min="1" :max="999999" @change="numChange"></u-number-box>
  25. </view>
  26. </u-form-item>
  27. </u-form>
  28. </view>
  29. <view class="product-footer">
  30. <view class="button-cancel" @click="isShow=false">取消</view>
  31. <view class="button-confirm" @click="handleConfirm">确定</view>
  32. </view>
  33. </view>
  34. </u-mask>
  35. </template>
  36. <script>
  37. import { numberToFixed } from '@/libs/tools'
  38. export default {
  39. props: {
  40. openModal: { // 弹框显示状态
  41. type: Boolean,
  42. default: false
  43. },
  44. infoData: {
  45. tyoe: Object,
  46. default: ()=>{
  47. return null
  48. }
  49. },
  50. },
  51. data() {
  52. return {
  53. isShow: this.openModal, // 是否打开弹框
  54. theme: '',
  55. form: {
  56. price: null,
  57. qty: 1,
  58. },
  59. rules: {
  60. price: [ { required: true, message: '请输入销售单价', trigger: ['change','blur'] } ],
  61. qty: [ { required: true, type: 'number', message: '请输入销售数量', trigger: 'blur' } ]
  62. },
  63. }
  64. },
  65. mounted() {
  66. this.$refs.uForm.setRules(this.rules)
  67. this.theme = getApp().globalData.theme
  68. },
  69. methods: {
  70. // 确认
  71. handleConfirm(){
  72. this.$refs.uForm.validate(valid => {
  73. if (valid) {
  74. console.log('验证通过')
  75. this.$emit('confirm', this.form)
  76. } else {
  77. console.log('验证失败')
  78. }
  79. })
  80. },
  81. // 小数点后两位
  82. numberToFixed: function (key, num, max) {
  83. let val = this.form[key]
  84. let ret = numberToFixed(val, num, max)
  85. this.$nextTick(() => {
  86. this.form[key] = ret
  87. })
  88. },
  89. numChange(val){
  90. if (val.value < 1){
  91. this.$nextTick(() => {
  92. this.form.qty = 0
  93. })
  94. } else if (val.value > 999999){
  95. this.$nextTick(() => {
  96. this.form.qty = 999999
  97. })
  98. }else{
  99. this.form.qty = Number(val.value)
  100. }
  101. },
  102. },
  103. watch: {
  104. // 父页面传过来的弹框状态
  105. openModal (newValue, oldValue) {
  106. this.isShow = newValue
  107. },
  108. // 重定义的弹框状态
  109. isShow (newValue, oldValue) {
  110. if (!newValue) {
  111. this.$emit('close')
  112. }
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. .productModal{
  119. width: 100%;
  120. height: 100%;
  121. .text-c{
  122. text-align: center;
  123. }
  124. .padding_3{
  125. padding: 6upx 0;
  126. }
  127. .product-con{
  128. width: 78%;
  129. margin: 45% auto 0;
  130. background-color: #fff;
  131. border-radius: 24upx;
  132. .product-main{
  133. padding: 20upx 30upx 0;
  134. .list-item-tit{
  135. padding-bottom: 12upx;
  136. border-bottom: 1px solid #e4e7ed;
  137. .item-tit{
  138. font-weight: bold;
  139. color: rgb(48, 49, 51);
  140. font-size: 28upx;
  141. padding-left: 10upx;
  142. border-left: 6upx solid #000;
  143. line-height: 1;
  144. }
  145. }
  146. .list-item-con{
  147. padding: 14upx 0 16upx;
  148. font-size: 26upx;
  149. .pimgs{
  150. margin-right: 16upx;
  151. }
  152. }
  153. .form-content{
  154. border-top: 1px dashed #e4e7ed;
  155. .form-item{
  156. text-align: right;
  157. }
  158. }
  159. }
  160. .product-footer{
  161. font-size: 30upx;
  162. display: flex;
  163. justify-content: space-between;
  164. align-items: center;
  165. text-align: center;
  166. border-top: 1upx solid #E5E5E5;
  167. .button-cancel{
  168. color: #999;
  169. border-right: 1upx solid #E5E5E5;
  170. flex-grow: 1;
  171. padding: 20upx 0;
  172. }
  173. .button-confirm{
  174. color: #2A86F4;
  175. flex-grow: 1;
  176. padding: 20upx 0;
  177. }
  178. }
  179. }
  180. }
  181. </style>