schemeAdd.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back" title="方案信息"
  4. @clickLeft="back">
  5. </uni-nav-bar>
  6. <u-cell-group>
  7. <u-cell title="项目" arrow-direction="down">
  8. <uni-data-picker v-model="form.typeId" slot="value" :clear-icon='false' placeholder="请选择"
  9. :localdata="typeIdList" @change="typeOnchange">
  10. </uni-data-picker>
  11. </u-cell>
  12. <u-cell title="编码" arrow-direction="down">
  13. <u--input v-if="form.typeId != '2'" slot="value" placeholder="请输入" border="surround"
  14. v-model="form.code">
  15. </u--input>
  16. <view class="labels" slot="value" v-if="form.typeId == '2'">
  17. {{ form.code }}
  18. </view>
  19. </u-cell>
  20. <u-cell title="名称" arrow-direction="down">
  21. <u--input v-if="form.typeId == '2'" @click.native="selectProduct" slot="value" placeholder="请选择"
  22. border="surround" v-model="form.name">
  23. </u--input>
  24. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  25. v-model="form.name"></u--input>
  26. </u-cell>
  27. <u-cell title="型号" arrow-direction="down">
  28. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  29. v-model="form.categoryModel"></u--input>
  30. <view class="labels" slot="value" v-if="form.typeId == '2'">
  31. {{ form.categoryModel }}
  32. </view>
  33. </u-cell>
  34. <u-cell title="规格" arrow-direction="down">
  35. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  36. v-model="form.specification"></u--input>
  37. <view class="labels" slot="value" v-if="form.typeId == '2'">
  38. {{ form.specification }}
  39. </view>
  40. </u-cell>
  41. <u-cell title="仓库" arrow-direction="down">
  42. <template>
  43. <uni-data-picker v-if="form.typeId != '2'" v-model="form.warehouseId" slot="value"
  44. :clear-icon='false' placeholder="请选择" :localdata="warehouseList" @change="warehouseOnchange">
  45. </uni-data-picker>
  46. <u--input v-if="form.typeId == '2'" slot="value" placeholder="请输入" border="surround"
  47. v-model="form.warehouseName"></u--input>
  48. </template>
  49. </u-cell>
  50. <u-cell title="库存" arrow-direction="down">
  51. <!-- <u--input slot="value" placeholder="请输入" border="surround" v-model="form.warehouseNum"></u--input> -->
  52. <view class="labels" slot="value">
  53. {{ form.warehouseNum }}
  54. </view>
  55. </u-cell>
  56. <u-cell title="单位" arrow-direction="down">
  57. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  58. v-model="form.measureUnit"></u--input>
  59. <view class="labels" slot="value" v-if="form.typeId == '2'">
  60. {{ form.measureUnit }}
  61. </view>
  62. </u-cell>
  63. <u-cell title="数量" arrow-direction="down">
  64. <u--input slot="value" type="number" @input=" (val) =>inputChange(val,'totalCount')" placeholder="请输入"
  65. border="surround" v-model="form.totalCount"></u--input>
  66. </u-cell>
  67. <u-cell title="单价" arrow-direction="down">
  68. <u--input type="number" slot="value" @input="(val) =>inputChange(val,'singlePrice')" placeholder="请输入"
  69. border="surround" v-model="form.singlePrice"></u--input>
  70. </u-cell>
  71. <u-cell title="合计" arrow-direction="down">
  72. <view class="labels" slot="value">
  73. {{ form.settlementPrice }}
  74. </view>
  75. </u-cell>
  76. <u-cell title="详细内容" arrow-direction="down">
  77. <u--input slot="value" placeholder="请输入" border="surround" v-model="form.content"></u--input>
  78. </u-cell>
  79. <view class="footerButton">
  80. <u-button type="default" text="返回" @click="back"></u-button>
  81. <u-button type="primary" @click="save" text="保存"></u-button>
  82. </view>
  83. </u-cell-group>
  84. <u-toast ref="uToast"></u-toast>
  85. </view>
  86. </template>
  87. <script>
  88. export default {
  89. data() {
  90. return {
  91. form: {
  92. typeId: '2',
  93. code: '',
  94. name: '',
  95. categoryModel: '', // 型号
  96. specification: '', // 规格
  97. content: '', // 详细内容
  98. warehouseId: '', // 仓库
  99. warehouseNum: '', // 库存
  100. totalCount: '', // 数量
  101. measureUnit: '', // 单位
  102. singlePrice: '', // 单价
  103. settlementPrice: '', // 合计
  104. },
  105. typeIdList: [{
  106. text: '工时',
  107. value: '1'
  108. },
  109. {
  110. text: '零配件',
  111. value: '2'
  112. },
  113. {
  114. text: '差旅费',
  115. value: '3'
  116. }
  117. ],
  118. obtain: '主数据',
  119. warehouseList: [], // 仓库数据
  120. oldTypeId: '2', // 旧的项目选择
  121. }
  122. },
  123. onLoad(params) {
  124. let data = JSON.parse(params.data);
  125. if (data.code) {
  126. this.form = data;
  127. }
  128. console.log(data, 'params')
  129. this.obtain = params.obtain || '主数据'
  130. },
  131. created() {
  132. uni.$off('updateScheme');
  133. uni.$on('updateScheme', (data) => {
  134. this.form = {
  135. ...this.form,
  136. ...data
  137. };
  138. this.warehouseList = data.warehouseList.map((el) => {
  139. el.text = el.warehouse_name;
  140. el.value = el.warehouse_id;
  141. return el;
  142. });
  143. })
  144. },
  145. methods: {
  146. // 如果新的选择跟旧的一样 不做数据更改
  147. typeOnchange(e) {
  148. if (this.form.typeId == this.oldTypeId) {
  149. return;
  150. }
  151. this.oldTypeId = this.form.typeId;
  152. this.form = {
  153. typeId: e.detail.value[0].text,
  154. code: '',
  155. name: '',
  156. categoryModel: '', // 型号
  157. specification: '', // 规格
  158. content: '', // 详细内容
  159. warehouseId: '', // 仓库
  160. warehouseNum: '', // 库存
  161. totalCount: '', // 数量
  162. measureUnit: '', // 单位
  163. singlePrice: '', // 单价
  164. settlementPrice: '', // 合计
  165. }
  166. },
  167. warehouseOnchange(e) {
  168. },
  169. selectProduct() {
  170. uni.navigateTo({
  171. url: `/pages/salesServiceManagement/workOrder/components/selectProduct?obtain=${this.obtain}`
  172. })
  173. },
  174. save() {
  175. if (!this.form.name) {
  176. this.$refs.uToast.show({
  177. type: "warning",
  178. message: "请填写名称",
  179. })
  180. return;
  181. }
  182. uni.$emit('updateInfo', this.form);
  183. this.back();
  184. },
  185. inputChange(e, field) {
  186. // let value = e.replace(/[^\d]/g, '');
  187. // if (value.startsWith('0') && value.length > 1) {
  188. // value = value.replace(/^0+/, '');
  189. // }
  190. let value = '';
  191. if (field == 'singlePrice') {
  192. value = value.replace(/\./g, ''); // 如果不允许小数点,就移除所有小数点
  193. } else {
  194. value = e.replace(/[^\d]/g, '')
  195. if (value.startsWith('0') && value.length > 1) {
  196. value = value.replace(/^0+/, '');
  197. }
  198. }
  199. this.form[field] = value;
  200. let num1 = this.form.totalCount ? this.form.totalCount - 0 : 0;
  201. let num2 = this.form.singlePrice ? this.form.singlePrice - 0 : 0;
  202. this.form.settlementPrice = num1 * num2;
  203. },
  204. }
  205. }
  206. </script>
  207. <style scoped lang="scss">
  208. /deep/.u-cell__body__content {
  209. flex: none;
  210. margin-right: 16rpx;
  211. }
  212. .mainBox {
  213. padding-bottom: 84rpx;
  214. .labels {
  215. padding-left: 18rpx;
  216. }
  217. }
  218. .footerButton {
  219. width: 100%;
  220. height: 84rpx;
  221. display: flex;
  222. position: fixed;
  223. bottom: 0;
  224. /deep/.u-button {
  225. height: 100%;
  226. }
  227. >view {
  228. flex: 1;
  229. }
  230. }
  231. </style>