schemeAdd.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. import { getIdWarehouseList } from '@/api/salesServiceManagement/workOrder/index.js'
  89. export default {
  90. data() {
  91. return {
  92. form: {
  93. typeId: '2',
  94. code: '',
  95. name: '',
  96. categoryModel: '', // 型号
  97. specification: '', // 规格
  98. content: '', // 详细内容
  99. warehouseId: '', // 仓库
  100. warehouseNum: '', // 库存
  101. totalCount: '', // 数量
  102. measureUnit: '', // 单位
  103. singlePrice: '', // 单价
  104. settlementPrice: '', // 合计
  105. },
  106. typeIdList: [{
  107. text: '工时',
  108. value: '1'
  109. },
  110. {
  111. text: '零配件',
  112. value: '2'
  113. },
  114. {
  115. text: '差旅费',
  116. value: '3'
  117. }
  118. ],
  119. obtain: '主数据',
  120. warehouseList: [], // 仓库数据
  121. oldTypeId: '2', // 旧的项目选择
  122. }
  123. },
  124. onLoad(params) {
  125. let data = JSON.parse(params.data);
  126. if (data.code) {
  127. this.form = data;
  128. }
  129. console.log(data, 'params')
  130. this.obtain = params.obtain || '主数据'
  131. },
  132. created() {
  133. uni.$off('updateScheme');
  134. uni.$on('updateScheme', (data) => {
  135. this.form = {
  136. ...this.form,
  137. ...data
  138. };
  139. this.warehouseList = data.warehouseList.map((el) => {
  140. el.text = el.warehouse_name;
  141. el.value = el.warehouse_id;
  142. return el;
  143. });
  144. })
  145. },
  146. methods: {
  147. // 如果新的选择跟旧的一样 不做数据更改
  148. typeOnchange(e) {
  149. if (this.form.typeId == this.oldTypeId) {
  150. return;
  151. }
  152. this.oldTypeId = this.form.typeId;
  153. this.form = {
  154. typeId: e.detail.value[0].text,
  155. code: '',
  156. name: '',
  157. categoryModel: '', // 型号
  158. specification: '', // 规格
  159. content: '', // 详细内容
  160. warehouseId: '', // 仓库
  161. warehouseNum: '', // 库存
  162. totalCount: '', // 数量
  163. measureUnit: '', // 单位
  164. singlePrice: '', // 单价
  165. settlementPrice: '', // 合计
  166. }
  167. },
  168. warehouseOnchange(e) {
  169. },
  170. selectProduct() {
  171. uni.navigateTo({
  172. url: `/pages/salesServiceManagement/workOrder/components/selectProduct?obtain=${this.obtain}`
  173. })
  174. },
  175. save() {
  176. if (!this.form.name) {
  177. this.$refs.uToast.show({
  178. type: "warning",
  179. message: "请填写名称",
  180. })
  181. return;
  182. }
  183. uni.$emit('updateInfo', this.form);
  184. this.back();
  185. },
  186. inputChange(e, field) {
  187. // let value = e.replace(/[^\d]/g, '');
  188. // if (value.startsWith('0') && value.length > 1) {
  189. // value = value.replace(/^0+/, '');
  190. // }
  191. let value = '';
  192. if (field == 'singlePrice') {
  193. value = value.replace(/\./g, ''); // 如果不允许小数点,就移除所有小数点
  194. } else {
  195. value = e.replace(/[^\d]/g, '')
  196. if (value.startsWith('0') && value.length > 1) {
  197. value = value.replace(/^0+/, '');
  198. }
  199. }
  200. this.form[field] = value;
  201. let num1 = this.form.totalCount ? this.form.totalCount - 0 : 0;
  202. let num2 = this.form.singlePrice ? this.form.singlePrice - 0 : 0;
  203. this.form.settlementPrice = num1 * num2;
  204. },
  205. }
  206. }
  207. </script>
  208. <style scoped lang="scss">
  209. /deep/.u-cell__body__content {
  210. flex: none;
  211. margin-right: 16rpx;
  212. }
  213. .mainBox {
  214. padding-bottom: 84rpx;
  215. .labels {
  216. padding-left: 18rpx;
  217. }
  218. }
  219. .footerButton {
  220. width: 100%;
  221. height: 84rpx;
  222. display: flex;
  223. position: fixed;
  224. bottom: 0;
  225. /deep/.u-button {
  226. height: 100%;
  227. }
  228. >view {
  229. flex: 1;
  230. }
  231. }
  232. </style>